當前位置: 妍妍網 > 碼農

小麥苗PostgreSQL資料庫巡檢指令碼更新啦(已開源,親,可以去GitHub下載最新版)

2024-04-26碼農

1、巡檢指令碼簡介

該套資料庫巡檢指令碼多數為純SQL指令碼開發,如下所示:

  • 目前一共包含 33 個指令碼,若指令碼的副檔名為「.sql」則表示該指令碼為sql指令碼;若指令碼的副檔名為「.pl」則表示該指令碼為perl指令碼;若指令碼的副檔名為「.sh」則表示該指令碼為shell指令碼。

  • 對於Oracle的SQL指令碼而言,指令碼DB_Oracle_HC_lhr_v7.0.0_10g.sql適用於Oracle 10g資料庫,指令碼DB_Oracle_HC_lhr_v7.0.0_11g.sql適用於Oracle 11g的資料庫,指令碼DB_Oracle_HC_lhr_v7.0.0_12c.sql適用於Oracle 12c及其以上版本,這3個指令碼都是 唯讀 版本,這3個指令碼只會對資料庫做查詢操作,不會做DML和DDL操作,這也是很多朋友所期待的功能。

  • 指令碼DB_OS_HC_lhr_v7.0.0.pl是perl指令碼,執行後會對OS的資訊進行收集,並且輸出到html中。指令碼DB_OS_HC_lhr_v7.0.0.sh是shell指令碼,執行後會對OS的資訊進行收集。

  • 指令碼DB_MySQL_HC_lhr_v7.0.0.sql是MySQL指令碼,執行後會產生MySQL的健康檢查html報告,該指令碼為 唯讀 指令碼。該指令碼也適用於mariadb資料庫。

  • 指令碼DB_SQLServer_HC_lhr_v7.0.0_2005.sql和DB_SQLServer_HC_lhr_v7.0.0_2008R2.sql是SQL Server指令碼,存在部份DDL和DML操作,執行後會產生SQL Server的健康檢查html報告。指令碼DB_SQLServer_HC_lhr_v7.0.0_2005.sql最低支持2005版本,而指令碼DB_SQLServer_HC_lhr_v7.0.0_2008R2.sql最低支持2008R2版本,而指令碼DB_SQLServer_HC_lhr_v7.0.0_2016.sql最低支持2016版本。

  • 指令碼DB_PG_HC_lhr_v7.0.0.sql是PG資料庫指令碼,執行後會產生PostgreSQL資料庫的健康檢查html報告。

  • 指令碼DB_GP_HC_lhr_v7.0.0.sql是Greenplum資料庫指令碼,執行後會產生Greenplum資料庫的健康檢查html報告。

  • 指令碼DB_DM_HC_lhr_v7.0.0是達夢資料庫指令碼,執行後會產生達夢資料庫的健康檢查html報告。

  • 指令碼DB_TiDB_HC_lhr_v7.0.0.sql是TiDB資料庫指令碼,執行後會產生TiDB資料庫的健康檢查html報告。

  • 指令碼DB_openGauss_HC_lhr_v7.0.0.sql是openGauss資料庫指令碼,執行後會產生openGauss資料庫的健康檢查html報告。

  • 指令碼DB_DB2_HC_lhr_v7.0.0.sql是DB2資料庫指令碼,執行後會產生DB2資料庫的健康檢查html報告。

  • 指令碼DB_OceanBase_HC_lhr_v7.0.0.sql是DB2資料庫指令碼,執行後會產生OceanBase資料庫的健康檢查html報告。

  • 指令碼DB_kingbase_HC_lhr_v7.0.0.sql是人大金倉OLTP資料庫KES指令碼,執行後會產生人大金倉資料庫KES版的健康檢查html報告。

  • 指令碼DB_kingbase_kadb_HC_lhr_v7.0.0.sql是人大金倉分析型資料庫KingbaseAnalyticsDB及KADB資料庫指令碼,執行後會產生人大金倉KADB資料庫的健康檢查html報告。

  • 指令碼DB_GreatDB_HC_lhr_v7.0.0.sql是萬裏GreatDB資料庫指令碼,執行後會產生萬裏GreatDB資料庫的健康檢查html報告。

  • 指令碼DB_TBase_HC_lhr_v7.0.0.sql是TDSQL_for_PG(原 TBase)資料庫指令碼,執行後會產生TDSQL_for_PG(原 TBase)資料庫的健康檢查html報告。

  • 指令碼DB_MogDB_HC_lhr_v7.0.0.sql是MogDB資料庫指令碼,執行後會產生雲和恩墨MogDB資料庫的健康檢查html報告。

  • 指令碼DB_OushuDB_HC_lhr_v7.0.0.sql是OushuDB資料庫指令碼,執行後會產生OushuDB資料庫的健康檢查html報告。

  • 指令碼DB_PolarDB_for_PG_HC_lhr_v7.0.0.sql是PolarDB_for_PG資料庫指令碼,執行後會產生PolarDB_for_PG資料庫的健康檢查html報告。

  • 指令碼DB_OSCAR_HC_lhr_v7.0.0.sql是神舟通用資料庫指令碼,執行後會產生神通資料庫的健康檢查html報告。

  • 指令碼DB_GBase8a_HC_lhr_v7.0.0.sql是南大通用GBase 8a資料庫指令碼,執行後會產生南大通用GBase 8a資料庫的健康檢查html報告。

  • 指令碼DB_GBase8c_HC_lhr_v7.0.0.sql是南大通用GBase 8c資料庫指令碼,執行後會產生南大通用GBase 8c資料庫的健康檢查html報告。

  • 指令碼DB_StarRocks_HC_lhr_v7.0.0.sql是StarRocks資料庫指令碼,執行後會產生StarRocks資料庫的健康檢查html報告。

  • 指令碼DB_YMatrix_HC_lhr_v7.0.0.sql是matrixdb資料庫指令碼,執行後會產生YMatrix資料庫的健康檢查html報告。

  • 指令碼DB_YashanDB_HC_lhr_v7.0.0.sql是YashanDB資料庫指令碼,執行後會產生崖山資料庫的健康檢查html報告。

  • 2、巡檢指令碼特點

    1、可以巡檢 Oracle、MySQL(包括Mariadb)、SQL Server、PostgreSQL、Greenplum、OceanBase、TiDB、openGauss、DB2、達夢、人大金倉(KES+KADB)、萬裏GreatDB、TDSQL_for_PG(原 TBase)、MogDB、OushuDB、PolarDB_for_PG、神通、南大通用GBase 8a+8c、StarRocks、YMatrix、YashanDB 21 種資料庫,也可以巡檢Linux作業系統(後續會免費逐步增加MongoDB、Redis等資料庫)

    2、指令碼為綠色版、免安裝、純SQL文本

    3、跨平台,只要有 sqlplus(Oracle)、mysql(MySQL、Mariadb、TiDB、OceanBase、萬裏GreatDB、南大通用GBase 8a、StarRocks)、sqlcmd(SSMS、Navicat皆可)、psql(PG、Greenplum、openGauss、人大金倉KES+KADB、TBase、MogDB、OushuDB、PolarDB_for_PG、南大通用GBase 8c、YMatrix)、gsql(openGauss、GaussDB、MogDB、南大通用GBase 8c)、disql(國產達夢)、db2(DB2資料庫)、obclient(OceanBase)、ksql(人大金倉KES)、isql(神舟通用)、gccli(南大通用GBase 8a)、yasql(崖山資料庫) 環境即可執行指令碼

    4、指令碼內容視覺化,可以看到指令碼內容,因此可供學習資料庫使用

    5、相容Oracle 10g、11g、12c、18c、19c、20c、21c等高版本Oracle資料庫

    6、對Oracle 10g、11g、12c、18c、19c、20c、21c等版本分別提供了唯讀版(只對資料庫查詢,不做DDL和DML操作)

    7、MySQL最低支持5.5版本,小於5.5版本未進行測試

    8、SQL Server最低支持2005版本

    9、增刪監控項非常方便,只需要提供相關SQL即可

    10、一次購買,所有指令碼終身免費升級

    11、檢查內容非常全面

    12、針對每種資料庫,只有1個SQL指令碼,不存在巢狀呼叫指令碼等其它問題

    13、最終生成html檔格式的健康檢查結果

    14、Oracle資料庫對巡檢結果進行過濾,列出了資料庫有問題的內容

    15、對OS的資訊提供了收集(單獨指令碼)

    3、PG資料庫執行方式

    需要有psql客戶端,執行方式如下:

    1psql -U postgres -h 192.168.66.35 -p 54324 -d postgres -W -H -q -f D:\DB_PG_HC_lhr_v7.0.0.sql > d:\a.html

    輸入密碼,回車即可。

    註意:

    1、該指令碼的字元集為utf8,若修改檔內容請使用utf8格式開啟該檔。

    2、巡檢內容「 WAL日誌切換頻率(需要手動修改指令碼路徑) 」部份的「 /pg13/pgdata/pg_wal 」路徑需要手動修改為自己環境真實的路徑,否則會報錯: ERROR: absolute path not allowed

    註意:

    由於 使用者環境的版本或外掛程式問題 ,如下的報錯請忽略,不影響最終的結果:

    1[pg94@lhrpgall ~]$ psql -W -H -f DB_PG_HC_lhr_v7.0.0.sql > a.html
    2Password: 
    3psql:DB_PG_HC_lhr_v7.0.0.sql:291: ERROR: column p.prokind does not exist
    4LINE 2: CASE p.prokind
    5 ^
    6psql:DB_PG_HC_lhr_v7.0.0.sql:359: ERROR: column "total_exec_time" does not exist
    7LINE 3: round(total_exec_time::numeric, 2) AS total_time,
    8 ^
    9psql:DB_PG_HC_lhr_v7.0.0.sql:368: ERROR: column "mean_time" does not exist
    10LINE 4: round(mean_time::numeric, 2) AS mean_time,
    11 ^
    12psql:DB_PG_HC_lhr_v7.0.0.sql:385: ERROR: column "total_exec_time" does not exist
    13LINE 3: round(total_exec_time::numeric, 2) AS total_time,
    14 ^
    15psql:DB_PG_HC_lhr_v7.0.0.sql:401: ERROR: pg_stat_statements must be loaded via shared_preload_libraries
    16
    17psql:DB_PG_HC_lhr_v7.0.0.sql:423: ERROR: relation "pg_stat_wal_receiver" does not exist
    18LINE 1: select * from pg_stat_wal_receiver;
    19 ^
    20psql:DB_PG_HC_lhr_v7.0.0.sql:430: ERROR: function pg_current_wal_lsn() does not exist
    21LINE 3: pg_current_wal_lsn() AS A(c1)
    22 ^
    23HINT: No function matches the given name and argument types. You might need to add explicit type casts.
    24psql:DB_PG_HC_lhr_v7.0.0.sql:450: ERROR: relation "pg_publication" does not exist
    25LINE 1: select * from pg_publication;
    26 ^
    27psql:DB_PG_HC_lhr_v7.0.0.sql:453: ERROR: relation "pg_publication_tables" does not exist
    28LINE 1: select * from pg_publication_tables;
    29 ^
    30psql:DB_PG_HC_lhr_v7.0.0.sql:460: ERROR: relation "pg_stat_subscription" does not exist
    31LINE 1: select * from pg_stat_subscription;
    32 ^
    33psql:DB_PG_HC_lhr_v7.0.0.sql:464: ERROR: relation "pg_subscription" does not exist
    34LINE 1: select * from pg_subscription;
    35 ^
    36psql:DB_PG_HC_lhr_v7.0.0.sql:468: ERROR: relation "pg_subscription_rel" does not exist
    37LINE 1: select *,srrelid::reg class from pg_subscription_rel;
    38 ^
    39psql:DB_PG_HC_lhr_v7.0.0.sql:490: ERROR: relation "pg_file_settings" does not exist
    40LINE 1: select * from pg_file_settings;
    41 ^
    42psql:DB_PG_HC_lhr_v7.0.0.sql:528: ERROR: relation "pg_hba_file_rules" does not exist
    43LINE 1: select * from pg_hba_file_rules;
    44 ^
    45psql:DB_PG_HC_lhr_v7.0.0.sql:588: ERROR: absolute path not allowed
    46psql:DB_PG_HC_lhr_v7.0.0.sql:589: ERROR: could not open directory "/pg13/pgdata/pg_wal": Permission denied
    47psql:DB_PG_HC_lhr_v7.0.0.sql:666: ERROR: relation "pg_config" does not exist
    48LINE 1: SELECT * FROM pg_config ;
    49 ^

    4、html巡檢結果

    這裏只列出 部份結果 ,其它的詳細內容可以參考:https://share.weiyun.com/FQY9zcm0

    5、所有資料庫型別巡檢

    請參考:https://www.xmmup.com/shujukuxunjianjiaoben.html