一、巡检脚本简介

该套数据库巡检脚本多数为纯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报告。

二、巡检脚本特点

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、YashanDB21种数据库,也可以巡检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的信息提供了收集(单独脚本)

三、巡检结果展示

这里只列出部分结果,其它的详细内容可以参考:https://share.weiyun.com/FQY9zcm0

1、Oracle数据库

鼠标经过相关连接时会有相应的解释,如下图所示:

该脚本检查的内容较多,所以我对结果进行了过滤,如下:

点击链接即可查看结果:

数据库基本信息一目了然:

其它不再列举。

2、MySQL数据库

其它不再列举。

3、SQL Server数据库

其它不再列举。

4、PG数据库

其它不再列举。

5、达梦数据库

其它不再列举。

6、TiDB数据库

其它不再列举。

7、openGauss数据库

其它不再列举。

8、DB2数据库

其它不再列举。

9、OceanBase数据库

10、OS信息

其它不再列举。

11、Greenplum数据库

其它不再列举。

12、人大金仓数据库

KES

其它不再列举。

KADB

其它不再列举。

13、万里GreatDB数据库

其它不再列举。

14、TDSQL_for_PG(原 TBase)数据库

其它不再列举。

15、MogDB数据库

其它不再列举。

16、OushuDB数据库

其它不再列举。

17、PolarDB_for_PG数据库

其它不再列举。

18、神通数据库

其它不再列举。

19、南大通用GBase

GBase 8a

其它不再列举。

GBase 8c

其它不再截图。

20、StarRocks数据库

其它不再截图。

21、YMatrix数据库

其它不再截图。

22、YMatrix数据库

其它不再截图。

四、脚本运行方式

1、Oracle数据库

只要有sqlplus的客户端即可,且必须使用sqlplus客户端。

为了防止乱码,可以先配置环境变量:

# Linux环境设置
export LANG=en_US.GB2312
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

# Windows环境配置
set NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

若使用cmd或SecureCRT等软件,则还涉及这些软件本身的字符集配置!!!

若在服务器端,则可以直接运行:

sqlplus / as sysdba @DB_Oracle_HC_lhr_v7.0.0_12c.sql

若在远程sqlplus客户端运行,则:

sqlplus sys/lhr@192.168.59.130:1521/orcl as sysdba @DB_Oracle_HC_lhr_v7.0.0_12c.sql

注意事项

1、若脚本卡在告警日志部分,则可以考虑使用精简版

DB_Oracle_HC_lhr_v7.0.0_11g_精简版.sql
DB_Oracle_HC_lhr_v7.0.0_12c_精简版.sql

2、MySQL(Mariadb)数据库

只要有mysql客户端即可,使用MariaDB的客户端也可以,如下:

mysql -uroot -plhr -P3306 -s -f <  DB_MySQL_HC_lhr_v7.0.0.sql  > lhr_mysql_check.html

该脚本也适用于mariadb数据库

注意:

由于版本问题,如下的报错请忽略,不影响最终的结果:

