案例说明:

生产环境是单实例,测试环境是集群,现需要将生产环境的数据迁移到集群中运行,本文档详细介绍了从单实例环境恢复数据到集群环境的操作步骤,可以作为生产环境迁移数据的参考。

适用版本:

KingbaseES V8R6

本案例数据库版本(单实例和集群使用相同的版本):

test=# select version();
version
----------------------------------------------------------------------------------------------------------------------
KingbaseES V008R006C005B0041 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46), 64-bit
(1 row)

原集群节点信息:

[kingbase@node101 bin]$ ./repmgr cluster show
ID | Name | Role | Status | Upstream | Location | Priority | Timeline | Connection string
----+---------+---------+-----------+----------+----------+----------+----------+----------------------------------------------------------------------------------------------------------------------------------------------------
1 | node101 | primary | * running | | default | 100 | 13 | host=192.168.1.101 user=system dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
2 | node102 | standby | running | node101 | default | 100 | 13 | host=192.168.1.102 user=system dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3

一、单实例环境迁移前主备

Tips:

1)将单实例环境数据迁移到集群,需要停止单实例数据库服务,根据data目录数据的大小, 要估算停机窗口时间。

2)在关闭单实例数据库前,建议手工创建检查点,如果wal日志比较大,建议备份后,清理wal日志,只需要保留最近一天的日志到最近检查点后即可。

3)需要跨主机将单实例data目录拷贝到集群的主备库节点,需 根据网络带宽和节点数,估算整个拷贝时间。

1、查看数据信息

prod1=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+--------+----------+----------+-------------+-------------------
prod | system | UTF8 | ci_x_icu | zh_CN.UTF-8 |
prod1 | system | UTF8 | ci_x_icu | zh_CN.UTF-8 |
security | system | UTF8 | ci_x_icu | zh_CN.UTF-8 |
template0 | system | UTF8 | ci_x_icu | zh_CN.UTF-8 | =c/system +
| | | | | system=CTc/system
template1 | system | UTF8 | ci_x_icu | zh_CN.UTF-8 | =c/system +
| | | | | system=CTc/system
test | system | UTF8 | ci_x_icu | zh_CN.UTF-8 |
(6 rows) prod1=# select count(*) from t1;
count
--------
100000
(1 row)

2、关闭数据库服务

1)手工建立checkpoint
prod1=# select sys_switch_wal();
sys_switch_wal
----------------
0/3F74BD70
(1 row) prod1=# checkpoint;
CHECKPOINT

2)正常关闭数据库服务

[kingbase@node101 bin]$ ./sys_ctl stop -D /data/kingbase/v8r6_041/data
waiting for server to shut down.... done
server stopped

二、迁移数据到集群

1、停止集群

[kingbase@node101 bin]$ ./sys_monitor.sh stop
2022-06-20 10:33:40 Ready to stop all DB ...
.....
2022-06-20 10:33:55 begin to stop DB on "[192.168.1.102]".
2022-06-20 10:33:57 DB on "[192.168.1.101]" stop success.
2022-06-20 10:33:57 Done.

2、将集群的data目录备份

[kingbase@node101 bin]$ cd ../
[kingbase@node101 kingbase]$ mv data data.bk

3、将单实例的data目录拷贝到集群的主备节点

[kingbase@node101 v8r6_041]$ scp -r data node101:/home/kingbase/cluster/R6HA/kha/kingbase
[kingbase@node101 v8r6_041]$ scp -r data node102:/home/kingbase/cluster/R6HA/kha/kingbase

4、集群所有备库创建standby.signal文件

[kingbase@node102 kingbase]$ cd data
[kingbase@node102 data]$ touch standby.signal

5、创建kingbase.auto.conf、kingbase.conf、es_rep.conf文件:(所有节点)

[kingbase@node101 data]$ mv kingbase.auto.conf kingbase.auto.conf.bk

