PostgreSQL13逻辑备份pg_dump
环境参数:
linux版本:CentOS7.6
PG版本:13.5
前期准备
postgres=# create database wcbtest1;
CREATE DATABASE
postgres=# \c wcbtest1
You are now connected to database "wcbtest1" as user "postgres".
wcbtest1=# create table test1(id int,name varchar);
CREATE TABLE
wcbtest1=# insert into test1 values(1,'zhangsan');
INSERT 0 1
wcbtest1=# insert into test1 values(2,'lisi');
INSERT 0 1
wcbtest1=# insert into test1 values(3,'wangwu');
INSERT 0 1
逻辑备份:
[root@wcbpg /]# su - postgres
Last login: Wed Dec 15 16:12:53 CST 2021 on pts/4
#以insert的方式导出
-bash-4.2$ pg_dump wcbtest1 --insert > wcbtest1.sql
-bash-4.2$ ls -l
total 4
drwx------ 4 postgres postgres 51 Nov 28 23:37 13
-rw-r--r-- 1 postgres postgres 904 Dec 15 16:13 wcbtest1.sql
通过SQL恢复
postgres=# create database wcbtest2;
CREATE DATABASE
postgres=# \i wcbtest1.sql
wcbtest2=# select * from public.test1;
1 | zhangsan
2 | lisi
3 | wangwu