暂无图片
暂无图片
4
暂无图片
暂无图片
暂无图片

PostgreSQL参数—recovery_target_timeline

原创 李先生 2022-02-21
2278

PostgreSQL参数—recovery_target_timeline


PostgreSQL参数—recovery_target_timeline

参数说明

postgres=# show recovery_target_timeline; recovery_target_timeline -------------------------- 1 (1 row) postgres=# \x Expanded display is on. postgres=# select * from pg_settings where name = 'recovery_target_timeline'; -[ RECORD 1 ]---+---------------------------------------------- name | recovery_target_timeline setting | 1 unit | category | Write-Ahead Log / Recovery Target short_desc | Specifies the timeline to recover into. extra_desc | context | postmaster vartype | string source | configuration file min_val | max_val | enumvals | boot_val | latest reset_val | 1 sourcefile | /home/postgres/pgdata14/pg_rman_recovery.conf sourceline | 4 pending_restart | f postgres=#

参数含义

recovery_target_timeline ( ``string
指定恢复到特定时间轴。默认设置是沿着执行基本备份时的当前时间线恢复。将此设置为 latest 将恢复到存档中找到的最新时间轴,这在备用服务器中很有用。

除此之外,您只需要在复杂的重新恢复情况下设置此参数,您需要返回到在时间点恢复后到达的状态。

在通过pg_basebackup进行备份的时候添加参数“-R”就可以在备中自动产生recovery.conf文件,在这里就可以指定recovery_target_timeline=’‘和recovery_target_time=’'参数来进行精准恢复了,而这里的recovery_target_timeline参数可以直接填写时间线产生的“历史文件”名字用来指定恢复到哪一条时间线上去。

[postgres@lyp pg_wal]$ ll total 114696 -rw-------. 1 postgres postgres 16777216 Feb 17 23:01 00000002000000000000000E -rw-------. 1 postgres postgres 16777216 Feb 17 22:56 00000002000000000000000F -rw-------. 1 postgres postgres 16777216 Feb 17 22:51 000000020000000000000010 -rw-------. 1 postgres postgres 16777216 Feb 17 22:51 000000020000000000000011 -rw-------. 1 postgres postgres 16777216 Feb 17 22:51 000000020000000000000012 -rw-------. 1 postgres postgres 16777216 Feb 17 22:51 000000020000000000000013 -rw-------. 1 postgres postgres 16777216 Feb 17 22:51 000000020000000000000014 -rw-------. 1 postgres postgres 50 Feb 17 22:56 00000002.history drwx------. 2 postgres postgres 88 Feb 17 22:56 archive_status [postgres@lyp pg_wal]$

当我们基于时间点的还原后,时间线便会加1,并创建一个名为NewTimelineID.history的新文件。00000002.history即为时间线产生的“历史文件”名字。

[postgres@lyp ~]$ cat /home/postgres/pgdata14/pg_rman_recovery.conf # added by pg_rman 1.3.14 restore_command = 'cp /home/postgres/pgdata14/archive/%f %p' recovery_target_time = '2022-02-17 22:50:19' recovery_target_timeline = '1' [postgres@lyp ~]$

开启数据库之后通过读取归档日志就会将数据库恢复到’2022-02-17 22:50:19’这个时间点。

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论