Shared server guidance · Question & answer

How do I inspect PostgreSQL schemas and table structure in psql?

PostgreSQL objects live inside schemas, and an unqualified table name is resolved through the session’s search_path. A table that appears missing may be in a different schema or database. Inspect the connection context and use qualified names when comparing application structure.

BeginnerSupported PostgreSQL versions accessed through psql
Go to the answer

Before you start

  • An authenticated session with authorised metadata access.
  • The intended database, schema and table.

Instructions

1. Confirm database and search path

Check the current database and role before interpreting the catalogue. The search path determines which schema an unqualified name will use.

PostgreSQL psql
SELECT current_database(), current_user, current_schema();
SHOW search_path;

Reads session context and schema lookup order.

2. List relevant schemas and tables

The public schema is only an example. Use the schema expected by the application, especially on multi-tenant or migration-driven systems.

PostgreSQL psql
\dn
\dt public.*

Lists schemas and ordinary tables in the selected example schema without reading table rows.

3. Describe the selected relation

Replace public.orders with the actual qualified relation. Compare columns, indexes and constraints with the deployed application’s migration state.

PostgreSQL psql
\d public.orders

Shows structural information about the specified relation.

Check the result

  • The expected schema and relation are found in the intended database, and their structure matches the application version.

Troubleshooting

A table exists but an unqualified query says relation does not exist
Inspect search_path, schema permissions and any quoted mixed-case identifier. Use the intended qualified name rather than changing every session’s path globally.
Metadata output is incomplete
Check authorised visibility with the database administrator before requesting additional privileges.

Official references

Use the documentation for your installed version when a flag, service name or platform feature differs.