[PostgreSQL] DB 현황분석

Ja L·2023년 12월 15일
0

[PostgreSQL] Operation

목록 보기
22/39
  1. DB 사이즈 조회
    1-1) 모든 DB 조회 (ok)
    1-2) DB 별 스키마 조회 (ok)
    # 사이즈 조회
    
    SELECT schema_name,     
         pg_size_pretty(sum(table_size)::bigint) as "disk space",     (
    	   sum(table_size) / pg_database_size(current_database()) * 100) as "percent" 
    FROM (      
    		SELECT pg_catalog.pg_namespace.nspname as schema_name,
    		pg_relation_size(pg_catalog.pg_class.oid) as table_size      
    		FROM   pg_catalog.pg_class          
    		JOIN pg_catalog.pg_namespace               
    		ON relnamespace = pg_catalog.pg_namespace.oid 
    	) t 
    GROUP BY schema_name 
    ORDER BY schema_name; 
    # 스키마 정보 조회
    ```sql
    select catalog_name, schema_name, schema_owner from information_schema.schemata;
    1-3) DB의 스키마 별 테이블 조회
select table_catalog, table_schema, table_name, table_type from information_schema.tables where table_schema not in ('pg_catalog', 'information_schema') ;

1-4) DB별 테이블 사이즈 조회 (스키마 종합으로 결과 다 나옴)

SELECT relname AS table_name, 
       pg_relation_size(A.oid)/1024 AS "FILE_SIZE(KB)",
	   A.reltuples AS num_rows
from pg_class A,
(
select tablename 
FROM pg_tables 
WHERE schemaname NOT IN ('pg_catalog', 'information_schema')
) AS B 
WHERE A.relname = B.tablename; 
  1. 오브젝트 조회
    1-1) DB 오브젝트 조회
    1-1-1) 테이블 조회
    1-1-2) 인덱스 조회
    1-1-3) 함수 및 프로시저 조회
  2. User조회
    1-1) user조회
    pg_user
    1-2) 권한 조회
    pg_role
profile
DB Engineer

0개의 댓글

관련 채용 정보