Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V9XLW-0004lv-3q for pgsql-bugs@arkaria.postgresql.org; Wed, 14 Aug 2013 09:26:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1V9XLV-0000bE-J8 for pgsql-bugs@arkaria.postgresql.org; Wed, 14 Aug 2013 09:26:25 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V9XLT-0000aP-Tt for pgsql-bugs@postgresql.org; Wed, 14 Aug 2013 09:26:24 +0000 Received: from mail-pb0-x22d.google.com ([2607:f8b0:400e:c01::22d]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V9XLQ-0001Is-1U for pgsql-bugs@postgresql.org; Wed, 14 Aug 2013 09:26:22 +0000 Received: by mail-pb0-f45.google.com with SMTP id mc17so9117372pbc.32 for ; Wed, 14 Aug 2013 02:26:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:mime-version:content-type:from:in-reply-to:date:cc :message-id:references:to; bh=MnSephQ7NLtmp/no22B0/HAcdT4CSOgZtmTICBfdRYc=; b=JdS0bcN8ls+6+/IaKKPLLdLhLh1lrGEIXhnVxMgi+D5CXSSvhWQbOTITH955kai1DY FFOqnJq7B/TSIdlEg2WUQAkEhLEHlQYytomIeYzcJgVZIfvw6Z2vzeiGl69LQVQJlA8v kRN6LNV1qYu5pBcZuEid+Zje2gRy4KTPoXASu1qQwsCKx9XGyMrzrjlJRLkHM9vPQePL bfF1MVG3lbCHKQQch9eV4kIFsTkZ66iV51bLPyEOq13k+sLDbdtrYMhg7ePlgeRJZnLx +dSolznt28F43f5+O8lxQyxYo5CUO5UDBWUxCQk4KjkOaZI/ghKg5xfUdrAIXmex3OY4 a0Bw== X-Received: by 10.66.155.67 with SMTP id vu3mr8925418pab.42.1376472378666; Wed, 14 Aug 2013 02:26:18 -0700 (PDT) Received: from [192.168.0.102] (014136185055.ctinets.com. [14.136.185.55]) by mx.google.com with ESMTPSA id mz5sm18282330pbc.18.2013.08.14.02.26.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 14 Aug 2013 02:26:18 -0700 (PDT) Subject: Re: Recovery.conf PITR by recovery_target_time Mime-Version: 1.0 (Apple Message framework v1085) Content-Type: multipart/alternative; boundary=Apple-Mail-14-880700230 From: "ascot.moss@gmail.com" In-Reply-To: Date: Wed, 14 Aug 2013 17:26:14 +0800 Cc: "ascot.moss@gmail.com" , pgsql-bugs@postgresql.org Message-Id: <626319BE-63BA-4B41-BF65-EC422C21B6E0@gmail.com> References: <1375985902.2599.YahooMailNeo@web162904.mail.bf1.yahoo.com> <22CFCCDF-F7A3-4F5C-A3B5-5BBE01708AB8@gmail.com> To: Michael Paquier X-Mailer: Apple Mail (2.1085) X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --Apple-Mail-14-880700230 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Thanks very much! I guess you should use the same machine to carry out = the PITR while I am using two physical machines. I will try it again. On 13 Aug 2013, at 12:11 PM, Michael Paquier wrote: > It looks that you are missing something. Similarly to what you did, = here is an example of PITR using a base backup: > 1) Here is my master node doing some archiving: > $ psql -c 'show archive_command' -p 5432 > archive_command =20 > -------------------------------------------------------- > cp -i %p /home/mpaquier/bin/pgsql/archive/node_5432/%f > (1 row) > 2) Creating data folder of new node using a base backup: > pg_basebackup -D ~/bin/pgsql/slave -p 5432 > echo "port =3D 5433" >> ~/bin/pgsql/slave/postgresql.conf > This node will run with port 5433. > 3) Creating some data: > $ psql -c 'CREATE TABLE aa AS SELECT generate_series(1,1000000) AS a' = -p 5432 > SELECT 1000000 > $ date > 2013-08-12 19:47:33 GMT > $ psql -c 'CREATE TABLE bb AS SELECT generate_series(1,1000000) AS a' = -p 5432 > SELECT 1000000 > Similarly to what you did, after doing the recovery table bb will not = exist on the node recovered with PITR. > 4) Preparing recovery for slave: > echo "restore_command =3D 'cp -i = /home/mpaquier/bin/pgsql/archive/node_5432/%f %p'" > = ~/bin/pgsql/slave/recovery.conf > echo "recovery_target_time =3D '2013-08-12 19:47:33 GMT'" >> = ~/bin/pgsql/slave/recovery.conf > 5) Time to perform the PITR: > $ tail -n3 ~/bin/pgsql/slave/pg_log/postgresql-2013-08-12_195441.log > LOG: recovery stopping before commit of transaction 1305, time = 2013-08-12 19:48:22.436774+00 > LOG: recovery has paused > HINT: Execute pg_xlog_replay_resume() to continue. > Note that in this case the recovery has stopped such as you can check = the status of the node before resuming its activity (you can as well = enforce the resume if you wish) > 6) Now let's check that the node is in a correct state: > $ psql -p 5433 > psql (9.3beta2) > Type "help" for help. >=20 > mpaquier=3D# \d > List of relations > Schema | Name | Type | Owner =20 > --------+------+-------+---------- > public | aa | table | mpaquier > (1 row) > And only table aa exists. >=20 > Here is more input after resume xlog replay. > mpaquier=3D# create table bb (a int); -- Node is still in read-only = mode > ERROR: 25006: cannot execute CREATE TABLE in a read-only transaction > LOCATION: PreventCommandIfReadOnly, utility.c:270 > mpaquier=3D# select pg_xlog_replay_resume(); > pg_xlog_replay_resume=20 > ----------------------- > =20 > (1 row) > mpaquier=3D# create table bb (a int); > CREATE TABLE >=20 > Et voila! >=20 > On Mon, Aug 12, 2013 at 7:34 PM, ascot.moss@gmail.com = wrote: > > - check tables from psql: > > postgres=3D# select count(1) from test26; > > count > > --------- > > 2600000 > > (1 row) > Perhaps you are connecting to the master node and not the node that = has been recovered when querying that? >=20 > Regards, > --=20 > Michael --Apple-Mail-14-880700230 Content-Transfer-Encoding: 7bit Content-Type: text/html; charset=us-ascii Thanks very much!  I guess you should use the same machine to carry out the PITR while I am using two physical machines. I will try it again.


