【我和openGauss的故事】体验openGauss 5.0极简版一主一备部署,延时回放和主备切换功能

老老老JR老北
发布于 2023-9-6 15:22
浏览
0收藏

概要

openGauss的安装在官方文档的描述中,以企业生产环境为标准进行安装部署较为详细。但在个人基本的功能测试需求下,这样的安装操作显得有些复杂。

极简版安装的使用主体主要针对高校和个人测试环境,相对企业安装流程更简单快捷,更加适合高校学生或者个人功能测试的场景,该软件包中并不包含OM工具,采用脚本可以实现一键式安装部署一主一备节点。

默认情况下,openGauss备机会尽快恢复来自于主机的XLOG记录。这个功能允许备机将回放延时一段指定的时间后进行回放。提供一份可查询一段时间之前的数据副本,可以更方便的纠正用户误操作等错误。

openGauss支持备机延时回放,本文通过使用极简版进行一主一备安装部署,体验延时回放及主备切换功能。希望通过基本的操作示例对大家能有所帮助。

安装准备

前提条件:

  • 获取openGauss极简版安装包
  • 创建用户组和普通用户
  • 普通用户必须有数据库包解压路径、安装路径的读、写和执行操作权限,并且安装路径必须为空。
  • 普通用户对下载的openGauss压缩包有执行权限。
  • 安装前请检查指定的openGauss端口矩阵中所有端口是否被占用,如果被占用请更改端口或者停止当前使用端口进程。

获取安装包

从openGauss开源社区下载对应平台的安装包,选择极简版安装包(不安装OM等组件)。

准备软硬件安装环境

我们使用x86_64平台的CentOS 7.6操作系统,CPU:2核3.0GHz,内存:16GB,硬盘空间:300GB

软件依赖要求

openGauss的软件依赖要求如表1 软件依赖要求所示。

表1 软件依赖要求

所需软件

建议版本

libaio-devel

建议版本:0.3.109-13

flex

要求版本:2.5.31 以上

bison

建议版本:2.7-4

ncurses-devel

建议版本:5.9-13.20130511

glibc-devel

建议版本:2.17-111

patch

建议版本:2.7.1-10

redhat-lsb-core

建议版本:4.1

readline-devel

建议版本:7.0-13

libnsl(openEuler+x86环境中)

建议版本:2.28-36

使用操作系统ISO源中,下列依赖软件的默认安装包,若不存在下列软件,可参看软件对应的建议版本。

# mount -o loop /mnt/OS/Linux/CentOS/CentOS-7-x86_64-Everything-1810.iso /media/
# vi /etc/yum.repos.d/iso.repo
---添加如下内容:
[iso]
name=iso
baseurl=file:///media
enable=1
gpgcheck=0

# yum makecache

# yum install -y libaio-devel flex bison ncurses-devel glibc-devel patch redhat-lsb-core readline-devel
修改操作系统配置

---关闭防火墙
# systemctl stop firewalld
# systemctl disable firewalld

---永久关闭SELinux
# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux

---配置文件系统描述符
# echo "* soft nofile 1000000" >>/etc/security/limits.conf
# echo "* hard nofile 1000000" >>/etc/security/limits.conf

---重启生效
# reboot

创建组和用户

# groupadd dbgroup
# useradd -g dbgroup omm
# passwd omm

解压安装包

解压安装包,检查安装目录及文件是否齐全。在安装包所在目录执行以下命令:

# cd /opt
# mkdir openGaussSimp
# chown -R omm:dbgroup openGauss
$ tar -jxf /stage/openGauss-5.0.0-CentOS-64bit.tar.bz2 -C /opt/openGaussSimp/
$ ll /opt/openGaussSimp/
总用量 16
drwxr-xr-x. 2 omm dbgroup 4096 3月 29 03:20 bin
drwxr-xr-x. 3 omm dbgroup 22 3月 29 03:20 etc
drwxr-xr-x. 3 omm dbgroup 24 3月 29 03:20 include
drwxr-xr-x. 4 omm dbgroup 95 3月 29 03:20 jre
drwxr-xr-x. 5 omm dbgroup 4096 3月 29 03:20 lib
drwxr-xr-x. 5 omm dbgroup 53 3月 29 03:20 share
drwxr-xr-x. 2 omm dbgroup 78 3月 29 03:20 simpleInstall
-rw-r--r--. 1 omm dbgroup 32 3月 29 03:20 version.cfg

一主一备节点安装部署

安装

$ cd /opt/openGauss/simpleInstall/
$ ll
  总用量 56
  -rw-r--r--. 1 omm dbgroup 10827 3月 29 03:20 finance.sql
  -rw-r--r--. 1 omm dbgroup 13009 3月 29 03:20 install.sh
  -rw-r--r--. 1 omm dbgroup 5056 3月 29 03:20 README.md
  -rw-r--r--. 1 omm dbgroup 19713 3月 29 03:20 school.sql


$ sh install.sh -w password --multinode
[step 1]: check parameter
[step 2]: check install env and os setting
[step 3]: change_gausshome_owner
[step 4]: set environment variables

[init primary datanode.]
The files belonging to this database system will be owned by user "omm".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default text search configuration will be set to "english".

