ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • postgresql 유용한 쿼리
    Postgresql / PPAS/운영 2014. 11. 20. 23:42

    - 현재 active중인 쿼리 보기

    select * from pg_stat_activity;

    - db 통계정보 보기
    SELECT * FROM pg_stat_database;

    - 테이블 통계정보 보기
    select * from pg_stat_all_tables

    - db사이즈 조회
    select * from pg_size_pretty(pg_database_size('testDatabase'));

    - tablespace size조회
    select * from pg_size_pretty(pg_tablespace_size('pg_default'));

    -현재 스키마 조회
    select current_schema(); 

    - table 목록 보기
    postgresql: \d
    postgresql: SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';

    - db목록 보기
    postgresql: \l
    postgresql: SELECT datname FROM pg_database;

    - 컬럼 내용 보기
    postgresql: \d table
    postgresql: SELECT column_name FROM information_schema.columns WHERE table_name ='table';

    DESCRIBE TABLE
    postgresql: \d+ table
    postgresql: SELECT column_name FROM information_schema.columns WHERE table_name ='table'


    - user 정보 보기

    select * from pg_user where usename = CURRENT_USER;


    - 현재 유저 정보 보기

    select CURRENT_USER;


    -function 내용보기

    SELECT prosrc FROM pg_proc WHERE proname = 'partitioning_trigger_login';



    -index 조회하기


    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    SELECT i.relname as indname,
           i.relowner as indowner,
           idx.indrelid::regclass,
           am.amname as indam,
           idx.indkey,
           ARRAY(
           SELECT pg_get_indexdef(idx.indexrelid, k + 1, true)
           FROM generate_subscripts(idx.indkey, 1) as k
           ORDER BY k
           ) as indkey_names,
           idx.indexprs IS NOT NULL as indexprs,
           idx.indpred IS NOT NULL as indpred
    FROM   pg_index as idx
    JOIN   pg_class as i
    ON     i.oid = idx.indexrelid
    JOIN   pg_am as am
    ON     i.relam = am.oid
    and i.relname not like 'pg%';



    -컴마 붙이기

     select to_char(123456789, 'FM999,999,990'); 


    -index table space 변경

    ALTER INDEX tb_ham_log_login_2013_11_first_idx1 SET TABLESPACE tbs_ham


    'Postgresql / PPAS > 운영' 카테고리의 다른 글

    [PPAS] Backup & Recovery  (0) 2015.01.02
    Vacuum 실행 구조  (0) 2014.12.05
    - Table Space -  (0) 2014.11.20
    PostgreSQL 통계 정보 보기  (0) 2014.11.20
    [PPAS / Postgresql] O/S swap memory 사용시 대처 요령  (0) 2014.11.18
Designed by Tistory.