C:\Users\lhrxxt>mysql -uroot -plhr -h192.168.1.35 -P3415 -s -f < D:\DB_MySQL_HC_lhr_v7.0.0.sql > d:\tmp.html
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1193 (HY000) at line 159: Unknown system variable 'show_compatibility_56'
ERROR 1146 (42S02) at line 205: Table 'performance_schema.global_variables' doesn't exist
ERROR 1193 (HY000) at line 370: Unknown system variable 'innodb_page_size'
ERROR 1146 (42S02) at line 509: Table 'performance_schema.global_variables' doesn't exist
ERROR 1146 (42S02) at line 546: Table 'performance_schema.hosts' doesn't exist
ERROR 1054 (42S22) at line 634: Unknown column 'a.type' in 'where clause'
ERROR 1054 (42S22) at line 662: Unknown column 'a.type' in 'where clause'
ERROR 1054 (42S22) at line 732: Unknown column 'trx_is_read_only' in 'field list'
ERROR 1146 (42S02) at line 811: Table 'performance_schema.metadata_locks' doesn't exist
ERROR 1146 (42S02) at line 872: Table 'performance_schema.metadata_locks' doesn't exist
ERROR 1146 (42S02) at line 905: Table 'sys.processlist' doesn't exist
ERROR 1146 (42S02) at line 919: Table 'sys.schema_table_lock_waits' doesn't exist
ERROR 1146 (42S02) at line 940: Table 'performance_schema.global_status' doesn't exist
ERROR 1146 (42S02) at line 979: Table 'performance_schema.events_stages_current' doesn't exist
ERROR 1146 (42S02) at line 995: Table 'performance_schema.events_statements_summary_by_digest' doesn't exist
ERROR 1146 (42S02) at line 1027: Table 'sys.session' doesn't exist
ERROR 1146 (42S02) at line 1040: Table 'sys.session' doesn't exist
ERROR 1146 (42S02) at line 1053: Table 'performance_schema.events_statements_summary_by_digest' doesn't exist
ERROR 1146 (42S02) at line 1080: Table 'sys.statement_analysis' doesn't exist
ERROR 1146 (42S02) at line 1096: Table 'performance_schema.events_statements_summary_by_digest' doesn't exist
ERROR 1146 (42S02) at line 1149: Table 'sys.statement_analysis' doesn't exist
ERROR 1146 (42S02) at line 1165: Table 'performance_schema.table_io_waits_summary_by_index_usage' doesn't exist
ERROR 1146 (42S02) at line 1187: Table 'performance_schema.events_statements_summary_by_digest' doesn't exist
ERROR 1146 (42S02) at line 1222: Table 'performance_schema.events_statements_summary_by_digest' doesn't exist
ERROR 1146 (42S02) at line 1276: Table 'sys.schema_unused_indexes' doesn't exist
ERROR 1146 (42S02) at line 1295: Table 'mysql.innodb_index_stats' doesn't exist
ERROR 1146 (42S02) at line 1349: Table 'performance_schema.global_variables' doesn't exist
ERROR 1146 (42S02) at line 1386: Table 'performance_schema.global_status' doesn't exist
ERROR 1054 (42S22) at line 1411: Unknown column 'a.PROCESSLIST_COMMAND' in 'where clause'
ERROR 1146 (42S02) at line 1470: Table 'performance_schema.replication_group_members' doesn't exist
ERROR 1146 (42S02) at line 1514: Table 'performance_schema.replication_connection_configuration' doesn't exist
ERROR 1146 (42S02) at line 1539: Table 'performance_schema.clone_status' doesn't exist
ERROR 1146 (42S02) at line 1550: Table 'performance_schema.clone_progress' doesn't exist
ERROR 1146 (42S02) at line 1619: Table 'performance_schema.global_status' doesn't exist

C:\Users\lhrxxt>mysql -uroot -plhr -h192.168.1.35 -P3416 -s -f < D:\DB_MySQL_HC_lhr_v7.0.0.sql > d:\tmp.html
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1193 (HY000) at line 159: Unknown system variable 'show_compatibility_56'
ERROR 1146 (42S02) at line 205: Table 'performance_schema.global_variables' doesn't exist
ERROR 1146 (42S02) at line 509: Table 'performance_schema.global_variables' doesn't exist
ERROR 1054 (42S22) at line 634: Unknown column 'HISTORY' in 'field list'
ERROR 1054 (42S22) at line 662: Unknown column 'HISTORY' in 'field list'
ERROR 1146 (42S02) at line 811: Table 'performance_schema.metadata_locks' doesn't exist
ERROR 1146 (42S02) at line 872: Table 'performance_schema.metadata_locks' doesn't exist
ERROR 1146 (42S02) at line 905: Table 'sys.processlist' doesn't exist
ERROR 1146 (42S02) at line 919: Table 'sys.schema_table_lock_waits' doesn't exist
ERROR 1146 (42S02) at line 940: Table 'performance_schema.global_status' doesn't exist
ERROR 1054 (42S22) at line 979: Unknown column 'WORK_COMPLETED' in 'field list'
ERROR 1146 (42S02) at line 995: Table 'sys.x$ps_digest_95th_percentile_by_avg_us' doesn't exist
ERROR 1146 (42S02) at line 1027: Table 'sys.session' doesn't exist
ERROR 1146 (42S02) at line 1040: Table 'sys.session' doesn't exist
ERROR 1305 (42000) at line 1053: FUNCTION sys.format_statement does not exist
ERROR 1146 (42S02) at line 1080: Table 'sys.statement_analysis' doesn't exist
ERROR 1305 (42000) at line 1096: FUNCTION sys.format_statement does not exist
ERROR 1146 (42S02) at line 1149: Table 'sys.statement_analysis' doesn't exist
ERROR 1305 (42000) at line 1165: FUNCTION sys.format_time does not exist
ERROR 1305 (42000) at line 1187: FUNCTION sys.format_statement does not exist
ERROR 1305 (42000) at line 1222: FUNCTION sys.format_statement does not exist
ERROR 1146 (42S02) at line 1276: Table 'sys.schema_unused_indexes' doesn't exist
ERROR 1146 (42S02) at line 1349: Table 'performance_schema.global_variables' doesn't exist
ERROR 1146 (42S02) at line 1386: Table 'performance_schema.global_status' doesn't exist
ERROR 1054 (42S22) at line 1411: Unknown column 'HISTORY' in 'field list'
ERROR 1146 (42S02) at line 1470: Table 'performance_schema.replication_group_members' doesn't exist
ERROR 1146 (42S02) at line 1514: Table 'performance_schema.replication_connection_configuration' doesn't exist
ERROR 1146 (42S02) at line 1539: Table 'performance_schema.clone_status' doesn't exist
ERROR 1146 (42S02) at line 1550: Table 'performance_schema.clone_progress' doesn't exist
ERROR 1146 (42S02) at line 1619: Table 'performance_schema.global_status' doesn't exist

