引言
随着数字化时代的快速发展,数据库作为企业信息化的核心,其稳定性和性能对于企业至关重要。openGauss 6.0.0 openGauss是一款开源关系型数据库管理系统,采用木兰宽松许可证v2发行。openGauss内核深度融合华为在数据库领域多年的经验,结合企业级场景需求,持续构建竞争力特性。凭借其高性能、高可靠、高安全、易运维等特性,赢得了众多企业的青睐。本文将详细介绍openGauss 6.0.0 新版数据库的日常运维,帮助用户更好地管理和维护数据库。
一、启停 openGauss
以操作系统用户omm登录数据库主节点。
[root@worker1 ~]# su - omm
Last login: Fri May 17 16:29:59 CST 2024 on pts/0
[omm@worker1 ~]$
1、启动openGauss
使用以下命令启动openGauss。
gs_om -t start
实验示例
[omm@worker1 script]$ gs_om -t start
Starting cluster.
=========================================
[SUCCESS] worker1:
[2024-06-04 14:04:56.387][76539][][gs_ctl]: gs_ctl started,datadir is /opt/openGauss/install/data/dn1
[2024-06-04 14:04:56.390][76539][][gs_ctl]: another server might be running; Please use the restart command
=========================================
Successfully started.
[omm@worker1 script]$
2、停止openGauss
以操作系统用户omm登录数据库主节点。
使用以下命令停止openGauss。
gs_om -t stop
实验示例
[omm@worker1 script]$ gs_om -t stop
Stopping cluster.
=========================================
Successfully stopped cluster.
=========================================
End stop cluster.
[omm@worker1 script]$
说明: 启停节点及AZ的操作请参见《工具与命令参考》中“服务端工具 > gs_om”章节。
3、错误排查
如果启动openGauss或者停止openGauss服务失败,请根据日志文件中的日志信息排查错误,参见日志参考。
如果是超时导致启动失败,可以执行如下命令,设置启动超时时间,默认超时时间为300s。
gs_om -t start --time-out=300
[omm@worker1 script]$ gs_om -t start --time-out=300
Starting cluster.
=========================================
[SUCCESS] worker1
2024-06-04 14:06:51.484 665eaefb.1 [unknown] 139781304941184 [unknown] 0 dn_6001 01000 0 [BACKEND] WARNING: could not create any HA TCP/IP sockets
2024-06-04 14:06:51.484 665eaefb.1 [unknown] 139781304941184 [unknown] 0 dn_6001 01000 0 [BACKEND] WARNING: could not create any HA TCP/IP sockets
=========================================
Successfully started.
[omm@worker1 script]$
4、日志类型参考
在数据库运行过程中,会出现大量日志,既有保证数据库安全可靠的WAL日志(预写式日志,也称为Xlog),也有用于数据库日常维护的运行和操作日志等。在数据库发生故障时,可以参考这些日志进行问题定位和数据库恢复的操作。
日志类型
日志类型的详细说明请参见下表。
*类型* | *说明* |
---|---|
系统日志 | 数据库系统进程运行时产生的日志,记录系统进程的异常信息。 |
操作日志 | 通过客户端工具(例如gs_guc)操作数据库时产生的日志。 |
Trace日志 | 打开数据库的调试开关后,会记录大量的Trace日志。这些日志可以用来分析数据库的异常信息。 |
黑匣子日志 | 数据库系统崩溃的时候,通过故障现场堆、栈信息可以分析出故障发生时的进程上下文,方便故障定位。黑匣子具有在系统崩溃时,dump出进程和线程的堆、栈、寄存器信息的功能。 |
审计日志 | 开启数据库审计功能后,将数据库用户的某些操作记录在日志中,这些日志称为审计日志。 |
WAL日志 | 又称为REDO日志,在数据库异常损坏时,可以利用WAL日志进行恢复。由于WAL日志的重要性,所以需要经常备份这些日志。 |
性能日志 | 数据库系统在运行时检测物理资源的运行状态的日志,在对外部资源进行访问时的性能日志,例如:磁盘、OBS等。 |
二、查看 openGauss 状态
背景信息
openGauss支持查看整个openGauss的状态,通过查询结果确认openGauss或者单个主机的运行状态是否正常。
前提条件
openGauss已经启动。
操作步骤
以操作系统用户omm登录数据库主节点。
1、使用如下命令查询openGauss状态:
[omm@worker1 script]$ gs_ctl status
[2024-06-04 14:07:34.222][77045][][gs_ctl]: gs_ctl status,datadir is /opt/openGauss/install/data/dn1
gs_ctl: server is running (PID: 76866)
/opt/openGauss/install/app/bin/gaussdb "-D" "/opt/openGauss/install/data/dn1"
[omm@worker1 script]$
2、若要查询某主机上的实例状态:
请在命令中增加“-h”项。示例如下:
[omm@worker1 script]$ gs_om -t status -h worker1
-----------------------------------------------------------------------
cluster_state : Normal
redistributing : No
-----------------------------------------------------------------------
node : 1
node_name : worker1
instance_id : 6001
node_ip : 172.10.20.121
data_path : /opt/openGauss/install/data/dn1
instance_port : 15000
type : Datanode
instance_state : Normal
az_name : AZ1
instance_role : Normal
-----------------------------------------------------------------------
[omm@worker1 script]$
其中,worker1为待查询主机的名称。
3、查看openGauss详细状态信息,含实例状态信息。
[omm@worker1 script]$ gs_om -t status --detail
[ Cluster State ]
cluster_state : Normal
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip port instance state
--------------------------------------------------------------------------------------------------
1 worker1 172.10.20.121 15000 6001 /opt/openGauss/install/data/dn1 P Primary Normal
[omm@worker1 script]$
三、openGauss 例行维护
1、日维护检查项
1.1 检查openGauss状态
通过openGauss提供的工具查询数据库和实例状态,确认数据库和实例都处于正常的运行状态,可以对外提供数据服务。
检查实例状态
[omm@worker1 script]$ gs_check -U omm -i CheckClusterState
Parsing the check items config file successfully
Distribute the context file to remote hosts successfully
Start to health check for the cluster. Total Items:1 Nodes:1
Checking... [=========================] 1/1
Start to analysis the check result
CheckClusterState...........................OK
The item run on 1 nodes. success: 1
Analysis the check result successfully
Success. All check items run completed. Total:1 Success:1
For more information please refer to /opt/openGauss/install/tool/script/gspylib/inspection/output/CheckReport_202406045113977563.tar.gz
[omm@worker1 script]$
1.2 检查锁信息
锁机制是数据库保证数据一致性的重要手段,检查相关信息可以检查数据库的事务和运行状况。
查询数据库中的锁信息
openGauss=# SELECT * FROM pg_locks;
locktype | database | relation | page | tuple | bucket | virtualxid | transactionid | classid | objid | objsubid | virtualtransaction | pid | sessionid
| mode | granted | fastpath | locktag | global_sessionid
------------+----------+----------+------+-------+--------+------------+---------------+---------+-------+----------+--------------------+-----------------+-----------------
+-----------------+---------+----------+-------------------+------------------
relation | 15737 | 12191 | | | | | | | | | 10/361 | 139774354519808 | 139774354519808
| AccessShareLock | t | t | 3d79:2f9f:0:0:0:0 | 0:0#0</