微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PostgreSql9 查看数据库相关信息

1、检查数据库版本:

postgres=# select version();
                                                   version                      
                             
--------------------------------------------------------------------------------
-----------------------------
 Postgresql 9.4.2 on x86_64-redhat-linux-gnu,compiled by gcc (GCC) 5.1.1 201504
22 (Red Hat 5.1.1-1),64-bit
(1 行记录)

2、查看数据库启动时间:
postgres=# select pg_postmaster_start_time();
   pg_postmaster_start_time    
-------------------------------
 2015-06-12 19:06:23.031591+08

截至当前时间,运行了多长时间:
postgres=# select current_timestamp - pg_postmaster_start_time() as uptime;
     uptime      
-----------------
 02:34:13.631323

postgres=# select date_trunc('second',current_timestamp-pg_postmaster_start_time()) as uptime;
  uptime  
----------
 02:36:10

3、列出当前所有数据库

bash-4.3$ psql -l
                                     资料库列表
   名称    |  拥有者  | 字元编码 |  校对规则   |    Ctype    |       存取权限        
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 template0 | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(3 行记录)


ostgres=# select datname from pg_database;
  datname  
-----------
 template1
 template0
 postgres
(3 行记录)

4、查看数据库文件大小


postgres=# select pg_database_size(current_database());
 pg_database_size 
------------------
          6999828

上面是当前数据库
postgres=# select current_database();
 current_database 
------------------
 postgres

或者所有数据库文件大小:


postgres=# select sum(pg_database_size(datname)) from pg_database;
   sum    
----------
 20738844
(1 行记录)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