查看数据库大小
pg_size_pretty:将数据库用量展示为KB、MB、GB等样式,查看更直观
查看具体某个数据库的大小
select pg_size_pretty(pg_database_size('postgres'));
查看所有数据库的大小
select pg_database.datname, pg_size_pretty (pg_database_size(pg_database.datname)) AS size from pg_database;
查看表大小
查看具体表的大小
SELECT pg_size_pretty(pg_relation_size('pg_attribute'));
倒序查看当前库public模式下所有表的大小
SELECT
table_schema || '.' || table_name AS table_full_name,
pg_size_pretty ( pg_total_relation_size ( '"' || table_schema || '"."' || table_name || '"' ) ) AS size
FROM
information_schema.TABLES
ORDER BY
pg_total_relation_size ( '"' || table_schema || '"."' || table_name || '"' )
DESC;
查看表的字段信息
其中pg_attribute表的attrelid对应pg_class 的oid 字段
select
attrelid,
attnum,
attname,
attnotnull
from
pg_attribute
where
attrelid = (select oid from pg_class where relname = 'pg_attribute') order by attnum;
查看系统元数据配置
select * from gp_segment_configuration ;
字段解释:
- dbid 和content : 表示数据库的ID
- role :代表当前角色
- preferred_role :代表首选角色,也就是原本应该出演的角色
- mode=‘s/c/r’ : 三个取值分别代表synced, change logging, resyncing
- status=‘u/d’ : 两个取值分别代表up,down。
磁盘空间查询
数据库查看使用量
select * from gp_toolkit.gp_disk_free;
系统命令行查看(在此例中“host_list”为所有服务器节点清单,“data”为数据存放目录,根据实际目录文件名查询即可)
gpssh -f host_list -e “df -h |grep data”
会话管理
查数据库中的活跃连接
select * from pg_stat_activity; ### 查活跃链接详情
show max_connections; ### 查看最大连接数
会话查询
select datid,
datname,
pid,
sess_id,
usesysid,
usename,
client_ad
标签:语句,查看,记录,数据库,pg,table,select,size
From: https://blog.csdn.net/Aurevoirs/article/details/140968222