open Gauss 数据库-05 openGauss数据库备份恢复指导手册

news2024/10/6 4:05:00

发文章是为了证明自己真的掌握了一个知识,同时给他人带来帮助,如有问题,欢迎指正,祝大家万事胜意! 

目录

前言

openGauss数据库备份恢复 

1 实验介绍

1.1 关于本实验

1.2 实验目的

2 实验前提

3 物理备份和恢复

3.1 实验前提

3.2 物理备份

3.3 物理备份恢复

4 逻辑备份和恢复

4.1 实验前提

4.2 gs_dump

4.2.1 介绍

4.2.2 注意事项

4.2.4 gs_dump 备份示例 2

4.2.5 gs_dump 备份示例 3

4.2.6 gs_dump 备份示例 4

4.2.6 gs_dump 备份示例 4

4.3 gs_dumpall

4.3.1 介绍

4.3.2 操作步骤

4.4 gs_restore

​​​​​​​4.4.1 介绍

4.4.2 gs_restore 导入示例 1

4.4.3 gs_restore 导入示例 2

4.4.4 gs_restore 导入示例 3

4.4.5 gs_restore 导入示例 4

4.4.6 gs_restore 导入示例 5


前言

我的环境:

设备名称设备型号软件版本
虚拟机VMwareVMware-workstation-full-17.5.1
操作系统openEuler   openEuler 22.3LTS
数据库openGauss  openGauss 5.0.0

 需要的工具,大家不用现在下,后面用到了再下也可以,如果需要相关文件,可以评论,其实大多数都是可以去官网下的哈,因为我只能通过网盘给大家,文件又有点大,网盘的速度大家都是清楚的哈哈,所以还是推荐大家去官网,如果实在找不到可以找我

openGauss数据库备份恢复 

1 实验介绍

1.1 关于本实验

本实验主要描述 openGauss 数据库支持的两种备份恢复类型、多种备份恢复方案,并能够在备
份和恢复过程中提供数据的可靠性保障机制。

1.2 实验目的

掌握 openGauss 数据库中逻辑备份与恢复方法;
掌握 openGauss 数据库物理备份与恢复的方法;
能够在备份和恢复过程中提供数据的可靠性保障机制。

2 实验前提

在对数据库进行备份前,对数据库进行如下操作:
步骤 1 切换到 omm 用户,以操作系统用户 omm 登录数据库主节点。
[root@node0 ~]# su - omm
Last login: Mon Apr  8 19:47:35 CST 2024 on tty1


Welcome to 5.10.0-153.12.0.92.oe2203sp2.x86_64

System information as of time: 	2024年 04月 08日 星期一 20:18:18 CST

