Getting Information About Databases and Tables

When you create a table, PostgreSQL stores the definition of that table in the system catalog. The system catalog is a collection of PostgreSQL tables. You can issue SELECT statements against the system catalog tables just like any other table, but there are easier ways to view table and index definitions.

When you are using the psql client application, you can view the list of tables defined in your database using the \d meta-command:

movies=# \d
            List of relations
       Name       | Type  |     Owner
------------------+-------+---------------
 customers        | table | bruce
 rentals          | table | bruce
 tapes            | table | bruce

To see the detailed definition of a particular table, use the \d table-name meta-command:

 movies=# ...

Get PostgreSQL, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.