Useful PostgreSQL Queries and Commands
Connecting as root
$sudo -u postgres psql
Connect to database server:
$psql --username=myusername --host=localhost --password
Select a database with name mydatabase:
myusername=>\c mydatabase;
List all tables:
myusername=>\dt;
Get table structure:
myusername=>\d+ my_table;
Take a dump
$pg_dump --username=myusername --host=localhost --password mydatabase > db.sql
Import a database
$psql --username=myusername --host=localhost --password mydatabase < db.sql