On 13 Aug 2013, at 12:11 PM, Michael Paquier wrote:

It looks that you are missing something. Similarly to what you did, here is an example of PITR using a base backup:
1) Here is my master node doing some archiving:
$ psql -c 'show archive_command' -p 5432
                    archive_command                    
--------------------------------------------------------
 cp -i %p /home/mpaquier/bin/pgsql/archive/node_5432/%f
(1 row)
2) Creating data folder of new node using a base backup:
pg_basebackup -D ~/bin/pgsql/slave -p 5432
echo "port = 5433" >> ~/bin/pgsql/slave/postgresql.conf
This node will run with port 5433.
3) Creating some data:
$ psql -c 'CREATE TABLE aa AS SELECT generate_series(1,1000000) AS a' -p 5432
SELECT 1000000
$ date
2013-08-12 19:47:33 GMT
$ psql -c 'CREATE TABLE bb AS SELECT generate_series(1,1000000) AS a' -p 5432
SELECT 1000000
Similarly to what you did, after doing the recovery table bb will not exist on the node recovered with PITR.
4) Preparing recovery for slave:
echo "restore_command = 'cp -i /home/mpaquier/bin/pgsql/archive/node_5432/%f %p'" > ~/bin/pgsql/slave/recovery.conf
echo "recovery_target_time = '2013-08-12 19:47:33 GMT'" >> ~/bin/pgsql/slave/recovery.conf
5) Time to perform the PITR:
$ tail -n3 ~/bin/pgsql/slave/pg_log/postgresql-2013-08-12_195441.log
LOG:  recovery stopping before commit of transaction 1305, time 2013-08-12 19:48:22.436774+00
LOG:  recovery has paused
HINT:  Execute pg_xlog_replay_resume() to continue.
Note that in this case the recovery has stopped such as you can check the status of the node before resuming its activity (you can as well enforce the resume if you wish)
6) Now let's check that the node is in a correct state:
$ psql -p 5433
psql (9.3beta2)
Type "help" for help.

mpaquier=# \d
        List of relations
 Schema | Name | Type  |  Owner  
--------+------+-------+----------
 public | aa   | table | mpaquier
(1 row)
And only table aa exists.

Here is more input after resume xlog replay.
mpaquier=# create table bb (a int); -- Node is still in read-only mode
ERROR:  25006: cannot execute CREATE TABLE in a read-only transaction
LOCATION:  PreventCommandIfReadOnly, utility.c:270
mpaquier=# select pg_xlog_replay_resume();
 pg_xlog_replay_resume
-----------------------
 
(1 row)
mpaquier=# create table bb (a int);
CREATE TABLE

Et voila!

On Mon, Aug 12, 2013 at 7:34 PM, ascot.moss@gmail.com <ascot.moss@gmail.com> wrote:
>         - check tables from psql:
>                 postgres=# select count(1) from test26;
>                   count
>                 ---------
>                 2600000
>                 (1 row)
Perhaps you are connecting to the master node and not the node that has been recovered when querying that?

Regards,
--
Michael

--Apple-Mail-14-880700230--