creating directory /opt/openGauss/data/master ... ok
creating subdirectories ... in ordinary occasionok
creating configuration files ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 1024MB
Begin init undo subsystem meta.
[INIT UNDO] Init undo subsystem meta successfully.
creating template1 database in /opt/openGauss/data/master/base/1 ... The core dump path is an invalid directory
2023-07-20 16:55:31.270 [unknown] [unknown] localhost 139958306611456 0[0:0#0] [BACKEND] WARNING: macAddr is 55880/310234098, sysidentifier is 3662156413/3421696841, randomNum is 3743216457
ok
initializing pg_authid ... ok
setting password ... ok
initializing dependencies ... ok
loading PL/pgSQL server-side language ... ok
creating system views ... ok
creating performance views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
initialize global configure for bucketmap length ... ok
creating information schema ... ok
loading foreign-data wrapper for distfs access ... ok
loading foreign-data wrapper for log access ... ok
loading hstore extension ... ok
loading foreign-data wrapper for MOT access ... ok
loading security plugin ... ok
update system tables ... ok
creating snapshots catalog ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
freezing database template0 ... ok
freezing database template1 ... ok
freezing database postgres ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run gs_initdb.

Success. You can now start the database server of single node using:

gaussdb -D /opt/openGauss/data/master --single_node

or
 gs_ctl start -D /opt/openGauss/data/master -Z single_node -l logfile

[init slave datanode.]
The files belonging to this database system will be owned by user "omm".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default text search configuration will be set to "english".

creating directory /opt/openGauss/data/slave ... ok
creating subdirectories ... in ordinary occasionok
creating configuration files ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 1024MB
Begin init undo subsystem meta.
[INIT UNDO] Init undo subsystem meta successfully.
creating template1 database in /opt/openGauss/data/slave/base/1 ... The core dump path is an invalid directory
2023-07-20 16:55:54.473 [unknown] [unknown] localhost 139719775543552 0[0:0#0] [BACKEND] WARNING: macAddr is 55880/310234098, sysidentifier is 3662156413/3421692616, randomNum is 2853364424
ok
initializing pg_authid ... ok
setting password ... ok
initializing dependencies ... ok
loading PL/pgSQL server-side language ... ok
creating system views ... ok
creating performance views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
initialize global configure for bucketmap length ... ok
creating information schema ... ok
loading foreign-data wrapper for distfs access ... ok
loading foreign-data wrapper for log access ... ok
loading hstore extension ... ok
loading foreign-data wrapper for MOT access ... ok
loading security plugin ... ok
update system tables ... ok
creating snapshots catalog ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
freezing database template0 ... ok
freezing database template1 ... ok
freezing database postgres ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run gs_initdb.

Success. You can now start the database server of single node using:

gaussdb -D /opt/openGauss/data/slave --single_node

or
 gs_ctl start -D /opt/openGauss/data/slave -Z single_node -l logfile

[config datanode.]
remote_read_mode = non_authentication
host all all 192.168.9.191/32 trust
[start primary datanode.]
[2023-07-20 16:56:17.641][15074][][gs_ctl]: gs_ctl started,datadir is /opt/openGauss/data/master 
[2023-07-20 16:56:17.676][15074][][gs_ctl]: waiting for server to start...
.0 LOG: [Alarm Module]can not read GAUSS_WARNING_TYPE env.

0 LOG: [Alarm Module]Host Name: L7DBMerge.base.online

0 LOG: [Alarm Module]Host IP: L7DBMerge.base.online. Copy hostname directly in case of taking 10s to use 'gethostbyname' when /etc/hosts does not contain <HOST IP>

0 LOG: [Alarm Module]Cluster Name: dbCluster

0 LOG: [Alarm Module]Invalid data in AlarmItem file! Read alarm English name failed! line: 57

0 WARNING: failed to open feature control file, please check whether it exists: FileName=gaussdb.version, Errno=2, Errmessage=No such file or directory.
0 WARNING: failed to parse feature control file: gaussdb.version.
0 WARNING: Failed to load the product control file, so gaussdb cannot distinguish product version.
The core dump path is an invalid directory
2023-07-20 16:56:17.745 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [BACKEND] LOG: when starting as multi_standby mode, we couldn't support data replicaton.
gaussdb.state does not exist, and skipt setting since it is optional.2023-07-20 16:56:17.750 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [BACKEND] LOG: [Alarm Module]can not read GAUSS_WARNING_TYPE env.

2023-07-20 16:56:17.750 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [BACKEND] LOG: [Alarm Module]Host Name: L7DBMerge.base.online

2023-07-20 16:56:17.750 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [BACKEND] LOG: [Alarm Module]Host IP: L7DBMerge.base.online. Copy hostname directly in case of taking 10s to use 'gethostbyname' when /etc/hosts does not contain <HOST IP>

2023-07-20 16:56:17.750 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [BACKEND] LOG: [Alarm Module]Cluster Name: dbCluster

2023-07-20 16:56:17.750 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [BACKEND] LOG: [Alarm Module]Invalid data in AlarmItem file! Read alarm English name failed! line: 57

2023-07-20 16:56:17.765 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [BACKEND] LOG: loaded library "security_plugin"
2023-07-20 16:56:17.775 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [BACKEND] WARNING: could not create any HA TCP/IP sockets
2023-07-20 16:56:17.799 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [BACKEND] LOG: InitNuma numaNodeNum: 1 numa_distribute_mode: none inheritThreadPool: 0.
2023-07-20 16:56:17.799 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [BACKEND] LOG: reserved memory for backend threads is: 220 MB
2023-07-20 16:56:17.799 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [BACKEND] LOG: reserved memory for WAL buffers is: 128 MB
2023-07-20 16:56:17.799 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [BACKEND] LOG: Set max backend reserve memory is: 348 MB, max dynamic memory is: 8143 MB
2023-07-20 16:56:17.799 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [BACKEND] LOG: shared memory 3284 Mbytes, memory context 8491 Mbytes, max process memory 12288 Mbytes
2023-07-20 16:56:17.799 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [BACKEND] LOG: shared memory that key is 5432001 is owned by pid 1786
2023-07-20 16:56:17.849 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [CACHE] LOG: set data cache size(402653184)
2023-07-20 16:56:17.873 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [SEGMENT_PAGE] LOG: Segment-page constants: DF_MAP_SIZE: 8156, DF_MAP_BIT_CNT: 65248, DF_MAP_GROUP_EXTENTS: 4175872, IPBLOCK_SIZE: 8168, EXTENTS_PER_IPBLOCK: 1021, IPBLOCK_GROUP_SIZE: 4090, BMT_HEADER_LEVEL0_TOTAL_PAGES: 8323072, BktMapEntryNumberPerBlock: 2038, BktMapBlockNumber: 25, BktBitMaxMapCnt: 512
2023-07-20 16:56:17.889 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [BACKEND] LOG: gaussdb: fsync file "/opt/openGauss/data/master/gaussdb.state.temp" success
2023-07-20 16:56:17.890 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [BACKEND] LOG: create gaussdb state file success: db state(STARTING_STATE), server mode(Primary), connection index(1)
2023-07-20 16:56:17.912 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [BACKEND] LOG: max_safe_fds = 974, usable_fds = 1000, already_open = 16
The core dump path is an invalid directory
2023-07-20 16:56:17.914 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [BACKEND] LOG: user configure file is not found, it will be created.
2023-07-20 16:56:17.918 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [BACKEND] LOG: the configure file /opt/openGauss/etc/gscgroup_omm.cfg doesn't exist or the size of configure file has changed. Please create it by root user!
2023-07-20 16:56:17.918 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [BACKEND] LOG: Failed to parse cgroup config file.
2023-07-20 16:56:17.926 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [EXECUTOR] WARNING: Failed to obtain environment value $GAUSSLOG!
2023-07-20 16:56:17.926 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [EXECUTOR] DETAIL: N/A
2023-07-20 16:56:17.926 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [EXECUTOR] CAUSE: Incorrect environment value.
2023-07-20 16:56:17.926 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [EXECUTOR] ACTION: Please refer to backend log for more details.
2023-07-20 16:56:17.927 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [EXECUTOR] WARNING: Failed to obtain environment value $GAUSSLOG!
2023-07-20 16:56:17.927 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [EXECUTOR] DETAIL: N/A
2023-07-20 16:56:17.927 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [EXECUTOR] CAUSE: Incorrect environment value.
2023-07-20 16:56:17.927 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [EXECUTOR] ACTION: Please refer to backend log for more details.
2023-07-20 16:56:17.927 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [EXECUTOR] WARNING: Failed to obtain environment value $GAUSSLOG!
2023-07-20 16:56:17.927 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [EXECUTOR] DETAIL: N/A
2023-07-20 16:56:17.927 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [EXECUTOR] CAUSE: Incorrect environment value.
2023-07-20 16:56:17.927 [unknown] [unknown] localhost 139830592221440 0[0:0#0] 0 [EXECUTOR] ACTION: Please refer to backend log for more details.

[2023-07-20 16:56:18.681][15074][][gs_ctl]: done
[2023-07-20 16:56:18.681][15074][][gs_ctl]: server started (/opt/openGauss/data/master)
[build and start slave datanode.]
[2023-07-20 16:56:18.691][15146][][gs_ctl]: gs_ctl full build ,datadir is /opt/openGauss/data/slave
[2023-07-20 16:56:18.691][15146][][gs_ctl]: fopen build pid file "/opt/openGauss/data/slave/gs_build.pid" success
[2023-07-20 16:56:18.691][15146][][gs_ctl]: fprintf build pid file "/opt/openGauss/data/slave/gs_build.pid" success
[2023-07-20 16:56:18.694][15146][][gs_ctl]: fsync build pid file "/opt/openGauss/data/slave/gs_build.pid" success
[2023-07-20 16:56:18.694][15146][][gs_ctl]: stop failed, killing gaussdb by force ...
[2023-07-20 16:56:18.694][15146][][gs_ctl]: command [ps c -eo pid,euid,cmd | grep gaussdb | grep -v grep | awk '{if($2 == curuid && $1!="-n") print "/proc/"$1"/cwd"}' curuid=`id -u`| xargs ls -l | awk '{if ($NF=="/opt/openGauss/data/slave") print $(NF-2)}' | awk -F/ '{print $3 }' | xargs kill -9 >/dev/null 2>&1 ] path: [/opt/openGauss/data/slave] 
[2023-07-20 16:56:18.712][15146][][gs_ctl]: server stopped
[2023-07-20 16:56:18.712][15146][][gs_ctl]: current workdir is (/opt/openGauss/simpleInstall).
[2023-07-20 16:56:18.713][15146][][gs_ctl]: set gaussdb state file when full build build:db state(BUILDING_STATE), server mode(STANDBY_MODE), build mode(FULL_BUILD).
[2023-07-20 16:56:18.713][15146][datanode2][gs_ctl]: Get repl_auth_mode is and repl_uuid is 
[2023-07-20 16:56:18.717][15146][datanode2][gs_ctl]: build try host(192.168.9.191) port(5433) success
[2023-07-20 16:56:18.717][15146][datanode2][gs_ctl]: connected to server success, build started.
[2023-07-20 16:56:18.752][15146][datanode2][gs_ctl]: clear old target dir success
[2023-07-20 16:56:18.752][15146][datanode2][gs_ctl]: create build tag file success
[2023-07-20 16:56:18.752][15146][datanode2][gs_ctl]: create build tag file again success
[2023-07-20 16:56:18.752][15146][datanode2][gs_ctl]: get system identifier success
[2023-07-20 16:56:18.771][15146][datanode2][gs_ctl]: receiving and unpacking files...
[2023-07-20 16:56:18.771][15146][datanode2][gs_ctl]: create backup label success
INFO: The starting position of the xlog copy of the full build is: 0/2434A60. The slot minimum LSN is: 0/0. The disaster slot minimum LSN is: 0/0. The logical slot minimum LSN is: 0/0.
[2023-07-20 16:56:18.969][15146][datanode2][gs_ctl]: xlog start point: 0/2434A60
[2023-07-20 16:56:18.969][15146][datanode2][gs_ctl]: begin build tablespace list
[2023-07-20 16:56:18.969][15146][datanode2][gs_ctl]: finish build tablespace list
[2023-07-20 16:56:18.969][15146][datanode2][gs_ctl]: begin get xlog by xlogstream
[2023-07-20 16:56:18.969][15146][datanode2][gs_ctl]: starting background WAL receiver
[2023-07-20 16:56:18.969][15146][datanode2][gs_ctl]: starting walreceiver
[2023-07-20 16:56:18.970][15146][datanode2][gs_ctl]: begin receive tar files
[2023-07-20 16:56:18.970][15146][datanode2][gs_ctl]: receiving and unpacking files...
[2023-07-20 16:56:18.975][15146][datanode2][gs_ctl]: build try host(192.168.9.191) port(5433) success
[2023-07-20 16:56:18.975][15146][datanode2][gs_ctl]: check identify system success
[2023-07-20 16:56:18.983][15146][datanode2][gs_ctl]: send START_REPLICATION 0/2000000 success
[2023-07-20 16:56:19.645][15146][datanode2][gs_ctl]: finish receive tar files
[2023-07-20 16:56:19.645][15146][datanode2][gs_ctl]: xlog end point: 0/3000058
[2023-07-20 16:56:19.646][15146][datanode2][gs_ctl]: fetching MOT checkpoint
gs_ctl: no mot checkpoint exists
[2023-07-20 16:56:19.646][15146][datanode2][gs_ctl]: waiting for background process to finish streaming...
[2023-07-20 16:56:24.005][15146][datanode2][gs_ctl]: starting fsync all files come from source.
[2023-07-20 16:56:37.583][15146][datanode2][gs_ctl]: finish fsync all files.
[2023-07-20 16:56:37.594][15146][datanode2][gs_ctl]: build dummy dw file success
[2023-07-20 16:56:37.594][15146][datanode2][gs_ctl]: rename build status file success
[2023-07-20 16:56:37.596][15146][datanode2][gs_ctl]: full build build completed(/opt/openGauss/data/slave).
[2023-07-20 16:56:37.629][15146][datanode2][gs_ctl]: waiting for server to start...
.0 LOG: [Alarm Module]can not read GAUSS_WARNING_TYPE env.

0 LOG: [Alarm Module]Host Name: L7DBMerge.base.online

0 LOG: [Alarm Module]Host IP: L7DBMerge.base.online. Copy hostname directly in case of taking 10s to use 'gethostbyname' when /etc/hosts does not contain <HOST IP>

0 LOG: [Alarm Module]Cluster Name: dbCluster

0 LOG: [Alarm Module]Invalid data in AlarmItem file! Read alarm English name failed! line: 57

0 WARNING: failed to open feature control file, please check whether it exists: FileName=gaussdb.version, Errno=2, Errmessage=No such file or directory.
0 WARNING: failed to parse feature control file: gaussdb.version.
0 WARNING: Failed to load the product control file, so gaussdb cannot distinguish product version.
The core dump path is an invalid directory
2023-07-20 16:56:37.699 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [BACKEND] LOG: when starting as multi_standby mode, we couldn't support data replicaton.
2023-07-20 16:56:37.706 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [BACKEND] LOG: [Alarm Module]can not read GAUSS_WARNING_TYPE env.

2023-07-20 16:56:37.706 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [BACKEND] LOG: [Alarm Module]Host Name: L7DBMerge.base.online

2023-07-20 16:56:37.706 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [BACKEND] LOG: [Alarm Module]Host IP: L7DBMerge.base.online. Copy hostname directly in case of taking 10s to use 'gethostbyname' when /etc/hosts does not contain <HOST IP>

2023-07-20 16:56:37.706 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [BACKEND] LOG: [Alarm Module]Cluster Name: dbCluster

2023-07-20 16:56:37.706 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [BACKEND] LOG: [Alarm Module]Invalid data in AlarmItem file! Read alarm English name failed! line: 57

2023-07-20 16:56:37.722 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [BACKEND] LOG: loaded library "security_plugin"
2023-07-20 16:56:37.731 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [BACKEND] WARNING: could not create any HA TCP/IP sockets
2023-07-20 16:56:37.766 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [BACKEND] LOG: InitNuma numaNodeNum: 1 numa_distribute_mode: none inheritThreadPool: 0.
2023-07-20 16:56:37.766 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [BACKEND] LOG: reserved memory for backend threads is: 220 MB
2023-07-20 16:56:37.766 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [BACKEND] LOG: reserved memory for WAL buffers is: 128 MB
2023-07-20 16:56:37.766 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [BACKEND] LOG: Set max backend reserve memory is: 348 MB, max dynamic memory is: 8143 MB
2023-07-20 16:56:37.766 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [BACKEND] LOG: shared memory 3284 Mbytes, memory context 8491 Mbytes, max process memory 12288 Mbytes
2023-07-20 16:56:37.766 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [BACKEND] LOG: shared memory that key is 5632001 is owned by pid 1894
2023-07-20 16:56:37.822 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [CACHE] LOG: set data cache size(402653184)
2023-07-20 16:56:37.848 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [SEGMENT_PAGE] LOG: Segment-page constants: DF_MAP_SIZE: 8156, DF_MAP_BIT_CNT: 65248, DF_MAP_GROUP_EXTENTS: 4175872, IPBLOCK_SIZE: 8168, EXTENTS_PER_IPBLOCK: 1021, IPBLOCK_GROUP_SIZE: 4090, BMT_HEADER_LEVEL0_TOTAL_PAGES: 8323072, BktMapEntryNumberPerBlock: 2038, BktMapBlockNumber: 25, BktBitMaxMapCnt: 512
2023-07-20 16:56:37.874 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [BACKEND] LOG: gaussdb: fsync file "/opt/openGauss/data/slave/gaussdb.state.temp" success
2023-07-20 16:56:37.874 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [BACKEND] LOG: create gaussdb state file success: db state(STARTING_STATE), server mode(Standby), connection index(1)
2023-07-20 16:56:37.897 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [BACKEND] LOG: max_safe_fds = 972, usable_fds = 1000, already_open = 18
The core dump path is an invalid directory
2023-07-20 16:56:37.899 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [BACKEND] LOG: the configure file /opt/openGauss/etc/gscgroup_omm.cfg doesn't exist or the size of configure file has changed. Please create it by root user!
2023-07-20 16:56:37.899 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [BACKEND] LOG: Failed to parse cgroup config file.
2023-07-20 16:56:37.912 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [EXECUTOR] WARNING: Failed to obtain environment value $GAUSSLOG!
2023-07-20 16:56:37.912 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [EXECUTOR] DETAIL: N/A
2023-07-20 16:56:37.912 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [EXECUTOR] CAUSE: Incorrect environment value.
2023-07-20 16:56:37.912 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [EXECUTOR] ACTION: Please refer to backend log for more details.
2023-07-20 16:56:37.913 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [EXECUTOR] WARNING: Failed to obtain environment value $GAUSSLOG!
2023-07-20 16:56:37.913 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [EXECUTOR] DETAIL: N/A
2023-07-20 16:56:37.913 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [EXECUTOR] CAUSE: Incorrect environment value.
2023-07-20 16:56:37.913 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [EXECUTOR] ACTION: Please refer to backend log for more details.
2023-07-20 16:56:37.913 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [EXECUTOR] WARNING: Failed to obtain environment value $GAUSSLOG!
2023-07-20 16:56:37.913 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [EXECUTOR] DETAIL: N/A
2023-07-20 16:56:37.913 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [EXECUTOR] CAUSE: Incorrect environment value.
2023-07-20 16:56:37.913 [unknown] [unknown] localhost 140210215690496 0[0:0#0] 0 [EXECUTOR] ACTION: Please refer to backend log for more details.
.................
[2023-07-20 16:56:55.660][15146][datanode2][gs_ctl]: done
[2023-07-20 16:56:55.660][15146][datanode2][gs_ctl]: server started (/opt/openGauss/data/slave)
[2023-07-20 16:56:55.660][15146][datanode2][gs_ctl]: fopen build pid file "/opt/openGauss/data/slave/gs_build.pid" success
[2023-07-20 16:56:55.660][15146][datanode2][gs_ctl]: fprintf build pid file "/opt/openGauss/data/slave/gs_build.pid" success
[2023-07-20 16:56:55.727][15146][datanode2][gs_ctl]: fsync build pid file "/opt/openGauss/data/slave/gs_build.pid" success
import sql file
Would you like to create a demo database (yes/no)? yes
Load demoDB [school,finance] success.
[complete successfully]: You can start or stop the database server using:
 primary: gs_ctl start|stop|restart -D $GAUSSHOME/data/master -M primary
 standby: gs_ctl start|stop|restart -D $GAUSSHOME/data/slave -M standby

安装后检查

安装执行完成后,使用ps和gs_ctl查看进程是否正常。

$ ps ux | grep gaussdb
omm      15077  1.7  8.2 6124380 675456 ?      Ssl  16:56   0:02 /opt/openGauss/bin/gaussdb -D /opt/openGauss/data/master -M primary
omm      15173  2.0  5.4 6345480 444352 ?      Ssl  16:56   0:02 /opt/openGauss/bin/gaussdb -D /opt/openGauss/data/slave -M standby
$ gs_ctl query -D /opt/openGaussSimp/data/master/
[2023-07-24 17:31:43.810][17978][][gs_ctl]: gs_ctl query ,datadir is /opt/openGauss/data/master 
 HA state:           
    local_role                     : Primary
    static_connections             : 1
    db_state                       : Normal
    detail_information             : Normal

 Senders info:       
    sender_pid                     : 15236
    local_role                     : Primary
    peer_role                      : Standby
    peer_state                     : Normal
    state                          : Streaming
    sender_sent_location           : 0/403E448
    sender_write_location          : 0/403E448
    sender_flush_location          : 0/403E448
    sender_replay_location         : 0/403E448
    receiver_received_location     : 0/403E448
    receiver_write_location        : 0/403E448
    receiver_flush_location        : 0/403E448
    receiver_replay_location       : 0/403E448
    sync_percent                   : 100%
    sync_state                     : Sync
    sync_priority                  : 1
    sync_most_available            : Off
    channel                        : 192.168.9.191:5433-->192.168.9.191:43042

 Receiver info:      
No information 


[omm@L7DBMerge ~]$ gs_ctl query -D /opt/openGaussSimp/data/slave/
[2023-07-24 17:33:08.807][18087][][gs_ctl]: gs_ctl query ,datadir is /opt/openGauss/data/slave 
 HA state:           
    local_role                     : Standby
    static_connections             : 1
    db_state                       : Normal
    detail_information             : Normal

 Senders info:       
No information 
 Receiver info:      
    receiver_pid                   : 15235
    local_role                     : Standby
    peer_role                      : Primary
    peer_state                     : Normal
    state                          : Normal
    sender_sent_location           : 0/403E568
    sender_write_location          : 0/403E568
    sender_flush_location          : 0/403E568
    sender_replay_location         : 0/403E568
    receiver_received_location     : 0/403E568
    receiver_write_location        : 0/403E568
    receiver_flush_location        : 0/403E568
    receiver_replay_location       : 0/403E568
    sync_percent                   : 100%
    channel                        : 192.168.9.191:43042<--192.168.9.191:5433

openGauss主节点端口号,默认5432。备节点端口号会使用主端口号+200,默认5632。

连接数据库

---连接主节点:
$ gsql -d postgres -p 5432
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:07:56 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

openGauss=#


---连接备节点:
$ gsql -d postgres -p 5632
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:07:56 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

openGauss=#

启停主备节点

主节点: 
gs_ctl start|stop|restart -D /opt/openGaussSimp/data/master -M primary

备节点: 
gs_ctl start|stop|restart -D /opt/openGaussSimp/data/slave -M standby

延时回放

查看对应参数值

---主节点:
openGauss=# show synchronous_commit;
 synchronous_commit 
--------------------
 on
(1 row)

openGauss=# show recovery_min_apply_delay;
 recovery_min_apply_delay 
--------------------------
 0
(1 row)

---备节点:
openGauss=# show synchronous_commit;
 synchronous_commit 
--------------------
 on
(1 row)

openGauss=# show recovery_min_apply_delay;
 recovery_min_apply_delay 
--------------------------
 0
(1 row)

主备节点立即复制

---主节点创建表并插入记录
openGauss=# \d+
No relations found.

openGauss=# create table t_delay (id int,instime date);
CREATE TABLE


openGauss=# \d+
                                      List of relations
 Schema |  Name   | Type  | Owner |  Size   |             Storage              | Description 
--------+---------+-------+-------+---------+----------------------------------+-------------
 public | t_rapid | table | omm   | 0 bytes | {orientation=row,compression=no} | 
(1 row)



openGauss=# insert into t_rapid values(1,localtimestamp);
INSERT 0 1
openGauss=# select now();select * from t_rapid;
              now              
-------------------------------
 2023-07-25 10:14:19.756149+08
(1 row)

 id |       instime       
----+---------------------
  1 | 2023-07-25 10:14:18
(1 row)

openGauss=# insert into t_rapid values(2,localtimestamp);
INSERT 0 1
openGauss=# select now();select * from t_rapid;
              now              
-------------------------------
 2023-07-25 10:15:00.765355+08
(1 row)

 id |       instime       
----+---------------------
  1 | 2023-07-25 10:14:18
  2 | 2023-07-25 10:14:59
(2 rows)







---备节点:

openGauss=# \d+
                                      List of relations
 Schema |  Name   | Type  | Owner |  Size   |             Storage              | Description 
--------+---------+-------+-------+---------+----------------------------------+-------------
 public | t_rapid | table | omm   | 0 bytes | {orientation=row,compression=no} | 
(1 row)

openGauss=# select now();select * from t_rapid;
              now              
-------------------------------
 2023-07-25 10:14:22.040042+08
(1 row)

 id |       instime       
----+---------------------
  1 | 2023-07-25 10:14:18
(1 row)

openGauss=# select now();select * from t_rapid;
              now              
-------------------------------
 2023-07-25 10:15:02.369679+08
(1 row)

 id |       instime       
----+---------------------
  1 | 2023-07-25 10:14:18
  2 | 2023-07-25 10:14:59
(2 rows)

主备节点延时回放

配置备节点参数

---延时回放时间设置为60秒
$ gs_guc reload -D /opt/openGaussSimp/data/master/ -c "recovery_min_apply_delay = 60000"
The gs_guc run with the following arguments: [gs_guc -D /opt/openGaussSimp/data/master/ -c recovery_min_apply_delay = 60000 reload ].
expected instance path: [/opt/openGaussSimp/data/master/postgresql.conf]
gs_guc reload: recovery_min_apply_delay=60000: [/opt/openGaussSimp/data/master/postgresql.conf]
server signaled

Total instances: 1. Failed instances: 0.
Success to perform gs_guc!


---主节点:
openGauss=# show recovery_min_apply_delay;
 recovery_min_apply_delay 
--------------------------
 0
(1 row)


---备节点:
openGauss=# show recovery_min_apply_delay;
 recovery_min_apply_delay 
--------------------------
 1min
(1 row)
验证延时回放

---主节点:
openGauss=# select now();create table t_delay (id int,instime date);
              now              
-------------------------------
 2023-07-25 10:19:15.213658+08
(1 row)

CREATE TABLE
openGauss=# \d+
                                       List of relations
 Schema |  Name   | Type  | Owner |    Size    |             Storage              | Description 
--------+---------+-------+-------+------------+----------------------------------+-------------
 public | t_delay | table | omm   | 0 bytes    | {orientation=row,compression=no} | 
 public | t_rapid | table | omm   | 8192 bytes | {orientation=row,compression=no} | 
(2 rows)

openGauss=# insert into t_delay values(1,localtimestamp);
INSERT 0 1
openGauss=# select now();select * from t_delay;
              now              
-------------------------------
 2023-07-25 10:21:33.585342+08
(1 row)

 id |       instime       
----+---------------------
  1 | 2023-07-25 10:21:28
(1 row)

openGauss=# insert into t_delay values(2,localtimestamp);
INSERT 0 1
openGauss=# select now();select * from t_delay;
              now              
-------------------------------
 2023-07-25 10:22:42.892056+08
(1 row)

 id |       instime       
----+---------------------
  1 | 2023-07-25 10:21:28
  2 | 2023-07-25 10:22:42
(2 rows)



---备节点:
openGauss=# select now();select * from t_delay;
              now              
-------------------------------
 2023-07-25 10:22:22.012958+08
(1 row)

 id | instime 
----+---------
(0 rows)
---1分钟内没有数据复制过来

openGauss=# select now();select * from t_delay;
             now              
------------------------------
 2023-07-25 10:22:31.88414+08
(1 row)

 id |       instime       
----+---------------------
  1 | 2023-07-25 10:21:28
(1 row)
---1分钟后第一条数据复制过来

openGauss=# select now();select * from t_delay;
             now              
------------------------------
 2023-07-25 10:23:38.93457+08
(1 row)

 id |       instime       
----+---------------------
  1 | 2023-07-25 10:21:28
(1 row)
---第2条数据在1分钟内也没有复制过来

openGauss=# select now();select * from t_delay;
              now              
-------------------------------
 2023-07-25 10:23:43.511753+08
(1 row)

 id |       instime       
----+---------------------
  1 | 2023-07-25 10:21:28
  1 | 2023-07-25 10:22:42
(2 rows)
---主节点插入第2条记录1分钟后,复制到备节点可以查询到
验证主节点删除表,在备库点查询该表

openGauss=# drop table t_delay;
DROP TABLE

openGauss=# \d+
                                       List of relations
 Schema |  Name   | Type  | Owner |    Size    |             Storage              | Description 
--------+---------+-------+-------+------------+----------------------------------+-------------
 public | t_rapid | table | omm   | 8192 bytes | {orientation=row,compression=no} | 
(1 row)


---延时时间段内在备节点查询该表会挂起会话,备节点回放后才会返回
openGauss-# select now();select * from t_delay;
ERROR:  syntax error at or near "time"
LINE 1: time
        ^
ERROR:  relation "t_delay" does not exist on datanode1
LINE 1: select * from t_delay;
                      ^
openGauss=# \d+
                                       List of relations
 Schema |  Name   | Type  | Owner |    Size    |             Storage              | Description 
--------+---------+-------+-------+------------+----------------------------------+-------------
 public | t_rapid | table | omm   | 8192 bytes | {orientation=row,compression=no} | 
(1 row)

主备节点切换

执行切换

---切换现备节点为主节点
$ gs_ctl switchover -D /opt/openGaussSimp/data/slave/
[2023-07-25 10:26:55.538][13012][][gs_ctl]: gs_ctl switchover ,datadir is /opt/openGaussSimp/data/slave 
[2023-07-25 10:26:55.538][13012][][gs_ctl]: switchover term (1)
[2023-07-25 10:26:55.542][13012][][gs_ctl]: waiting for server to switchover........
[2023-07-25 10:27:00.566][13012][][gs_ctl]: done
[2023-07-25 10:27:00.566][13012][][gs_ctl]: switchover completed (/opt/openGaussSimp/data/slave)

$ gs_ctl query -D /opt/openGaussSimp/data/slave/
[2023-07-25 10:27:23.456][13084][][gs_ctl]: gs_ctl query ,datadir is /opt/openGaussSimp/data/slave 
 HA state:           
    local_role                     : Primary
    static_connections             : 1
    db_state                       : Normal
    detail_information             : Normal

 Senders info:       
    sender_pid                     : 13050
    local_role                     : Primary
    peer_role                      : Standby
    peer_state                     : Normal
    state                          : Streaming
    sender_sent_location           : 0/5F15DC8
    sender_write_location          : 0/5F15DC8
    sender_flush_location          : 0/5F15DC8
    sender_replay_location         : 0/5F15DC8
    receiver_received_location     : 0/5F15DC8
    receiver_write_location        : 0/5F15DC8
    receiver_flush_location        : 0/5F15DC8
    receiver_replay_location       : 0/5F15DC8
    sync_percent                   : 100%
    sync_state                     : Sync
    sync_priority                  : 1
    sync_most_available            : Off
    channel                        : 192.168.9.191:5633-->192.168.9.191:39950

 Receiver info:      
No information 
---查看原备节点已成为主节点

$ gs_ctl query -D /opt/openGaussSimp/data/master/
[2023-07-25 10:27:09.177][13064][][gs_ctl]: gs_ctl query ,datadir is /opt/openGaussSimp/data/master 
 HA state:           
    local_role                     : Standby
    static_connections             : 1
    db_state                       : Normal
    detail_information             : Normal

 Senders info:       
No information 
 Receiver info:      
    receiver_pid                   : 13049
    local_role                     : Standby
    peer_role                      : Primary
    peer_state                     : Normal
    state                          : Normal
    sender_sent_location           : 0/5F15DC8
    sender_write_location          : 0/5F15DC8
    sender_flush_location          : 0/5F15DC8
    sender_replay_location         : 0/5F15DC8
    receiver_received_location     : 0/5F15DC8
    receiver_write_location        : 0/5F15DC8
    receiver_flush_location        : 0/5F15DC8
    receiver_replay_location       : 0/5F15DC8
    sync_percent                   : 100%
    channel                        : 192.168.9.191:39950<--192.168.9.191:5633
---查看原主节点已自动切换为备节点

---切换后的主备节点的原有会话执行操作,会自动重连数据库:
openGauss=# show recovery_min_apply_delay;
WARNING:  Session unused timeout.
FATAL:  terminating connection due to administrator command
could not send data to server: Broken pipe
The connection to the server was lost. Attempting reset: Succeeded.


openGauss=# \d+
FATAL:  terminating connection due to administrator command
could not send data to server: Broken pipe
The connection to the server was lost. Attempting reset: Succeeded.

验证延时

---切换后的备节点:
openGauss=# create table t_delay (id int,instime date);
ERROR:  cannot execute CREATE TABLE in a read-only transaction
openGauss=# select now();create table t_delay (id int,instime date);
              now              
-------------------------------
 2023-07-25 10:29:01.915622+08
(1 row)

ERROR:  cannot execute CREATE TABLE in a read-only transaction
---不能进行写入操作


---切换后的主节点:
openGauss=# show recovery_min_apply_delay;
 recovery_min_apply_delay 
--------------------------
 1min
(1 row)

openGauss=# select now();create table t_delay (id int,instime date);
              now              
-------------------------------
 2023-07-25 10:29:19.473593+08
(1 row)

CREATE TABLE
openGauss=# \d+
                                       List of relations
 Schema |  Name   | Type  | Owner |    Size    |             Storage              | Description 
--------+---------+-------+-------+------------+----------------------------------+-------------
 public | t_delay | table | omm   | 0 bytes    | {orientation=row,compression=no} | 
 public | t_rapid | table | omm   | 8192 bytes | {orientation=row,compression=no} | 
(2 rows)




openGauss=# insert into t_delay values(3,localtimestamp);
INSERT 0 1
openGauss=# select now();select * from t_delay;
              now              
-------------------------------
 2023-07-25 10:30:13.892301+08
(1 row)

 id |       instime       
----+---------------------
  3 | 2023-07-25 10:30:13
(1 row)


---切换后的备节点:
openGauss=# select now();select * from t_delay;
              now              
-------------------------------
 2023-07-25 10:30:13.327388+08
(1 row)

 id |       instime       
----+---------------------
  3 | 2023-07-25 10:30:13
(1 row)

openGauss=# show recovery_min_apply_delay;
 recovery_min_apply_delay 
--------------------------
 0
(1 row)

---立刻就能查到切换后主节点复制过来的数据,切换后的备节点参数recovery_min_apply_delay为默认的0


---在切换后的备节点中需要再配置参数
$ gs_guc reload -D /opt/openGaussSimp/data/master/ -c "recovery_min_apply_delay = 60000"
The gs_guc run with the following arguments: [gs_guc -D /opt/openGaussSimp/data/master/ -c recovery_min_apply_delay = 60000 reload ].
expected instance path: [/opt/openGaussSimp/data/master/postgresql.conf]
gs_guc reload: recovery_min_apply_delay=60000: [/opt/openGaussSimp/data/master/postgresql.conf]
server signaled

Total instances: 1. Failed instances: 0.
Success to perform gs_guc!


---再次验证延时回放,备节点插入记录
openGauss=# insert into t_delay values(4,localtimestamp);
INSERT 0 1
openGauss=# select now();select * from t_delay;
             now              
------------------------------
 2023-07-25 10:31:31.95094+08
(1 row)

 id |       instime       
----+---------------------
  3 | 2023-07-25 10:30:13
  4 | 2023-07-25 10:31:29
(2 rows)


openGauss=# select now();select * from t_delay;
              now              
-------------------------------
 2023-07-25 10:31:29.230721+08
(1 row)

 id |       instime       
----+---------------------
  3 | 2023-07-25 10:30:13
(1 row)

openGauss=# select now();select * from t_delay;
              now              
-------------------------------
 2023-07-25 10:32:35.092483+08
(1 row)

 id |       instime       
----+---------------------
  3 | 2023-07-25 10:30:13
  4 | 2023-07-25 10:31:29
(2 rows)
---延时时间到1分钟后,第4条记录已复制过来

还原主备关系

$ gs_ctl switchover -D /opt/openGaussSimp/data/master/
[2023-07-25 10:33:02.040][13524][][gs_ctl]: gs_ctl switchover ,datadir is /opt/openGaussSimp/data/master 
[2023-07-25 10:33:02.040][13524][][gs_ctl]: switchover term (1)
[2023-07-25 10:33:02.044][13524][][gs_ctl]: waiting for server to switchover........
[2023-07-25 10:33:07.070][13524][][gs_ctl]: done
[2023-07-25 10:33:07.070][13524][][gs_ctl]: switchover completed (/opt/openGaussSimp/data/mas
ter)
---还原后的主备节点关系
$ gs_ctl query -D /opt/openGaussSimp/data/master/
[2023-07-25 10:33:11.096][13571][][gs_ctl]: gs_ctl query ,datadir is /opt/openGaussSimp/data/master 
 HA state:           
    local_role                     : Primary
    static_connections             : 1
    db_state                       : Normal
    detail_information             : Normal

 Senders info:       
    sender_pid                     : 13561
    local_role                     : Primary
    peer_role                      : Standby
    peer_state                     : Normal
    state                          : Streaming
    sender_sent_location           : 0/5F18120
    sender_write_location          : 0/5F18120
    sender_flush_location          : 0/5F18120
    sender_replay_location         : 0/5F18120
    receiver_received_location     : 0/5F18120
    receiver_write_location        : 0/5F18120
    receiver_flush_location        : 0/5F18120
    receiver_replay_location       : 0/5F18120
    sync_percent                   : 100%
    sync_state                     : Sync
    sync_priority                  : 1
    sync_most_available            : Off
    channel                        : 192.168.9.191:5433-->192.168.9.191:50220

 Receiver info:      
No information 


$ gs_ctl query -D /opt/openGaussSimp/data/slave/
[2023-07-25 10:33:13.628][13580][][gs_ctl]: gs_ctl query ,datadir is /opt/openGaussSimp/data/slave 
 HA state:           
    local_role                     : Standby
    static_connections             : 1
    db_state                       : Normal
    detail_information             : Normal

 Senders info:       
No information 
 Receiver info:      
    receiver_pid                   : 13560
    local_role                     : Standby
    peer_role                      : Primary
    peer_state                     : Normal
    state                          : Normal
    sender_sent_location           : 0/5F18120
    sender_write_location          : 0/5F18120
    sender_flush_location          : 0/5F18120
    sender_replay_location         : 0/5F18120
    receiver_received_location     : 0/5F18120
    receiver_write_location        : 0/5F18120
    receiver_flush_location        : 0/5F18120
    receiver_replay_location       : 0/5F18120
    sync_percent                   : 100%
    channel                        : 192.168.9.191:50220<--192.168.9.191:5433


---主备节点会话
openGauss=# select now();select * from t_delay;
WARNING:  Session unused timeout.
FATAL:  terminating connection due to administrator command
could not send data to server: Broken pipe
The connection to the server was lost. Attempting reset: Succeeded.
 id |       instime       
----+---------------------
  3 | 2023-07-25 10:30:13
  4 | 2023-07-25 10:31:29
(2 rows)


openGauss=# select now();select * from t_delay;
FATAL:  terminating connection due to administrator command
could not send data to server: Broken pipe
The connection to the server was lost. Attempting reset: Succeeded.
 id |       instime       
----+---------------------
  3 | 2023-07-25 10:30:13
  4 | 2023-07-25 10:31:29
(2 rows)

总结

openGauss支持通过配置GUC参数recovery_min_apply_delay设定延时时间,使某个备机延时一段时间回放来自主机的事务日志。参数取值范围:整型,0~INT_MAX,单位为毫秒。参数默认值:0(不增加延迟)

延时回放功能的限制:

  • recovery_min_apply_delay参数主节点设置无效,必须设置在需要延迟的备节点上。
  • 延迟时间是根据主服务器上事务提交的时间戳与备机上的当前时间来计算,因此需要保证主备系统时钟一致。
  • 主备切换之后,原主节点若需延迟,需要再手动配置此参数。
  • 当synchronous_commit被设置为on时,同步复制会受到这个延时的影响,每一个COMMIT都需要等待备机回放结束后才会返回。
  • 使用这个特性也会让hot_standby_feedback被延迟,这可能导致主服务器的膨胀,两者一起使用时要小心。
  • 主节点执行了持有AccessExclusive锁的DDL操作,比如DROP和TRUNCATE操作,在备机延迟回放该条记录期间,在备机上对该操作对象执行查询操作会等待锁释放之后才会返回。





文章转载自公众号:openGauss

分类
标签
已于2023-9-6 15:22:38修改
收藏
回复
举报
回复
    相关推荐