C:\Users\lhrxxt>mysql -uroot -plhr -h192.168.1.35 -P3418 -s -f < D:\DB_MySQL_HC_lhr_v7.0.0.sql > d:\tmp.html
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1193 (HY000) at line 159: Unknown system variable 'show_compatibility_56'
ERROR 1109 (42S02) at line 214: Unknown table 'GLOBAL_VARIABLES' in information_schema
ERROR 1109 (42S02) at line 518: Unknown table 'GLOBAL_VARIABLES' in information_schema
ERROR 1109 (42S02) at line 699: Unknown table 'INNODB_LOCKS' in information_schema
ERROR 1109 (42S02) at line 719: Unknown table 'INNODB_LOCK_WAITS' in information_schema
ERROR 1109 (42S02) at line 747: Unknown table 'INNODB_LOCK_WAITS' in information_schema
ERROR 1109 (42S02) at line 949: Unknown table 'GLOBAL_STATUS' in information_schema
ERROR 1109 (42S02) at line 1358: Unknown table 'GLOBAL_VARIABLES' in information_schema
ERROR 1109 (42S02) at line 1395: Unknown table 'GLOBAL_STATUS' in information_schema
ERROR 1146 (42S02) at line 1539: Table 'performance_schema.clone_status' doesn't exist
ERROR 1146 (42S02) at line 1550: Table 'performance_schema.clone_progress' doesn't exist
ERROR 1109 (42S02) at line 1628: Unknown table 'GLOBAL_STATUS' in information_schema

C:\Users\lhrxxt> mysql -uroot -plhr -h192.168.1.35 -P3419 -s -f < DB_MySQL_HC_lhr_v7.0.0.sql > mariadb.html
ERROR 1193 (HY000) at line 159: Unknown system variable 'show_compatibility_56'
ERROR 1146 (42S02) at line 205: Table 'performance_schema.global_variables' doesn't exist
ERROR 1146 (42S02) at line 509: Table 'performance_schema.global_variables' doesn't exist
ERROR 1054 (42S22) at line 732: Unknown column 'trx_adaptive_hash_latched' in 'field list'
ERROR 1146 (42S02) at line 905: Table 'sys.processlist' doesn't exist
ERROR 1146 (42S02) at line 919: Table 'sys.schema_table_lock_waits' doesn't exist
ERROR 1146 (42S02) at line 995: Table 'sys.x$ps_digest_95th_percentile_by_avg_us' doesn't exist
ERROR 1146 (42S02) at line 1027: Table 'sys.session' doesn't exist
ERROR 1146 (42S02) at line 1040: Table 'sys.session' doesn't exist
ERROR 1305 (42000) at line 1053: FUNCTION sys.format_statement does not exist
ERROR 1146 (42S02) at line 1080: Table 'sys.statement_analysis' doesn't exist
ERROR 1305 (42000) at line 1096: FUNCTION sys.format_statement does not exist
ERROR 1146 (42S02) at line 1149: Table 'sys.statement_analysis' doesn't exist
ERROR 1305 (42000) at line 1165: FUNCTION sys.format_time does not exist
ERROR 1305 (42000) at line 1187: FUNCTION sys.format_statement does not exist
ERROR 1305 (42000) at line 1222: FUNCTION sys.format_statement does not exist
ERROR 1146 (42S02) at line 1276: Table 'sys.schema_unused_indexes' doesn't exist
ERROR 1146 (42S02) at line 1349: Table 'performance_schema.global_variables' doesn't exist
ERROR 1146 (42S02) at line 1470: Table 'performance_schema.replication_group_members' doesn't exist
ERROR 1146 (42S02) at line 1514: Table 'performance_schema.replication_connection_status' doesn't exist
ERROR 1146 (42S02) at line 1539: Table 'performance_schema.clone_status' doesn't exist
ERROR 1146 (42S02) at line 1550: Table 'performance_schema.clone_progress' doesn't exist

3、SQL Server数据库

脚本DB_SQLServer_HC_lhr_v7.0.0_2005.sql、DB_SQLServer_HC_lhr_v7.0.0_2008R2.sql和DB_SQLServer_HC_lhr_v7.0.0_2016.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版本。

