HostOnNet Blog

Working with PostgreSQL psql

psql command is used to connect to PostgreSQL database. To login to PostgreSQL database, run

psql -U username-here -W

You will be asked to enter password.

List all databases

To list all databases use command \list or \l

\list

Connect to a database

Before you can use a database, you need to connect to it with

\connect DB-NAME

List all tables in a database

\dt
\dt *.

Or

SELECT table_schema,table_name FROM information_schema.tables ORDER BY table_schema,table_name;

Posted in Database