updated June 18, 2020

PostgeSQL database console useful commands

The list of useful commands in the PostgreSQL command line client (console):

1. Show to which database the console is connected

 \conninfo
It outputs:
You are connected to database "dbname" as user "user" on host "host" at port "port".

2. Show the databases list on the server

\l

3. Show the current database tables or objects list

\dt
\d

4. Show the table definition

\d table_name

5. Show the command history or save it into the file

\s
\s filename

6. Execute commands from the file

\i filename

7. Show help for the command.

\h command
Example:
\h SELECT