Whether you’re debugging queries, automating CI/CD workflows, or just getting familiar with a new database, knowing how to list tables in PostgreSQL is a foundational skill. From psql commands to Python scripts, there’s no shortage of ways to get the job done.
But access comes with responsibility—especially when your database holds sensitive data. That’s why understanding not just the how, but the how to do it securely, is critical.
In this guide, you’ll learn multiple ways to list tables in Postgres—and how to enhance the process with centralized access, audit logs, and least-privilege controls that make database access secure by default.
There are several requirements you must meet before you can leverage the methods we’re about to discuss, including:
PostgreSQL tables can be broadly categorized into three types: user-defined, system, and temporary tables.
As the name suggests, user-defined tables are created by the end user to store application-specific data. System tables or catalogs, on the other hand, come predefined and are created by the database vendor. They contain metadata about the database’s configuration, objects, and structure, and they reside in pg_catalog.
Lastly, temporary tables are created during specific sessions or transactions to store data, such as results from complex queries. These are dropped at the end of the session or transaction, hence the name "temporary."
SQL queries are the language or questions you use to ask a database for specific answers. There are two queries you can use to list tables in Postgres:
The information_schema lets you list all the tables in a PostgreSQL database and see the metadata of the 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 works across RDBMSs like SQL and MySQL, it lacks some PostgreSQL-specific metadata.
This SQL query provides more PostgreSQL-specific context like ownership and tablespace information.
Its syntax:
SELECT schemaname, tablename FROM pg_catalog.pg_tables
WHERE schemaname NOT IN ('pg_catalog', 'information_schema');
The psql command-line tool lets you interact with PostgreSQL databases. One of the simplest ways to use psql is through the \dt command.
In place of \dt, you can also use the following commands, depending on the information you want to display:
Yet another Postgres list tables alternative is pgAdmin, a graphical user interface (GUI) for managing PostgreSQL databases. This is the easiest method to use, especially for inexperienced users, because it provides a visual interface with a tree-like structure. The process:
This method uses code and APIs to list tables in Postgres. With code, for example, you can use programming languages like Python and Node.js to connect to your PostgreSQL database and execute queries to list tables. 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 (); } );
While all the Postgres show tables methods we’ve discussed work and are easy to follow, be aware that the slightest misconfiguration can lead to an expensive security incident. That’s why it’s important to follow several best practices, including:
When working with either of the Postgres show tables methods, you may encounter errors — don’t let them stop you in your tracks. Here’s how you can solve them:
| Issue | Cause | Solution |
|---|---|---|
| PurposePermission denied | Insufficient access | Check user access rights |
| Schema not found | Incorrect name |
|
| psql: not found | Missing client | Install PostgreSQL tools |
| bypgAdmin not syncing | Cached UI | Refresh or reconnect |
This involves using techniques and tools to identify and analyze tables automatically, especially in CI/CD workflows. For instance, using Bash:
psql -U your_user -d your_db -c "\dt *.*" > tables_list.txt
The above command lists all the tables across all schemas and saves the results in the file tables_list.txt. It’s also helpful for automated database inventory, audits, or schema diffing in pipelines.
Knowing how to list tables in PostgreSQL is essential—whether you're exploring a new database, building automation into your CI/CD workflows, or performing routine audits. But access without oversight is a security risk waiting to happen.
Manually running \dt, executing SQL, or connecting via Python scripts may get you the table names—but without visibility, control, or audit logs, every query is a potential blind spot. Delinea simplifies the process while securing every step.
Traditional methods require local usernames, passwords, or stored secrets that are hard to rotate and easy to leak. Delinea replaces static credentials with real-time, identity-based access.
.pgpass files or embed secrets in scriptsResult: users connect securely without ever seeing a password—and permissions can be revoked instantly.
Instead of manually granting SELECT on system catalogs or troubleshooting schema access errors, Delinea lets you:
Dev teams get fast, secure access. Security teams stay in control.
With Delinea, every database query—including SELECT table_name statements and schema explorations—is logged automatically:
Security events aren’t hidden in application logs or forgotten cron jobs—they’re captured in full.
Letting developers explore pg_catalog or information_schema tables unrestricted? That’s a misstep.
Delinea helps you:
Zero Trust access doesn’t just apply to users—it applies to queries, too.
CI/CD automations often include schema checks, test table listings, and metadata scans. Delinea enables these workflows without compromising secrets:
No more hardcoded passwords or shadow access in your automation scripts.
Whether you’re using psql, pgAdmin, or Python, listing PostgreSQL tables should be easy—but not unaccountable.
Delinea gives you centralized access, full audit trails, and policy-based controls to ensure that even the simplest table listing is secure, observable, and compliant.
Ready to make PostgreSQL access secure by default? Book a demo and see how it’s done.