Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uWKRg-00CHdY-C5 for pgsql-general@arkaria.postgresql.org; Mon, 30 Jun 2025 19:45:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uWKRe-001zkH-GY for pgsql-general@arkaria.postgresql.org; Mon, 30 Jun 2025 19:45:39 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uWKRe-001zk9-29 for pgsql-general@lists.postgresql.org; Mon, 30 Jun 2025 19:45:38 +0000 Received: from mail-oi1-x22e.google.com ([2607:f8b0:4864:20::22e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uWKRc-004opY-2r for pgsql-general@lists.postgresql.org; Mon, 30 Jun 2025 19:45:37 +0000 Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-407a3913049so2713043b6e.2 for ; Mon, 30 Jun 2025 12:45:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751312736; x=1751917536; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=t/HZdZM/wYdYKgS5UzZXMjXasCeI+wJDoQMnN9QI1kk=; b=ObYBICvGg1MBl9jXNV1ryqwsvuqzlH3W34kIGm3dqb8u3PWP2qsoKc1xGUvsm4C6dA R3jgMGYg+WkugK/4Vpq9lt6iroz4EGP3usbtrVJK3mept7Qh+LF4zyQdyBdgBPPm0rSQ seA+epn8iDT1iv+cz2L61dspuR9Zl3bEiUX1ikQPEn0PootA+fzIyvsoXWbOvbJyN+C5 JD0bkfdu8ODm9Up1qgMT1LcwAIFojKORIfbgENon9cLtQHV+9pesrY70s2cL7ZkUvjzp LivJ6tIWBNYS1SRva6y/7hkT5k/hboXqLjypj3AvHlWRffPWZMrpP4Giwv9QMDkfQEVj A/9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751312736; x=1751917536; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=t/HZdZM/wYdYKgS5UzZXMjXasCeI+wJDoQMnN9QI1kk=; b=M/dQ3xYkgcfzlJ26Ax74KDvbPU5oqHFgK8cVRn29/3u/jeur5ZQJKRoX/2qUrJ74M9 +q9XzXXKvPAdqiu+bmZdFwc2R4o/QDgdDtmO2cpcuU5QfXvSKW1cahr90l2F/1GpnGxK SLDFNJYap+EULru4/21WPVyPR3sfH+4RFCujM+DplWVM027RMuLgLyWq2Xg0oGl32aqr 511DQBMqfeZ4ESJo12Ib0A71/kGCFYOLe2mBLVALGZcVndSaMsTiXOKMkQpJp74PsuXT xr2kZeSiQaM6bxV33fegBOyE4Fp55VvzgStmPAqCqkQp0bgvVMxAUsaeYN+4M1LO1L/I ShrQ== X-Gm-Message-State: AOJu0YzPKRu7doyhMeXQi6rN5GK5Wc5a7MobCIbcYoyFuj9j2fnpTCF4 95jKDfJtOoNB4XiHbsGGt00kJcnYLPwUYEZyFwOpT32cFeTYCMbkPL/r6ZJeTNoEPTXcXaUqZ1L TgX/3iathE911jcYZVZbAj3o/41G71+hIfQ== X-Gm-Gg: ASbGncuFZS8g1OcK/BqEgzmfkLzPbTTUPAkjscYZPx30nXJUIh7FxxJboghF+8e7JgR VqspYC5LrA/nM/n2zI+tbkd4V123rFl/36uyZf4AObV76OdQwRdO0su4q6o1yLhGYxQaykeKxLr lEhOc4BLezslhNP44dXpX6lclAHZSh4TsVHQXAbu8A3diog/nLICaOwKp0keJK7AEUFP5565QYt nnCVQ== X-Google-Smtp-Source: AGHT+IEspsY/M+HPwCS6jW7I2YfIC75dImpRX4YOaSHWi7YqKucRqixvcgrg5FZM9ysidgsGo6PxlGSv+bH2ZvpHXKI= X-Received: by 2002:a05:6808:4f20:b0:407:59ac:d73f with SMTP id 5614622812f47-40b33e43f8cmr12975387b6e.21.1751312736272; Mon, 30 Jun 2025 12:45:36 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Ron Johnson Date: Mon, 30 Jun 2025 15:45:24 -0400 X-Gm-Features: Ac12FXwcut-dt5O45wwT7cn3JdT2K88-p7N_gS8ZsxFc_6iJgQTlg6oGObi-USM Message-ID: Subject: Re: Simulate a PITR in postgresql 16 To: Franklin Anderson de Oliveira Souza Cc: pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="00000000000089464a0638cf45d7" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000089464a0638cf45d7 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Using PgBackRest might be more convenient, since it handles everything you need, is multithreaded, never removes too many wal files, compresses files if you want and also encrypts them if you want. (In 2025, I also leave pg_wal on the same mount point as data/. Disk space is plentiful and it's just more convenient.) On Mon, Jun 30, 2025 at 3:35=E2=80=AFPM Franklin Anderson de Oliveira Souza= < franklinbr@gmail.com> wrote: > I'm trying to simulate a PITR in postgresql 16 with the following steps: > > directorys: > /data/primary > /data/base > /data/wals > /data/csv > > 1- Create cluster to primary postgresql: > /usr/pgsql-16/bin/initd -D /data/primary > > 2- Start Cluster (1111 port) > /usr/pgsql-16/bin/pg_ctl -D /data/primary start > > 3- Create Database, table, user and slot: > create database "Foo"; > \c Foo; > create table public.acme(hash text); > create role "UserReplication" with login password '123' replication; > select pg_create_physical_replication_slot('slot_wals'); > > 4- Start pg_receivewal: > /usr/pgsql-16/bin/pg_receivewal --host=3Dlocalhost --port=3D1111 > --username=3DUserReplication --slot=3Dslot_wals --verbose --no-loop > --directory=3D/data/wals > > 5- Load file csv on primary server > \COPY public.acme(hash) FROM '/data/csv/file_21444.csv' WITH (FORMAT csv)= ; > > example of file contents: > $ head -n 10 /data/csv/file_21444.csv > hash > 0b035a242b54076056a59 > 4be85c5bcc5fe22191933 > bb5632427c397b421b928 > 6ad913964b556d93379d7 > 99a072b776804e115bb2e > 199834e3fe2d244e09543 > ba296a09a91423401c901 > 9657bfcae2e017e9d6f42 > 0e2d4b2594006930da843 > > At this point wals were created in the /data/wals directory by > pg_receivewal due to the applied load of item 5 on the primary server. > > 6- Create pg_basebackup > pg_basebackup -U UserReplication -h localhost -p1111 -P -v > --wal-method=3Dstream --checkpoint=3Dfast -D /data/base/ > > 7- New load file csv on primary server > \COPY public.acme(hash) FROM '/data/csv/file_38629.csv' WITH (FORMAT csv)= ; > > more wals were created by pg_receivewal with new data load. > > Now I will start the cluster generated by pg_basebackup with the > restore_command parameter > configured to feed on the wals logs generated from the last data load, > thus leaving it updated with the same data as the primary: > > 8- Restore Command Parameter > restore_command =3D 'cp /data/wals/%f %p' # command to use to restore an > archived WAL file > > and > > touch /data/base/recovery.signal > > 9- Start Cluster (2222 port) > /usr/pgsql-16/bin/pg_ctl -D /data/base start > > but when I see the logs I have a surprise > > ----------------- > LOG: starting PostgreSQL 16.3 on x86_64-pc-linux-gnu, compiled by gcc > (GCC) 8.5.0 20210514 (Red Hat 8.5.0-22), 64-bit > LOG: listening on IPv6 address "::1", port 2222 > LOG: listening on IPv4 address "127.0.0.1", port 2222 > LOG: listening on Unix socket "/run/postgresql/.s.PGSQL.2222" > LOG: listening on Unix socket "/tmp/.s.PGSQL.2222" > LOG: database system was shut down at 2025-06-30 12:15:28 -04 > cp: cannot stat '/dados/temp/wals/00000002.history': No such file or > directory > ----------------- > > > The restore_command requires the .history file but it does not exist > in any of the clusters in this simple test, which is wrong in this > example ? Tanks > > -- > foobar > > > --=20 Death to , and butter sauce. Don't boil me, I'm still alive. lobster! --00000000000089464a0638cf45d7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Using PgBackRest might be more convenient, since it handle= s everything you need, is multithreaded, never removes too many wal files, = compresses files if you want and also encrypts them if you want.

(In 2025, I also leave pg_wal on the same mount point as data/.=C2= =A0 Disk space is plentiful and it's just more convenient.)
=
On Mon, Jun 30, 2025 at 3:35=E2=80=AFPM Franklin Anderson d= e Oliveira Souza <franklinbr@gma= il.com> wrote:
I'm trying to simulate a PITR in postgresql 16 with the following= steps:

directorys:
/data/primary
/data/base
/data/wals
/data/csv

1- Create cluster to primary postgresql:
/usr/pgsql-16/bin/initd -D /data/primary

2- Start Cluster (1111 port)
/usr/pgsql-16/bin/pg_ctl -D /data/primary start

3- Create Database, table, user and slot:
create database "Foo";
\c Foo;
create table public.acme(hash text);
create role "UserReplication" with login password '123' r= eplication;
select pg_create_physical_replication_slot('slot_wals');

4- Start pg_receivewal:
/usr/pgsql-16/bin/pg_receivewal --host=3Dlocalhost --port=3D1111
--username=3DUserReplication --slot=3Dslot_wals --verbose --no-loop
--directory=3D/data/wals

5- Load file csv on primary server
\COPY public.acme(hash) FROM '/data/csv/file_21444.csv' WITH (FORMA= T csv);

example of file contents:
$ head -n 10 /data/csv/file_21444.csv
hash
0b035a242b54076056a59
4be85c5bcc5fe22191933
bb5632427c397b421b928
6ad913964b556d93379d7
99a072b776804e115bb2e
199834e3fe2d244e09543
ba296a09a91423401c901
9657bfcae2e017e9d6f42
0e2d4b2594006930da843

At this point wals were created in the /data/wals directory by
pg_receivewal due to the applied load of item 5 on the primary server.

6- Create pg_basebackup
pg_basebackup -U UserReplication -h localhost -p1111 -P -v
--wal-method=3Dstream --checkpoint=3Dfast -D /data/base/

7- New load file csv on primary server
\COPY public.acme(hash) FROM '/data/csv/file_38629.csv' WITH (FORMA= T csv);

more wals were created by pg_receivewal with new data load.

Now I will start the cluster generated by pg_basebackup with the
restore_command parameter
configured to feed on the wals logs generated from the last data load,
thus leaving it updated with the same data as the primary:

8- Restore Command Parameter
restore_command =3D 'cp /data/wals/%f %p' # command to use to resto= re an
archived WAL file

and

touch /data/base/recovery.signal

9- Start Cluster (2222 port)
/usr/pgsql-16/bin/pg_ctl -D /data/base start

but when I see the logs I have a surprise

-----------------
LOG: starting PostgreSQL 16.3 on x86_64-pc-linux-gnu, compiled by gcc
(GCC) 8.5.0 20210514 (Red Hat 8.5.0-22), 64-bit
LOG: listening on IPv6 address "::1", port 2222
LOG: listening on IPv4 address "127.0.0.1", port 2222
LOG: listening on Unix socket "/run/postgresql/.s.PGSQL.2222"
LOG: listening on Unix socket "/tmp/.s.PGSQL.2222"
LOG: database system was shut down at 2025-06-30 12:15:28 -04
cp: cannot stat '/dados/temp/wals/00000002.history': No such file o= r directory
-----------------


The restore_command requires the .history file but it does not exist
in any of the clusters in this simple test, which is wrong in this
example ? Tanks

--
foobar




--
Death to <Redacted>, and butter sauce.Don't boil me, I'm still alive.
<Redacted> lobs= ter!
--00000000000089464a0638cf45d7--