nickjoIT

각종 조회 본문

DB/postgresql

각종 조회

nickjo 2016. 9. 27. 01:39

- 현재 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


[참고사이트]

http://egloos.zum.com/hampro1024/v/3737585


'DB > postgresql' 카테고리의 다른 글

[ubuntu]pgadmin4 설치  (0) 2017.03.05
sql 모음  (0) 2016.11.01
테이블 컬럼 정보 확인  (0) 2016.09.25
Postgresql 문법  (0) 2016.09.03
linux에서 postgresql shell 접속  (0) 2016.03.09
Comments