Command Line and PSQL

PSQL

Below are some basic commands you may use via command line.

2. Start, Stop, or Restart PostgreSQL

service postgresql start | stop | restart


3. Connect to PostgreSQL

$ su - postgres

$ psql

If you set a password for postgres, you will be prompted for it here.

4. Connect to a database

# \c database

5. Install Extension

# \c database

# create extension "hstore";

6. List Tables:

# \dt

7. Describe Table:

# \d

8. Change User Password:

# alter user username with password 'newPassword';

9. List Schema:

# \dn

10. List Users:

# \du

11. Load SQL File:

psql -W -U user -H host < file.sql

12. Dump Database to File:

pg_dump -W -U user -h host db_name < file.sql