Select Page

Sometimes it is necessary to use the psql command line tool to quickly explore odds in database. Often you also need to use some commands to view structure of your database or tables. In PostgreSQL (and also in other database systems) you can do that by querying system tables like pg_tables , pg_class , pg_attribute  and so on.

Following you’ll find some quick commands for doing that a little bit easier.

Command Description
d This command is in general the shortcut for “describe”. In other database systems the “desc” keyword is used instead.
dt Displays all your user defined tables.
dT Displays all your user defined data types.
df Displays all your user defined functions.
di Displays all your user defined indexes.
dv Displays all your user defined views.
dn Displays all namespaces.
du Displays all users.
l Displays all databases.
d [tablename] Describes the table [tablename] with all fields and indexes.

Also most of this commands can be used in combination with a search pattern. So dt proj_*  will list all tables with the prefix proj_  respectively.