# 将原集群的文件复制
[kingbase@node101 data]$ cp ../data.bk/kingbase.auto.conf ./ [kingbase@node101 data]$ cat kingbase.auto.conf
# Do not edit this file manually!
# It will be overwritten by the ALTER SYSTEM command.
enable_upper_colname = 'on'
wal_retrieve_retry_interval = '5000'
primary_conninfo = 'user=system connect_timeout=10 host=192.168.1.102 port=54321 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3 application_name=node101'
recovery_target_timeline = 'latest'
primary_slot_name = 'repmgr_slot_1'
synchronous_standby_names = '1 (node102)' [kingbase@node101 data]$ cp ../data.bk/kingbase.conf ./
[kingbase@node101 data]$ cp ../data.bk/es_rep.conf ./

三、创建和配置流复制

Tips:

1)注意保证所有节点的数据库服务启动正常。

2)如果数据库服务启动失败,注意查看sys_log(尤其是备库)。

3)如果流复制失败,可以根据备库sys_log获取到备库无法流复制的原因(如本案例,是因为复制槽问题引起)。

1、sys_ctl启动主备库数据库服务

[kingbase@node101 bin]$ ./sys_ctl start -D ../data
waiting for server to start....2022-06-20 11:02:01.860 CST [30274] WARNING: enable_upper_colname can only be
.......
server started

2、查看流复制状态

test=# select * from sys_stat_replication;
pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | backend_xmin | state |
sent_lsn | write_lsn | flush_lsn | replay_lsn | write_lag | flush_lag | replay_lag | sync_priority | sync_state | reply_time
-----+----------+---------+------------------+-------------+-----------------+-------------+---------------+--------------+-------+-
---------+-----------+-----------+------------+-----------+-----------+------------+---------------+------------+------------
(0 rows) # 如以上所示流复制创建失败,查看备库sys_log,因为复制槽原因,导致备库无法创建流复制。

如下图所示:

3、查看复制槽信息

test=# select * from sys_replication_slots;
slot_name | plugin | slot_type | datoid | database | temporary | active | active_pid | xmin | catalog_xmin | restart_lsn | confi
rmed_flush_lsn
--------------+--------+-----------+--------+----------+-----------+--------+------------+------+--------------+-------------+------
---------------
slot_node102 | | physical | | | f | f | | | | 0/370B4F68 |
slot_node101 | | physical | | | f | f | | | | |
(2 rows)

4、重新创建复制槽

test=# select sys_drop_replication_slot('slot_node101');
sys_drop_replication_slot
--------------------------- (1 row) test=# select sys_drop_replication_slot('slot_node102');
sys_drop_replication_slot
--------------------------- (1 row) test=# select * from sys_replication_slots;
slot_name | plugin | slot_type | datoid | database | temporary | active | active_pid | xmin | catalog_xmin | restart_lsn | confirmed_flush_lsn
-----------+--------+-----------+--------+----------+-----------+--------+------------+------+--------------+-------------+---------------------
(0 rows) test=# select sys_create_physical_replication_slot('repmgr_slot_2');
sys_create_physical_replication_slot
--------------------------------------
(repmgr_slot_2,)
(1 row) test=# select sys_create_physical_replication_slot('repmgr_slot_1');
sys_create_physical_replication_slot
--------------------------------------
(repmgr_slot_1,)
(1 row) test=# select * from sys_replication_slots;
slot_name | plugin | slot_type | datoid | database | temporary | active | active_pid | xmin | catalog_xmin | restart_lsn | confirmed_flush_lsn
---------------+--------+-----------+--------+----------+-----------+--------+------------+------+--------------+-------------+---------------------
repmgr_slot_2 | | physical | | | f | t | 31655 | 915 | | 0/420001E0 |
repmgr_slot_1 | | physical | | | f | f | | | | |
(2 rows) test=# select * from sys_stat_replication;
pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | backend_xmin | state | sent_lsn | write_lsn | flush_lsn | replay_lsn | write_lag | flush_lag | replay_lag | sync_priority | sync_state | reply_time
-------+----------+---------+------------------+---------------+-----------------+-------------+-------------------------------+---- 31655 | 10 | system | node102 | 192.168.1.102 | | 36924 | 2022-06-20 11:07:38.664780+08 | | streaming | 0/420001E0 | 0/420001E0 | 0/420001E0 | 0/420001E0 | | | | 1 | sync | 2022-06-20 11:08:05.571558+08
(1 row) # 如上所示,重新创建正确的复制槽后,流复制恢复正常。

