INFORMATION_SCHEMA는 SQL 표준에서 정의된 메타데이터 조회용 시스템 스키마이다.
PostgreSQL에서는 information_schema와 더불어 pg_catalog가 실무 메타데이터의 핵심을 이룬다.
원칙
information_schemapg_catalogSELECT schema_name
FROM information_schema.schemata;
SELECT schema_name
FROM information_schema.schemata
WHERE schema_name LIKE 'test%';
SELECT nspname
FROM pg_namespace;
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public';
SELECT table_name, table_type
FROM information_schema.tables
WHERE table_schema = 'public';
SELECT relname, relkind
FROM pg_class
JOIN pg_namespace n ON n.oid = relnamespace
WHERE nspname = 'public';
SELECT
column_name,
data_type,
is_nullable,
column_default
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'user';
SELECT attname, atttypid, attnotnull
FROM pg_attribute
WHERE attrelid = 'user'::regclass;
SELECT *
FROM information_schema.key_column_usage
WHERE table_schema = 'public'
AND table_name = 'user';
SELECT column_name
FROM information_schema.key_column_usage
WHERE table_schema = 'public'
AND table_name = 'user'
AND constraint_name = 'user_pkey';
SELECT *
FROM pg_constraint;
| 항목 | INFORMATION_SCHEMA | pg_catalog |
|---|---|---|
| PK / FK | 가능 | 가능 |
| CHECK 제약 | 제한적 | 완전 |
| DEFERRABLE | 불가 | 가능 |
| 성능 | 보통 | 우수 |
SELECT
table_name,
column_name,
referenced_table_name,
referenced_column_name
FROM information_schema.key_column_usage
WHERE table_schema = 'public'
AND referenced_table_name IS NOT NULL;
SELECT *
FROM pg_indexes
WHERE schemaname = 'public';
주의
information_schema는 인덱스 정보가 제한적임pg_catalog 사용PostgreSQL은 INFORMATION_SCHEMA에 용량 정보가 없음
SELECT
relname AS table_name,
pg_total_relation_size(relid) / 1024 / 1024 AS total_mb
FROM pg_catalog.pg_statio_user_tables;
SELECT table_schema, table_name
FROM information_schema.tables;
현재 사용자 권한 기준으로 자동 필터링
보안 점검 및 계정 분리 검증에 활용
SELECT table_schema, table_name, column_name
FROM information_schema.columns
WHERE column_name = 'user_id';
SELECT COUNT(*)
FROM information_schema.tables
WHERE table_schema = 'public'
AND table_name = 'user';
| 항목 | PostgreSQL | Oracle |
|---|---|---|
| 표준 SQL 준수 | 높음 | 낮음 |
| INFORMATION_SCHEMA | 정식 지원 | 참고 수준 |
| 메타데이터 핵심 | information_schema + pg_catalog | DBA / ALL / USER_ |
| 권한 처리 | 단일 카탈로그 + 필터링 | View 분리 |
| 실무 접근 방식 | 표준 → 내부 확장 | 자체 표준 중심 |
information_schema.*
pg_catalog.*
information_schema.tables
pg_indexes
pg_constraint