这3个脚本有2种运行模式:

3.1、命令行方式

-- 在本机直接运行
sqlcmd -d tempdb -y 0 -m 1 -i D:\DB_SQLServer_HC_lhr_v7.0.0_2008R2.sql -o D:\SQLServer_CHECK_LHR_20210914.html

-- 远程运行
sqlcmd -S 192.168.1.28 -U sa -P lhr -d tempdb -y 0 -m 1 -i D:\DB_SQLServer_HC_lhr_v7.0.0_2008R2.sql -o D:\SQLServer_CHECK_LHR_20210914.html

3.2、SSMS图形界面

需要使用SQL Server Management Studio (SSMS)或Navicat for SQLServer客户端软件,若使用SSMS,则需要配置查询结果中的xml数据的最大值,否则可能会出现最终的html表格错乱包含的问题(配置非XML数据为2097152,XML数据为不限制),配置后重启SSMS再运行脚本,然后将输出结果保存为html文件即可。

image-20240425161421043
image-20240425161421043

乱码问题

若是有乱码,需要将连接到的数据库配置为Chinese_PRC_BIN排序规则,然后重新运行脚本:

-- 修改lhrdb数据库的排序规则
alter database lhrdb COLLATE Chinese_PRC_BIN

-- 然后脚本的第8行修改为
use lhrdb;

4、PostgreSQL数据库

需要有psql客户端,运行方式如下:

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

输入密码,回车即可。

注意:

1、该脚本的字符集为utf8,若修改文件内容请使用utf8格式打开该文件。

2、巡检内容“WAL日志切换频率(需要手动修改脚本路径)”部分的“/pg13/pgdata/pg_wal”路径需要手动修改为自己环境真实的路径,否则会报错:ERROR: absolute path not allowed

注意:

由于用户环境的版本或插件问题,如下的报错请忽略,不影响最终的结果:

[pg94@lhrpgall ~]$ psql -W -H -f DB_PG_HC_lhr_v7.0.0.sql  >  d:\lhr_PG_check.html        
Password: 
psql:DB_PG_HC_lhr_v7.0.0.sql:291: ERROR:  column p.prokind does not exist
LINE 2:  CASE p.prokind
              ^
psql:DB_PG_HC_lhr_v7.0.0.sql:359: ERROR:  column "total_exec_time" does not exist
LINE 3:       round(total_exec_time::numeric, 2) AS total_time,
                    ^
psql:DB_PG_HC_lhr_v7.0.0.sql:368: ERROR:  column "mean_time" does not exist
LINE 4:       round(mean_time::numeric, 2) AS mean_time,
                    ^
psql:DB_PG_HC_lhr_v7.0.0.sql:385: ERROR:  column "total_exec_time" does not exist
LINE 3:       round(total_exec_time::numeric, 2) AS total_time,
                    ^
psql:DB_PG_HC_lhr_v7.0.0.sql:401: ERROR:  pg_stat_statements must be loaded via shared_preload_libraries                    

psql:DB_PG_HC_lhr_v7.0.0.sql:423: ERROR:  relation "pg_stat_wal_receiver" does not exist
LINE 1: select * from pg_stat_wal_receiver;
                      ^
psql:DB_PG_HC_lhr_v7.0.0.sql:430: ERROR:  function pg_current_wal_lsn() does not exist
LINE 3:      pg_current_wal_lsn() AS A(c1)
             ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
psql:DB_PG_HC_lhr_v7.0.0.sql:450: ERROR:  relation "pg_publication" does not exist
LINE 1: select * from pg_publication;
                      ^
psql:DB_PG_HC_lhr_v7.0.0.sql:453: ERROR:  relation "pg_publication_tables" does not exist
LINE 1: select * from pg_publication_tables;
                      ^
psql:DB_PG_HC_lhr_v7.0.0.sql:460: ERROR:  relation "pg_stat_subscription" does not exist
LINE 1: select * from pg_stat_subscription;
                      ^
psql:DB_PG_HC_lhr_v7.0.0.sql:464: ERROR:  relation "pg_subscription" does not exist
LINE 1: select * from pg_subscription;
                      ^
psql:DB_PG_HC_lhr_v7.0.0.sql:468: ERROR:  relation "pg_subscription_rel" does not exist
LINE 1: select *,srrelid::regclass from pg_subscription_rel;
                                        ^
psql:DB_PG_HC_lhr_v7.0.0.sql:490: ERROR:  relation "pg_file_settings" does not exist
LINE 1: select * from pg_file_settings;
                      ^
psql:DB_PG_HC_lhr_v7.0.0.sql:528: ERROR:  relation "pg_hba_file_rules" does not exist
LINE 1: select * from pg_hba_file_rules;
                      ^                      
