错误报告和日志配置
确保开启日志收集器
说明
参数logging_collector控制开启后端日志收集进程logger进行日志收集。该进程捕获发送到stderr或csvlog的日志消息并写入日志文件。这种记录日志的方法比将日志记录到syslog更加有效,因为某些类型的消息在syslog的输出中无法显示。
实现
检查方法:
检查logging_collector参数值是否为on,如果不为on则失败。
openGauss=# show logging_collector;
logging_collector
-------------------
on
(1 row)
修复方法:
在postgresql.conf配置文件中修改参数logging_collector为on,然后重启数据库。
gs_guc set -Z datanode -N all -I all -c "logging_collector=on"
gs_om -t stop && gs_om -t start
确保日志名称配置正确
说明
参数log_filename设置服务器运行日志文件的名称。建议使用%转义字符定义日志文件名称,以便能够自动包含日期和时间信息,从而方便对日志文件进行有效的管理。
实现
检查方法:
检查log_filename参数配置,建议保持默认配置,即使用包含日期和时间信息的格式。
openGauss=# show log_filename;
log_filename
--------------------------------
postgresql-%Y-%m-%d_%H%M%S.log
(1 row)
修复方法:
gs_guc reload -Z datanode -N all -I all -c "log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'"
确保日志文件权限配置正确
说明
当开启参数logging_collector时,可以使用参数log_file_mode设置服务器日志文件的权限。因为日志文件中可能含有用户数据,所以日志文件访问必须受到限制,以防止日志信息泄露或被篡改。
实现
检查方法:
检查log_file_mode参数值是否为0600,如果不是则失败。
openGauss=# show log_file_mode;
log_file_mode
---------------
0600
(1 row)
修复方法:
gs_guc reload -Z datanode -N all -I all -c "log_file_mode=0600"
禁止覆盖写入同名日志文件
说明
参数log_truncate_on_rotation设置日志消息的写入方式。当设置为on时,数据库会以覆盖写入的方式写入服务器日志消息,这意味着当日志文件被轮转时,新的日志消息会覆盖旧的日志消息。当设置为off时,新的日志消息会被附加到同名的现有日志文件上,而不会覆盖旧的日志。为确保日志保留更长时间,需要将此参数设置为off,禁止覆盖写入同名日志文件。
实现
检查方法:
检查log_truncate_on_rotation参数值是否为off,如果不为off则失败。
openGauss=# show log_truncate_on_rotation;
log_truncate_on_rotation
--------------------------
off
(1 row)
修复方法:
gs_guc reload -Z datanode -N all -I all -c "log_truncate_on_rotation=off"
确保单个日志文件最大记录时间配置正确
说明
参数log_rotation_age用于设置单个日志文件最大的日志记录时间。当日志记录时间超过该参数设置的最大值时,服务器将自动创建新的日志文件。正确的配置有助于避免日志文件过于频繁地产生,同时避免单个日志文件过大导致管理不便。
实现
检查方法:
检查log_rotation_age参数配置,建议配置为默认值1d(即一天)。
openGauss=# show log_rotation_age;
log_rotation_age
------------------
1d
(1 row)
修复方法:
参数log_rotation_age单位为min,默认值为1d,即1440min。
gs_guc reload -Z datanode -N all -I all -c "log_rotation_age=1d"
确保单个日志文件最大容量配置正确
说明
参数log_rotation_size用于设置单个日志文件的最大容量。当日志文件达到该最大容量时,服务器将自动创建新的日志文件,以避免日志文件过大导致管理困难。
实现
检查方法:
检查log_rotation_size参数配置,建议配置为默认值20MB。
openGauss=# show log_rotation_size;
log_rotation_size
-------------------
20MB
(1 row)
修复方法:
参数log_rotation_size单位为KB,默认值为20MB。
gs_guc reload -Z datanode -N all -I all -c "log_rotation_size=20MB"
确保客户端日志等级配置正确
说明
参数client_min_messages控制按设置的等级将消息发送到客户端。有效的值包括debug、debug5、debug4、debug3、debug2、debug1、info、notice、warning、error、log、fatal、panic,其中debug和debug2等效。每个等级都包括排在他后面的所有级别中的日志。在实际设置过程中,如果设置的级别大于error,例如为fatal或panic,系统会默认将级别转为error。
实现
检查方法:
检查client_min_messages参数值,如果为debug或debug1~debug5则配置可能不正确。
openGauss=# show client_min_messages;
client_min_messages
---------------------
notice
(1 row)
修复方法:
gs_guc reload -Z datanode -N all -I all -c "client_min_messages=notice"
确保服务器日志等级配置正确
说明
参数log_min_messages控制按的等级将消息写入到服务器日志。有效的值包括debug、debug5、debug4、debug3、debug2、debug1、info、notice、warning、error、log、fatal、panic。其中debug和debug2等效,每个级别都包含排在他后面的所有级别中的信息。
实现
检查方法:
检查log_min_messages参数值,如果为debug或debug1~debug5则配置可能不正确。
openGauss=# show log_min_messages;
log_min_messages
------------------
warning
(1 row)
修复方法:
设置参数log_min_messages为warning。
gs_guc reload -Z datanode -N all -I all -c "log_min_messages=warning"
确保记录产生错误的SQL语句日志级别配置正确
说明
参数log_min_error_statement控制是否在服务器日志中记录产生错误的SQL语句。有效值包括debug、debug5、debug4、debug3、debug2、debug1、info、notice、warning、error、log、fatal、panic。设置为error时,表示产生error、fatal、panic级别错误的语句都将被记录。设置为panic时,表示关闭此特性。由于有的SQL语句中包含用户个人信息,如果不需要记录出错的SQL语句,可以将参数设置为panic。
实现
检查方法:
检查log_min_error_statement参数值是否为error,如果不为error则配置可能不正确。
openGauss=# show log_min_error_statement;
log_min_error_statement
-------------------------
error
(1 row)
修复方法:
设置参数log_min_error_statement为error。
gs_guc reload -Z datanode -N all -I all -c "log_min_error_statement=error"
确保开启用户登录时日志记录功能
说明
参数log_connections用于记录每次尝试连接到服务器的日志,以及成功完成客户端连接认证的日志。
实现
检查方法:
通过执行以下SQL命令来检查log_connections参数值是否为on,如果不为on则失败。
openGauss=# show log_connections;
log_connections
-----------------
off
(1 row)
修复方法:
设置参数log_connections为on。
gs_guc reload -Z datanode -N all -I all -c "log_connections=on"
确保开启用户注销时日志记录功能
说明
参数log_disconnections用于设置是否记录客户端结束连接的信息,包括在会话结束时在服务器日志中输出一行,并包含会话的持续时间。
实现
检查方法:
检查log_disconnections参数的值是否为on,如果不为on则失败。
openGauss=# show log_disconnections;
log_disconnections
--------------------
off
(1 row)
修复方法:
设置参数log_disconnections为on。
gs_guc reload -Z datanode -N all -I all -c "log_disconnections=on"
确保写入服务器日志的详细度配置正确
说明
参数log_error_verbosity用于控制写入服务器日志的详细度。有效值包括TERSE、DEFAULT和VERBOSE。
实现
检查方法:
检查log_error_verbosity参数值是否为default,如果不为default则失败。
openGauss=# show log_error_verbosity;
log_error_verbosity
---------------------
default
(1 row)
修复方法:
设置参数log_error_verbosity为default。
gs_guc reload -Z datanode -N all -I all -c "log_error_verbosity=default"
确保日志不记录主机名
说明
参数log_hostname控制连接日志消息中是否记录主机名。当log_hostname设置为on时,连接日志消息会同时显示连接主机的IP地址和主机名。由于解析主机名需要一定的时间,这可能会带来额外的性能开销。因此,建议将log_hostname设置为off,这样连接日志中只记录IP地址而不记录主机名。
实现
检查方法:
检查log_hostname参数值是否为off,如果不为off则失败。
openGauss=# show log_hostname;
log_hostname
--------------
off
(1 row)
修复方法:
设置log_hostname参数为off。
gs_guc reload -Z datanode -N all -I all -c "log_hostname=off"
确保关闭解析树调试打印开关
说明
参数debug_print_parse用于控制是否打印查询的解析树结果。当该参数设置为on时,查询的解析树结果将被打印到日志中,这可能会占用较多的日志空间,并对查询性能产生负面影响。在生产环境中,建议将debug_print_parse参数设置为off,以禁止将查询的解析树结果打印到日志中。
实现
检查方法:
检查debug_print_parse参数值是否为off,如果不为off则失败。
openGauss=# show debug_print_parse;
debug_print_parse
-----------------
off
(1 row)
修复方法:
设置参数debug_print_parse为off。
gs_guc reload -Z datanode -N all -I all -c "debug_print_parse=off"
确保关闭执行计划调试打印开关
说明
参数debug_print_plan用于控制是否打印查询的执行计划到日志中。默认情况下,该参数设置为off,表示不打印执行计划。但是,如果将其设置为on,则会将查询的执行计划打印到日志中,这可能会占用大量的日志空间,并对查询性能产生负面影响。因此,在生产环境中,建议将debug_print_plan参数设置为off,以禁止将查询的执行计划打印到日志中。
实现
检查方法:
检查debug_print_plan参数值是否为off,如果不为off则失败。
openGauss=# show debug_print_plan;
debug_print_plan
----------------
off
(1 row)
修复方法:
将debug_print_plan参数设置为off。
gs_guc reload -Z datanode -N all -I all -c "debug_print_plan=off"
确保关闭查询重写调试打印开关
说明
参数debug_print_rewritten用于控制是否打印查询重写的结果到日志中。默认情况下,该参数设置为off,表示不打印查询重写结果。但是,如果将其设置为on,则会将查询重写的结果打印到日志中,这可能会占用大量的日志空间,并对查询性能产生负面影响。因此,在生产环境中,建议将debug_print_rewritten参数设置为off,以禁止将查询重写结果打印到日志中。
实现
检查方法:
检查debug_print_rewritten参数值是否为off,如果不为off则失败。
openGauss=# show debug_print_rewritten;
debug_print_rewritten
----------------------
off
(1 row)
修复方法:
将debug_print_rewritten参数设置为off。
gs_guc reload -Z datanode -N all -I all -c "debug_print_rewritten=off"