There are four methods for listing the tables in a PostgreSQL database: a SQL query, the psql \dt command, the pgAdmin tree, or a script in Python or Node.js. Each takes seconds. Each also runs on a credential that can read far more than table names.
Whether you’re debugging queries, automating CI/CD workflows, or just getting familiar with a new database, this guide works through all four.
But access comes with responsibility, especially when your database holds sensitive data. Knowing how to list tables matters less than knowing how to list them without leaving an unaudited path to the rows behind them.
Before you use any of these methods, you need:
PostgreSQL tables can be broadly categorized into three types: user-defined, system and temporary tables.
The end user creates user-defined tables to hold application-specific data. The database vendor ships the system tables or catalogs, which hold metadata about the database's configuration, objects and structure and live in pg_catalog.
Temporary tables exist for a single session or transaction and hold working data such as the results of a complex query. PostgreSQL drops them when the session or transaction ends.
Two SQL queries retunr the table list. Pick the one that matches the metadata you need.
The information_schema lets you list the tables in a PostgreSQL database and view metadata for database objects.
Its basic syntax is:
SELECT table_schema, table_name
FROM information_schema.tables
WHERE table_type = 'BASE TABLE' AND table_schema NOT IN ('pg_catalog', 'information_schema');
While information_schema also works on other relational databases such as SQL Server and MySQL, but it leaves out some PostgreSQL-specific metadata.
This queryretuns PostgreSQL-specific context that information_schema omits, including table ownership and tablespace.
Its syntax is:
SELECT schemaname, tablename FROM pg_catalog.pg_tables
WHERE schemaname NOT IN ('pg_catalog', 'information_schema');
The psql command-line tool connects you to a PostgreSQL database from a terminal. The \dt command lists the tables.
In place of \dt, you can also use the following commands, depending on the information you want to display:
pgAdmin is a graphical interface for managing PostgreSQL databases. Its tree view makes it the fastest route for anyone who would rather not work in a terminal:
Python and Node.js both connect to a PostgreSQL database and run the same catalog query. Here's how:
import psycopg2
conn = psycopg2.connect(...)
cur = conn.cursor()
cur.execute("""
SELECT table_schema, table_name
FROM information_schema.tables
WHERE table_type = 'BASE TABLE'
AND table_schema NOT IN ('pg_catalog', 'information_schema'); """)
print(cur.fetchall())
cur.close()
conn.close()
const { Client } = require('pg'); const client = new Client({ /* connection config */ }); client.connec t(); client.query ( `SELECT table_schema, table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema NOT IN ('pg_catalog', 'information_schema')`, (err, res) => { if (err) throw err; res.rows.forEac h(row => console.log (row)); client.end (); } );
Every method above works. Every one also runs as a database user with rights to read the catalog, which turns a routine listing into an exposure when the account is over-permissioned. Four controls reduce that risk:
Four errors come up most often. Each has a one-line fix.
| Issue | Cause | Solution |
|---|---|---|
| Permission denied | Insufficient access | Check the user's access rights |
| Schema not found | Incorrect name |
|
| psql: not found | Missing client | Install PostgreSQL tools |
| pgAdmin not syncing | Cached UI | Refresh the browser or reconnect the server |
A pipeline can list tables on every run to check a schema or build an inventory. In Bash:
psql -U your_user -d your_db -c "\dt *.*" > tables_list.txt
That command lists the tables in every schema and writes them to tables_list.txt, ready for a database inventory, an audit or a schema diff.
Listing tables is read-only. The access behind it is not. The same connection that returns table names can also return rows, and in most environments, it runs under a credential that is issued once and reviewed rarely. Delinea puts the credential and the session under policy instead of under a developer's control:
That is the same zero trust principle you already apply to a login, applied to the database connection behind it. You keep every method in this guide. What changes is who holds the credential and whether anyone can answer, a quarter later, who listed those tables and why.
See how database access runs under policy: book a demo.