四、配置repmgr集群管理(主库完成)

1、创建esrep库和esrep用户:

# 根据原集群用户的密码,创建esrep用户
[kingbase@node102 data]$ cat ~/.encpwd
*:*:*:system:MTIzNDU2NzhhYg==
#*:*:*:system:MTIzNDU2Cg==
*:*:*:esrep:S2luZ2Jhc2VoYTExMA==
[kingbase@node102 data]$ echo 'S2luZ2Jhc2VoYTExMA=='|base64 -d
Kingbaseha110 test=# create database esrep;
CREATE DATABASE
test=# create user esrep with superuser password 'Kingbaseha110';
CREATE ROLE # 根据原集群的密码,修改system用户密码
[kingbase@node101 bin]$ echo 'MTIzNDU2NzhhYg=='|base64 -d
12345678ab[kingbase@node./ksql -U system test
ksql (V8.0)
Type "help" for help. test=# alter user system with password '12345678ab';
ALTER ROLE

2、创建repmgr extension

# 注意在kingbase.conf中支持repmgr extension

[kingbase@node101 bin]$ cat ../data/kingbase.conf |grep repmgr
........
shared_preload_libraries = 'repmgr,liboracle_parser, synonym, plsql, force_view, kdb_flashback,plugin_debugger, plsql_plugin_debugger, plsql_plprofiler, ora_commands,kdb_ora_expr, sepapower, dblink, sys_kwr, sys_ksh, sys_spacequota, sys_stat_statements, backtrace, kdb_utils_function, auto_bmr, sys_squeeze' #主库创建repmgr extension
test=# create extension repmgr;
CREATE EXTENSION

3、注册主备库到repmgr集群

1)注册primary节点

[kingbase@node101 bin]$ ./repmgr primary register --force
INFO: connecting to primary database...
NOTICE: attempting to install extension "repmgr"
NOTICE: "repmgr" extension successfully installed
NOTICE: primary node record (ID: 1) registered [kingbase@node101 bin]$ ./repmgr cluster show
ID | Name | Role | Status | Upstream | Location | Priority | Timeline | Connection string
----+---------+---------+-----------+----------+----------+----------+----------+----------------------------------------------------------------------------------------------------------------------------------------------------
1 | node101 | primary | * running | | default | 100 | 1 | host=192.168.1.101 user=system dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3

2)注册standby节点

[kingbase@node102 bin]$ ./repmgr standby register --force
INFO: connecting to local node "node102" (ID: 2)
INFO: connecting to primary database
WARNING: --upstream-node-id not supplied, assuming upstream node is primary (node ID 1)
INFO: standby registration complete
NOTICE: standby node "node102" (ID: 2) successfully registered

3)查看集群节点状态

[kingbase@node102 bin]$ ./repmgr cluster show
ID | Name | Role | Status | Upstream | Location | Priority | Timeline | Connection string
----+---------+---------+-----------+----------+----------+----------+----------+----------------------------------------------------------------------------------------------------------------------------------------------------
1 | node101 | primary | * running | | default | 100 | 1 | host=192.168.1.101 user=system dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
2 | node102 | standby | running | node101 | default | 100 | 1 | host=192.168.1.102 user=system dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3

五、验证数据

1、重启集群

