从port 5435恢复到 port 5436的一次实验
———————————————————————————#
目录
5、创建表,插入2000行数据,commit提交,记录xact_id
6、插入1000行数据,commit提交,记录xact_id
报错,--3、pg_basebackup -p 5435 -U postgres -D /pgccc/pgdata_basebackup/ -Pv
1、root用户建立好新的备份数据实例
root:
mkdir pgdata_basebackup
chown postgres:root pgdata_basebackup/
chmod +R 0750 pgdata_basebackup/
———————————————————————————#
2、切回postgres用户,修改参数文件,重启
vim postgres.conf
wal_level='replica'
archive_mode='on'
archive_command='cp %p /xx/xx/%f'
pg_ctl restart
———————————————————————————#
3、写pg_basebackup命令
pg_basebackup -p 5435 -U postgres -D /pgccc/pgdata_basebackup/ -Pv
执行结果为:
pg_basebackup -p 5435 -U postgres -D /pgccc/pgdata_basebackup/ -Pv
pg_basebackup: initiating base backup, waiting for checkpoint to complete
pg_basebackup: checkpoint completed
pg_basebackup: write-ahead log start point: 0/24000028 on timeline 1
pg_basebackup: starting background WAL receiver
pg_basebackup: created temporary replication slot "pg_basebackup_3162"
63149/63149 kB (100%), 1/1 tablespace
pg_basebackup: write-ahead log end point: 0/24000100
pg_basebackup: waiting for background process to finish streaming ...
pg_basebackup: syncing data to disk ...
pg_basebackup: renaming backup_manifest.tmp to backup_manifest
pg_basebackup: base backup completed
———————————————————————————#
4、检查
~~
pg_verifybackup /pgccc/pgdata_basebackup/
backup successfully verified
~~
cat /pgccc/pgdata_basebackup/backup_label
START WAL LOCATION: 0/24000028 (file 000000010000000000000024)
CHECKPOINT LOCATION: 0/24000060
BACKUP METHOD: streamed
BACKUP FROM: primary
START TIME: 2023-06-02 04:29:52 CST
LABEL: pg_basebackup base backup
START TIMELINE: 1
~~
more /pgccc/pgdata_basebackup/backup_manifest
———————————————————————————#
5、创建表,插入2000行数据,commit提交,记录xact_id
postgres=# create table zcjbakcs(id int,name text);
CREATE TABLE
postgres=# insert into zcjbakcs select n,n||'_zcj' from generate_series(1,2000) n;
INSERT 0 2000
postgres=# commit;
WARNING: there is no transaction in progress
COMMIT
postgres=# select pg_switch_wal();
pg_switch_wal
---------------
0/250234F0
(1 row)
postgres=# select pg_current_xact_id();
pg_current_xact_id
--------------------
1045
(1 row)
———————————————————————————#
6、插入1000行数据,commit提交,记录xact_id
postgres=# insert into zcjbakcs select n,n||'2_zcj' from generate_series(1,1000) n;
INSERT 0 1000
postgres=# commit;
WARNING: there is no transaction in progress
COMMIT
postgres=# select pg_switch_wal();
pg_switch_wal
---------------
0/26018CF0
(1 row)
postgres=# select pg_current_xact_id();
pg_current_xact_id
--------------------
1048
(1 row)
———————————————————————————#
7、去新实例数据路径:pgdata_basebackup
修改postgresql.conf
port改为5436
restore_command='cp /pgccc/pgdata_5432/pg_archive/%f %p '
recovery_target_xid='1000'
recovery_target_action = 'promote'
———————————————————————————#
8、创建recovery.signal
这新实例数据路径下创建recovery.signal
———————————————————————————#
9、启动
./pg_ctl -D /pgccc/pgdata_basebackup/ start
查行数
———————————————————————————#
报错,--3、
pg_basebackup -p 5435 -U postgres -D /pgccc/pgdata_basebackup/ -Pv
[postgres@pgcs pgdata_5432]$ pg_basebackup -p 5435 -U postgres -D /pgccc/pgdata_basebackup/ -Pv
pg_basebackup: initiating base backup, waiting for checkpoint to complete
pg_basebackup: checkpoint completed
pg_basebackup: write-ahead log start point: 0/7000028 on timeline 1
pg_basebackup: error: directory "/pgccc/pgdata_5432/zcjtablespace" exists but is not empty
pg_basebackup: removing contents of data directory "/pgccc/pgdata_basebackup/"
--这说明你的pg有个表空间位置不对