System load: 	0.64
Processes: 	204
Memory used: 	42.8%
Swap used: 	13.5%
Usage On: 	25%
IP address: 	192.168.28.131
Users online: 	2
To run a command as administrator(user "root"),use "sudo <command>".
步骤 2 连接 openGauss 数据库。
[omm@node0 ~]$ gsql -d postgres -p 15400 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
步骤 3 创建 customer_t1 表。
openGauss=# DROP TABLE IF EXISTS customer_t1;
DROP TABLE
openGauss=# CREATE TABLE customer_t1 
openGauss-# ( 
openGauss(#  c_customer_sk integer, 
openGauss(#  c_customer_id char(5), 
openGauss(#  c_first_name char(6), 
openGauss(#  c_last_name char(8) 
openGauss(# );
CREATE TABLE
步骤 4 向表中插入数据。
openGauss=#  INSERT INTO customer_t1 (c_customer_sk, c_customer_id, c_first_name) VALUES 
openGauss-# (3769, 'hello', DEFAULT) , 
openGauss-# (6885, 'maps', 'Joes'), 
openGauss-# (4321, 'tpcds', 'Lily'), 
openGauss-# (9527, 'world', 'James');
INSERT 0 4
步骤 5 查看表中的数据。
openGauss=# select * from customer_t1;
 c_customer_sk | c_customer_id | c_first_name | c_last_name 
---------------+---------------+--------------+-------------
          3769 | hello         |              | 
          6885 | maps          | Joes         | 
          4321 | tpcds         | Lily         | 
          9527 | world         | James        | 
(4 rows)
步骤 6 创建 customer_t2
openGauss=# DROP TABLE IF EXISTS customer_t2;
NOTICE:  table "customer_t2" does not exist, skipping
DROP TABLE
openGauss=# CREATE TABLE customer_t2 
openGauss-# ( 
openGauss(#  c_customer_sk integer, 
openGauss(#  c_customer_id char(5), 
openGauss(#  c_first_name char(6), 
openGauss(#  c_last_name char(8) 
openGauss(# );
CREATE TABLE
步骤 7 向表中插入数据
openGauss=#  INSERT INTO customer_t2 (c_customer_sk, c_customer_id, c_first_name) VALUES 
openGauss-# (3769, 'hello', DEFAULT) , 
openGauss-# (6885, 'maps', 'Joes'), 
openGauss-# (9527, 'world', 'James');
INSERT 0 3
步骤 8 查看表中数据。
openGauss=# select * from customer_t2;
 c_customer_sk | c_customer_id | c_first_name | c_last_name 
---------------+---------------+--------------+-------------
          3769 | hello         |              | 
          6885 | maps          | Joes         | 
          9527 | world         | James        | 
(3 rows)
步骤 9 创建用户 lucy
openGauss=# DROP user IF EXISTS LUCY;
NOTICE:  role "lucy" does not exist, skipping
DROP ROLE
openGauss=# CREATE USER lucy WITH PASSWORD  "Bigdata@123";
CREATE ROLE
步骤 10 切换到 Lucy 用户
openGauss=# \c - lucy
Password for user lucy: 
Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database "postgres" as user "lucy".
步骤 11 创建 lucy shema 的表。
openGauss=> DROP TABLE IF EXISTS lucy.mytable;
NOTICE:  table "mytable" does not exist, skipping
DROP TABLE
openGauss=> CREATE TABLE mytable (firstcol int);
CREATE TABLE
步骤 12 向表中插入数据
openGauss=> INSERT INTO mytable values (100);
INSERT 0 1
步骤 13 查看表中数据
openGauss=> SELECT * from mytable;
 firstcol 
----------
      100
(1 row)
步骤 14 退出数据库:

openGauss=> \q
[omm@node0 ~]$ 

物理备份和恢复

openGauss 部署成功后,在数据库运行的过程中,会遇到各种问题及异常状态。 openGauss
提供了 gs_basebackup 工具做基础备份。 gs_basebackup 工具由操作系统用户 omm 执行。

3.1 实验前提

在数据库备份之前创建存储备份文件的文件夹。
步骤 1 切换到 omm 用户,以操作系统用户 omm 登录数据库主节点。

[root@node0 ~]# su - omm
Last login: Sat Apr 13 23:05:21 CST 2024 on tty1


Welcome to 5.10.0-153.12.0.92.oe2203sp2.x86_64

System information as of time: 	2024年 04月 13日 星期六 23:14:02 CST

System load: 	0.01
Processes: 	198
Memory used: 	37.9%
Swap used: 	9.5%
Usage On: 	25%
IP address: 	192.168.28.131
Users online: 	2
To run a command as administrator(user "root"),use "sudo <command>".
[omm@node0 ~]$ 
步骤 2 创建存储备份文件的文件夹。
[omm@node0 ~]$ mkdir -p /home/omm/physical/backup
[omm@node0 ~]$ 

3.2 物理备份

步骤 1 如果数据库服务没有启动,就启动数据库服务 ( 务必以操作系统用户 omm 启动数据库服务, 如果没有请切换用户)
[omm@node0 ~]$ gs_om -t start;
Starting cluster.
=========================================
[SUCCESS] node0:
[2024-04-13 23:16:40.080][8226][][gs_ctl]: gs_ctl started,datadir is /opt/huawei/install/data/dn 
[2024-04-13 23:16:40.086][8226][][gs_ctl]:  another server might be running; Please use the restart command
=========================================
Successfully started.
步骤 2 将数据库进行物理备份。
[omm@node0 ~]$ gs_basebackup -D /home/omm/physical/backup -p 15400
INFO:  The starting position of the xlog copy of the full build is: 0/3000028. The slot minimum LSN is: 0/0. The disaster slot minimum LSN is: 0/0. The logical slot minimum LSN is: 0/0.
[2024-04-13 23:18:08]:begin build tablespace list
[2024-04-13 23:18:08]:finish build tablespace list
[2024-04-13 23:18:08]:begin get xlog by xlogstream
                                                                              [2024-04-13 23:18:08]: check identify system success
                                                                              [2024-04-13 23:18:08]: send START_REPLICATION 0/3000000 success
                                                                              [2024-04-13 23:18:08]: keepalive message is received
                                                                              [2024-04-13 23:18:08]: keepalive message is received
[2024-04-13 23:18:13]:gs_basebackup: base backup successfully
参数 -D directory 表示备份文件输出的目录, 必选项
步骤 3 切换到存储备份文件夹查看备份文件。
[omm@node0 ~]$ cd /home/omm/physical/backup
[omm@node0 backup]$ ls
backup_label        pg_ident.conf  pg_xlog
base                pg_llog        postgresql.conf
cacert.pem          pg_location    postgresql.conf.bak
global              pg_logical     postgresql.conf.guc.bak
gswlm_userinfo.cfg  pg_multixact   postgresql.conf.lock
mot.conf            pg_notify      postmaster.pid.lock
pg_clog             pg_replslot    server.crt
pg_csnlog           pg_serial      server.key
pg_ctl.lock         pg_snapshots   server.key.cipher
pg_errorinfo        pg_stat_tmp    server.key.rand
pg_hba.conf         pg_tblspc      undo
pg_hba.conf.bak     pg_twophase
pg_hba.conf.lock    PG_VERSION

3.3 物理备份恢复

当数据库发生故障时需要从备份文件进行恢复。因为 gs_basebackup 是对数据库按二进制进行
备份,因此恢复时可以直接拷贝替换原有的文件, 或者直接在备份的库上启动数据库。
说明:
若当前数据库实例正在运行,直接从备份文件启动数据库可能会存在端口冲突,这时,需
要修配置文件的 port 参数,或者在启动数据库时指定一下端口。
若当前备份文件为主备数据库,可能需要修改一下主备之间的复制连接。即配置文件中的
postgre.conf 中的 replconninfo1 replconninfo2 等。
当数据库发生问题需要从备份进行恢复时,步骤如下:
步骤 1 停止 openGauss(( 务必以操作系统用户 omm 停止数据库服务,如果没有请切换用户 )
[omm@node0 backup]$ gs_om -t stop;
Stopping cluster.
=========================================
Successfully stopped cluster.
=========================================
End stop cluster.
[omm@node0 backup]$ 
步骤 2 清理原库中的所有或部分文件
查看数据库节点文件夹名称 ( 文件夹名称是数据库安装时定义的,不同数据可能不同 )
[omm@node0 ~]$ cd /opt/huawei/install/data
[omm@node0 data]$ ls
dn
查看文件列表如下:
[omm@node0 data]$ cd dn
[omm@node0 dn]$ ls
backup_label.old    pg_ident.conf  postgresql.conf
base                pg_llog        postgresql.conf.bak
cacert.pem          pg_location    postgresql.conf.guc.bak
gaussdb.state       pg_logical     postgresql.conf.lock
global              pg_multixact   postmaster.opts
gswlm_userinfo.cfg  pg_notify      postmaster.pid
mot.conf            pg_replslot    postmaster.pid.lock
pg_clog             pg_serial      server.crt
pg_csnlog           pg_snapshots   server.key
pg_ctl.lock         pg_stat_tmp    server.key.cipher
pg_errorinfo        pg_tblspc      server.key.rand
pg_hba.conf         pg_twophase    undo
pg_hba.conf.bak     PG_VERSION
pg_hba.conf.lock    pg_xlog
删除文件,对数据库文件进行破坏。
[omm@node0 dn]$ rm -rf *
[omm@node0 dn]$ ls
[omm@node0 dn]$ 
删除文件后,列表为空
[omm@node0 dn]$ rm -rf *
[omm@node0 dn]$ ls
[omm@node0 dn]$ 
删除文件后,列表为空
步骤 3 使用数据库系统用户权限从备份中还原需要的数据库文件, "/opt/huawei/install/data/d n "
dn 是数据库节点文件夹名称,不同数据库可能不同请查看确认。
[omm@node0 dn]$ cp -r /home/omm/physical/backup/. /opt/huawei/install/data/dn
[omm@node0 dn]$ 
备份时间大概需要几分钟,恢复后文件列表如下
[omm@node0 dn]$ cd /opt/huawei/install/data/dn
[omm@node0 dn]$ ls
backup_label        pg_ident.conf  pg_xlog
base                pg_llog        postgresql.conf
cacert.pem          pg_location    postgresql.conf.bak
global              pg_logical     postgresql.conf.guc.bak
gswlm_userinfo.cfg  pg_multixact   postgresql.conf.lock
mot.conf            pg_notify      postmaster.pid.lock
pg_clog             pg_replslot    server.crt
pg_csnlog           pg_serial      server.key
pg_ctl.lock         pg_snapshots   server.key.cipher
pg_errorinfo        pg_stat_tmp    server.key.rand
pg_hba.conf         pg_tblspc      undo
pg_hba.conf.bak     pg_twophase
pg_hba.conf.lock    PG_VERSION
若数据库中存在链接文件 , 需要修改使其链接到正确的文件。
步骤 4 重启数据库服务器, 并检查数据库内容,确保数据库已经恢复到所需的状态。
[omm@node0 dn]$ gs_om -t start;
Starting cluster.
=========================================

=========================================
Successfully started.

4 逻辑备份和恢复

通过逻辑导出对数据进行备份,逻辑备份只能基于备份时刻进行数据转储,所以恢复时也只能恢复到备份时保存的数据。对于故障点和备份点之间的数据,逻辑备份无能为力,逻辑备份适合备份那些很少变化的数据,当这些数据因误操作被损坏时,可以通过逻辑备份进行快速恢复。如果通过逻辑备份进行全库恢复,通常需要重建数据库,导入备份数据来完成,对于可用性要求很高的数据库,这种恢复时间太长,通常不被采用。由于逻辑备份具有平台无关性,所以更为常见的是逻辑备份被作为一个数据迁移及移动的主要手段。

4.1 实验前提

在数据库备份之前创建存储备份文件的文件夹。

步骤 1 切换到 omm 用户,以操作系统用户 omm 登录数据库主节点。

[root@node0 ~]# su - omm
Last login: Mon Apr 15 16:46:11 CST 2024 on pts/1


Welcome to 5.10.0-153.12.0.92.oe2203sp2.x86_64

System information as of time: 	2024年 04月 15日 星期一 17:16:22 CST

System load: 	0.06
Processes: 	199
Memory used: 	38.4%
Swap used: 	10.1%
Usage On: 	26%
IP address: 	192.168.28.131
Users online: 	2
To run a command as administrator(user "root"),use "sudo <command>".
步骤 2 创建存储备份文件的文件夹。
[omm@node0 ~]$ mkdir -p /home/omm/logical/backup
[omm@node0 ~]$ 

4.2 gs_dump

4.2.1 介绍

gs_dump openGauss 用于导出数据库相关信息的工具,用户可以自定义导出一个数据库或其中的对象(模式、表、视图等)。支持导出的数据库可以是默认数据库 postgres,也可以是自定义数据库。

主要功能:

gs_dump 可以创建四种不同的导出文件格式,通过[-F 或者--format=]选项指定,具体见官方文档

4.2.2 注意事项

如果 openGauss 有任何本地数据要添加到 template1 数据库,请将 gs_dump 的输出恢复

到一个真正的空数据库中,否则可能会因为被添加对象的定义被复制,出现错误。要创建

一个无本地添加的空数据库,需从 template0 而非 template1 复制,例如:


openGauss=# CREATE DATABASE foo WITH TEMPLATE template0;
CREATE DATABASE
tar 归档形式的文件大小不得超过 8GB tar 文件格式的固有限制)。 tar 文档整体大小和任
何其他输出格式没有限制,操作系统可能对此有要求。
gs_dump 生成的转储文件不包含优化程序用来做执行计划决定的统计数据。因此,最
好从某转储文件恢复之后运行 ANALYZE 以确保最佳效果。转储文件不包含任何 ALTER
DATABASE…SET 命令,这些设置由 gs_dumpall 转储,还有数据库用户和其他完成安装设
置。
使用 gs_dump 转储数据库为 SQL 文本文件或其它格式的操作:示例中 “Bigdata@123”
示数据库用户密码 “/home/omm/logical/backup/MPPDB_backup.sql” 表示导出的文件;
“26000” 表示数据库服务器端口; “postgres” 表示要访问的数据库名。
说明:导出操作时,请确保该目录存在并且当前的操作系统用户对其具有读写权限。

4.2.3 gs_dump 备份示例 1

执行 gs_dump,导出 postgres 数据库全量信息,导出的 MPPDB_backup.sql 文件格式为纯文本格式。

步骤 1 以操作系统用户 omm 登录数据库主节点。

[root@node0 ~]# su - omm
Last login: Mon Apr 15 17:16:22 CST 2024 on pts/1


Welcome to 5.10.0-153.12.0.92.oe2203sp2.x86_64

System information as of time: 	2024年 04月 15日 星期一 17:32:59 CST

System load: 	0.02
Processes: 	196
Memory used: 	39.3%
Swap used: 	11.6%
Usage On: 	26%
IP address: 	192.168.28.131
Users online: 	2
步骤 2 执行 gs_dump ,导出的 MPPDB_backup.sql 文件格式为纯文本格式。
[omm@node0 ~]$ gs_dump -U omm -W Bigdata@123 -f /home/omm/logical/backup/MPPDB_backup.sql -p 15400 postgres -F p
gs_dump[port='15400'][postgres][2024-04-15 17:34:35]: The total objects number is 516.
gs_dump[port='15400'][postgres][2024-04-15 17:34:35]: [100.00%] 516 objects have been dumped.
gs_dump[port='15400'][postgres][2024-04-15 17:34:35]: dump database postgres successfully
gs_dump[port='15400'][postgres][2024-04-15 17:34:35]: total time: 2624  ms
步骤 3 切换到 backup 文件夹,查看 MPPDB_backup.sql 文件。
[omm@node0 ~]$ ll /home/omm/logical/backup/
total 772
-rw------- 1 omm dbgrp 127566 Apr 15 09:48 bkp2.sql
-rw------- 1 omm dbgrp    972 Apr 15 09:35 bkp_shl2.sql
drwx------ 2 omm dbgrp   4096 Apr 15 09:34 MPPDB_backup
-rw------- 1 omm dbgrp 122523 Apr 15 09:45 MPPDB_backup2.sql
-rw------- 1 omm dbgrp 121108 Apr 15 09:33 MPPDB_backup.dmp
-rw------- 1 omm dbgrp 123098 Apr 15 17:34 MPPDB_backup.sql
-rw------- 1 omm dbgrp 277504 Apr 15 09:32 MPPDB_backup.tar
[omm@node0 ~]$ cat /home/omm/logical/backup/MPPDB_backup.sql
……
--
-- Name: inx_stu01; Type: INDEX; Schema: public; Owner: omm; Tablespace: 
--

CREATE INDEX inx_stu01 ON student USING btree (std_name) TABLESPACE pg_default;


--
-- Name: public; Type: ACL; Schema: -; Owner: omm
--

REVOKE ALL ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM omm;
GRANT CREATE,USAGE ON SCHEMA public TO omm;
GRANT USAGE ON SCHEMA public TO PUBLIC;


--
-- openGauss database dump complete
--
4.2.4 gs_dump 备份示例 2

执行 gs_dump,导出 postgres 数据库全量信息,导出的 MPPDB_backup.tar 文件格式tar格式。

步骤 1 以操作系统用户 omm 登录数据库主节点

[root@node0 ~]# su - omm
Last login: Mon Apr 15 17:32:59 CST 2024 on pts/1


Welcome to 5.10.0-153.12.0.92.oe2203sp2.x86_64

System information as of time: 	2024年 04月 15日 星期一 17:41:09 CST

System load: 	0.00
Processes: 	197
Memory used: 	39.4%
Swap used: 	12.1%
Usage On: 	26%
IP address: 	192.168.28.131
Users online: 	2
To run a command as administrator(user "root"),use "sudo <command>".
[omm@node0 ~]$ 

步骤 2 执行 gs_dump,导出的 MPPDB_backup.tar 文件格式为 tar 格式。

[omm@node0 ~]$ gs_dump -U omm -W Bigdata@123 -f /home/omm/logical/backup/MPPDB_backup.tar -p 15400 postgres -F t
gs_dump[port='15400'][postgres][2024-04-15 17:43:14]: The total objects number is 516.
gs_dump[port='15400'][postgres][2024-04-15 17:43:14]: [100.00%] 516 objects have been dumped.
gs_dump[port='15400'][postgres][2024-04-15 17:43:14]: dump database postgres successfully
gs_dump[port='15400'][postgres][2024-04-15 17:43:14]: total time: 1422  ms
[omm@node0 ~]$ 

步骤 3 查看生成的文件信息。

[omm@node0 ~]$ ll /home/omm/logical/backup/
total 772
-rw------- 1 omm dbgrp 127566 Apr 15 09:48 bkp2.sql
-rw------- 1 omm dbgrp    972 Apr 15 09:35 bkp_shl2.sql
drwx------ 2 omm dbgrp   4096 Apr 15 09:34 MPPDB_backup
-rw------- 1 omm dbgrp 122523 Apr 15 09:45 MPPDB_backup2.sql
-rw------- 1 omm dbgrp 121108 Apr 15 09:33 MPPDB_backup.dmp
-rw------- 1 omm dbgrp 123098 Apr 15 17:34 MPPDB_backup.sql
-rw------- 1 omm dbgrp 277504 Apr 15 17:43 MPPDB_backup.tar
4.2.5 gs_dump 备份示例 3

执行 gs_dump,导出 postgres 数据库全量信息,导出的 MPPDB_backup.dmp 文件格式为自定义归档格式。

步骤 1 以操作系统用户 omm 登录数据库主节点。

[root@node0 ~]# su - omm
Last login: Mon Apr 15 17:41:09 CST 2024 on pts/1


Welcome to 5.10.0-153.12.0.92.oe2203sp2.x86_64

System information as of time: 	2024年 04月 15日 星期一 17:45:32 CST

System load: 	0.93
Processes: 	199
Memory used: 	39.6%
Swap used: 	12.3%
Usage On: 	26%
IP address: 	192.168.28.131
Users online: 	2
To run a command as administrator(user "root"),use "sudo <command>".

步骤 2 执行 gs_dump,导出的 MPPDB_backup.dmp 文件格式为自定义归档格式。

[omm@node0 ~]$ gs_dump -U omm -W Bigdata@123 -f /home/omm/logical/backup/MPPDB_backup.dmp -p 15400 postgres -F c
gs_dump[port='15400'][postgres][2024-04-15 17:47:39]: The total objects number is 516.
gs_dump[port='15400'][postgres][2024-04-15 17:47:39]: [100.00%] 516 objects have been dumped.
gs_dump[port='15400'][postgres][2024-04-15 17:47:39]: dump database postgres successfully
gs_dump[port='15400'][postgres][2024-04-15 17:47:39]: total time: 1420  ms

步骤 3 查看生成的文件信息。

[omm@node0 ~]$ ll /home/omm/logical/backup/
total 772
-rw------- 1 omm dbgrp 127566 Apr 15 09:48 bkp2.sql
-rw------- 1 omm dbgrp    972 Apr 15 09:35 bkp_shl2.sql
drwx------ 2 omm dbgrp   4096 Apr 15 17:49 MPPDB_backup
-rw------- 1 omm dbgrp 122523 Apr 15 09:45 MPPDB_backup2.sql
-rw------- 1 omm dbgrp 121108 Apr 15 17:47 MPPDB_backup.dmp
-rw------- 1 omm dbgrp 123098 Apr 15 17:34 MPPDB_backup.sql
-rw------- 1 omm dbgrp 277504 Apr 15 17:43 MPPDB_backup.tar
4.2.6 gs_dump 备份示例 4

执行 gs_dump,导出 postgres 数据库全量信息,导出的 MPPDB_backup 文件格式为目录格式

步骤 1 以操作系统用户 omm 登录数据库主节点。

[root@node0 ~]# su - omm
Last login: Mon Apr 15 17:45:31 CST 2024 on pts/1


Welcome to 5.10.0-153.12.0.92.oe2203sp2.x86_64

System information as of time: 	2024年 04月 15日 星期一 20:02:07 CST

System load: 	0.10
Processes: 	196
Memory used: 	40.0%
Swap used: 	14.0%
Usage On: 	26%
IP address: 	192.168.28.131
Users online: 	2
To run a command as administrator(user "root"),use "sudo <command>".

步骤 2 执行 gs_dump,导出的 MPPDB_backup 文件格式为目录格式

[omm@node0 ~]$ gs_dump -U omm -W Bigdata@123 -f /home/omm/logical/backup/MPPDB_backup -p 15400 postgres -F d
gs_dump[port='15400'][postgres][2024-04-15 09:33:53]: The total objects number is 516.
gs_dump[port='15400'][postgres][2024-04-15 09:33:54]: [100.00%] 516 objects have been dumped.
gs_dump[port='15400'][postgres][2024-04-15 09:33:54]: dump database postgres successfully
gs_dump[port='15400'][postgres][2024-04-15 09:33:54]: total time: 2341 ms

步骤 3 查看生成的文件信息。

[omm@node0 ~]$ ll /home/omm/logical/backup/
total 772
-rw------- 1 omm dbgrp 127566 Apr 15 09:48 bkp2.sql
-rw------- 1 omm dbgrp    972 Apr 15 09:35 bkp_shl2.sql
drwx------ 2 omm dbgrp   4096 Apr 15 17:49 MPPDB_backup
-rw------- 1 omm dbgrp 122523 Apr 15 09:45 MPPDB_backup2.sql
-rw------- 1 omm dbgrp 121108 Apr 15 17:47 MPPDB_backup.dmp
-rw------- 1 omm dbgrp 123098 Apr 15 17:34 MPPDB_backup.sql
-rw------- 1 omm dbgrp 277504 Apr 15 17:43 MPPDB_backup.tar
4.2.6 gs_dump 备份示例 4

执行 gs_dump,导出 postgres 数据库全量信息,导出的 MPPDB_backup 文件格式为目录格式

步骤 1 以操作系统用户 omm 登录数据库主节点。

[root@node0 ~]# su - omm
Last login: Mon Apr 15 20:02:07 CST 2024 on pts/1


Welcome to 5.10.0-153.12.0.92.oe2203sp2.x86_64

System information as of time: 	2024年 04月 15日 星期一 20:10:39 CST

System load: 	0.15
Processes: 	197
Memory used: 	40.0%
Swap used: 	14.0%
Usage On: 	26%
IP address: 	192.168.28.131
Users online: 	2
To run a command as administrator(user "root"),use "sudo <command>".
[omm@node0 ~]$ 

步骤 2 执行 gs_dump,导出的 MPPDB_backup 文件格式为目录格式

[omm@node0 ~]$ gs_dump -U omm -W Bigdata@123 -f /home/omm/logical/backup/MPPDB_backup -p 15400 postgres -F d
gs_dump[port='15400'][postgres][2024-04-15 09:34:57]: The total objects number is 516.
gs_dump[port='15400'][postgres][2024-04-15 09:34:57]: [100.00%] 516 objects have been dumped.
gs_dump[port='15400'][postgres][2024-04-15 09:34:57]: dump database postgres successfully
gs_dump[port='15400'][postgres][2024-04-15 09:34:57]: total time: 1646 ms

步骤 3 查看生成的文件信息。

[omm@node0 ~]$ ll /home/omm/logical/backup/
total 772
-rw------- 1 omm dbgrp 127566 Apr 15 09:48 bkp2.sql
-rw------- 1 omm dbgrp    972 Apr 15 09:35 bkp_shl2.sql
drwx------ 2 omm dbgrp   4096 Apr 15 17:49 MPPDB_backup
-rw------- 1 omm dbgrp 122523 Apr 15 09:45 MPPDB_backup2.sql
-rw------- 1 omm dbgrp 121108 Apr 15 17:47 MPPDB_backup.dmp
-rw------- 1 omm dbgrp 123098 Apr 15 17:34 MPPDB_backup.sql
-rw------- 1 omm dbgrp 277504 Apr 15 17:43 MPPDB_backup.tar
4.2.7 gs_dump 备份示例 5
执行 gs_dump ,导出 postgres 数据库的 表(或视图、或序列、或外表)对象 ,例如表
customer_t1
步骤 1 以操作系统用户 omm 登录数据库主节点。
[root@node0 ~]# su - omm
Last login: Mon Apr 15 20:10:39 CST 2024 on pts/1


Welcome to 5.10.0-153.12.0.92.oe2203sp2.x86_64

System information as of time: 	2024年 04月 15日 星期一 20:16:26 CST

System load: 	0.14
Processes: 	196
Memory used: 	40.0%
Swap used: 	14.0%
Usage On: 	26%
IP address: 	192.168.28.131
Users online: 	2
To run a command as administrator(user "root"),use "sudo <command>".
[omm@node0 ~]$ 
步骤 2 执行 gs_dump ,导出的 MPPDB_backup 文件格式为目录格式
[omm@node0 ~]$ gs_dump -U omm -W Bigdata@123 -f /home/omm/logical/backup/bkp_shl2.sql-t public.customer_t1 -p 15400
gs_dump[port='15400'][postgres][2024-04-15 09:35:44]: The total objects number is 421.
gs_dump[port='15400'][postgres][2024-04-15 09:35:44]: [100.00%] 421 objects have been dumped.
gs_dump[port='15400'][postgres][2024-04-15 09:35:44]: dump database postgres successfully
gs_dump[port='15400'][postgres][2024-04-15 09:35:44]: total time: 1161 ms
步骤 3 查看生成的文件信息
[omm@node0 ~]$ ll /home/omm/logical/backup/
total 524
-rw------- 1 omm dbgrp 972 Apr 15 09:35 bkp_shl2.sql
drwx------ 2 omm dbgrp 4096 Apr 15 09:34 MPPDB_backup
-rw------- 1 omm dbgrp 121108 Apr 15 09:33 MPPDB_backup.dmp
-rw------- 1 omm dbgrp 123098 Apr 15 09:24 MPPDB_backup.sql
-rw------- 1 omm dbgrp 277504 Apr 15 09:32 MPPDB_backup.tar
步骤 4 查看生成的 sql 文件
[omm@node0 ~]$ cat /home/omm/logical/backup/bkp_shl2.sql
……
CREATE TABLE customer_t1 (
    c_customer_sk integer,
    c_customer_id character(5),
    c_first_name character(6),
    c_last_name character(8)
)
WITH (orientation=row, compression=no);


ALTER TABLE public.customer_t1 OWNER TO omm;

--
-- Data for Name: customer_t1; Type: TABLE DATA; Schema: public; Owner: omm
--

COPY customer_t1 (c_customer_sk, c_customer_id, c_first_name, c_last_name) FROM stdin;
3769	hello	\N	\N
6885	maps 	Joes  	\N
4321	tpcds	Lily  	\N
9527	world	James 	\N
\.
;

--
-- openGauss database dump complete
--

4.2.8 gs_dump 备份示例 6

执行 gs_dump,导出 postgres 数据库信息,但不导出/home/MPPDB_temp.sql 中指定的表信息。导出的 MPPDB_backup.sql 文件格式为纯文本格式。

步骤 1 以操作系统用户 omm 登录数据库主节点

[root@node0 ~]# su - omm
Last login: Mon Apr 15 20:16:26 CST 2024 on pts/1


Welcome to 5.10.0-153.12.0.92.oe2203sp2.x86_64

System information as of time: 	2024年 04月 15日 星期一 20:40:08 CST

System load: 	0.04
Processes: 	197
Memory used: 	40.1%
Swap used: 	14.2%
Usage On: 	26%
IP address: 	192.168.28.131
Users online: 	2
To run a command as administrator(user "root"),use "sudo <command>".
步骤 2 创建 MPPDB_temp.sql ,填写不导出的表的表名。例如 customer_t1
[omm@node0 ~]$ vi /home/omm/logical/MPPDB_temp.sql
[omm@node0 ~]$ 

输入”i”,切换到 INSERT 模式,输入public.customer_t1”,按下”ESC”,并输入”:wq”后回车

保存后退出。

[omm@node0 ~]$ ll /home/omm/logical/backup/
total 644
-rw------- 1 omm dbgrp 972 Apr 15 09:35 bkp_shl2.sql
drwx------ 2 omm dbgrp 4096 Apr 15 09:34 MPPDB_backup
-rw------- 1 omm dbgrp 122523 Apr 15 09:45 MPPDB_backup2.sql
-rw------- 1 omm dbgrp 121108 Apr 15 09:33 MPPDB_backup.dmp
-rw------- 1 omm dbgrp 123098 Apr 15 09:24 MPPDB_backup.sql
-rw------- 1 omm dbgrp 277504 Apr 15 09:32 MPPDB_backup.tar

步骤 3 执行 gs_dump ,导出 postgres 数据库信息,但不导出 MPPDB_temp.sql 中指定的表信息
[omm@node0 ~]$ gs_dump -U omm -W Bigdata@123 -p 15400 postgres --exclude-tablefile=/home/omm/logical/MPPDB_temp.sql -f /home/omm/logical/backup/MPPDB_backup2.sql
gs_dump[port='15400'][postgres][2024-04-15 09:45:42]: The total objects number is 514.
gs_dump[port='15400'][postgres][2024-04-15 09:45:42]: [100.00%] 514 objects have been dumped.
gs_dump[port='15400'][postgres][2024-04-15 09:45:42]: dump database postgres successfully
gs_dump[port='15400'][postgres][2024-04-15 09:45:42]: total time: 1394 ms
步骤 4 查看生成的文件信息。
[omm@node0 ~]$ ll /home/omm/logical/backup/
total 644
-rw------- 1 omm dbgrp 972 Apr 15 09:35 bkp_shl2.sql
drwx------ 2 omm dbgrp 4096 Apr 15 09:34 MPPDB_backup
-rw------- 1 omm dbgrp 122523 Apr 15 09:45 MPPDB_backup2.sql
-rw------- 1 omm dbgrp 121108 Apr 15 09:33 MPPDB_backup.dmp
-rw------- 1 omm dbgrp 123098 Apr 15 09:24 MPPDB_backup.sql
-rw------- 1 omm dbgrp 277504 Apr 15 09:32 MPPDB_backup.tar

步骤 5 查看生成的 sql 文件,确认没有备份 customer_t1

[omm@node0 ~]$ cat /home/omm/logical/backup/MPPDB_backup2.sql
……

SET search_path = public;

--
-- Name: inx_stu01; Type: INDEX; Schema: public; Owner: omm; Tablespace: 
--

CREATE INDEX inx_stu01 ON student USING btree (std_name) TABLESPACE pg_default;


--
-- Name: public; Type: ACL; Schema: -; Owner: omm
--

REVOKE ALL ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM omm;
GRANT CREATE,USAGE ON SCHEMA public TO omm;
GRANT USAGE ON SCHEMA public TO PUBLIC;


--
-- openGauss database dump complete
--

4.3 gs_dumpall

4.3.1 介绍

gs_dumpall openGauss 用于导出所有数据库相关信息工具,它可以导出 openGauss

据库的所有数据,包括默认数据库 postgres 的数据、自定义数据库的数据、以及

openGauss 所有数据库公共的全局对象。

gs_dumpall 在导出 openGauss 所有数据库时分为两部分:

gs_dumpall 自身对所有数据库公共的全局对象进行导出,包括有关数据库用户和组,表

空间以及属性(例如,适用于数据库整体的访问权限)信息。

gs_dumpall 通过调用 gs_dump 来完成 openGauss 中各数据库的 SQL 脚本文件导出,该脚本文件包含将数据库恢复为其保存时的状态所需要的全部 SQL 语句。

以上两部分导出的结果为纯文本格式的 SQL 脚本文件,使用 gsql 运行该脚本文件可以恢复openGauss 数据库。

4.3.2 操作步骤
步骤 1 切换到 omm 用户,以操作系统用户 omm 登录数据库主节点。
[root@node0 ~]# su - omm
Last login: Mon Apr 15 20:40:08 CST 2024 on pts/1


Welcome to 5.10.0-153.12.0.92.oe2203sp2.x86_64

System information as of time: 	2024年 04月 17日 星期三 23:08:22 CST

System load: 	0.00
Processes: 	196
Memory used: 	11.8%
Swap used: 	0%
Usage On: 	26%
IP address: 	192.168.28.131
Users online: 	1
To run a command as administrator(user "root"),use "sudo <command>".
步骤 2 使用 gs_dumpall 一次导出 openGauss 的所有数据库。
[omm@node0 ~]$ gs_dumpall -f /home/omm/logical/backup/bkp2.sql -p 15400
gs_dump[port='15400'][dbname='db_tpcc02'][2024-04-17 23:10:58]: The total objects number is 427.
gs_dump[port='15400'][dbname='db_tpcc02'][2024-04-17 23:10:58]: [100.00%] 427 objects have been dumped.
gs_dump[port='15400'][dbname='db_tpcc02'][2024-04-17 23:10:58]: dump database dbname='db_tpcc02' successfully
gs_dump[port='15400'][dbname='db_tpcc02'][2024-04-17 23:10:58]: total time: 1494  ms
gs_dump[port='15400'][dbname='foo'][2024-04-17 23:11:00]: The total objects number is 427.
gs_dump[port='15400'][dbname='foo'][2024-04-17 23:11:00]: [100.00%] 427 objects have been dumped.
gs_dump[port='15400'][dbname='foo'][2024-04-17 23:11:00]: dump database dbname='foo' successfully
gs_dump[port='15400'][dbname='foo'][2024-04-17 23:11:00]: total time: 1504  ms
gs_dump[port='15400'][dbname='postgres'][2024-04-17 23:11:02]: The total objects number is 516.
gs_dump[port='15400'][dbname='postgres'][2024-04-17 23:11:02]: [100.00%] 516 objects have been dumped.
gs_dump[port='15400'][dbname='postgres'][2024-04-17 23:11:02]: dump database dbname='postgres' successfully
gs_dump[port='15400'][dbname='postgres'][2024-04-17 23:11:02]: total time: 1930  ms
gs_dumpall[port='15400'][2024-04-17 23:11:02]: dumpall operation successful
gs_dumpall[port='15400'][2024-04-17 23:11:02]: total time: 5055  ms
步骤 3 查看生成的文件信息。
[omm@node0 ~]$ ll /home/omm/logical/backup/
total 776
-rw------- 1 omm dbgrp 127566 Apr 17 23:11 bkp2.sql
-rw------- 1 omm dbgrp    972 Apr 15 09:35 bkp_shl2.sql
drwx------ 2 omm dbgrp   4096 Apr 15 17:49 MPPDB_backup
-rw------- 1 omm dbgrp 122523 Apr 15 09:45 MPPDB_backup2.sql
-rw------- 1 omm dbgrp 123098 Apr 15 20:32 MPPDB_backup.dmp
-rw------- 1 omm dbgrp 123098 Apr 15 17:34 MPPDB_backup.sql
-rw------- 1 omm dbgrp 277504 Apr 15 17:43 MPPDB_backup.tar

4.4 gs_restore

​​​​​​​4.4.1 介绍

gs_restore openGauss 提供的针对 gs_dump 导出数据的导入工具。通过此工具可由gs_dump 生成的导出文件进行导入。

gs_restore 工具由操作系统用户 omm 执行。

主要功能包含:

导入到数据库:

如果连接参数中指定了数据库,则数据将被导入到指定的数据库中。其中,并行导入必须

指定连接的密码。

导入到脚本文件:

如果未指定导入数据库,则创建包含重建数据库所必须的 SQL 语句脚本并写入到文件或者标准输出。等效于直接使用 gs_dump 导出为纯文本格式。

4.4.2 gs_restore 导入示例 1
执行 gs_restore ,将导出的 MPPDB_backup.tar 文件( tar 格式) 导入到 db_tpcc01 数据库。
步骤 1 切换到 omm 用户,以操作系统用户 omm 登录数据库主节点。
[root@node0 ~]# su - omm
Last login: Wed Apr 17 23:08:22 CST 2024 on pts/0


Welcome to 5.10.0-153.12.0.92.oe2203sp2.x86_64

System information as of time: 	2024年 04月 17日 星期三 23:14:53 CST

System load: 	0.06
Processes: 	196
Memory used: 	38.3%
Swap used: 	11.0%
Usage On: 	26%
IP address: 	192.168.28.131
Users online: 	1
To run a command as administrator(user "root"),use "sudo <command>".
步骤 2 连接 openGauss 数据库。
[omm@node0 ~]$ gsql -d postgres -p 15400 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
步骤 3 创建数据库。

openGauss=# DROP DATABASE IF EXISTS db_tpcc01;
NOTICE:  database "db_tpcc01" does not exist, skipping
DROP DATABASE
openGauss=# CREATE DATABASE db_tpcc01;
CREATE DATABASE
步骤 4 退出数据库。
openGauss=# \q
[omm@node0 ~]$ 

​​​​​​​步骤 5 执行 gs_restore,将导出的 MPPDB_backup.tar 文件(tar 格式)导入到 db_tpcc01 数据库。

[omm@node0 ~]$ gs_restore /home/omm/logical/backup/MPPDB_backup.tar -p 15400 -d db_tpcc01

如果成功,显示如下:

start restore operation ...
table mytable complete data imported !
table pmk_configuration complete data imported !
table pmk_meta_data complete data imported !
table pmk_snapshot complete data imported !
table pmk_snapshot_datanode_stat complete data imported !
table a complete data imported !
table class complete data imported !
table course complete data imported !
table customer_t1 complete data imported !
table customer_t2 complete data imported !
table mytable complete data imported !
table school_department complete data imported !
table student complete data imported !
table t1 complete data imported !
table t2 complete data imported !
table t_test complete data imported !
table teacher complete data imported !
table web_returns_p2 complete data imported !
Finish reading 87 SQL statements!
end restore operation ...
restore operation successful
total time: 1165  ms
步骤 6 连接 db_tpcc01 数据库。 ​​​​​​​
[omm@node0 ~]$ gsql -d db_tpcc01 -p 15400 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
步骤 7 查看数据库中恢复的 customer_t1 表。
db_tpcc01=#  select * from customer_t1;
 c_customer_sk | c_customer_id | c_first_name | c_last_name 
---------------+---------------+--------------+-------------
          3769 | hello         |              | 
          6885 | maps          | Joes         | 
          4321 | tpcds         | Lily         | 
          9527 | world         | James        | 
(4 rows)
步骤 8 退出 db_tpcc01 数据库。
db_tpcc01=# \q
[omm@node0 ~]$ 
4.4.3 gs_restore 导入示例 2

执行 gs_restore,将导出的 MPPDB_backup.dmp 文件(自定义归档格式)导入到 db_tpcc02数据库。

步骤 1 切换到 omm 用户,以操作系统用户 omm 登录数据库主节点

[root@node0 ~]# su - omm
Last login: Wed Apr 17 23:14:53 CST 2024 on pts/0


Welcome to 5.10.0-153.12.0.92.oe2203sp2.x86_64

System information as of time: 	2024年 04月 17日 星期三 23:25:56 CST

System load: 	0.06
Processes: 	197
Memory used: 	39.1%
Swap used: 	11.9%
Usage On: 	26%
IP address: 	192.168.28.131
Users online: 	1
To run a command as administrator(user "root"),use "sudo <command>".
步骤 2 连接 openGauss 数据库
[omm@node0 ~]$ gsql -d postgres -p 15400 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
步骤 3 创建数据库
openGauss=# DROP DATABASE IF EXISTS db_tpcc02;
NOTICE:  database "db_tpcc02" does not exist, skipping
DROP DATABASE
openGauss=#  CREATE DATABASE db_tpcc02;
CREATE DATABASE
步骤 4 退出数据库。
openGauss=# \q
[omm@node0 ~]$ 
步骤 5 执行 gs_restore ,将导出的 MPPDB_backup.dmp 文件(自定义归档格式)导入到 db_tpcc02数据库
[omm@node0 ~]$ gs_restore /home/omm/logical/backup/MPPDB_backup.dmp -p 15400 -d db_tpcc02
start restore operation ...
table mytable complete data imported !
table pmk_configuration complete data imported !
table pmk_meta_data complete data imported !
table pmk_snapshot complete data imported !
table pmk_snapshot_datanode_stat complete data imported !
table a complete data imported !
table class complete data imported !
table course complete data imported !
table customer_t1 complete data imported !
table customer_t2 complete data imported !
table mytable complete data imported !
table school_department complete data imported !
table student complete data imported !
table t1 complete data imported !
table t2 complete data imported !
table t_test complete data imported !
table teacher complete data imported !
table web_returns_p2 complete data imported !
Finish reading 87 SQL statements!
end restore operation ...
restore operation successful
total time: 862 ms
步骤 6 连接 db_tpcc02 数据库。
[omm@node0 ~]$ gsql -d db_tpcc02 -p 15400 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

步骤 7 查看数据库中恢复的 customer_t1 表。
db_tpcc02=# select * from customer_t1;
c_customer_sk | c_customer_id | c_first_name | c_last_name 
---------------+---------------+--------------+-------------
 3769 | hello | | 
 6885 | maps | Joes | 
 4321 | tpcds | Lily | 
 9527 | world | James | 
(4 rows)
步骤 8 退出 db_tpcc02 数据库
db_tpcc02=# \q
[omm@node0 ~]$ 
4.4.4 gs_restore 导入示例 3
执行 gs_restore ,将导出的 MPPDB_backup 文件(目录格式) 导入到 postgres 数据库。
步骤 1 切换到 omm 用户,以操作系统用户 omm 登录数据库主节点。
[root@node0 ~]# su - omm
Last login: Wed Apr 17 23:25:56 CST 2024 on pts/0


Welcome to 5.10.0-153.12.0.92.oe2203sp2.x86_64

System information as of time: 	2024年 04月 17日 星期三 23:43:58 CST

System load: 	0.30
Processes: 	196
Memory used: 	39.1%
Swap used: 	14.9%
Usage On: 	26%
IP address: 	192.168.28.131
Users online: 	1
To run a command as administrator(user "root"),use "sudo <command>".
步骤 2 连接 openGauss 数据库。
[omm@node0 ~]$ gsql -d postgres -p 15400 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
步骤 3 创建数据库。
openGauss=# DROP DATABASE IF EXISTS db_tpcc03;
NOTICE:  database "db_tpcc03" does not exist, skipping
DROP DATABASE
openGauss=# CREATE DATABASE db_tpcc03;
CREATE DATABASE

步骤 4 退出数据库

openGauss=# \q
步骤 5 执行 gs_restore ,将导出的 MPPDB_backup 文件(目录格式)导入到 db_tpcc03 数据库。
[omm@node0 ~]$ gs_restore /home/omm/logical/backup/MPPDB_backup -p 15400 -d db_tpcc03
start restore operation ...
table mytable complete data imported !
table pmk_configuration complete data imported !
table pmk_meta_data complete data imported !
table pmk_snapshot complete data imported !
table pmk_snapshot_datanode_stat complete data imported !
table a complete data imported !
table class complete data imported !
table course complete data imported !
table customer_t1 complete data imported !
table customer_t2 complete data imported !
table mytable complete data imported !
table school_department complete data imported !
table student complete data imported !
table t1 complete data imported !
table t2 complete data imported !
table t_test complete data imported !
table teacher complete data imported !
table web_returns_p2 complete data imported !
Finish reading 87 SQL statements!
end restore operation ...
restore operation successful
total time: 1836  ms
[omm@node0 ~]$ 
步骤 6 连接 db_tpcc03 数据库。
[omm@node0 ~]$ gsql -d db_tpcc03 -p 15400 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

步骤 7 查看数据库中恢复的 customer_t1 表。
db_tpcc03=#  select * from customer_t1;
 c_customer_sk | c_customer_id | c_first_name | c_last_name 
---------------+---------------+--------------+-------------
          3769 | hello         |              | 
          6885 | maps          | Joes         | 
          4321 | tpcds         | Lily         | 
          9527 | world         | James        | 
(4 rows)

步骤 8 退出 db_tpcc03 数据库。 ​​​​​​​
db_tpcc03=# \q
[omm@node0 ~]$ 
4.4.5 gs_restore 导入示例 4
执行 gs_restore ,使用自定义归档格式的 MPPDB_backup.dmp 文件来进行如下导入操作。
导入时在重新创建数据库对象前,清理(删除)已存在于将要还原的数据库中的数据库对象。
步骤 1 由于在备份示例 1 已经将所有对象恢复到 db_tpcc01 数据库中,所以在再次导入时如果不先删除已经存在的对象,会出现报错信息。
[omm@node0 ~]$ gs_restore -W Bigdata@123 /home/omm/logical/backup/MPPDB_backup.dmp -p 15400 -d db_tpcc01
start restore operation ...
……
Error from TOC entry 3728; 1259 41282 INDEX inx_stu01 omm
could not execute query: ERROR: relation "inx_stu01" already exists
 Command was: CREATE INDEX inx_stu01 ON student USING btree (std_name) TABLESPACE 
pg_default;
Finish reading 87 SQL statements!
end restore operation ...
WARNING: errors ignored on restore: 69
restore operation successful
total time: 1166 ms
步骤 2 连接 db_tpcc01 数据库
[omm@node0 ~]$ gsql -d db_tpcc01 -p 15400 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
步骤 3 查看数据库中恢复的 customer_t1 表。

db_tpcc01=# select * from customer_t1;
 c_customer_sk | c_customer_id | c_first_name | c_last_name 
---------------+---------------+--------------+-------------
          3769 | hello         |              | 
          6885 | maps          | Joes         | 
          4321 | tpcds         | Lily         | 
          9527 | world         | James        | 
(4 rows)
原有数据表并没有被删除,导入的数据表以数据追加的方式导入数据。
步骤 4 退出数据库
db_tpcc01=# \q
[omm@node0 ~]$ 
步骤 5 输入以下命令,使用 -c 参数手工删除依赖,导入完成后再重新创建
[omm@node0 ~]$ gs_restore -W Bigdata@123 /home/omm/logical/backup/MPPDB_backup.dmp -p 15400 -d db_tpcc01 -e -c
start restore operation ...
table mytable complete data imported !
table pmk_configuration complete data imported !
table pmk_meta_data complete data imported !
table pmk_snapshot complete data imported !
table pmk_snapshot_datanode_stat complete data imported !
table a complete data imported !
table class complete data imported !
table course complete data imported !
table customer_t1 complete data imported !
table customer_t2 complete data imported !
table mytable complete data imported !
table school_department complete data imported !
table student complete data imported !
table t1 complete data imported !
table t2 complete data imported !
table t_test complete data imported !
table teacher complete data imported !
table web_returns_p2 complete data imported !
Finish reading 87 SQL statements!
end restore operation ...
restore operation successful
total time: 1285 ms
注:如果原对象存在跨模式的依赖则需手工强制干预。
步骤 6 连接 db_tpcc01 数据库
[omm@node0 ~]$ gsql -d db_tpcc01 -p 15400 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
步骤 7 查看数据库中恢复的 customer_t1
db_tpcc01=# select * from customer_t1;
 c_customer_sk | c_customer_id | c_first_name | c_last_name 
---------------+---------------+--------------+-------------
          3769 | hello         |              | 
          6885 | maps          | Joes         | 
          4321 | tpcds         | Lily         | 
          9527 | world         | James        | 
(4 rows)
步骤 8 退出数据库
db_tpcc01=# \q
[omm@node0 ~]$ 
原有数据表已经被清除,恢复的是导入的数据表
4.4.6 gs_restore 导入示例 5
执行 gs_restore ,使用自定义归档格式的 MPPDB_backup.dmp 文件来进行如下导入操作。
只导入 PUBLIC 模式下表 customer_t1 的定义。
步骤 1 切换到 omm 用户,以操作系统用户 omm 登录数据库主节点。
[root@node0 ~]# su - omm
Last login: Thu Apr 18 11:39:13 CST 2024 on pts/0


Welcome to 5.10.0-153.12.0.92.oe2203sp2.x86_64

System information as of time: 	2024年 04月 18日 星期四 11:48:17 CST

System load: 	0.08
Processes: 	196
Memory used: 	38.3%
Swap used: 	10.5%
Usage On: 	26%
IP address: 	192.168.28.131
Users online: 	1
To run a command as administrator(user "root"),use "sudo <command>".
步骤 2 连接 openGauss 数据库。
[omm@node0 ~]$ gsql -d postgres -p 15400 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
步骤 3 创建数据库。
openGauss=# DROP DATABASE IF EXISTS db_tpcc04;
NOTICE:  database "db_tpcc04" does not exist, skipping
DROP DATABASE
openGauss=# CREATE DATABASE db_tpcc04;
CREATE DATABASE
openGauss=# 
步骤 4 退出数据库。
openGauss=# \q
[omm@node0 ~]$ 
步骤 5 执行 gs_restore ,只导入 PUBLIC 模式下表 customer_t1 的定义。
[omm@node0 ~]$ gs_restore /home/omm/logical/backup/MPPDB_backup.dmp -p 15400 -d db_tpcc04 -n public -t customer_t1
table customer_t1 complete data imported !
Finish reading 87 SQL statements!
end restore operation ...
restore operation successful
total time: 34 ms
步骤 6 连接 db_tpcc04 数据库。
[omm@node0 ~]$ gsql -d db_tpcc04 -p 15400 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
步骤 7 查看数据库中恢复的 customer_t1 表。
db_tpcc04=# select * from customer_t1;
c_customer_sk | c_customer_id | c_first_name | c_last_name 
---------------+---------------+--------------+-------------
 3769 | hello | | 
 6885 | maps | Joes | 
 4321 | tpcds | Lily | 
 9527 | world | James | 
(4 rows)
步骤 8 查看 postgres 数据库中 LUCY 模式下的表。
db_tpcc04=#  select * from lucy.mytable;
ERROR:  schema "lucy" does not exist
LINE 1: select * from lucy.mytable;
                      ^
db_tpcc04=# 
步骤 9 查看 postgres 数据库中 PUBLIC 模式下的 customer_t2
db_tpcc04=# select * from customer_t2;
ERROR:  relation "customer_t2" does not exist on dn_6001
LINE 1: select * from customer_t2;
                      ^
db_tpcc04=# 
说明只恢复了 PUBLIC shema 模式下的的 customer_t1 表。
本实验结束。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1606084.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Day3 权限管理

Day3 权限管理 这里会总结构建项目过程中遇到的问题&#xff0c;以及一些个人思考&#xff01;&#xff01; 学习方法&#xff1a; 1 github源码 文档 官网 2 内容复现 &#xff0c;实际操作 项目源码同步更新到github 欢迎大家star~ 后期会更新并上传前端项目 创建管理员…

技术周刊的转变:如何平衡热爱与现实?

大家好&#xff0c;我是那个自己打脸自己的猫哥&#xff0c;本来说周刊不做订阅制的&#xff0c;现在却推出了订阅专栏。今天想为自己辩护一下&#xff0c;同时聊聊技术周刊今后的发展计划。 首先回顾一下我过去的想法吧&#xff0c;然后再解释为什么会突然出现转变。 出于对…

Stable Diffusion 3 API 发布!超越Midjourney v6和DALL-E 3

Stable Diffusion 3 于 2 月首次宣布作为预览版发布。而今天&#xff0c;StabilityAI 正式推出了 Stable Diffusion 3 和 Stable Diffusion 3 Turbo API 的API接口服务。 Stability AI 称仍在持续改进该模型&#xff0c;并没有说明发布日期。模型还没发布&#xff0c;但API先来…

Python | Leetcode Python题解之第28题找出字符串中的第一个匹配项的下标

题目&#xff1a; 题解&#xff1a; class Solution:def strStr(self, haystack: str, needle: str) -> int:# Func: 计算偏移表def calShiftMat(st):dic {}for i in range(len(st)-1,-1,-1):if not dic.get(st[i]):dic[st[i]] len(st)-idic["ot"] len(st)1re…

JS-39-underscore01-初识underscore

一、underscore简介 前面我们已经讲过了&#xff0c;JavaScript是函数式编程语言&#xff0c;支持高阶函数和闭包。 函数式编程非常强大&#xff0c;可以写出非常简洁的代码。例如Array的map()和filter()方法&#xff1a; use strict; var a1 [1, 4, 9, 16]; var a2 a1.ma…

数据结构书后习题

p17 1&#xff0c; 个人解答&#xff1a; int DeleteMinElem(SqList &L,int &min) {int j 0;if (L.length 0){printf("error!");return 0;}int min L.data[0];for (int i 1; i < L.length; i){if (L.data[i] < min){min L.data[i];j i;}}L.dat…

电工与电子技术选择题填空题计算题复习题含参考答案

答案&#xff1a;更多答案&#xff0c;请关注【电大搜题】微信公众号 答案&#xff1a;更多答案&#xff0c;请关注【电大搜题】微信公众号 答案&#xff1a;更多答案&#xff0c;请关注【电大搜题】微信公众号 电工与电子技术复习题 一 . 单选题&#xff08;共 33 题&a…

[渗透测试学习] TwoMillion-HackTheBox

TwoMillion-HackTheBox 信息搜集 nmap扫描一下 nmap -sV -v 10.10.11.221扫描结果 PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.1 (Ubuntu Linux; protocol 2.0) 80/tcp open http nginx 3851/tcp f…

SAP 技巧:如何查询TCODE的节点路径。

目录 SAP 技巧&#xff1a;如何查询TCODE的节点路径。 步骤一&#xff1a;在命令栏里输入&#xff1a;Search_SAP_Menu 会弹出以上页面&#xff0c;然后输入你想查询的T-code。回车。 步骤二&#xff1a;找到正确路径&#xff0c; SAP 技巧&#xff1a;如何查询TCODE的节点路…

0418WeCross搭建 + Caliper测试TPS

1. 基本信息 虚拟机名称&#xff1a;Pure-Ununtu18.04 WeCross位置&#xff1a;/root/wecross-demo 2. 搭建并启动WeCross 参考官方指导文档 https://wecross.readthedocs.io/zh-cn/v1.2.0/docs/tutorial/demo/demo.html 访问WeCross网页管理平台 http://localhost:8250/s/…

变频超声波驱鸟器,变电站驱鸟

随着春夏季来临&#xff0c;各种鸟类活动也愈发频繁。这一时期&#xff0c;变电站内有很多中大型鸟类&#xff0c;选择在户外架空高压裸导线龙门架、主变进线支撑架等重要设备上筑巢停留&#xff0c;它们筑巢所用的枝干和各类杂物&#xff0c;时常会掉落&#xff0c;引发设备短…

SQL Server Management Studio 显示行号

前言 在使用 SQL Server Management Studio (SSMS) 进行数据库管理和查询时&#xff0c;能够看到代码的行号是非常有用的。这可以帮助您更容易地定位代码错误、讨论特定的代码行&#xff0c;或者在执行长查询时快速找到特定行。在本文中&#xff0c;我将向您展示如何在 SSMS 中…

怎么你出的MES方案像屎一样?

最近在一个群里面&#xff0c;大家普遍感受到制定MES技术方案变得越来越困难&#xff0c;客户也变得越来越挑剔&#xff0c;方案的复杂度也在不断增加。在竞标过程中&#xff0c;各方技术水平的差距变得越来越小&#xff0c;这让人们感到相当困扰。考虑到这一问题&#xff0c;我…

OpenHarmony多媒体-ohos_videocompressor

介绍 videoCompressor是一款ohos高性能视频压缩器。 目前实现的能力&#xff1a; 支持视频压缩 使用本工程 有两种方式可以下载本工程&#xff1a; 开发者如果想要使用本工程,可以使用git命令 git clone https://gitee.com/openharmony-sig/ohos_videocompressor.git --…

U盘文件突然消失?别急,这里有数据恢复的终极攻略!

在日常的工作和生活中&#xff0c;U盘几乎成了我们随身携带的“数据小仓库”&#xff0c;存放着各种重要的文件。然而&#xff0c;就在某一天&#xff0c;你突然发现U盘中的文件神秘失踪&#xff0c;仿佛从未存在过一般。这种突如其来的U盘文件消失&#xff0c;无疑让人措手不及…

docker拉取镜像速度慢

解决办法是配置阿里云镜像加速 在docker desktop的docker engine里添加 "registry-mirrors": ["https://owzy8hoh.mirror.aliyuncs.com"] 修改以后重启docker 参考&#xff1a; 【docker】Windows10系统下安装并配置阿里云镜像加速_docker desktop 配置…

MySQL中InnoDB的行级锁

InnoDB 实现了以下两种类型的行锁。 共享锁&#xff08;S&#xff09;&#xff1a;又称为读锁&#xff0c;简称S锁&#xff0c;共享锁就是多个事务对于同一数据可以共享一把锁&#xff0c;都能访问到数据&#xff0c;但是只能读不能修改。 排他锁&#xff08;X&#xff09;&am…

仿真科普|从设计到研发,CAE仿真技术为汽车智造保驾护航

2024年3月28日&#xff0c;对于汽车产业来说&#xff0c;是历史性的一天&#xff0c;作为近年汽车行业发布会流量最大的一次&#xff0c;小米SU7的发布让整个汽车圈为之沸腾&#xff0c;成功收割全平台热搜。时至今日&#xff0c;小米汽车依然热度不减。 随着“蔚、小、理、特…

利用米家通断器与双控开关改造排风扇,或手动或定时运行

改造前的排风扇接线图如下&#xff1a; 改造要求&#xff1a;实现手动与智能运行两种控制方式&#xff0c;互不影响。 改造后的米家通断器与双控开关接线图如下&#xff1a; 默认米家通断器与双控开关都是关闭状态。

Leetcode 4.18

Leetcode 1.无重复字符的最长子串2.最长回文子串3.整数反转4.字符串转换整数 (atoi)5.正则表达式匹配 1.无重复字符的最长子串 无重复字符的最长子串 滑动窗口&#xff0c;先让右指针右移&#xff0c;如果发现这个子串有元素和右指针当前元素重复。 则&#xff1a; 左指针右移…