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 distributors table bruce rentals table bruce returns table John Whorfin tapes table bruce To see the detailed definition of a particular table, use the \d table-name meta-command: movies=# \d tapes Table "tapes" Column Type Modifiers ---------+-----------------------+----------- tape_id character(8) not null title character varying(80) dist_id integer Primary key: tapes_pkey Triggers: RI_ConstraintTrigger_74939, RI_ConstraintTrigger_74941, RI_ConstraintTrigger_74953 You can also view a list of all indexes defined in your database. The \di meta-command displays indexes: movies=# \di List of relations Name Type Owner ---------------------------+-------+--------------- customers_pkey index Administrator distributors_pkey index Administrator tapes_pkey index Administrator You can see the full definition for any given index using the \d index-name meta-command: movies=# \d tapes Index "tapes_pkey" Column Type ---------+-------------- tape_id character(8) unique btree (primary key) Table 3.1 shows a complete list of the system catalog- related meta-commands in psql : Table 3.1. System Catalog Meta-Commands
|