check_postgres指令碼集檢查資料庫健康情況
check_postgres.pl是一個 Perl 指令碼,它針對一個或多個PG資料庫執行許多不同的測試檢查。使用 psql 程式收集資訊。
check_postgres涉及方面比較廣泛,不僅有常規方面檢查,同時也涉及一些主流工具的檢查,如:pgbouncer、pgAgent、slony、bucardo等。
可以去如下網站下載指令碼
[postgres@t1ysl ~]$ ll total 208 -rw-r--r-- 1 postgres dba 209715 Aug 10 2021 check_postgres.tar.gz
[postgres@t1ysl ~]$ tar -xf check_postgres.tar.gz [postgres@t1ysl ~]$ ll total 208 drwxr-xr-x 3 postgres dba 289 Feb 4 2020 check_postgres-2.25.0 -rw-r--r-- 1 postgres dba 209715 Aug 10 2021 check_postgres.tar.gz
安裝所需環境
[root@t1ysl ~]# yum install perl-DBI perl-DBD-Pg perl-DBD-Pg-tests perl-Time-HiRes -y Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.tuna.tsinghua.edu.cn * extras: mirrors.tuna.tsinghua.edu.cn * updates: mirrors.tuna.tsinghua.edu.cn
安裝
[root@t1ysl check_postgres-2.25.0]# perl Makefile.PL Configuring check_postgres 2.25.0 Checking if your kit is complete... Warning: the following files are missing in your kit: MYMETA.json MYMETA.yml Please inform the author. Writing Makefile for check_postgres [root@t1ysl check_postgres-2.25.0]# make cp check_postgres.pl blib/script/check_postgres.pl /usr/bin/perl -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/check_postgres.pl Manifying blib/man1/check_postgres.1p [root@t1ysl check_postgres-2.25.0]# make install Appending installation info to /usr/lib64/perl5/perllocal.pod [root@t1ysl check_postgres-2.25.0]# mkdir -p /opt/check_postgres/bin [root@t1ysl check_postgres-2.25.0]# chown postgres:postgres /opt/check_postgres/ -R [root@t1ysl check_postgres-2.25.0]# su - postgres Last login: Mon Jul 26 06:16:02 CST 2021 on pts/1 [postgres@t1ysl ~]$ cd /opt/check_postgres/bin/ [postgres@t1ysl bin]$ check_postgres.pl --symlinks Created "check_postgres_archive_ready" Created "check_postgres_autovac_freeze" Created "check_postgres_backends" Created "check_postgres_bloat" Created "check_postgres_checkpoint" Created "check_postgres_cluster_id" Created "check_postgres_commitratio" Created "check_postgres_connection" Created "check_postgres_custom_query" Created "check_postgres_database_size" [postgres@t1ysl bin]$ ll total 0 lrwxrwxrwx 1 postgres dba 32 Jul 26 07:21 check_postgres_archive_ready -> /usr/local/bin/check_postgres.pl lrwxrwxrwx 1 postgres dba 32 Jul 26 07:21 check_postgres_autovac_freeze -> /usr/local/bin/check_postgres.pl lrwxrwxrwx 1 postgres dba 32 Jul 26 07:21 check_postgres_backends -> /usr/local/bin/check_postgres.pl lrwxrwxrwx 1 postgres dba 32 Jul 26 07:21 check_postgres_bloat -> /usr/local/bin/check_postgres.pl lrwxrwxrwx 1 postgres dba 32 Jul 26 07:21 check_postgres_checkpoint -> /usr/local/bin/check_postgres.pl lrwxrwxrwx 1 postgres dba 32 Jul 26 07:21 check_postgres_cluster_id -> /usr/local/bin/check_postgres.pl lrwxrwxrwx 1 postgres dba 32 Jul 26 07:21 check_postgres_commitratio -> /usr/local/bin/check_postgres.pl lrwxrwxrwx 1 postgres dba 32 Jul 26 07:21 check_postgres_connection -> /usr/local/bin/check_postgres.pl lrwxrwxrwx 1 postgres dba 32 Jul 26 07:21 check_postgres_custom_query -> /usr/local/bin/check_postgres.pl lrwxrwxrwx 1 postgres dba 32 Jul 26 07:21 check_postgres_database_size -> /usr/local/bin/check_postgres.pl lrwxrwxrwx 1 postgres dba 32 Jul 26 07:21 check_postgres_dbstats -> /usr/local/bin/check_postgres.pl lrwxrwxrwx 1 postgres dba 32 Jul 26 07:21 check_postgres_disabled_triggers -> /usr/local/bin/check_postgres.pl lrwxrwxrwx 1 postgres dba 32 Jul 26 07:21 check_postgres_disk_space -> /usr/local/bin/check_postgres.p
使用
[postgres@t1ysl bin]$ ./check_postgres_txn_idle --port=6000 --warning='+50' --critical='5 for 10 seconds' POSTGRES_TXN_IDLE OK: DB "postgres" (host:/opt/data6000) (port=6000) no idle in transaction | time=0.01s transaction_time=0;;10 [postgres@t1ysl bin]$ ./check_postgres_locks --warning=100 --critical="total=200:exclusive=20" POSTGRES_LOCKS OK: DB "postgres" (host:/opt/data6000) (port=6000) total=1 | time=0.00s postgres.exclusive=0;;20 postgres.total=1;100;200 template1.exclusive=0;;20 template1.total=0;100;200 [postgres@t1ysl bin]$ check_postgres.pl --action=connection --db=postgres POSTGRES_CONNECTION OK: DB "postgres" (host:/opt/data6000) (port=6000) version 12.1 | time=0.00s [postgres@t1ysl bin]$ ./check_postgres_query_time --port=6000 --warning='3 minutes' --critical='5 minutes' POSTGRES_QUERY_TIME OK: DB "postgres" (host:/opt/data6000) (port=6000) longest query: 0s | time=0.01s query_time=0s;180;300
支援的檢查如下
archive_ready - Check the number of WAL files ready in the pg_xlog/archive_status autovac_freeze - Checks how close databases are to autovacuum_freeze_max_age. backends - Number of connections, compared to max_connections. bloat - Check for table and index bloat. checkpoint - Checks how long since the last checkpoint cluster_id - Checks the Database System Identifier commitratio - Report if the commit ratio of a database is too low. connection - Simple connection check. custom_query - Run a custom query. database_size - Report if a database is too big. dbstats - Returns stats from pg_stat_database: Cacti output only disabled_triggers - Check if any triggers are disabled disk_space - Checks space of local disks Postgres is using. fsm_pages - Checks percentage of pages used in free space map. fsm_relations - Checks percentage of relations used in free space map. hitratio - Report if the hit ratio of a database is too low. hot_standby_delay - Check the replication delay in hot standby setup index_size - Checks the size of indexes only. last_analyze - Check the maximum time in seconds since any one table has been analyzed. last_autoanalyze - Check the maximum time in seconds since any one table has been autoanalyzed. last_autovacuum - Check the maximum time in seconds since any one table has been autovacuumed. last_vacuum - Check the maximum time in seconds since any one table has been vacuumed. listener - Checks for specific listeners. locks - Checks the number of locks. logfile - Checks that the logfile is being written to correctly. new_version_bc - Checks if a newer version of Bucardo is available. new_version_box - Checks if a newer version of boxinfo is available. new_version_cp - Checks if a newer version of check_postgres.pl is available. new_version_pg - Checks if a newer version of Postgres is available. new_version_tnm - Checks if a newer version of tail_n_mail is available. pgagent_jobs - Check for no failed pgAgent jobs within a specified period of time. pgb_pool_cl_active - Check the number of active clients in each pgbouncer pool. pgb_pool_cl_waiting - Check the number of waiting clients in each pgbouncer pool. pgb_pool_maxwait - Check the current maximum wait time for client connections in pgbouncer pools. pgb_pool_sv_active - Check the number of active server connections in each pgbouncer pool. pgb_pool_sv_idle - Check the number of idle server connections in each pgbouncer pool. pgb_pool_sv_login - Check the number of login server connections in each pgbouncer pool. pgb_pool_sv_tested - Check the number of tested server connections in each pgbouncer pool. pgb_pool_sv_used - Check the number of used server connections in each pgbouncer pool. pgbouncer_backends - Check how many clients are connected to pgbouncer compared to max_client_conn. pgbouncer_checksum - Check that no pgbouncer settings have changed since the last check. prepared_txns - Checks number and age of prepared transactions. query_runtime - Check how long a specific query takes to run. query_time - Checks the maximum running time of current queries. relation_size - Checks the size of tables and indexes. replicate_row - Verify a simple update gets replicated to another server. same_schema - Verify that two databases have the exact same tables, columns, etc. sequence - Checks remaining calls left in sequences. settings_checksum - Check that no settings have changed since the last check. slony_status - Ensure Slony is up to date via sl_status. table_size - Checks the size of tables only. timesync - Compare database time to local system time. txn_idle - Checks the maximum "idle in transaction" time. txn_time - Checks the maximum open transaction time. txn_wraparound - See how close databases are getting to transaction ID wraparound. version - Check for proper Postgres version. wal_files - Check the number of WAL files in the pg_xlog directory
其餘使用方法可以參考
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69990629/viewspace-2788122/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle 資料庫效能健康檢查指令碼Oracle資料庫指令碼
- (轉)oracle 資料庫效能健康檢查指令碼Oracle資料庫指令碼
- 資料庫健康檢查 sqlplus 指令碼資料庫SQL指令碼
- 一個簡單資料庫健康檢查指令碼資料庫指令碼
- oracle 資料庫效能健康檢查指令碼[轉帖]Oracle資料庫指令碼
- 使用shell指令碼檢視資料庫負載情況指令碼資料庫負載
- 檢查備份情況的指令碼指令碼
- 使用shell指令碼檢測資料庫連線訪問情況指令碼資料庫
- 資料庫健康檢查(轉)資料庫
- 使用shell指令碼檢視資料庫負載情況(第二篇)指令碼資料庫負載
- ORAchk-資料庫健康檢查資料庫
- MySQL資料庫健康檢查--MySQL巡檢MySql資料庫
- 資料庫的常規檢查指令碼資料庫指令碼
- 巧用shell生成資料庫檢查指令碼資料庫指令碼
- 資料庫的檢查步驟指令碼資料庫指令碼
- 漫談Oracle資料庫健康檢查Oracle資料庫
- Oracle資料庫健康檢查常用SQLOracle資料庫SQL
- MSSQL資料庫健康檢查--SQL Server巡檢SQL資料庫Server
- oracle資料庫健康檢查報告模板Oracle資料庫
- 資料庫日常健康檢查方式方法資料庫
- Sqlserver查詢alwayson同步情況指令碼(2)SQLServer指令碼
- Sqlserver查詢alwayson同步情況指令碼(1)SQLServer指令碼
- 檢視過去的session鎖情況指令碼Session指令碼
- [20170515]檢查資料庫scn指令碼.txt資料庫指令碼
- oracle 資料庫中壞塊概念和檢查指令碼Oracle資料庫指令碼
- 檢視PG資料庫的許可權情況資料庫
- 通過shell指令碼檢視資料庫表空間使用情況指令碼資料庫
- 透過shell指令碼檢視資料庫表空間使用情況指令碼資料庫
- 【轉】Oracle:檢查被鎖資料在V$LOCK中的情況Oracle
- Oracle運維指令碼-檢視DB各時間段健康狀況Oracle運維指令碼
- DB健康檢查使用RDA收集資料
- 檢查資料檔案使用情況和能夠resize到高水位值指令碼指令碼
- 檢查資料庫資料欄位命名規範和合法性的指令碼資料庫指令碼
- java查詢資料庫,int型欄位為null的情況Java資料庫Null
- 檢查oracle的patch的升級情況Oracle
- RAC指令碼檢查指令碼
- Linux 系統健康巡檢指令碼Linux指令碼
- ORACLE提供檢驗RAC是否健康指令碼Oracle指令碼