1. 程式人生 > >greenplum 常用SQL(不斷更新)

greenplum 常用SQL(不斷更新)

-- 查詢使用者所建的表及其表中記錄數(非精確值,取決於vacuum的頻率,但用於分析足夠精度了)
select a.relname,b.reltuples,b.relpages
from pg_stat_user_tables a,pg_class b 
where a.relname=b.relname  and b.relname like 'tb2014%' order by a.relname
建立GP表空間
psql gpdb
create tablespace TBS_DW_DATA filespace gpfsdw;
SET default_tablespace = TBS_DW_DATA;

刪除GP資料庫
gpdeletesystem -d /gpmaster/gpseg-1 -f

檢視segment配置
select * from gp_segment_configuration;

檔案系統
select * from pg_filespace_entry;

磁碟、資料庫空間
SELECT * FROM gp_toolkit.gp_disk_free ORDER BY dfsegment;

SELECT * FROM gp_toolkit.gp_size_of_database ORDER BY sodddatname;

日誌
SELECT * FROM gp_toolkit.__gp_log_master_ext;

SELECT * FROM gp_toolkit.__gp_log_segment_ext;

表描述
/d+ <tablename>

表分析
VACUUM ANALYZE tablename;

表資料分佈
SELECT gp_segment_id, count(*) FROM <table_name> GROUP BY gp_segment_id;

表佔用空間
SELECT relname as name, sotdsize/1024/1024 as size_MB, sotdtoastsize as toast, sotdadditionalsize as other
FROM gp_toolkit.gp_size_of_table_disk as sotd, pg_class
WHERE sotd.sotdoid = pg_class.oid ORDER BY relname;

索引佔用空間
SELECT soisize/1024/1024 as size_MB, relname as indexname
FROM pg_class, gp_toolkit.gp_size_of_index
WHERE pg_class.oid = gp_size_of_index.soioid
AND pg_class.relkind='i';

OBJECT的操作統計
SELECT schemaname as schema, objname as table, usename as role, actionname as action, subtype as type, statime as time
FROM pg_stat_operations
WHERE objname = '<name>';

鎖
SELECT locktype, database, c.relname, l.relation, l.transactionid, l.transaction, l.pid, l.mode, l.granted, a.current_query
FROM pg_locks l, pg_class c, pg_stat_activity a
WHERE l.relation=c.oid
AND l.pid=a.procpid
ORDER BY c.relname;

佇列
SELECT * FROM pg_resqueue_status;


 學習資料: