opengauss数据库的日常运维操作

主从切换

1.1 在从节点执行如下命令
python 复制代码
gs_ctl switchover -D /opt/huawei/install/data/dn
cm_ctl switchover -n 1 -D /opt/huawei/install/data/dn
1.2 查看集群状态
python 复制代码
gs_om -t status --detail
1.3 如果主节点宕机,可以使用如下命令进行failover
python 复制代码
gs_ctl failover -D /opt/huawei/install/data/dn
1.4 switchover或failover成功后,需要保存当前主备机器信息
python 复制代码
gs_om -t refreshconf
1.5 当某个节点故障后,需要在故障的节点重建备库,进行修复

如果data直接删除了的话,需要先拷贝postgresql.conf到对应的dn目录下,并修改primary_conninfo的信息后build

python 复制代码
gs_ctl build -b auto -D /opt/huawei/install/data/dn

远程操作

opengauss不支持管理员远程登陆,需要创建应用用户进行登陆:

python 复制代码
gs_guc reload -N all -I all -c "listen_addresses = '*'"
gs_guc reload -N all -I all -h "host all all 0.0.0.0/0 sha256"
CREATE USER postgres WITH PASSWORD '123qqq...A';

开启归档

python 复制代码
mkdir -p /opt/huawei/install/wal_archive
gs_guc reload -N all -I all -c "archive_mode=on"
gs_guc reload -N all -I all -c "archive_command='cp %p /opt/huawei/install/wal_archive/%f'"

异步修改为同步

4.1 可以直接使用集群管理命令进行修改
python 复制代码
gs_guc reload -N all -I all -c "synchronous_commit = on"
gs_guc reload -N all -I all -c "synchronous_standby_names = 'FIRST 2(dn_6002,dn_6003)'"

有些参数必须重启集群才能生效:

python 复制代码
gs_om -t stop && gs_om -t start
4.2 也可以直接修改配置文件
python 复制代码
vi postgresql.conf
synchronous_standby_names = 'FIRST 2(dn_6002,dn_6003)'
gs_ctl -D /opt/huawei/install/data/dn reload

增加及删除节点

5.1 删除节点

查看当前备节点日志接收状态:

python 复制代码
select * from pg_stat_get_wal_receiver();

移除备节点,在主节点执行:

python 复制代码
gs_dropnode -U omm -G dbgrp -h 10.0.0.12

删除从节点数据,在从节点执行

参数表示将数据也一并删除卸载

python 复制代码
gs_uninstall --delete-data -L
5.2 添加节点

注意:在添加节点之前,要添加节点的目录,用户,软件包路径,以及环境变量要与主节点一致,具体操作略。

1)在主节点添加对所有节点的互信
python 复制代码
# 添加整个集群的IP地址:
cd /opt/software/openGauss/script
vi hostfile
10.0.0.10
10.0.0.11
10.0.0.12
# 创建root用户互信:
./gs_sshexkey -f hostfile
# 创建omm用户互信:
su - omm
cd /opt/software/openGauss/script
./gs_sshexkey -f hostfile
)在主节点修改XML配置文件,添加如下信息
python 复制代码
vi /opt/software/openGauss/cluster_config.xml
        <!-- 节点2上的部署信息 -->
        <DEVICE sn="gsdb02">
            <!-- 节点2的主机名称 -->
            <PARAM name="name" value="gsdb02"/>
            <!-- 节点2所在的AZ及AZ优先级 -->
            <PARAM name="azName" value="AZ1"/>
            <PARAM name="azPriority" value="1"/>
            <!-- 节点2的IP,如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->
            <PARAM name="backIp1" value="10.0.0.11"/>
            <PARAM name="sshIp1" value="10.0.0.11"/>
        </DEVICE>

        <!-- 节点3上的部署信息 -->
        <DEVICE sn="gsdb03">
            <!-- 节点3的主机名称 -->
            <PARAM name="name" value="gsdb03"/>
            <!-- 节点3所在的AZ及AZ优先级 -->
            <PARAM name="azName" value="AZ1"/>
            <PARAM name="azPriority" value="1"/>
            <!-- 节点3的IP,如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->
            <PARAM name="backIp1" value="10.0.0.12"/>
            <PARAM name="sshIp1" value="10.0.0.12"/>
        </DEVICE>
3)在主节点添加环境变量
python 复制代码
vi /etc/profile
export PGDATA=/opt/huawei/install/data/dn
export GPHOME=/opt/huawei/install/om
export GAUSSHOME=/opt/huawei/install/app
export PGHOST=/opt/huawei/install/om/omm_mppdb
export PATH=/root/gauss_om/omm/script:$GAUSSHOME/bin:$PATH

升 级

