1、查询数据库版本
select version();
2、查询数据库的运行时间
select current_timestamp-pg_postmaster_start_time() as uptime;
3、查询数据库的数据量
SELECT
datname ,
a.rolname ,
pg_encoding_to_char(encoding) ,
datcollate ,
datctype ,
pg_size_pretty(pg_database_size(datname))
FROM
pg_database d ,
pg_authid a
WHERE
d.datdba = a.oid
AND datname NOT IN (\‘template0\‘ ,\‘template1\‘ ,\‘postgres\‘ )
ORDER BY
pg_database_size(datname) DESC;
4、 查询手游数据库连接数使用情况
SELECT
s.setting \"可用连接数\" ,
a.used_session \"已使用连接数\" ,
s.setting::bigintwww.diuxie.com - a.used_session \"剩余连接数\"
FROM
pg_settings s,
(
SELECT
COUNT(*) AS used_session
FROM
pg_stat_activity) a
WHERE
s.name=\‘max_connections\‘;
5、查询数据库参数配置
select name,setting,unit from pg_settings;
6、查询当前数据库
select current_database();