笔记:之前登录master节点看pg_log目录下的文件,后面每次这样看感觉挺不方便的,查了一下文档
select ma.logtime at time zone 'CST' as logtime,ma.loguser,ma.logpid,ma.loghost,ma.logstate,ma.logmessage,ma.logdetail from gp_toolkit.gp_log_database ma order by logtime desc limit 200;
这个就是查的pg_log下的日志文件,只是是外部表形式,所以性能有一些差,只要定时切割pg_log下面的文件就行,还有一个视图 gp_toolkit.gp_log_system, 它与 gp_toolkit.gp_log_database 区别是一个是all,一个是current_database。
表空间间隙查看方法(膨胀):
select * from gp_toolkit.gp_log_database;
表空间间隙收缩方法:
#!/bin/bash DBNAME="<database_name>" SYSTABLES="' pg_catalog.' || relname || ';' from pg_class a, pg_namespace b where a.relnamespace=b.oid and b.nspname='pg_catalog' and a.relkind='r'" psql -tc "SELECT 'VACUUM' || $SYSTABLES" $DBNAME | psql -a $DBNAME reindexdb -s -d $DBNAME analyzedb -s pg_catalog -d $DBNAME
查锁情况:
SELECT least(query_start,xact_start) + '8 hour' start_time ,pg_locks.pid , pg_database.datname , pg_stat_activity.usename , locktype , mode , pg_stat_activity.application_name , state , CASE WHEN granted='f' THEN 'wait_lock' WHEN granted='t' THEN 'get_lock' END lock_satus , pg_stat_activity.query , count(*)::float FROM pg_locks JOIN pg_database ON pg_locks.database=pg_database.oid JOIN pg_stat_activity on pg_locks.pid=pg_stat_activity.pid WHERE NOT pg_locks.pid=pg_backend_pid() AND pg_stat_activity.application_name<>'pg_statsinfod' GROUP BY pg_locks.pid, pg_database.datname,pg_stat_activity.usename, locktype, mode, pg_stat_activity.application_name, state , lock_satus ,pg_stat_activity.query, start_time ORDER BY 2 desc;