The Server Hierarchy
PostgreSQL organises data in three levels:
Server
└── Databases ← isolated containers (\l to list)
└── Schemas ← namespaces inside a database (\dn to list)
└── Tables ← where the data lives (\dt to list, \d to describe)
Databases are fully isolated. A query in beer_db cannot touch a table
in social_db without an explicit cross-database mechanism such as a foreign data wrapper. You connect to one database per
session. To switch, run \c other_db or start a new psql session.
Schemas are namespaces inside a database. Multiple schemas let teams share a
database without table names colliding. The default schema is called public.
The Meta-Command Cheat Sheet
\l → list all databases on the server
\dn → list all schemas in the current database
\dt → list tables visible in the current search path
\dt schema.* → list all tables in a specific schema
\d tablename → full definition: columns, types, constraints, indexes
\df → list all functions
information_schema: Meta-Commands in SQL Form
psql description commands query PostgreSQL system catalogs. information_schema offers standard SQL views of metadata visible to your role.
You can write the same queries yourself — useful in scripts, BI tools, or when
you need more than the meta-command gives you:
-- List every table and its schema in the current database
SELECT table_schema, table_name
FROM information_schema.tables
WHERE table_type = 'BASE TABLE'
AND table_schema NOT IN ('pg_catalog', 'information_schema')
ORDER BY table_schema, table_name;
-- Column list for a specific table
SELECT column_name, data_type, is_nullable
FROM information_schema.columns
WHERE table_schema = 'public' AND table_name = 'breweries'
ORDER BY ordinal_position;
Did you know?
psql can show the catalog queries behind its description commands with \set ECHO_HIDDEN on. The shortcuts have SQL machinery under the hood. PostgreSQL documentation.
Key concepts
Schema
A named namespace inside a database. Tables, views, and functions belong to a schema. One database can have many schemas — useful for isolating teams or separating application data from reporting data.
information_schema
A standard metadata schema with views such as tables, columns, table_constraints, and routines. It describes objects visible to your role using ordinary SQL.