[kingbase@node101 bin]$ ./sys_monitor.sh restart
2022-06-20 11:26:21 Ready to stop all DB ...
......
2022-06-20 11:27:03 repmgrd on "[192.168.1.102]" start success.
ID | Name | Role | Status | Upstream | repmgrd | PID | Paused? | Upstream last seen
----+---------+---------+-----------+----------+---------+-------+---------+--------------------
1 | node101 | primary | * running | | running | 5641 | no | n/a
2 | node102 | standby | running | node101 | running | 22473 | no | 0 second(s) ago
[2022-06-20 11:27:08] [NOTICE] redirecting logging output to "/home/kingbase/cluster/R6HA/kha/kingbase/log/kbha.log" [2022-06-20 11:27:13] [NOTICE] redirecting logging output to "/home/kingbase/cluster/R6HA/kha/kingbase/log/kbha.log" 2022-06-20 11:27:19 Done.

2、查看repmgrd进程状态(所有节点)

[kingbase@node101 bin]$ ps -ef |grep repmgr
kingbase 5641 1 0 11:26 ? 00:00:00 /home/kingbase/cluster/R6HA/kha/kingbase/bin/repmgrd -d -v -f /home/kingbase/cluster/R6HA/kha/kingbase/bin/../etc/repmgr.conf
kingbase 5879 1 0 11:27 ? 00:00:00 /home/kingbase/cluster/R6HA/kha/kingbase/bin/kbha -A daemon -f /home/kingbase/cluster/R6HA/kha/kingbase/bin/../etc/repmgr.conf

3、验证迁移后数据

[kingbase@node101 bin]$ ./ksql -U system test
ksql (V8.0)
Type "help" for help. test=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+--------+----------+----------+-------------+-------------------
esrep | system | UTF8 | ci_x_icu | zh_CN.UTF-8 |
prod | system | UTF8 | ci_x_icu | zh_CN.UTF-8 |
prod1 | system | UTF8 | ci_x_icu | zh_CN.UTF-8 |
security | system | UTF8 | ci_x_icu | zh_CN.UTF-8 |
template0 | system | UTF8 | ci_x_icu | zh_CN.UTF-8 | =c/system +
| | | | | system=CTc/system
template1 | system | UTF8 | ci_x_icu | zh_CN.UTF-8 | =c/system +
| | | | | system=CTc/system
test | system | UTF8 | ci_x_icu | zh_CN.UTF-8 |
(7 rows) test=# \c prod1
You are now connected to database "prod1" as user "system".
prod1=# \d
List of relations
Schema | Name | Type | Owner
--------+---------------------+-------+--------
public | sys_stat_statements | view | system
public | t1 | table | system
(2 rows) prod1=# select count(*) from t1;
count
--------
100000
(1 row) # 迁移后数据和迁移前数据一致,迁移成功。

六、总结

 1、从单实例环境迁移数据到集群,如果需要保证数据一致,必须要将单实例及集群停库,对于生产环境,要考虑停机窗口。
2、如果需要将原集群数据重新加载到新的集群,需要将原集群数据做逻辑备份,但是在导入时如果有重复数据需注意处理。(如将测试数据再导入到新的集群中,可能有许多数据会重复)。
3、申请停机窗口,要考虑原单实例数据量的大小、主机间的网络带宽、集群节点数、集群配置时间、集群启动故障的处理时间等。

