Beginner LevelPostgreSQL
What are System Catalogs (pg_class, pg_attribute, pg_type, pg_index)?
❓ Interview Prompt: Explain System Catalog tables (`pg_class`, `pg_attribute`, `pg_type`, `pg_index`, `pg_namespace`) and querying schema metadata.
System Catalogs are internal system tables where PostgreSQL stores metadata about all database objects (tables, columns, indexes, types, permissions):
Key Catalogs:
•
'pg_class': Stores table, index, sequence, and view catalog metadata.
•
'pg_attribute': Stores column attribute definitions.
•
'pg_type': Stores data type definitions.
Code Implementation Example
sql
-- Query total table size and row estimate from pg_class system catalog
SELECT relname, reltuples, pg_size_pretty(pg_relation_size(oid)) AS table_size
FROM pg_class
WHERE relkind = 'r' AND relname = 'orders';💡Querying table sizes directly from the pg_class system catalog.
🎯 Interview Key Takeaway
Query system catalogs like pg_class and pg_attribute to build custom schema discovery tools.
#System Catalogs#pg_class#pg_attribute#Beginner
Back to all PostgreSQL Questions→