psql:DB_PG_HC_lhr_v7.0.0.sql:588: ERROR:  absolute path not allowed
psql:DB_PG_HC_lhr_v7.0.0.sql:589: ERROR:  could not open directory "/pg13/pgdata/pg_wal": Permission denied
psql:DB_PG_HC_lhr_v7.0.0.sql:666: ERROR:  relation "pg_config" does not exist
LINE 1: SELECT * FROM pg_config ;
                      ^

5、达梦数据库

在Windows下运行:

disql -S SYSDBA/SYSDBA@192.168.1.35 `d:\DB_DM_HC_lhr_v7.0.0.sql

在Linux下运行:

disql -S SYSDBA/SYSDBA \`/home/dmdba/DB_DM_HC_lhr_v7.0.0.sql > /dev/null

注意:

1、若不能出结果,则多半是字符集的问题,请将脚本修改为UTF8格式的文件(或使用DB_DM_HC_lhr_v7.0.0_utf8.sql脚本),然后再运行脚本。

6、TiDB数据库

只要有mysql客户端即可,使用MariaDB的客户端也可以,如下:

mysql -uroot -plhr -P4000 -s -f <  DB_TiDB_HC_lhr_v7.0.0.sql  > lhr_mysql_check.html

7、openGauss数据库

需要有华为的gsql客户端,或PostgreSQL数据库的psql客户端都可以,运行方式如下:

若是openGauss或华为的GaussDB数据库的gsql客户端,则执行:

gsql -U gaussdb -h 192.168.8.8 -p 15432 -d postgres -W'lhr@123XXT' -H -f D:\DB_openGauss_HC_lhr_v7.0.0.sql > d:\openGauss_health_check.html

若是PostgreSQL数据库的psql客户端,则执行:

psql -U gaussdb -h 192.168.8.8 -p 54324 -d postgres -W -H -f D:\DB_openGauss_HC_lhr_v7.0.0.sql > d:\openGauss_health_check.html

psql需要输入密码,回车即可。

注意:

1、该脚本的字符集为utf8,请使用utf8格式打开该文件。

2、建议使用omm用户在服务器本地跑脚本。

8、DB2数据库

需要有db2数据库客户端,运行方式如下:

① 客户端在Windows平台,连接到本地db2数据库:

db2cmd
db2 connect to lhrdb && db2 -txf D:\DB_DB2_HC_lhr_v7.0.0.sql >  d:\lhr_db2_health_check.html

② 客户端在Linux平台,连接到本地db2数据库:

db2 connect to lhrdb; db2 -txf DB_DB2_HC_lhr_v7.0.0.sql > lhr_db2_health_check_`date +'%Y%m%d%H%M%S'`.html

③ 客户端在Windows平台,需要连接到远程的linux服务器:

db2cmd
db2 connect to test user db2inst1 using lhr && db2 -txf D:\DB_DB2_HC_lhr_v7.0.0.sql >  D:\lhr_db2_health_check.html

注意:

1、建议直接在服务端运行,因为个别巡检命令只支持在服务端运行。

2、该脚本只能对当前的数据库进行检测,若需要检查其它数据库,请重新跑脚本,并修改连接到的数据库名称,例如:db2 connect to test;

9、OceanBase数据库

有mysql客户端或者obclient都可以,如下:

-- 使用obclient客户端
obclient -uroot@sys -p -h192.168.8.8 -P2883  -f --silent  <  DB_OceanBase_HC_lhr_v7.0.0.sql > lhr_OceanBase_check.html

-- 使用mysql客户端
mysql -uroot@sys -p -h192.168.8.8 -P2883  -f --silent  <  DB_OceanBase_HC_lhr_v7.0.0.sql > lhr_OceanBase_check.html

10、OS信息

操作系统信息的收集是perl脚本,运行方式如下所示。

[root@OCPLHR lhr]# ll
total 28
-rw-r--r-- 1 oracle oinstall 25791 Jul 10 17:15 DB_OS_HC_lhr_v7.0.0.pl
[root@OCPLHR lhr]# perl DB_OS_HC_lhr_v7.0.0.pl 
[root@OCPLHR lhr]# ll
total 56
-rw-r--r-- 1 oracle oinstall 25791 Jul 10 17:15 DB_OS_HC_lhr_v7.0.0.pl
-rw-r--r-- 1 root   root     26289 Jul 10 17:19 LHR_OSCHECK_REPORT_OCPLHR_20190710171939.html
[root@OCPLHR lhr]# 
[root@OCPLHR lhr]# sh DB_OS_HC_lhr_v7.0.0.sh 
检查结果:./HostDailyCheck--20220825.txt

若运行报如下的错误:

[root@ecs-9b83 ~]# sh DB_OS_HC_lhr_v7.0.0.sh
DB_OS_HC_lhr_v7.0.0.sh: line 9: $'\r': command not found
: No such file or directorye 13: /etc/profile
[root@ecs-9b83 ~]# chmod +x DB_OS_HC_lhr_v7.0.0.sh
[root@ecs-9b83 ~]# ./DB_OS_HC_lhr_v7.0.0.sh       
-bash: ./DB_OS_HC_lhr_v7.0.0.sh: /bin/bash^M: bad interpreter: No such file or directory

则需要使用dos2unix进行格式化:

[root@ecs-9b83 ~]# dos2unix DB_OS_HC_lhr_v7.0.0.sh
dos2unix: converting file DB_OS_HC_lhr_v7.0.0.sh to Unix format ...
[root@ecs-9b83 ~]# ./DB_OS_HC_lhr_v7.0.0.sh 
检查结果:./HostDailyCheck--20220825.txt

11、Greenplum数据库

和PostgreSQL数据库相似,需要有psql客户端,运行方式如下:

psql -U gpadmin -h 192.168.8.8 -p 5432 -d lhrgpdb -H -f D:\DB_GP_HC_lhr_v7.0.0.sql > d:\a.html

输入密码,回车即可。

注意:

1、该脚本的字符集为utf8,请使用utf8格式打开该文件。

12、人大金仓

KES

和PostgreSQL数据库相似,需要有psql客户端或者有人大金仓的ksql客户端都可以,运行方式如下:

ksql -U kingbase -h 192.168.8.8 -p 54321 -d test -W -H -f D:\DB_kingbase_HC_lhr_v7.0.0.sql > d:\a.html
psql -U kingbase -h 192.168.8.8 -p 54321 -d test -W -H -f D:\DB_kingbase_HC_lhr_v7.0.0.sql > d:\a.html

输入密码,回车即可。

注意:

1、该脚本的字符集为utf8,请使用utf8格式打开该文件。

KADB

和GreenPlum数据库相似,需要有psql客户端,运行方式如下:

psql -U mppadmin -h 192.168.8.8 -p 5432 -d lhrgpdb -W -H -f D:\DB_kingbase_kadb_HC_lhr_v7.0.0.sql > d:\a.html

输入密码,回车即可。

注意:

1、该脚本的字符集为utf8,请使用utf8格式打开该文件。

13、万里GreatDB数据库

只要有mysql客户端即可,使用MariaDB的客户端也可以,如下:

mysql -uroot -plhr -P3306 -s -f <  DB_GreatDB_HC_lhr_v7.0.0.sql  > lhr_GreatDB_check.html

14、TDSQL_for_PG(原 TBase)数据库

需要有psql客户端,运行方式如下:

psql -U tbase -h 192.168.8.8 -p 30004 -d postgres -W -H -f D:\DB_TBase_HC_lhr_v7.0.0.sql > D:\TBase_health_check.html

输入密码,回车即可。

注意:

1、该脚本的字符集为utf8,请使用utf8格式打开该文件。

15、MogDB数据库

需要有华为的gsql客户端,或PostgreSQL数据库的psql客户端都可以,运行方式如下:

若是openGauss或华为的GaussDB数据库的gsql客户端,则执行:

gsql -U lhr -h 192.168.8.8 -p 25432 -d postgres -W'lhr@123XXT' -H -f D:\DB_MogDB_HC_lhr_v7.0.0.sql > d:\MogDB_health_check.html

若是PostgreSQL数据库的psql客户端,则执行:

psql -U lhr -h 192.168.8.8 -p 25432 -d postgres -W -H -f D:\DB_MogDB_HC_lhr_v7.0.0.sql > d:\MogDB_health_check.html

psql需要输入密码,回车即可。

注意:

1、该脚本的字符集为utf8,请使用utf8格式打开该文件。

2、建议使用omm用户在服务器本地跑脚本。

16、OushuDB数据库

需要有psql客户端,运行方式如下:

psql -U gpadmin -h 192.168.8.8 -p 5432 -d postgres  -H -f D:\DB_OushuDB_HC_lhr_v7.0.0.sql > d:\DB_OushuDB_check.html

输入密码,回车即可。

注意:

1、该脚本的字符集为utf8,请使用utf8格式打开该文件。

17、PolarDB_for_PG数据库

需要有psql客户端,运行方式如下:

psql -U postgres -h 192.168.8.8 -p 5432 -d postgres  -H -f D:\DB_PolarDB_for_PG_HC_lhr_v7.0.0.sql > d:\PolarDB_for_PG_health_check.html

输入密码,回车即可。

注意:

1、该脚本的字符集为utf8,请使用utf8格式打开该文件。

18、神通数据库

需要有神舟通用数据库的专用isql客户端,运行方式如下:

isql -U sysdba/lhr -h 192.168.8.8 -p 2003 -q -t -f d:\DB_OSCAR_HC_lhr_v7.0.0.sql > d:\a.html

回车即可。

19、南大通用GBase

GBase 8a

只要有南大通用GBase 8a的默认客户端gccli或gbasemysql客户端即可,使用MariaDB的客户端也可以,如下:

-- 使用gccli命令行
gccli -uroot -plhr -h192.168.8.8 -P5258  -f -s  <  DB_GBase8a_HC_lhr_v7.0.0 > lhr_GBase8a_check.html

-- 使用gbase命令行
gbase -uroot -plhr -h192.168.8.8 -P5258  -f -s  <  DB_GBase8a_HC_lhr_v7.0.0 > lhr_GBase8a_check.html


-- Windows上,可以使用MySQL客户端,使用5.7版本,否则会报错:ERROR 1043 (08S01): Bad handshake
D:\db\MySQL\mysql-5.7.30-winx64\bin\mysql -uroot -plhr -h192.168.8.8 -P5258 -f -s  <  DB_GBase8a_HC_lhr_v7.0.0 > lhr_GBase8a_check.html

GBase 8c

需要有GBase 8c的gsql客户端,或PostgreSQL数据库的psql客户端都可以,运行方式如下:

若是GBase 8c或华为的GaussDB数据库的gsql客户端,则执行:

gsql -U gha -h 192.168.8.8 -p 5432 -d postgres -W'lhr@123XXT' -H -f D:\DB_GBase8c_HC_lhr_v7.0.0.sql > d:\GBase8c_health_check.html

若是PostgreSQL数据库的psql客户端,则执行:

psql -U gha -h 192.168.8.8 -p 5432 -d postgres -W -H -f D:\DB_GBase8c_HC_lhr_v7.0.0.sql > d:\GBase8c_health_check.html

psql需要输入密码,回车即可。

注意:

1、该脚本的字符集为utf8,请使用utf8格式打开该文件。

2、建议使用gbase用户在服务器本地跑脚本。

20、StarRocks数据库

只要有mysql客户端即可,使用MariaDB的客户端也可以,如下:

mysql -uroot -p -P3306 -s -f <  DB_StarRocks_HC_lhr_v7.0.0.sql  > lhr_StarRocks_check.html

21、YMatrix数据库

和PostgreSQL数据库相似,需要有psql客户端,运行方式如下:

psql -U mxadmin -h 192.168.8.8 -p 64340 -d postgres -W -H -f D:\DB_YMatrix_HC_lhr_v7.0.0.sql > d:\lhr_YMatrix_check.html

输入密码,回车即可。

注意:

1、该脚本的字符集为utf8,请使用utf8格式打开该文件。

22、YashanDB数据库

需要有yasql客户端,运行方式如下:

yasql / as sysdba  -f DB_YashanDB_HC_lhr_v7.0.0.sql > /dev/null

输入密码,回车即可。

注意:

1、该脚本的字符集为utf8,请使用utf8格式打开该文件。

五、其它问题

请看视频《小麦苗数据库健康检查脚本使用说明.wmv》或阅读《【DB健康巡检(Oracle+MySQL+SQLServer+OS)】小麦苗巡检脚本使用说明_LHR.pdf》。

视频观看地址:https://www.bilibili.com/video/BV1K54y1U7CE

六、软件著作权登记证书

小麦苗编写的该巡检系统已申请“中华人民共和国国家版权局计算机软件著作权登记证书”,请购买的朋友不要随意传播,否则将追究法律责任,并且收回脚本,不再提供免费更新,谢谢。

相关证书见下图:

七、版本重大更新历史

对于小的bug更新不再此列出,直接修改脚本:

1、2015.10月推出Oracle巡检脚本,中间经过N次更新,2018.12.06更新一次,支持12c

2、2019.07.02重大更新,添加了10g、11g、12c版本的只读版本

3、2019.07.10加上了OS信息的收集

4、2019.07.12加上了对MySQL数据库的巡检

5、2019.09.24对Oracle的展示做了优化,修改了个别内容

6、2020.09.30加上了对SQL Server数据库的巡检

7、2020.12.16加上了对PostgreSQL数据库的巡检

8、2021.10.13加上了对达梦数据库的巡检

9、2021.10.18加上了对TiDB数据库的巡检

10、2021.10.23加上了对TiDB数据库的巡检

11、2021.10.29加上了对db2数据库的巡检

12、2021.10.31加上了对OceanBase数据库的巡检,并且去掉了MySQL和TiDB之前只能在Linux上运行的限制

13、2022.3.8加上了对Greenplum数据库的巡检

14、2022.3.28加上了对人大金仓KES数据库的巡检

15、2022.4.8加上了对万里数据库GreatDB的巡检

16、2022.4.11加上了对TDSQL_for_PG(原 TBase)数据库的巡检

17、2022.4.18加上了对MogDB数据库的巡检

18、2022.4.20加上了对OushuDB数据库的巡检

19、2022.4.21加上了对TDSQL_for_PG数据库的巡检

20、2022.4.22加上了对PolarDB_for_PG数据库的巡检

21、2023.3.6加上了对南大通用GBase 8a数据库的巡检

22、2023.3.18加上了对南大通用GBase 8a数据库的巡检

23、2023.3.29加上了对StarRocks数据库的巡检

24、2023.4.6加上了对YMatrix数据库的巡检

25、2023.7.6加上了对人大金仓KADB数据库的巡检

26、2023.11.21加上了对崖山YashanDB数据库的巡检

27、2024.03.27加上了对SQL Server新版本新特性的一些支持,例如加密、BPE、查询存储等,新增DB_SQLServer_HC_lhr_v7.0.0_2016.sql脚本

八、购买方式

目前售价99元,包括Oracle + MySQL + SQL Server + PostgreSQL + Greenplum + 达梦 + 人大金仓(KES、KADB) + 万里GreatDB + OceanBase + TiDB + openGauss + TDSQL_for_PG(原 TBase) + DB2 + MogDB + OushuDB + PolarDB_for_PG + 神舟通用 + 南大通用GBase(8a、8c) + OS + StarRocks + YMatrix + YashanDB的脚本,可以巡检21种数据库,后续免费优化,加量不加价,支持以下购买方式:

1、微信红包,请加我微信:db_bao,或用微信扫描以下二维码加麦老师微信:

2、QQ红包,请加我QQ:646634621,或用QQ扫以下二维码加我QQ:

3、微店购买连接:https://k.weidian.com/o5iECboc

我的微店的二维码如下所示:

九、脚本购买须知

1、该脚本系列不讲价,不答疑,不解惑。若不会使用,请参考本文的脚本运行方式;若还不会使用请付费答疑,参考:https://www.dbaup.com/xiaomaimiaoshujukuchengjieyewujieshao.html#fu_fei_zi_xun_ye_wu

2、99元包括所有脚本吗? 答:是的,99元包括数据库巡检所有脚本,且免费更新!!!

3、脚本支持单个脚本售卖吗? 答:支持,可以只买Oracle,或只买MySQL脚本等等,单个脚本售价20元,不讲价,且不支持免费更新!!!

4、乱码问题,请自行解决。可以考虑配置变量或修改sql文件的编码格式为UTF8(在windows上,新建一个utf8格式的文件,然后复制粘贴即可)。例如,Oracle或达梦的乱码问题,若实在解决不了,请在Windows环境下的客户端上跑吧。最后若还不行,可以使用付费答疑,参考:https://www.dbaup.com/xiaomaimiaoshujukuchengjieyewujieshao.html#fu_fei_zi_xun_ye_wu

5、除了Oracle有针对特定版本的脚本外,其它数据库都没有针对某个版本的脚本。所以,不同数据库的版本,运行可能会有个别错误显示在界面上(例如某个视图不存在等问题,例如MySQL、PG、GreenPlum等数据库脚本),但是,不会影响最终html的格式效果! 参考:https://www.dbaup.com/mysqlshujukuxunjianjiaoben.html#zhu_yi

6、脚本放在腾讯的微云里,下载的时候别用迅雷,也别打包下载,否则下载不了或下载完成后用不了,请单个文件下载,或转存到自己的微云里用微云客户端下载!!!若微云(https://www.weiyun.com、http://share.weiyun.com)访问不了,则**肯定是你的DNS的问题**,请修改为`114.114.114.114`再尝试,或关闭360等杀毒软件,或用DNS修复器修复DNS。

7、脚本里的个人信息或跑马灯信息是可以修改的,自己使用文本工具打开脚本,搜索相关内容进行替换即可。

8、后续更新怎么获取? 答:购买后会发一个下载地址,后期更新也会在该地址,自己自行下载更新脚本即可。注意:购买单个脚本不支持免费更新。

9、何时更新? 答:请关注麦老师朋友圈或公众号(DB宝),会进行通知。

十、About Me


● 个人QQ号(646634621),微信号(db_bao),注明添加缘由 ● 最新修改时间:2024年3月


使用微信客户端扫描下面的二维码来关注小麦苗的微信公众号(DB宝)及QQ群(DBA宝典)、添加小麦苗微信, 学习最实用的数据库技术。


Copyright © 小麦苗 2024 修订时间: 2024-09-10 17:26:28

results matching ""

    No results matching ""