Useful PostgreSQL (psql) Console Commands - Quick Reference

Last updated:

Gain access to the PostgreSQL console (Linux)

( using user postgres)

sudo -u postgres psql

List all databases

\l

Connect to a database

\c my_database_name

List all tables in the current (connected to) database

\dt

Shows detailed information about a table

\d my_table_name

See all available commands

\?

Quit postgres CLI

\q

Drop all columns in your db and re-create the DB (with no tables)

drop schema public cascade; create schema public;

Change a user's password

ALTER USER postgres PASSWORD 'newPassword';

References

P.S.: All examples run on psql (PostgreSQL) 9.1.10 on Ubuntu 13.04.

Dialogue & Discussion