PostgreSQL Insight Monitor  pgstat

pgstat 是一个连接到数据库并获取数据库的活动状态的命令行工具。

PostgreSQL有许多状态:

archiver for pg_stat_archiver

bgwriter for pg_stat_bgwriter

connection for connections by type

database for pg_stat_database

table for pg_stat_all_tables

tableio for pg_statio_all_tables

index for pg_stat_all_indexes

function for pg_stat_user_function

tatement for pg_stat_statements

pbpools for pgBouncer pools statistics

pbstats for pgBouncer general statistics

安装pgstat

[root@node1 soft_bak]# git clone https://github.com/gleu/pgstats

[root@node1 soft_bak]# cd pgstats/

[root@node1 pgstats]# ls

License  Makefile  pgcsvstat.c  pgstat.c

[root@node1 pgstats]# make PG_CONFIG=/usr/local/pg945/bin/pg_config

gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -O2 -I/usr/local/pg945/include -I. -I./ -I/usr/local/pg945/include/postgresql/server -I/usr/local/pg945/include/postgresql/internal -D_GNU_SOURCE   -c -o pgcsvstat.o pgcsvstat.c

gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -O2 pgcsvstat.o -L/usr/local/pg945/lib -lpgcommon -lpgport -L/usr/local/pg945/lib -lpq -L/usr/local/pg945/lib -Wl,--as-needed -Wl,-rpath,'/usr/local/pg945/lib',--enable-new-dtags -o pgcsvstat

gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -O2 -I/usr/local/pg945/include -I. -I./ -I/usr/local/pg945/include/postgresql/server -I/usr/local/pg945/include/postgresql/internal -D_GNU_SOURCE   -c -o pgstat.o pgstat.c

gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -O2 pgstat.o -L/usr/local/pg945/lib -lpgcommon -lpgport -L/usr/local/pg945/lib -lpq -L/usr/local/pg945/lib -Wl,--as-needed -Wl,-rpath,'/usr/local/pg945/lib',--enable-new-dtags -o pgstat

查看pgstat 帮助

[postgres@node3 pgstats]$ ./pgstat --help

pgstat gathers statistics from a PostgreSQL database.

Usage:

pgstat [OPTIONS] [delay [count]]

General options:

-f FILTER      include only this object

-H             display human-readable values

-n             do not redisplay header

-s STAT        stats to collect

-v             verbose

-?|--help      show this help, then exit

-V|--version   output version information, then exit

Connection options:

-h HOSTNAME    database server host or socket directory

-p PORT        database server port number

-U USER        connect as specified database user

-d DBNAME      database to connect to

The default stat is pg_stat_bgwriter, but you can change it with the -s command line option,

and one of its value (STAT):

* archiver     for pg_stat_archiver

* bgwriter     for pg_stat_bgwriter

* connection   (only for > 9.1)

* database     for pg_stat_database

* table        for pg_stat_all_tables

* tableio      for pg_statio_all_tables

* index        for pg_stat_all_indexes

* function     for pg_stat_user_function

* statement    for pg_stat_statements (needs the extension)

* xlog         for xlog writes (only for > 9.2)

* tempfile     for temporary file usage

* pbpools      for pgBouncer pools statistics

* pbstats      for pgBouncer statistics

查看数据库连接相关信息

可以看到这个数据库有好多连接,需要连接池

查看一个数据库pgbench测试信息

查看表级别的信息

查看指定的表状态信息(通过-f来过滤)

对pg_stat_statements的支持

[postgres@node3 pgstats]$ ./pgstat -s statement -d postgres

pgstat: Cannot find the pg_stat_statements extension.

修改

shared_preload_libraries = 'pg_stat_statements'

# Add settings for extensions here

pg_stat_statements.max = 10000

pg_stat_statements.track = all

[postgres@node3 data]$ cd ../bin/

[postgres@node3 bin]$ ./psql

psql (9.4.5)

Type "help" for help.

postgres=# create extension pg_stat_statements ;

CREATE EXTENSION

[postgres@node3 bin]$ ./pg_ctl -D ../data/ stop -m fast

waiting for server to shut down..... done

server stopped

[postgres@node3 bin]$ ./pg_ctl -D ../data/ start

server starting

[postgres@node3 bin]$ LOG:  database system was shut down at 2016-01-15 14:51:09 CST

LOG:  MultiXact member wraparound protections are now enabled

LOG:  database system is ready to accept connections

LOG:  autovacuum launcher started

[postgres@node3 bin]$ ./psql

psql (9.4.5)

Type "help" for help.

postgres=# select pg_stat_statements_reset();

pg_stat_statements_reset

--------------------------

(1 row)

在数据库运行当中,WAL发生了 多少写操作

以可读的方式显示

