agora inbox for pgsql-zh-general@postgresql.org  
help / color / mirror / Atom feed
From: Quan Zongliang <zongliang.quan@postgresdata.com>
To: pgsql-zh-general@postgresql.org <pgsql-zh-general@postgresql.org>
Subject: Postgres 10 highlight - recovery_target_lsn(官方博客翻译)
Date: Tue, 13 Sep 2016 14:52:58 +0800
Message-ID: <e0e168fd-74dc-5bfe-1d64-798de03ee71d@postgresdata.com> (raw)
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-zh-general>

原文链接:
http://paquier.xyz/postgresql-2/postgres-10-recovery-target-lsn/
翻译水平有限,如有疑问以原文为准。

PITR时,PG提供几种估算停止点的方法来停止恢复(WAL重演):
recovery_target_time指定时间戳
recovery_target_name指定名字(用户使用函数pg_create_restore_point()定义的恢复目标)
recovery_target_xid指定XID,恢复到指定事务ID提交的时刻
recovery_target = ‘immediate’ 指定恢复到服务器能够到达的一致性状态
recovery_target_inclusive也可以影响恢复点设置,默认为true。(恢复参数列表见 
这里)

今天的文章是关于新的恢复点类型,由下边的提交引入到PostgreSQL 10:
commit: 35250b6ad7a8ece5cfe54c0316c180df19f36c13
author: Simon Riggs <simon@2ndQuadrant.com>
date: Sat, 3 Sep 2016 17:48:01 +0100
New recovery target recovery_target_lsn

Michael Paquie

LSN是WAL流的位置(也可以成为WAL日志偏移量offset),简单说就是一组知道记录在哪里插入的位置定义,比如“0/7000290”,使用这个参数可以指定记录级恢复。在很多案例中这非常有用,最常见的例子是WAL损坏而用户想尽可能多的恢复数据,不需要深度分析WAL段去查找设置哪一个事务ID或者时间,只需要把它设置到某一记录就好。甚至可以利用像pg_current_xlog_location()这样常规的SQL,找到正在运行的服务器的当前LSN位置。

下边用一个做过基础备份(能够向前重演)的数据库作为例子演示:
=# CREATE TABLE data_to_recover(id int);
CREATE TABLE
=# INSERT INTO data_to_recover VALUES (generate_series(1, 100));
INSERT 0 100
=# SELECT pg_current_xlog_location();
  pg_current_xlog_location
--------------------------
  0/3019838
(1 row)

插入到数据库中的数据使用WAL到位置“0/3019838”(原文 
0/152F080怀疑有误),继续插入更多数据:
=# INSERT INTO data_to_recover VALUES (generate_series(101, 200));
INSERT 0 100
=# SELECT pg_current_xlog_location();
  pg_current_xlog_location
--------------------------
  0/301B1B0
(1 row)

后来插入的数据消耗了一些(WAL)记录,现在我们用包含下边内容的recovery.conf恢复到前100条记录的插入状态(确定最后的WAL段已经归档)。
recovery_target_lsn = '0/3019838'
restore_command = 'cp /path/to/archive/%f %p'

PITR完成以后,会提示类似下边内容的日志(然后恢复暂停)
LOG:  recovery stopping after WAL position (LSN) "0/3019838"

登录到这个结点,只有100条数据:
=# SELECT count(*) FROM data_to_recover;
  count
-------
    100
(1 row)
对我个人而言,它是个强大的工具。

翻译结束

-- 
权宗亮
神州飞象(北京)数据科技有限公司
我们的力量源自最先进的开源数据库PostgreSQL
zongliang.quan@postgresdata.com



-- 
Sent via pgsql-zh-general mailing list (pgsql-zh-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-zh-general



Message-ID: <e0e168fd-74dc-5bfe-1d64-798de03ee71d@postgresdata.com>
Permalink:  ../e0e168fd-74dc-5bfe-1d64-798de03ee71d@postgresdata.com/
Also on:    postgresql.org/message-id/e0e168fd-74dc-5bfe-1d64-798de03ee71d@postgresdata.com

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-zh-general@postgresql.org
  Cc: zongliang.quan@postgresdata.com
  Subject: Re: Postgres 10 highlight - recovery_target_lsn(官方博客翻译)
  In-Reply-To: <e0e168fd-74dc-5bfe-1d64-798de03ee71d@postgresdata.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox