1. 程式人生 > >postgresql資料庫基本資訊檢視

postgresql資料庫基本資訊檢視

切換至postgresql資料庫使用者pguser 或 postgres(根據自己實際情況)

1.  1 SELECT version(); 

2.對的

2. 檢視資料庫大小:

 1 SELECT pg_size_pretty(pg_database_size('tianrun')) As fulldbsize; 

 3. 檢視所有的資料庫的大小:

1 select pg_database.datname, pg_size_pretty (pg_database_size(pg_database.datname)) AS
size from pg_database;

4. 檢視各資料庫資料建立時間:

1 select datname,(pg_stat_file(format('%s/%s/PG_VERSION', 
2 case 
3 when spcname='pg_default' then 'base' 
4 else 'pg_tblspc/'||t2.oid||'/PG_11_201804061/' 
5 end, 
6 t1.oid))).* 
7 from pg_database t1,pg_tablespace t2 where t1.dattablespace=t2.oid;

 5.按佔空間大小,順序檢視所有表的大小

1 select relname, pg_size_pretty(pg_relation_size(relid)) from pg_stat_user_tables where schemaname='public' order by pg_relation_size(relid) desc;

 6. 按佔空間大小,順序檢視索引大小

1 select relname, pg_size_pretty(pg_relation_size(relid)) from pg_stat_user_tables where schemaname='public' order
by pg_relation_size(relid) desc;