The command shows tables, columns, and data types in an Amazon Redshift schema by querying catalog views such as information_schema.tables and pg_table_def.
Run a SELECT on information_schema.tables filtering by table_schema.This view is ANSI-standard, always up to date, and works even when compression encodings change.
SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_name;
SELECT tablename FROM pg_table_def WHERE schemaname = 'public' GROUP BY tablename;
This works on external & temporary tables, but excludes views.
Query information_schema.columns or pg_table_def, passing both schema and table name.The rows include column name, data type, encoding, and sort key flags.
SELECT column_name, data_type FROM information_schema.columns WHERE table_schema='public' AND table_name='orders';
Use pg_table_def when you need encoding, diststyle, or sortkey details. Use information_schema for portable SQL and faster metadata scans.
1. Always filter by table_schema to avoid scanning thousands of system tables.
2. Order results alphabetically for readability.
3. Cache frequent metadata queries in your IDE or script.
4.Grant USAGE on schema to analysts instead of full SELECT on every table.
Redshift folds un-quoted identifiers to lower-case. Quoting mixed-case table names forces exact matches. Fix by using lower-case or quoting consistently.
pg_table_def scans every node and can be slow. Filter by schemaname and tablename or switch to information_schema for faster performance.
No.Use \dt
in psql or the SELECT statements above.
You must connect to each database individually; catalog views do not cross database boundaries.
Revoke USAGE on the schema and grant it only to specific roles. Tables inside become invisible without USAGE.
.
No. Use information_schema.columns or \d in psql instead.
Yes. It reflects committed DDL instantly, unlike some third-party catalogs that cache metadata.
Wrap the SELECT queries in psql or Python scripts, store results in temp tables, and diff them between environments.