opengauss教程FG007-openGauss启动关闭与状态检查
目录大纲
Part01-基础概念与理论知识
1.1 启动关闭原理
openGauss数据库的启动和关闭是日常运维中最基本的操作,了解其原理对于保证数据库的稳定运行至关重要。风哥教程参考opengauss官方文档,启动和关闭过程涉及以下几个核心步骤:
- 启动过程:
- 加载配置文件
- 初始化内存结构
- 启动后台进程
- 加载数据文件
- 启动网络监听
- 关闭过程:
- 停止接受新连接
- 处理完现有事务
- 关闭后台进程
- 写入检查点
- 释放资源
1.2 状态检查机制
状态检查是监控数据库健康状况的重要手段,openGauss提供了多种状态检查工具和命令:
- 进程状态检查:检查数据库进程是否正常运行
- 连接状态检查:检查数据库连接数和连接状态
- 性能状态检查:检查数据库的性能指标
- 复制状态检查:检查主备复制状态(集群环境)
- 资源使用检查:检查数据库的资源使用情况
1.3 常见启动模式
- 正常启动:完整启动数据库实例,包括所有服务
- 单用户模式:启动数据库到单用户模式,用于紧急修复
- 只读模式:启动数据库到只读状态,用于数据恢复或维护
- 维护模式:启动数据库到维护状态,用于系统维护
风哥提示:不同的启动模式适用于不同的场景,需要根据实际情况选择合适的启动模式。
Part02-生产环境规划与建议
2.1 启动关闭策略
生产环境启动关闭策略
- 启动策略:
- 定期维护时的启动:提前检查配置文件和环境
- 故障恢复后的启动:检查数据一致性
- 集群启动:按照主节点→备节点的顺序启动
- 关闭策略:
- 计划关闭:提前通知业务方,选择低峰期
- 紧急关闭:尽量使用正常关闭命令,避免强制关闭
- 集群关闭:按照备节点→主节点的顺序关闭
2.2 状态检查频率
生产环境中,状态检查的频率应该根据数据库的重要性和业务需求来确定:
- 日常检查:每小时一次基本状态检查
- 详细检查:每天一次详细状态检查
- 全面检查:每周一次全面状态检查
- 实时监控:通过监控系统实时监控数据库状态
风哥提示:
2.3 故障处理预案
制定完善的故障处理预案,确保在数据库出现异常时能够快速响应:
- 启动失败处理:检查日志,分析原因,采取相应措施
- 关闭失败处理:尝试正常关闭,必要时强制关闭
- 状态异常处理:根据异常类型采取相应的处理措施
- 应急演练:定期进行故障处理演练,提高应急响应能力
Part03-生产环境项目实施方案
3.1 启动流程
# 单机启动流程
[opengauss@fgedu.net.cn ~]$ gs_ctl start -D /opengauss/fgdata
[2024-01-01 10:00:00]: The server is starting…
[2024-01-01 10:00:01]: The server was successfully started.
# 集群启动流程
[opengauss@fgedu-primary.net.cn ~]$ gs_om -t start
Starting cluster…
=========================================
Successfully started.
[opengauss@fgedu.net.cn ~]$ gs_ctl start -D /opengauss/fgdata
[2024-01-01 10:00:00]: The server is starting…
[2024-01-01 10:00:01]: The server was successfully started.
# 集群启动流程
[opengauss@fgedu-primary.net.cn ~]$ gs_om -t start
Starting cluster…
=========================================
Successfully started.
3.2 关闭流程
# 单机关闭流程(正常关闭)
[opengauss@fgedu.net.cn ~]$ gs_ctl stop -D /opengauss/fgdata
[2024-01-01 10:00:00]: The server is stopping…
学习交流加群风哥微信: itpux-com
[2024-01-01 10:00:01]: The server was successfully stopped.
# 单机关闭流程(强制关闭)
[opengauss@fgedu.net.cn ~]$ gs_ctl stop -D /opengauss/fgdata -m fast
[2024-01-01 10:00:00]: The server is stopping…
[2024-01-01 10:00:01]: The server was successfully stopped.
# 集群关闭流程
[opengauss@fgedu-primary.net.cn ~]$ gs_om -t stop
Stopping cluster…
=========================================
Successfully stopped.
[opengauss@fgedu.net.cn ~]$ gs_ctl stop -D /opengauss/fgdata
[2024-01-01 10:00:00]: The server is stopping…
学习交流加群风哥微信: itpux-com
[2024-01-01 10:00:01]: The server was successfully stopped.
# 单机关闭流程(强制关闭)
[opengauss@fgedu.net.cn ~]$ gs_ctl stop -D /opengauss/fgdata -m fast
[2024-01-01 10:00:00]: The server is stopping…
[2024-01-01 10:00:01]: The server was successfully stopped.
# 集群关闭流程
[opengauss@fgedu-primary.net.cn ~]$ gs_om -t stop
Stopping cluster…
=========================================
Successfully stopped.
3.3 状态检查方案
# 基本状态检查
[opengauss@fgedu.net.cn ~]$ gs_ctl status -D /opengauss/fgdata
[2024-01-01 10:00:00]: gs_ctl status: server is running (PID: 12345)
# 集群状态检查
[opengauss@fgedu-primary.net.cn ~]$ gs_om -t status
———————————————————————–
cluster_state : Normal
redistributing : No
———————————————————————–
node node_ip instance state
———————————————————————–
1 fgedu-primary.net.cn 192.168.1.100 6001 /opengauss/fgdata/data1 P Primary Normal
2 fgedu-standby.net.cn 192.168.1.101 6002 /opengauss/fgdata/data2 S Standby Normal
———————————————————————–
[opengauss@fgedu.net.cn ~]$ gs_ctl status -D /opengauss/fgdata
[2024-01-01 10:00:00]: gs_ctl status: server is running (PID: 12345)
# 集群状态检查
[opengauss@fgedu-primary.net.cn ~]$ gs_om -t status
———————————————————————–
cluster_state : Normal
redistributing : No
———————————————————————–
node node_ip instance state
———————————————————————–
1 fgedu-primary.net.cn 192.168.1.100 6001 /opengauss/fgdata/data1 P Primary Normal
2 fgedu-standby.net.cn 192.168.1.101 6002 /opengauss/fgdata/data2 S Standby Normal
———————————————————————–
Part04-生产案例与实战讲解
4.1 单机启动与关闭
# 启动数据库实例
[opengauss@fgedu.net.cn ~]$ gs_ctl start -D /opengauss/fgdata
[2024-01-01 10:00:00]: The server is starting…
[2024-01-01 10:00:01]: The server was successfully started.
# 检查启动状态
[opengauss@fgedu.net.cn ~]$ gs_ctl status -D /opengauss/fgdata
学习交流加群风哥QQ113257174
[2024-01-01 10:00:05]: gs_ctl status: server is running (PID: 12345)
# 连接数据库验证
[opengauss@fgedu.net.cn ~]$ gsql -d postgres -U opengauss
Password for user opengauss:
gsql ((openGauss 5.0.0 build 12345) compiled at 2024-01-01 00:00:00)
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type “help” for help.
postgres=# SELECT version();
version
—————————————————————————————————————————
openGauss 5.0.0 build 12345 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 7.3.0, 64-bit
(1 row)
# 关闭数据库实例
[opengauss@fgedu.net.cn ~]$ gs_ctl stop -D /opengauss/fgdata
[2024-01-01 10:30:00]: The server is stopping…
[2024-01-01 10:30:01]: The server was successfully stopped.
# 检查关闭状态
[opengauss@fgedu.net.cn ~]$ gs_ctl status -D /opengauss/fgdata
[2024-01-01 10:30:05]: gs_ctl status: server is stopped
[opengauss@fgedu.net.cn ~]$ gs_ctl start -D /opengauss/fgdata
[2024-01-01 10:00:00]: The server is starting…
[2024-01-01 10:00:01]: The server was successfully started.
# 检查启动状态
[opengauss@fgedu.net.cn ~]$ gs_ctl status -D /opengauss/fgdata
学习交流加群风哥QQ113257174
[2024-01-01 10:00:05]: gs_ctl status: server is running (PID: 12345)
# 连接数据库验证
[opengauss@fgedu.net.cn ~]$ gsql -d postgres -U opengauss
Password for user opengauss:
gsql ((openGauss 5.0.0 build 12345) compiled at 2024-01-01 00:00:00)
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type “help” for help.
postgres=# SELECT version();
version
—————————————————————————————————————————
openGauss 5.0.0 build 12345 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 7.3.0, 64-bit
(1 row)
# 关闭数据库实例
[opengauss@fgedu.net.cn ~]$ gs_ctl stop -D /opengauss/fgdata
[2024-01-01 10:30:00]: The server is stopping…
[2024-01-01 10:30:01]: The server was successfully stopped.
# 检查关闭状态
[opengauss@fgedu.net.cn ~]$ gs_ctl status -D /opengauss/fgdata
[2024-01-01 10:30:05]: gs_ctl status: server is stopped
4.2 集群启动与关闭
# 启动集群
[opengauss@fgedu-primary.net.cn ~]$ gs_om -t start
Starting cluster…
=========================================
Successfully started.
# 检查集群状态
[opengauss@fgedu-primary.net.cn ~]$ gs_om -t status
———————————————————————–
cluster_state : Normal
redistributing : No
———————————————————————–
node node_ip instance state
———————————————————————–
1 fgedu-primary.net.cn 192.168.1.100 6001 /opengauss/fgdata/data1 P Primary Normal
2 fgedu-standby.net.cn 192.168.1.101 6002 /opengauss/fgdata/data2 S Standby Normal
———————————————————————–
# 关闭集群
更多视频教程www.fgedu.net.cn
[opengauss@fgedu-primary.net.cn ~]$ gs_om -t stop
Stopping cluster…
=========================================
Successfully stopped.
# 检查集群关闭状态
[opengauss@fgedu-primary.net.cn ~]$ gs_om -t status
———————————————————————–
cluster_state : Down
redistributing : No
———————————————————————–
node node_ip instance state
———————————————————————–
1 fgedu-primary.net.cn 192.168.1.100 6001 /opengauss/fgdata/data1 P Primary Down
2 fgedu-standby.net.cn 192.168.1.101 6002 /opengauss/fgdata/data2 S Standby Down
———————————————————————–
[opengauss@fgedu-primary.net.cn ~]$ gs_om -t start
Starting cluster…
=========================================
Successfully started.
# 检查集群状态
[opengauss@fgedu-primary.net.cn ~]$ gs_om -t status
———————————————————————–
cluster_state : Normal
redistributing : No
———————————————————————–
node node_ip instance state
———————————————————————–
1 fgedu-primary.net.cn 192.168.1.100 6001 /opengauss/fgdata/data1 P Primary Normal
2 fgedu-standby.net.cn 192.168.1.101 6002 /opengauss/fgdata/data2 S Standby Normal
———————————————————————–
# 关闭集群
更多视频教程www.fgedu.net.cn
[opengauss@fgedu-primary.net.cn ~]$ gs_om -t stop
Stopping cluster…
=========================================
Successfully stopped.
# 检查集群关闭状态
[opengauss@fgedu-primary.net.cn ~]$ gs_om -t status
———————————————————————–
cluster_state : Down
redistributing : No
———————————————————————–
node node_ip instance state
———————————————————————–
1 fgedu-primary.net.cn 192.168.1.100 6001 /opengauss/fgdata/data1 P Primary Down
2 fgedu-standby.net.cn 192.168.1.101 6002 /opengauss/fgdata/data2 S Standby Down
———————————————————————–
4.3 状态检查实战
# 检查数据库进程状态
[opengauss@fgedu.net.cn ~]$ ps -ef | grep gaussdb
opengauss 12345 1 0 10:00 ? 00:00:00 /opengauss/app/bin/gaussdb -D /opengauss/fgdata
# 检查数据库连接状态
[opengauss@fgedu.net.cn ~]$ gsql -d postgres -U opengauss -c “SELECT count(*) FROM pg_stat_activity;
“
count
——-
1
(1 row)
# 检查数据库性能状态
[opengauss@fgedu.net.cn ~]$ gsql -d postgres -U opengauss -c “SELECT * FROM pg_stat_database WHERE datname = ‘postgres’;
“
-[ RECORD 1 ]—-+——————————
datid | 13013
datname | postgres
numbackends | 1
xact_commit | 100
xact_rollback | 0
blks_read | 1000
blks_hit | 5000
tup_returned | 10000
tup_fetched | 5000
更多学习教程公众号风哥教程itpux_com
tup_inserted | 1000
tup_updated | 500
tup_deleted | 100
conflicts | 0
temp_files | 0
temp_bytes | 0
deadlocks | 0
blk_read_time | 0
blk_write_time | 0
session_time | 0
active_time | 0
idle_in_transaction_time | 0
backend_xmin |
# 检查主备复制状态
[opengauss@fgedu-primary.net.cn ~]$ gs_ctl query -D /opengauss/fgdata/data1
[2024-01-01 10:00:00]: The cluster status is Normal.
[2024-01-01 10:00:00]: local_role : Primary
[2024-01-01 10:00:00]: static_connections : 1
[2024-01-01 10:00:00]: db_state : Normal
[2024-01-01 10:00:00]: detail_information : All nodes are normal.
[opengauss@fgedu.net.cn ~]$ ps -ef | grep gaussdb
opengauss 12345 1 0 10:00 ? 00:00:00 /opengauss/app/bin/gaussdb -D /opengauss/fgdata
# 检查数据库连接状态
[opengauss@fgedu.net.cn ~]$ gsql -d postgres -U opengauss -c “SELECT count(*) FROM pg_stat_activity;
“
count
——-
1
(1 row)
# 检查数据库性能状态
[opengauss@fgedu.net.cn ~]$ gsql -d postgres -U opengauss -c “SELECT * FROM pg_stat_database WHERE datname = ‘postgres’;
“
-[ RECORD 1 ]—-+——————————
datid | 13013
datname | postgres
numbackends | 1
xact_commit | 100
xact_rollback | 0
blks_read | 1000
blks_hit | 5000
tup_returned | 10000
tup_fetched | 5000
更多学习教程公众号风哥教程itpux_com
tup_inserted | 1000
tup_updated | 500
tup_deleted | 100
conflicts | 0
temp_files | 0
temp_bytes | 0
deadlocks | 0
blk_read_time | 0
blk_write_time | 0
session_time | 0
active_time | 0
idle_in_transaction_time | 0
backend_xmin |
# 检查主备复制状态
[opengauss@fgedu-primary.net.cn ~]$ gs_ctl query -D /opengauss/fgdata/data1
[2024-01-01 10:00:00]: The cluster status is Normal.
[2024-01-01 10:00:00]: local_role : Primary
[2024-01-01 10:00:00]: static_connections : 1
[2024-01-01 10:00:00]: db_state : Normal
[2024-01-01 10:00:00]: detail_information : All nodes are normal.
Part05-风哥经验总结与分享
5.1 启动关闭最佳实践
- 启动前检查:
- 检查配置文件是否正确
- 检查磁盘空间是否充足
- 检查网络连接是否正常
- 检查系统资源是否足够
from DB视频:www.itpux.com
- 关闭前准备:
- 通知业务方即将进行关闭操作
- 确保所有事务已提交
- 备份重要数据
- 选择合适的关闭模式
- 操作顺序:
- 集群启动:先启动主节点,再启动备节点
- 集群关闭:先关闭备节点,再关闭主节点
5.2 状态检查要点
- 定期检查:建立定期检查机制,及时发现问题
- 全面检查:不仅检查进程状态,还要检查性能和资源使用情况
- 异常处理:对于检查发现的异常,及时处理并记录
- 监控集成:将状态检查集成到监控系统中,实现自动报警
5.3 常见问题与解决方案
常见启动关闭问题及解决方法
- 问题1:启动失败,提示端口被占用
- 症状:启动数据库时提示端口已被占用
- 解决方案:检查是否有其他进程占用了该端口,使用lsof命令查看并终止占用端口的进程
- 问题2:关闭失败,提示有活跃连接
- 症状:关闭数据库时提示有活跃连接
- 解决方案:可以使用-m fast参数强制关闭,或者先终止所有连接后再关闭
- 问题3:状态检查显示集群异常
- 症状:集群状态检查显示节点异常
- 解决方案:检查异常节点的日志,分析原因,采取相应的修复措施
- 问题4:主备复制状态异常
- 症状:主备复制状态显示异常
- 解决方案:检查网络连接,确保备节点正常运行,必要时重建主备关系
风哥提示:启动关闭和状态检查是数据库日常运维的基础操作,掌握这些操作对于保证数据库的稳定运行至关重要。在生产环境中,应该建立完善的操作流程和监控机制,确保数据库的安全和稳定。
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