KingbaseES V8R6集群维护案例之--单实例数据迁移到集群案例的更多相关文章

  1. Redis单实例数据迁移到集群

    环境说明 单机redis redis集群 192.168.41.101:7000 master 192.168.41.101:7001 master 192.168.41.102:7000 maste ...

  2. kingbaseES R3 集群备库转换为单实例库案例

    案例说明: 在生产环境需要将集群中架构转换为单实例环境,本案例以备库转换为单实例库为案例,介绍了两种方案,一种在数据库数据量小的环境下采用 sys_dumpall 导出导入方式建立单实例库:另外一种是 ...

  3. 项目案例之GitLab的数据迁移

    项目案例之GitLab的数据迁移 链接:https://pan.baidu.com/s/1CgaEv12cwfbs5RxcNpxdAg 提取码:fytm 复制这段内容后打开百度网盘手机App,操作更方 ...

  4. KingbaseES V8R6C6备份恢复案例之---单实例sys_baackup.sh备份

    案例说明: KingbaseES V8R6C6中sys_backup.sh在通用机单实例环境,默认需要通过securecmdd工具以及kingbase和root用户之间的ssh互信,执行备份初始化(i ...

  5. KingbaseES V8R3 备份恢复案例之--单实例环境sys_rman脚本备份案例

    案例说明: sys_rman是KingbaseES数据库的物理备份工具,支持数据库的全备和增量备份,由于sys_rman工具使用需要配置多个参数,对于一般用户使用不是很方便.为方便用户在Kingbas ...

  6. Elasticsearch:单节点数据迁移

    Elasticsearch数据迁移:windows单节点迁移到windows 将源数据中的ES安装目录下的data/nodes目录整体拷贝到目标ES的对应目录下 迁移前请备份:迁移后需要重启ES: E ...

  7. MongoDB复制集之将现有的单节点服务器转换为复制集

    服务器情况:   现有的单节点 Primary     192.168.126.9:27017   新增的节点    Secondry  192.168.126.8:27017    仲裁节点     ...

  8. Hbase 0.92.1集群数据迁移到新集群

    老集群 hbase(main):001:0> status 4 servers, 0 dead, 0.0000 average load hbase(main):002:0> list T ...

  9. KingbaseES V8R3集群管理维护案例之---集群迁移单实例架构

    案例说明: 在生产中,需要将KingbaseES V8R3集群转换为单实例架构,可以采用以下方式快速完成集群架构的迁移. 适用版本: KingbaseES V8R3 当前数据库版本: TEST=# s ...

随机推荐

  1. Numpy的ndarray数组基础

    NumPy 最重要的一个特点是其 N 维数组对象 ndarray,它是一系列同类型数据的集合,以 0 下标为开始进行集合中元素的索引. ndarray 对象是用于存放同类型元素的多维数组. 1.数组的 ...

  2. Java开发学习(九)----IOC之核心容器

    这里所说的核心容器,大家可以把它简单的理解为ApplicationContext,前面虽然已经用到过,但是并没有系统的介绍过,接下来咱们从以下几个问题入手来下容器的相关知识: 如何创建容器? 创建好容 ...

  3. 深入理解Apache Hudi异步索引机制

    在我们之前的文章中,我们讨论了多模式索引的设计,这是一种用于Lakehouse架构的无服务器和高性能索引子系统,以提高查询和写入性能.在这篇博客中,我们讨论了构建如此强大的索引所需的机制,异步索引机制 ...

  4. 虚拟机启动时报’A start job is running for /etc/rc.local .. Compatibility错误。

    虚拟机启动时报'A start job is running for /etc/rc.local .. Compatibility错误. 问题已经存在很长时间了,但是不影响ssh登录,遂置之未理. 经 ...

  5. PaddleOCR系列(二)--hubserving & pdserving & hub install

    一.各种部署方式特点及注意事项 简称 hubserving=PaddleHub Serving pdserving=PaddleHub Serving hub install =指通过paddlehu ...

  6. # 8 快速入门 dubbo

    8 快速入门 dubbo 所需资料 注册中心 Zookeeper 安装 zookeeper 官方推荐使用 zookeeper 注册中心: 注册中心负责服务地址的注册与查找,相当于目录服务: 服务提供者 ...

  7. Hadoop中HDFS 的相关进程以及工作流程图(详细流程图)

  8. 常用的函数式接口_Supplier和常用的函数式接口Supplier接口练习_求数组中元素最大值

    Supplier接口 package com.yang.Test.SupplierStudy; import java.util.function.Supplier; /** * 常用的函数式接口 * ...

  9. Python logging日志管理

    import logging logger = logging.getLogger("simple_example") logger.setLevel(logging.DEBUG) ...

  10. JDBC与ODBC的区别

    JDBC简介JDBC(Java Data Base Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,它是Java十三个规范之一.可以为多种关系数据库提供统一访 ...