A short refresher for navigating PostgreSQL databases, schemas, and objects from the psql command line.
Schemas
List all schemas:
\dn
List schemas with additional information:
\dn+
Check the current schema search path:
SHOW search_path;
Set the schema search path for the current session:
SET search_path TO schema_name;
Databases
List databases:
\l
Connect to another database:
\c database_name
Show the current connection:
\conninfo
Show the current database:
SELECT current_database();
Show the current user:
SELECT current_user;
Tables
List tables in the current schema:
\dt
List tables in a specific schema:
\dt schema_name.*
List tables across all schemas:
\dt *.*
List tables with additional information:
\dt+
Show the structure of a table:
\d table_name
Show detailed information about a table:
\d+ table_name
Other Database Objects
List views:
\dv
List functions:
\df
List indexes:
\di
List sequences:
\ds
List installed extensions:
\dx
Exit psql
\q
These commands cover most of the basic navigation and object discovery you'll need when working with PostgreSQL from the command line.
This article was originally published by DEV Community and written by Amelye Chatila.
Read original article on DEV Community