查看临时文件和临时文件的大小

也可以通过pg_stat_database查看

更多的使用可以查看pgstat.c文件。

PostgreSQL Insight Monitor pgstat的更多相关文章

  1. postgresql学习之安装篇

    ---恢复内容开始--- 安装方法: 1.可以使用操作系统自带的安装源 2.可以使用官网下载的源码进行安装 3.可以使用编译好的包入.run格式的安装包安装(本文使用的是这种安装方法,下载地址http ...

  2. PostgreSQL Monitor pg_view

    PostgreSQL Monitor pg_view https://github.com/zalando/pg_view Requirements Linux 2.6, python 2.6, ps ...

  3. PostgreSQL Monitor pg_activity

    PostgreSQL Monitor pg_activity Command line tool for PostgreSQL server activity monitoring. https:// ...

  4. Streaming replication slots in PostgreSQL 9.4

    Streaming replication slots are a pending feature in PostgreSQL 9.4, as part of the logical changese ...

  5. PostgreSQL数据库系统的进程结构

    PostgreSQL数据库系统的主要功能都集中于Postgres程序,其入口是Main模块中的main函数,在初始化数据集簇,启动数据库服务器是,都将从这里开始执行.Main模块主要的工作时确定当前的 ...

  6. Measuring PostgreSQL Checkpoint Statistics

    Checkpoints can be a major drag on write-heavy PostgreSQL installations. The first step toward ident ...

  7. Understanding postgresql.conf : log*

    After loooong pause, adding next (well, second) post to the “series“. This time, I'd like to describ ...

  8. Use Spring Insight Developer to Analyze Code, Install it with Tomcat, and Extend it with Plugins--转载

    原文地址:http://www.tomcatexpert.com/blog/2012/12/05/use-spring-insight-developer-analyze-code-install-i ...

  9. Cloud Insight 仪表盘上线 | 全面监控 Redis

    OneAPM 作为应用性能领域的新兴领军企业,近期发布了重量级新产品-- Cloud Insight 数据管理平台,用它能够监控所有基础组件,并通过 tag 标签对数据进行管理. 近日,Cloud I ...

随机推荐

  1. NEC学习 ---- 布局 -两列, 左侧定宽,右侧自适应

    CSS代码:以下两处代码是NEC中CSS初始化样式和功能性样式.今后的NEC研究中,默认这两处是引用的. /* 这是CSS reset 代码 --- 初始化样式 */ /* reset */ html ...

  2. 图解SQL多表关联查询

      图解SQL多表关联查询     网上看了篇文章关于多表连接的,感觉很好,记录下来,以便日后自己学习  内连接     左连接     右连接       全外连接   1. 查两表关联列相等的数据 ...

  3. ubuntu挂载其他分区到/home下,将当前分区内容替换

    有时候,我们装系统时,可能因为没注意,把某一个分区分小了,导致到最后,我们的那个盘容不下了, 这时,面临的两个选择就是:要么卸载一些软件,要么重新分区,重装系统,其实,还可以这样,去把其他 多余的盘分 ...

  4. java BufferedWriter and BufferedReader

    //Listing 5-2. Demonstrating the BufferedWriter and BufferedReader Classes import java.io.BufferedRe ...

  5. 點擊按鈕后彈出新頁面導致原頁面CSS失效

    比方说在页面里面有个LinkButton,要点击以后要打开新窗口,而且新窗口的URL是根据用户选择结果动态产生的.LinkButton的代码这样写:    protected void Service ...

  6. C/C++ 中长度为0的数组

    参考文献:http://blog.csdn.net/zhaqiwen/article/details/7904515 近日在看项目中的框架代码时,发现了了一个奇特的语法:长度为0的数组例如 uint8 ...

  7. Android性能优化典范(转)

    转载自oschina. 2015年伊始,Google发布了关于Android性能优化典范的专题, 一共16个短视频,每个3-5分钟,帮助开发者创建更快更优秀的Android App.课程专题不仅仅介绍 ...

  8. 如何由新特性跳转到App首页

    前一段时间,一个哥们问我怎么跳转. 1.首先,要获取到当前的window,因为是在window层面上显示,所以,在window层面上进行push. 2.参照上面一条. // 显示状态栏 UIAppli ...

  9. DBCC TRACEON/TRACEOFF/TRACESTATUS

    1. enable trace DBCC TRACEON ( trace# [ ,...n ][ , -1 ] ) [ WITH NO_INFOMSGS ] trace# Is the number ...

  10. Linux主机安全

    Linux主机安全 1.  禁用远程登录root. 2.修改ssh默认端口 暂定为3600. 3.  输错三次密码,禁用5分钟. 3.1 非图形界面登录 vim /etc/pam.d/login 在# ...