6.1 创建新包目录,并上传软件包
python 复制代码
mkdir -p /opt/software/gaussdb_upgrade
tar xf openGauss-3.0.0-CentOS-64bit-all.tar.gz
tar xf openGauss-3.0.0-CentOS-64bit-om.tar.g
chown -R omm:dbgrp /opt/software/
6.2 在就地升级或灰度升级前执行前置脚本gs_preinstall
python 复制代码
cd /opt/software/gaussdb_upgrade/script
./gs_preinstall -U omm -G dbgrp -X /opt/software/openGauss/cluster_config.xml
6.3 进行升级

使用gs_upgradectl脚本执行就地升级:

python 复制代码
cd /opt/software/gaussdb_upgrade/script
./gs_upgradectl -t auto-upgrade -X /opt/software/openGauss/cluster_config.xml

也可以进行灰度升级:

python 复制代码
gs_upgradectl -t auto-upgrade -X /opt/software/openGauss/cluster_config.xml --grey
6.4 升级版本查询
python 复制代码
gs_ssh -c "gsql -V"
6.5 完成升级提交
python 复制代码
gs_upgradectl -t commit-upgrade  -X /opt/software/openGauss/cluster_config.xml
6.6 也可以升级回滚
python 复制代码
gs_upgradectl -t auto-rollback  -X /opt/software/openGauss/cluster_config.xml

说明:如果数据异常,可以进行强制回滚:

python 复制代码
gs_upgradectl -t auto-rollback -X /opt/software/openGauss/cluster_config.xml --force

设置备机可读

python 复制代码
vi postgresql.conf
wal_level=hot_standby;
hot_standby = on

卸载opengauss

7.1 使用gs_uninstall卸载openGauss,在omm用户下执行
python 复制代码
gs_uninstall --delete-data
7.2 openGauss环境清理是对环 境准备脚本gs_preinstall所做设置的清理,在root下执行
python 复制代码
cd /opt/software/openGauss/script
./gs_postuninstall -U omm -X /opt/software/openGauss/cluster_config.xml --delete-user --delete-group
7.3 删除残留软件目录
python 复制代码
rm -rf /opt/*

启停opengauss

python 复制代码
gs_ctl -t start
gs_ctl -t stop

状态查询

python 复制代码
gs_om -t status --detail

查看某主机上的实例状态:

python 复制代码
gs_om -t status --h  db01

cm基础命令

python 复制代码
cm_ctl query -Civdp
cm_ctl stop
cm_ctl start
cm_ctl switchover -n 2 -D dn1
cm_ctl build -n 2 -D dn1

--cm_ctl start/stop数据库

--一主多备数据库部署模式下启动/停止所有数据库服务:

python 复制代码
cm_ctl stop
cm_ctl start

--启动/停止单个主机上的所有实例(含CM):

python 复制代码
cm_ctl stop -n nodeid
cm_ctl start -n nodeid

--单独启动/停止某个实例进程(数据库进程):

python 复制代码
cm_ctl stop -n nodeid -D datadir
cm_ctl start -n nodeid -D datadir

--启动/停止整个AZ:

python 复制代码
cm_ctl stop -z ALL
cm_ctl start -z ALL

--重复停止所有/某个实例:

python 复制代码
cm_ctl stop -n nodeid
cm_ctl stop -n nodeid

--重复启动所有/某个实例:

python 复制代码
cm_ctl start -n nodeid
cm_ctl start -n nodeid

--&&连接使用:

python 复制代码
cm_ctl stop && cm_ctl start
cm_ctl stop -n nodeid && cm_ctl start -n nodeid

后续有遇到问题在更新,看到这里了,点赞关注支持一下吧~~~~~

相关推荐
网硕互联的小客服25 分钟前
遇到网站500内部服务器错误如何处理?如何预防这样的问题发生?
运维·服务器·安全
叮咚侠28 分钟前
Ubuntu 24.04.3 LTS 中 vdb 的 UUID 永久挂载没有显示的磁盘的操作步骤
linux·运维·ubuntu·挂载磁盘
GAOJ_K31 分钟前
滚柱导轨中的密封件如何判断是否需更换?
运维·人工智能·科技·自动化·制造
代码or搬砖31 分钟前
SQL核心语法总结:从基础操作到高级窗口函数
java·数据库·sql
38 分钟前
TIDB——TIKV——读写与coprocessor
数据库·分布式·tidb·
skyyx20021 小时前
写给网工新手:子网掩码基本概念和一些计算方法
运维·网络
大猫和小黄1 小时前
若依微服务全面适配PostgreSQL-OpenGauss数据库
数据库·微服务·postgresql·若依
老徐电商数据笔记2 小时前
技术复盘第二篇:电商数据主题域划分企业级实践
大数据·数据库·数据仓库·零售·教育电商·技术面试
jfqqqqq2 小时前
postgres查询、重设自增序列的起始值
数据库·sql·postgres·自增序列
杰克崔2 小时前
进程内mmap锁相互干扰问题
linux·运维·服务器·车载系统