PostgreSQL psql: Schema Navigation Quick Reference
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…
Navigating PostgreSQL databases, schemas, and objects can be easily accomplished using the psql command line interface. This refresher provides a quick guide to the most useful commands.
To list all schemas in the database, simply use the command \dn. If you want more detailed information about each schema, add the plus sign: \dn+. To check the current schema search path, use the command SHOW search_path; You can set this path for the current session with the command SET search_path TO schema_name ;.
Listing databases is straightforward with the command \l. To switch to a different database, use the command \c database_name. The current connection can be viewed with \conninfo, while the current database is shown with the command SELECT current_database (); The current user is displayed with SELECT current_user ;.
To list the tables within the current schema, use the command \dt. For tables in a specific schema, specify the schema name: \dt schema_name . * . To view all tables across all schemas, use \dt * . * . Additional information about tables can be displayed with \dt +.
To examine the structure of a table, run \d table_name. For more detailed information, use \d+ table_name. Other database objects such as views, functions, indexes, and sequences can be listed using \dv, \df, \di, and \ds respectively. All installed extensions can be seen with \dx.
Once you've completed your navigation tasks, you can exit psql by typing \q. These commands should cover the basic navigation and object discovery needs when working with PostgreSQL from the command line.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.