PostgreSQL学徒

pgcheck工具发布啦

1前言

前几天祖传SQL发出去之后,不少小伙伴在后台留言想要获取,本来想着就是收集一下我日常经常用的SQL,写着写着干脆就直接写成一个工具好了,你好我好大家好。现在,很高兴地告诉大家,pgcheck 工具正式 release 了~

2如何使用

使用方式很简单,直接执行即可。在之前的基础上,我进一步完善了一下

[postgres@xiongcc pgcheck_tool]$ ./pgcheck 
Description: The script is used to collect specified information
Usage:
 ./pgcheck relation database schema         : list information about tables and indexes in the specified schema
 ./pgcheck alltoast database schema         : list all toasts and their corresponding tables
 ./pgcheck reltoast database relname        : list the toast information of the specified table
 ./pgcheck dbstatus database                : list all database status and statistics
 ./pgcheck index_bloat database             : index bloat information (estimated value)
 ./pgcheck index_duplicate database         : index duplicate information
 ./pgcheck index_low database               : index low efficiency information
 ./pgcheck index_state database             : index detail information
 ./pgcheck lock database                    : lock wait queue and lock wait state
 ./pgcheck checkpoint database              : background and checkpointer state
 ./pgcheck freeze database                  : database transaction id consuming state
 ./pgcheck replication database             : streaming replication (physical) state
 ./pgcheck connections database             : database connections and current query
 ./pgcheck long_transaction database        : long transaction detail
 ./pgcheck relation_bloat database          : relation bloat information (estimated value)
 ./pgcheck vacuum_state database            : current vacuum progress information
 ./pgcheck index_create database            : index create progress information
 ./pgcheck wal_archive database             : wal archive progress information
 ./pgcheck wal_generate database wal_path   : wal generate speed (you should provide extra wal directory)
 ./pgcheck wait_event database              : wait event and wait event type
 ./pgcheck partition database               : native and inherit partition info (estimated value)
 ./pgcheck object database user             : get the objects owned by the user in the specified database
 ./pgcheck --help or -h                     : print this help information

 Author: xiongcc@PostgreSQL学徒, github: https://github.com/xiongcccc.
 If you have any feedback or suggestions, feel free to contact with me.
 Email: [email protected]/[email protected]. Wechat: _xiongcc

目前支持的功能项如下,基本囊括了日常运维PostgreSQL需要的查询:

  • 查看指定模式下的表状态信息
  • 查看指定模式下所有toast表的信息以及指定某个表的toast信息
  • 查看数据库的整体状态信息,不同版本会有不同显式(请指定准确版本的psql环境变量,因为不同版本的系统视图会有所差异,代码里做了判断,否则可能会报错)
  • 查看索引膨胀率/冗余索引/低效索引/索引整体信息
  • 查看索引信息
  • 查看检查点和后台写进程状态
  • 查看年龄
  • 查看流复制状态
  • 查看连接数和当前正在允许的查询
  • 查看长事务
  • 查看表膨胀,表膨胀依赖于统计信息,所以为了更加准确,最好做之前做一个analyze,该查询会稍微耗费点时间
  • 查看索引创建进度,12以后的版本才支持,之前的版本会提示视图不存在并退出
  • 查看WAL归档状态
  • 查看WAL生成速度
  • 查看等待时间
  • 查看分区表信息,包括原生分区和继承式分区
  • 查看用户拥有的对象,以及成员关系

工具目前已经开源,地址在 https://github.com/xiongcccc/pgcheck,喜欢的老铁记得一键三连。

另外有些PGer可能还没有拿到 《PostgreSQL DBA Daily 1.0》 以及 《PostgreSQL Architecture》 大图,可以在另外一个仓库自行获取 https://github.com/xiongcccc/PostgreSQL-ecosystem,这个仓库主要用于分享一些报告、书籍和个人经验等。

3后续

目前 pgcheck 完全免费,使用方式也很简单,只需要配置好正确的环境变量即可(版本也要对,比如你要检查13的库,那么psql需要是13的版本,因为代码里会做一些判断,不同版本直接的查询有所差异)

各位在使用过程中有任何BUG或者建议,可以随时联系我

后续我会不断完善该工具,比如添加操作系统层的一键获取。