mkdir -p /build
wget -q -O - \ https://github.com/pgbackrest/pgbackrest/archive/release/2.54.1.tar.gz | \ tar zx -C /build
sudo apt-get install python3-distutils meson gcc libpq-dev libssl-dev libxml2-dev \ pkg-config liblz4-dev libzstd-dev libbz2-dev libz-dev libyaml-dev libssh2-1-dev
meson setup /build/pgbackrest /build/pgbackrest-release-2.54.1
ninja -C /build/pgbackrest
sudo apt-get install postgresql-client libxml2 libssh2-1
sudo scp build:/build/pgbackrest/src/pgbackrest /usr/bin
sudo chmod 755 /usr/bin/pgbackrest
sudo mkdir -p -m 770 /var/log/pgbackrest
sudo chown postgres:postgres /var/log/pgbackrest
sudo mkdir -p /etc/pgbackrest
sudo mkdir -p /etc/pgbackrest/conf.d
sudo touch /etc/pgbackrest/pgbackrest.conf
sudo chmod 640 /etc/pgbackrest/pgbackrest.conf
sudo chown postgres:postgres /etc/pgbackrest/pgbackrest.conf
sudo -u postgres pgbackrest
pgBackRest 2.54.1 - General help Usage: pgbackrest [options] [command] Commands: annotate add or modify backup annotation archive-get get a WAL segment from the archive archive-push push a WAL segment to the archive backup backup a database cluster check check the configuration expire expire backups that exceed retention help get help info retrieve information about backups repo-get get a file from a repository repo-ls list files in a repository restore restore a database cluster server pgBackRest server server-ping ping pgBackRest server stanza-create create the required stanza data stanza-delete delete a stanza stanza-upgrade upgrade a stanza start allow pgBackRest processes to run stop stop pgBackRest processes from running verify verify contents of the repository version get version Use 'pgbackrest help [command]' for more information.
sudo -u postgres /usr/lib/postgresql/15/bin/initdb \ -D /var/lib/postgresql/15/demo -k -A peer
sudo pg_createcluster 15 demo
Configuring already existing cluster (configuration: /etc/postgresql/15/demo, data: /var/lib/postgresql/15/demo, owner: 102:103) Ver Cluster Port Status Owner Data directory Log file 15 demo 5432 down postgres /var/lib/postgresql/15/demo /var/log/postgresql/postgresql-15-demo.log
sudo -u postgres bash -c ' \ export PGBACKREST_LOG_PATH=/path/set/by/env && \ pgbackrest --log-level-console=error help backup log-path'
pgBackRest 2.54.1 - 'backup' command - 'log-path' option help Path where log files are stored. The log path provides a location for pgBackRest to store log files. Note that if log-level-file=off then no log path is required.
current: /path/set/by/env
default: /var/log/pgbackrest
sudo mkdir -p /var/lib/pgbackrest
sudo chmod 750 /var/lib/pgbackrest
sudo chown postgres:postgres /var/lib/pgbackrest
sudo pg_ctlcluster 15 demo restart
sudo -u postgres pgbackrest --stanza=demo --log-level-console=info stanza-create
P00 INFO: stanza-create command begin 2.54.1: --exec-id=1042-55083a83 --log-level-console=info --no-log-timestamp --pg1-path=/var/lib/postgresql/15/demo --repo1-cipher-pass=--repo1-cipher-type=aes-256-cbc --repo1-path=/var/lib/pgbackrest --stanza=demo P00 INFO: stanza-create for stanza 'demo' on repo1
P00 INFO: stanza-create command end: completed successfully
sudo -u postgres pgbackrest --stanza=demo --log-level-console=info check
P00 INFO: check command begin 2.54.1: --exec-id=1050-38a41fb9 --log-level-console=info --no-log-timestamp --pg1-path=/var/lib/postgresql/15/demo --repo1-cipher-pass=--repo1-cipher-type=aes-256-cbc --repo1-path=/var/lib/pgbackrest --stanza=demo P00 INFO: check repo1 configuration (primary) P00 INFO: check repo1 archive for WAL (primary)
P00 INFO: WAL segment 000000010000000000000001 successfully archived to '/var/lib/pgbackrest/archive/demo/15-1/0000000100000000/000000010000000000000001-975128076458a721cbec712b0f730e7c7cf71f74.gz' on repo1
P00 INFO: check command end: completed successfully
sudo -u postgres pgbackrest --stanza=demo \ --log-level-console=info backup
P00 INFO: backup command begin 2.54.1: --exec-id=1074-323d70ce --log-level-console=info --no-log-timestamp --pg1-path=/var/lib/postgresql/15/demo --repo1-cipher-pass=--repo1-cipher-type=aes-256-cbc --repo1-path=/var/lib/pgbackrest --repo1-retention-full=2 --stanza=demo --start-fast
P00 WARN: no prior backup exists, incr backup has been changed to full
P00 INFO: execute non-exclusive backup start: backup begins after the requested immediate checkpoint completes P00 INFO: backup start archive = 000000010000000000000002, lsn = 0/2000028 [filtered 3 lines of output] P00 INFO: check archive for segment(s) 000000010000000000000002:000000010000000000000003 P00 INFO: new backup label = 20241216-150925F
P00 INFO: full backup size = 21.8MB, file total = 961
P00 INFO: backup command end: completed successfully P00 INFO: expire command begin 2.54.1: --exec-id=1074-323d70ce --log-level-console=info --no-log-timestamp --repo1-cipher-pass=--repo1-cipher-type=aes-256-cbc --repo1-path=/var/lib/pgbackrest --repo1-retention-full=2 --stanza=demo
sudo -u postgres pgbackrest --stanza=demo --type=diff \ --log-level-console=info backup
[filtered 7 lines of output] P00 INFO: check archive for segment(s) 000000010000000000000004:000000010000000000000005 P00 INFO: new backup label = 20241216-150925F_20241216-150929D
P00 INFO: diff backup size = 8.3KB, file total = 961
P00 INFO: backup command end: completed successfully P00 INFO: expire command begin 2.54.1: --exec-id=1099-5363c32b --log-level-console=info --no-log-timestamp --repo1-cipher-pass=--repo1-cipher-type=aes-256-cbc --repo1-path=/var/lib/pgbackrest --repo1-retention-full=2 --stanza=demo
#m h dom mon dow command 30 06 * * 0 pgbackrest --type=full --stanza=demo backup 30 06 * * 1-6 pgbackrest --type=diff --stanza=demo backup
sudo -u postgres pgbackrest info
stanza: demo status: ok cipher: aes-256-cbc db (current) wal archive min/max (15): 000000010000000000000001/000000010000000000000005
full backup: 20241216-150925F
timestamp start/stop: 2024-12-16 15:09:25+00 / 2024-12-16 15:09:28+00 wal start/stop: 000000010000000000000002 / 000000010000000000000003 database size: 21.8MB, database backup size: 21.8MB repo1: backup set size: 2.9MB, backup size: 2.9MB
diff backup: 20241216-150925F_20241216-150929D
timestamp start/stop: 2024-12-16 15:09:29+00 / 2024-12-16 15:09:30+00 wal start/stop: 000000010000000000000004 / 000000010000000000000005 database size: 21.8MB, database backup size: 8.3KB repo1: backup set size: 2.9MB, backup size: 448B backup reference total: 1 full
sudo pg_ctlcluster 15 demo stop
sudo -u postgres rm /var/lib/postgresql/15/demo/global/pg_control
sudo pg_ctlcluster 15 demo start
Error: /usr/lib/postgresql/15/bin/pg_ctl /usr/lib/postgresql/15/bin/pg_ctl start -D /var/lib/postgresql/15/demo -l /var/log/postgresql/postgresql-15-demo.log -s -o -c config_file="/etc/postgresql/15/demo/postgresql.conf" exited with status 1:
postgres: could not find the database system
Expected to find it in the directory "/var/lib/postgresql/15/demo", but could not open file "/var/lib/postgresql/15/demo/global/pg_control": No such file or directory Examine the log output.
sudo -u postgres find /var/lib/postgresql/15/demo -mindepth 1 -delete
sudo -u postgres pgbackrest --stanza=demo restore
sudo pg_ctlcluster 15 demo start
sudo -u postgres cat \ /var/lib/postgresql/pgbackrest/doc/example/pgsql-pgbackrest-info.sql
-- An example of monitoring pgBackRest from within PostgreSQL -- -- Use copy to export data from the pgBackRest info command into the jsonb -- type so it can be queried directly by PostgreSQL. -- Create monitor schema create schema monitor; -- Get pgBackRest info in JSON format create function monitor.pgbackrest_info() returns jsonb AS $$ declare data jsonb; begin -- Create a temp table to hold the JSON data create temp table temp_pgbackrest_data (data text); -- Copy data into the table directly from the pgBackRest info command copy temp_pgbackrest_data (data) from program 'pgbackrest --output=json info' (format text); select replace(temp_pgbackrest_data.data, E'\n', '\n')::jsonb into data from temp_pgbackrest_data; drop table temp_pgbackrest_data; return data; end $$ language plpgsql;
sudo -u postgres psql -f \ /var/lib/postgresql/pgbackrest/doc/example/pgsql-pgbackrest-info.sql
sudo -u postgres cat \ /var/lib/postgresql/pgbackrest/doc/example/pgsql-pgbackrest-query.sql
-- Get last successful backup for each stanza -- -- Requires the monitor.pgbackrest_info function. with stanza as ( select data->'name' as name, data->'backup'->( jsonb_array_length(data->'backup') - 1) as last_backup, data->'archive'->( jsonb_array_length(data->'archive') - 1) as current_archive from jsonb_array_elements(monitor.pgbackrest_info()) as data ) select name, to_timestamp( (last_backup->'timestamp'->>'stop')::numeric) as last_successful_backup, current_archive->>'max' as last_archived_wal from stanza;
sudo -u postgres psql -f \ /var/lib/postgresql/pgbackrest/doc/example/pgsql-pgbackrest-query.sql
name | last_successful_backup | last_archived_wal --------+------------------------+-------------------------- "demo" | 2024-12-16 15:09:30+00 | 000000010000000000000005 (1 row)
sudo apt-get install jq
sudo -u postgres pgbackrest --output=json --stanza=demo info | \ jq '.[0] | .backup[-1] | .timestamp.stop'
1734361770
sudo -u postgres pgbackrest --output=json --stanza=demo info | \ jq '.[0] | .archive[-1] | .max'
"000000010000000000000005"
sudo -u postgres pgbackrest --stanza=demo --type=full backup
sudo -u postgres find /var/lib/pgbackrest/backup/demo/latest/ -type f | wc -l
5
sudo -u postgres pgbackrest --stanza=demo --annotation=source="demo backup" \ --annotation=key=value --type=full backup
sudo -u postgres pgbackrest --stanza=demo --set=20241216-150945F info
stanza: demo status: ok cipher: aes-256-cbc db (current) wal archive min/max (15): 000000020000000000000007/000000020000000000000009 full backup: 20241216-150945F timestamp start/stop: 2024-12-16 15:09:45+00 / 2024-12-16 15:09:48+00 wal start/stop: 000000020000000000000008 / 000000020000000000000009 lsn start/stop: 0/8000028 / 0/9000088 database size: 21.8MB, database backup size: 21.8MB repo1: backup size: 2.9MB database list: postgres (5)
annotation(s)
key: value source: demo backup
sudo -u postgres pgbackrest --stanza=demo --set=20241216-150945F \ --annotation=key= --annotation=new_key=new_value annotate
sudo -u postgres pgbackrest --stanza=demo --set=20241216-150945F info
stanza: demo status: ok cipher: aes-256-cbc db (current) wal archive min/max (15): 000000020000000000000007/000000020000000000000009 full backup: 20241216-150945F timestamp start/stop: 2024-12-16 15:09:45+00 / 2024-12-16 15:09:48+00 wal start/stop: 000000020000000000000008 / 000000020000000000000009 lsn start/stop: 0/8000028 / 0/9000088 database size: 21.8MB, database backup size: 21.8MB repo1: backup size: 2.9MB database list: postgres (5)
annotation(s)
new_key: new_value source: demo backup
sudo -u postgres pgbackrest --stanza=demo --type=full \ --log-level-console=detail backup
[filtered 973 lines of output] P00 INFO: repo1: remove expired backup 20241216-150943F P00 DETAIL: repo1: 15-1 archive retention on backup 20241216-150945F, start = 000000020000000000000008
P00 INFO: repo1: 15-1 remove archive, start = 000000020000000000000007, stop = 000000020000000000000007
P00 INFO: expire command end: completed successfully
sudo -u postgres pgbackrest --stanza=demo --type=full \ --log-level-console=info backup
[filtered 11 lines of output] P00 INFO: repo1: expire full backup 20241216-150945F P00 INFO: repo1: remove expired backup 20241216-150945F
P00 INFO: repo1: 15-1 remove archive, start = 000000020000000000000008, stop = 000000020000000000000009
P00 INFO: expire command end: completed successfully
rollingset of differentials for the last day or more. This allows quick restores to recent points-in-time but reduces overall space consumption.
sudo -u postgres pgbackrest --stanza=demo --type=diff backup
sudo -u postgres pgbackrest --stanza=demo --type=incr backup
sudo -u postgres pgbackrest --stanza=demo --type=diff \ --log-level-console=info backup
[filtered 10 lines of output] P00 INFO: backup command end: completed successfully P00 INFO: expire command begin 2.54.1: --exec-id=1537-0ebb29d2 --log-level-console=info --no-log-timestamp --repo1-cipher-pass=--repo1-cipher-type=aes-256-cbc --repo1-path=/var/lib/pgbackrest --repo1-retention-diff=1 --repo1-retention-full=2 --stanza=demo
P00 INFO: repo1: expire diff backup set 20241216-150952F_20241216-150954D, 20241216-150952F_20241216-150956I
P00 INFO: repo1: remove expired backup 20241216-150952F_20241216-150956I P00 INFO: repo1: remove expired backup 20241216-150952F_20241216-150954D P00 INFO: expire command end: completed successfully
sudo -u postgres pgbackrest --stanza=demo --type=diff \ --log-level-console=info backup
[filtered 6 lines of output] P00 INFO: backup stop archive = 000000020000000000000017, lsn = 0/17000050 P00 INFO: check archive for segment(s) 000000020000000000000016:000000020000000000000017
P00 INFO: new backup label = 20241216-150952F_20241216-151000D
P00 INFO: diff backup size = 8.3KB, file total = 961 P00 INFO: backup command end: completed successfully [filtered 2 lines of output]
sudo -u postgres pgbackrest --stanza=demo --log-level-console=detail \ --repo1-retention-archive-type=diff --repo1-retention-archive=1 expire
P00 INFO: expire command begin 2.54.1: --exec-id=1613-78385018 --log-level-console=detail --no-log-timestamp --repo1-cipher-pass=--repo1-cipher-type=aes-256-cbc --repo1-path=/var/lib/pgbackrest --repo1-retention-archive=1 --repo1-retention-archive-type=diff --repo1-retention-diff=2 --repo1-retention-full=2 --stanza=demo P00 DETAIL: repo1: 15-1 archive retention on backup 20241216-150950F, start = 00000002000000000000000A, stop = 00000002000000000000000B P00 DETAIL: repo1: 15-1 archive retention on backup 20241216-150952F, start = 00000002000000000000000C, stop = 00000002000000000000000D
P00 DETAIL: repo1: 15-1 archive retention on backup 20241216-150952F_20241216-150957D, start = 000000020000000000000012, stop = 000000020000000000000013
P00 DETAIL: repo1: 15-1 archive retention on backup 20241216-150952F_20241216-151000D, start = 000000020000000000000016
P00 INFO: repo1: 15-1 remove archive, start = 00000002000000000000000E, stop = 000000020000000000000011 P00 INFO: repo1: 15-1 remove archive, start = 000000020000000000000014, stop = 000000020000000000000015
P00 INFO: expire command end: completed successfully
sudo pg_ctlcluster 15 demo stop
sudo -u postgres pgbackrest --stanza=demo --delta \ --log-level-console=detail restore
[filtered 2 lines of output] P00 DETAIL: check '/var/lib/postgresql/15/demo' exists P00 DETAIL: remove 'global/pg_control' so cluster will not start if restore does not complete
P00 INFO: remove invalid files/links/paths from '/var/lib/postgresql/15/demo'
P00 DETAIL: remove invalid file '/var/lib/postgresql/15/demo/backup_label.old' P00 DETAIL: remove invalid file '/var/lib/postgresql/15/demo/base/1/pg_internal.init' [filtered 15 lines of output] P01 DETAIL: restore file /var/lib/postgresql/15/demo/backup_label (260B, 0.00%) checksum 9f9ae79bb90477b96b90a8229341e9ee89f921b2 P01 DETAIL: restore file /var/lib/postgresql/15/demo/pg_multixact/members/0000 - exists and matches backup (bundle 20241216-150952F/1/0, 8KB, 0.04%) checksum 0631457264ff7f8d5fb1edc2c0211992a67c73e6
P01 DETAIL: restore file /var/lib/postgresql/15/demo/PG_VERSION - exists and matches backup (bundle 20241216-150952F/1/40, 3B, 0.04%) checksum 587b596f04f7db9c2cad3d6b87dd2b3a05de4f35
P01 DETAIL: restore file /var/lib/postgresql/15/demo/global/pg_filenode.map - exists and matches backup (bundle 20241216-150952F/1/64, 512B, 0.04%) checksum 8426f71eec225fb3087aa80427d8e6b4e6a8a65b P01 DETAIL: restore file /var/lib/postgresql/15/demo/global/6247 - exists and matches backup (bundle 20241216-150952F/1/232, 8KB, 0.07%) checksum ea40c8171261ed36b40f1597297f0a111790313c [filtered 985 lines of output]
sudo pg_ctlcluster 15 demo start
sudo -u postgres psql -c "create database test1;"
CREATE DATABASE
sudo -u postgres psql -c "create database test2;"
CREATE DATABASE
sudo -u postgres psql -c "create table test1_table (id int); \ insert into test1_table (id) values (1);" test1
CREATE TABLE INSERT 0 1
sudo -u postgres psql -c "create table test2_table (id int); \ insert into test2_table (id) values (2);" test2
CREATE TABLE INSERT 0 1
sudo -u postgres pgbackrest --stanza=demo --type=incr backup
sudo -u postgres du -sh /var/lib/postgresql/15/demo/base/32768
7.3M /var/lib/postgresql/15/demo/base/32768
sudo -u postgres pgbackrest --stanza=demo \ --set=20241216-150952F_20241216-151010I info
[filtered 12 lines of output] repo1: backup size: 2.0MB backup reference list: 20241216-150952F, 20241216-150952F_20241216-151000D
database list: postgres (5), test1 (32768), test2 (32769)
sudo pg_ctlcluster 15 demo stop
sudo -u postgres pgbackrest --stanza=demo --delta \ --db-include=test2 --type=immediate --target-action=promote restore
sudo pg_ctlcluster 15 demo start
sudo -u postgres psql -c "select * from test2_table;" test2
id ---- 2 (1 row)
sudo -u postgres psql -c "select * from test1_table;" test1
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: relation mapping file "base/32768/pg_filenode.map" contains invalid data
sudo -u postgres du -sh /var/lib/postgresql/15/demo/base/32768
8.0K /var/lib/postgresql/15/demo/base/32768
sudo -u postgres psql -c "drop database test1;"
DROP DATABASE
sudo -u postgres psql -c "select oid, datname from pg_database order by oid;"
oid | datname -------+----------- 1 | template1 4 | template0 5 | postgres
32769 | test2
(4 rows)
sudo -u postgres psql -c "begin; \ create table important_table (message text); \ insert into important_table values ('Important Data'); \ commit; \ select * from important_table;"
[filtered 4 lines of output] message ----------------
Important Data
(1 row)
sudo -u postgres psql -Atc "select current_timestamp"
2024-12-16 15:10:20.768816+00
sudo -u postgres psql -c "begin; \ drop table important_table; \ commit; \ select * from important_table;"
BEGIN DROP TABLE
COMMITERROR: relation "important_table" does not exist
LINE 1: ...le important_table; commit; select * from important_... ^
sudo -u postgres pgbackrest --stanza=demo --type=incr backup
sudo -u postgres pgbackrest info
[filtered 38 lines of output] backup reference total: 1 full, 1 diff
incr backup: 20241216-150952F_20241216-151022I
timestamp start/stop: 2024-12-16 15:10:22+00 / 2024-12-16 15:10:23+00 wal start/stop: 00000004000000000000001B / 00000004000000000000001B [filtered 2 lines of output]
sudo pg_ctlcluster 15 demo stop
sudo -u postgres pgbackrest --stanza=demo --delta \ --set=20241216-150952F_20241216-151022I --target-timeline=current \ --type=time "--target=2024-12-16 15:10:20.768816+00" --target-action=promote restore
sudo pg_ctlcluster 15 demo start
[filtered 13 lines of output] LOG: database system is ready to accept read-only connections LOG: redo done at 0/1B000100 system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.04 s
FATAL: recovery ended before configured recovery target was reached
LOG: startup process (PID 1985) exited with exit code 1 LOG: terminating any other active server processes [filtered 3 lines of output]
sudo -u postgres pgbackrest --stanza=demo --delta \ --type=time "--target=2024-12-16 15:10:20.768816+00" \ --target-action=promote restore
sudo -u postgres cat /var/lib/postgresql/15/demo/postgresql.auto.conf
[filtered 9 lines of output] # Recovery settings generated by pgBackRest restore on 2024-12-16 15:10:26 restore_command = 'pgbackrest --stanza=demo archive-get %f "%p"'
recovery_target_time = '2024-12-16 15:10:20.768816+00'
recovery_target_action = 'promote'
sudo pg_ctlcluster 15 demo start
sudo -u postgres psql -c "select * from important_table"
message ----------------
Important Data
(1 row)
sudo -u postgres cat /var/log/postgresql/postgresql-15-demo.log
[filtered 4 lines of output] LOG: database system was interrupted; last known up at 2024-12-16 15:10:10 UTC LOG: restored log file "00000004.history" from archive
LOG: starting point-in-time recovery to 2024-12-16 15:10:20.768816+00
LOG: starting backup recovery with redo LSN 0/1A000028, checkpoint LSN 0/1A000060, on timeline ID 3 LOG: restored log file "00000004.history" from archive [filtered 5 lines of output] LOG: database system is ready to accept read-only connections LOG: restored log file "00000004000000000000001B" from archive
LOG: recovery stopping before commit of transaction 734, time 2024-12-16 15:10:22.191871+00
LOG: redo done at 0/1A0253C8 system usage: CPU: user: 0.00 s, system: 0.01 s, elapsed: 0.10 s
LOG: last completed transaction was at log time 2024-12-16 15:10:19.456101+00
LOG: restored log file "00000004000000000000001A" from archive LOG: selected new timeline ID: 5 [filtered 5 lines of output]
sudo pg_ctlcluster 15 demo stop
sudo -u postgres pgbackrest --stanza=demo --log-level-console=info stop
P00 INFO: stop command begin 2.54.1: --exec-id=2107-9ec16802 --log-level-console=info --no-log-timestamp --stanza=demo
P00 INFO: stop command end: completed successfully
sudo -u postgres pgbackrest --stanza=demo --repo=1 \ --log-level-console=info stanza-delete
P00 INFO: stanza-delete command begin 2.54.1: --exec-id=2114-93d0eb9a --log-level-console=info --no-log-timestamp --pg1-path=/var/lib/postgresql/15/demo --repo=1 --repo1-cipher-pass=--repo1-cipher-type=aes-256-cbc --repo1-path=/var/lib/pgbackrest --stanza=demo
P00 INFO: stanza-delete command end: completed successfully
hierarchical namespaceas this will cause errors during expire.
sudo -u postgres pgbackrest --stanza=demo --log-level-console=info stanza-create
P00 INFO: stanza-create command begin 2.54.1: --exec-id=2184-3469c962 --log-level-console=info --no-log-timestamp --pg1-path=/var/lib/postgresql/15/demo --repo2-azure-account=--repo2-azure-container=demo-container --repo2-azure-key= --repo1-cipher-pass= --repo1-cipher-type=aes-256-cbc --repo1-path=/var/lib/pgbackrest --repo2-path=/demo-repo --repo2-type=azure --stanza=demo P00 INFO: stanza-create for stanza 'demo' on repo1 P00 INFO: stanza-create for stanza 'demo' on repo2
P00 INFO: stanza-create command end: completed successfully
sudo -u postgres pgbackrest --stanza=demo --repo=2 \ --log-level-console=info backup
P00 INFO: backup command begin 2.54.1: --exec-id=2193-c0242312 --log-level-console=info --no-log-timestamp --pg1-path=/var/lib/postgresql/15/demo --process-max=4 --repo=2 --repo2-azure-account=--repo2-azure-container=demo-container --repo2-azure-key= --repo1-block --repo1-bundle --repo1-cipher-pass= --repo1-cipher-type=aes-256-cbc --repo1-path=/var/lib/pgbackrest --repo2-path=/demo-repo --repo1-retention-diff=2 --repo1-retention-full=2 --repo2-retention-full=4 --repo2-type=azure --stanza=demo --start-fast
P00 WARN: no prior backup exists, incr backup has been changed to full
P00 INFO: execute non-exclusive backup start: backup begins after the requested immediate checkpoint completes P00 INFO: backup start archive = 00000005000000000000001C, lsn = 0/1C000028 [filtered 3 lines of output] P00 INFO: check archive for segment(s) 00000005000000000000001C:00000005000000000000001C P00 INFO: new backup label = 20241216-151038F
P00 INFO: full backup size = 29.0MB, file total = 1263
P00 INFO: backup command end: completed successfully P00 INFO: expire command begin 2.54.1: --exec-id=2193-c0242312 --log-level-console=info --no-log-timestamp --repo=2 --repo2-azure-account=--repo2-azure-container=demo-container --repo2-azure-key= --repo1-cipher-pass= --repo1-cipher-type=aes-256-cbc --repo1-path=/var/lib/pgbackrest --repo2-path=/demo-repo --repo1-retention-diff=2 --repo1-retention-full=2 --repo2-retention-full=4 --repo2-type=azure --stanza=demo
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:ListBucket" ], "Resource": [ "arn:aws:s3:::demo-bucket" ], "Condition": { "StringEquals": { "s3:prefix": [ "", "demo-repo" ], "s3:delimiter": [ "/" ] } } }, { "Effect": "Allow", "Action": [ "s3:ListBucket" ], "Resource": [ "arn:aws:s3:::demo-bucket" ], "Condition": { "StringLike": { "s3:prefix": [ "demo-repo/*" ] } } }, { "Effect": "Allow", "Action": [ "s3:PutObject", "s3:PutObjectTagging", "s3:GetObject", "s3:GetObjectVersion", "s3:DeleteObject" ], "Resource": [ "arn:aws:s3:::demo-bucket/demo-repo/*" ] } ] }
sudo -u postgres pgbackrest --stanza=demo --log-level-console=info stanza-create
[filtered 4 lines of output] P00 INFO: stanza 'demo' already exists on repo2 and is valid P00 INFO: stanza-create for stanza 'demo' on repo3
P00 INFO: stanza-create command end: completed successfully
sudo -u postgres pgbackrest --stanza=demo --repo=3 \ --log-level-console=info backup
P00 INFO: backup command begin 2.54.1: --exec-id=2243-ef9e1153 --log-level-console=info --no-log-timestamp --pg1-path=/var/lib/postgresql/15/demo --process-max=4 --repo=3 --repo2-azure-account=--repo2-azure-container=demo-container --repo2-azure-key= --repo1-block --repo1-bundle --repo1-cipher-pass= --repo1-cipher-type=aes-256-cbc --repo1-path=/var/lib/pgbackrest --repo2-path=/demo-repo --repo3-path=/demo-repo --repo1-retention-diff=2 --repo1-retention-full=2 --repo2-retention-full=4 --repo3-retention-full=4 --repo3-s3-bucket=demo-bucket --repo3-s3-endpoint=s3.us-east-1.amazonaws.com --repo3-s3-key= --repo3-s3-key-secret= --repo3-s3-region=us-east-1 --repo2-type=azure --repo3-type=s3 --stanza=demo --start-fast
P00 WARN: no prior backup exists, incr backup has been changed to full
P00 INFO: execute non-exclusive backup start: backup begins after the requested immediate checkpoint completes P00 INFO: backup start archive = 00000005000000000000001D, lsn = 0/1D000028 [filtered 3 lines of output] P00 INFO: check archive for segment(s) 00000005000000000000001D:00000005000000000000001E P00 INFO: new backup label = 20241216-151047F
P00 INFO: full backup size = 29.0MB, file total = 1263
P00 INFO: backup command end: completed successfully P00 INFO: expire command begin 2.54.1: --exec-id=2243-ef9e1153 --log-level-console=info --no-log-timestamp --repo=3 --repo2-azure-account=--repo2-azure-container=demo-container --repo2-azure-key= --repo1-cipher-pass= --repo1-cipher-type=aes-256-cbc --repo1-path=/var/lib/pgbackrest --repo2-path=/demo-repo --repo3-path=/demo-repo --repo1-retention-diff=2 --repo1-retention-full=2 --repo2-retention-full=4 --repo3-retention-full=4 --repo3-s3-bucket=demo-bucket --repo3-s3-endpoint=s3.us-east-1.amazonaws.com --repo3-s3-key= --repo3-s3-key-secret= --repo3-s3-region=us-east-1 --repo2-type=azure --repo3-type=s3 --stanza=demo
sudo -u postgres mkdir -m 750 -p /var/lib/postgresql/.ssh
sudo -u postgres ssh-keygen -f /var/lib/postgresql/.ssh/id_rsa_sftp \ -t rsa -b 4096 -N "" -m PEM
sudo -u pgbackrest mkdir -m 750 -p /home/pgbackrest/.ssh
(sudo ssh root@pg-primary cat /var/lib/postgresql/.ssh/id_rsa_sftp.pub) | \ sudo -u pgbackrest tee -a /home/pgbackrest/.ssh/authorized_keys
strict
ssh-keyscan -H sftp-server >> /var/lib/postgresql/.ssh/known_hosts 2>/dev/null
sudo -u postgres pgbackrest --stanza=demo --log-level-console=info stanza-create
[filtered 6 lines of output] P00 INFO: stanza 'demo' already exists on repo3 and is valid P00 INFO: stanza-create for stanza 'demo' on repo4
P00 INFO: stanza-create command end: completed successfully
sudo -u postgres pgbackrest --stanza=demo --repo=4 \ --log-level-console=info backup
P00 INFO: backup command begin 2.54.1: --exec-id=2326-7914539c --log-level-console=info --no-log-timestamp --pg1-path=/var/lib/postgresql/15/demo --process-max=4 --repo=4 --repo2-azure-account=--repo2-azure-container=demo-container --repo2-azure-key= --repo1-block --repo1-bundle --repo4-bundle --repo1-cipher-pass= --repo1-cipher-type=aes-256-cbc --repo1-path=/var/lib/pgbackrest --repo2-path=/demo-repo --repo3-path=/demo-repo --repo4-path=/demo-repo --repo1-retention-diff=2 --repo1-retention-full=2 --repo2-retention-full=4 --repo3-retention-full=4 --repo3-s3-bucket=demo-bucket --repo3-s3-endpoint=s3.us-east-1.amazonaws.com --repo3-s3-key= --repo3-s3-key-secret= --repo3-s3-region=us-east-1 --repo4-sftp-host=sftp-server --repo4-sftp-host-key-hash-type=sha1 --repo4-sftp-host-user=pgbackrest --repo4-sftp-private-key-file=/var/lib/postgresql/.ssh/id_rsa_sftp --repo4-sftp-public-key-file=/var/lib/postgresql/.ssh/id_rsa_sftp.pub --repo2-type=azure --repo3-type=s3 --repo4-type=sftp --stanza=demo --start-fast P00 WARN: option 'repo4-retention-full' is not set for 'repo4-retention-full-type=count', the repository may run out of space HINT: to retain full backups indefinitely (without warning), set option 'repo4-retention-full' to the maximum.
P00 WARN: no prior backup exists, incr backup has been changed to full
P00 INFO: execute non-exclusive backup start: backup begins after the requested immediate checkpoint completes P00 INFO: backup start archive = 00000005000000000000001F, lsn = 0/1F000028 [filtered 3 lines of output] P00 INFO: check archive for segment(s) 00000005000000000000001F:000000050000000000000020 P00 INFO: new backup label = 20241216-151055F
P00 INFO: full backup size = 29.0MB, file total = 1263
P00 INFO: backup command end: completed successfully P00 INFO: expire command begin 2.54.1: --exec-id=2326-7914539c --log-level-console=info --no-log-timestamp --repo=4 --repo2-azure-account=--repo2-azure-container=demo-container --repo2-azure-key= --repo1-cipher-pass= --repo1-cipher-type=aes-256-cbc --repo1-path=/var/lib/pgbackrest --repo2-path=/demo-repo --repo3-path=/demo-repo --repo4-path=/demo-repo --repo1-retention-diff=2 --repo1-retention-full=2 --repo2-retention-full=4 --repo3-retention-full=4 --repo3-s3-bucket=demo-bucket --repo3-s3-endpoint=s3.us-east-1.amazonaws.com --repo3-s3-key= --repo3-s3-key-secret= --repo3-s3-region=us-east-1 --repo4-sftp-host=sftp-server --repo4-sftp-host-key-hash-type=sha1 --repo4-sftp-host-user=pgbackrest --repo4-sftp-private-key-file=/var/lib/postgresql/.ssh/id_rsa_sftp --repo4-sftp-public-key-file=/var/lib/postgresql/.ssh/id_rsa_sftp.pub --repo2-type=azure --repo3-type=s3 --repo4-type=sftp --stanza=demo P00 INFO: expire command end: completed successfully
sudo pg_ctlcluster 15 demo stop
sudo -u postgres pgbackrest --stanza=demo stop
sudo -u postgres pgbackrest --stanza=demo --repo=3 stanza-delete
sudo -u postgres pgbackrest --stanza=demo --repo=3 info
stanza: demo
status: error (missing stanza data)
cipher: none
mc ls --versions s3/demo-bucket/demo-repo/backup/demo/backup.info
[2024-12-16 15:11:01 UTC] 0B STANDARD 7f1a6b60-c216-4b27-b20b-eac66bd9414b v3 DEL backup.info [2024-12-16 15:10:52 UTC] 1.0KiB STANDARD 8c787d18-e0fb-4b81-a99e-be0aafccc48f v2 PUT backup.info [2024-12-16 15:10:47 UTC] 372B STANDARD fcd64a54-6d60-4106-8d07-a2c4c9fba75d v1 PUT backup.info
[2024-12-16 15:11:01 UTC] 0B STANDARD 13c1b7e1-22bb-453c-bc3e-f5262f113743 v3 DEL backup.info.copy [2024-12-16 15:10:52 UTC] 1.0KiB STANDARD 7aaa1925-53fb-4321-b077-944032075072 v2 PUT backup.info.copy
sudo -u postgres pgbackrest --stanza=demo --repo=3 \ --repo-target-time="2024-12-16 15:10:52+00" info
[filtered 5 lines of output] wal archive min/max (15): 00000005000000000000001D/00000005000000000000001E
full backup: 20241216-151047F
timestamp start/stop: 2024-12-16 15:10:47+00 / 2024-12-16 15:10:51+00 wal start/stop: 00000005000000000000001D / 00000005000000000000001E repo3: backup set size: 3.9MB, backup size: 3.9MB
sudo -u postgres pgbackrest --stanza=demo --repo=3 --delta \ --repo-target-time="2024-12-16 15:10:52+00" --log-level-console=info restore
P00 INFO: restore command begin 2.54.1: --delta --exec-id=2403-58129653 --log-level-console=info --no-log-timestamp --pg1-path=/var/lib/postgresql/15/demo --process-max=4 --repo=3 --repo2-azure-account=--repo2-azure-container=demo-container --repo2-azure-key= --repo1-cipher-pass= --repo1-cipher-type=aes-256-cbc --repo5-gcs-bucket=demo-bucket --repo5-gcs-key= --repo1-path=/var/lib/pgbackrest --repo2-path=/demo-repo --repo3-path=/demo-repo --repo4-path=/demo-repo --repo5-path=/demo-repo --repo3-s3-bucket=demo-bucket --repo3-s3-endpoint=s3.us-east-1.amazonaws.com --repo3-s3-key= --repo3-s3-key-secret= --repo3-s3-region=us-east-1 --repo4-sftp-host=sftp-server --repo4-sftp-host-key-hash-type=sha1 --repo4-sftp-host-user=pgbackrest --repo4-sftp-private-key-file=/var/lib/postgresql/.ssh/id_rsa_sftp --repo4-sftp-public-key-file=/var/lib/postgresql/.ssh/id_rsa_sftp.pub --repo-target-time="2024-12-16 15:10:52+00" --repo2-type=azure --repo3-type=s3 --repo4-type=sftp --repo5-type=gcs --stanza=demo
P00 INFO: repo3: restore backup set 20241216-151047F, recovery will start at 2024-12-16 15:10:47
P00 INFO: remove invalid files/links/paths from '/var/lib/postgresql/15/demo' P00 INFO: write updated /var/lib/postgresql/15/demo/postgresql.auto.conf [filtered 2 lines of output]
sudo pg_ctlcluster 15 demo start
sudo adduser --disabled-password --gecos "" pgbackrest
sudo apt-get install postgresql-client libxml2 libssh2-1
sudo scp build:/build/pgbackrest/src/pgbackrest /usr/bin
sudo chmod 755 /usr/bin/pgbackrest
sudo mkdir -p -m 770 /var/log/pgbackrest
sudo chown pgbackrest:pgbackrest /var/log/pgbackrest
sudo mkdir -p /etc/pgbackrest
sudo mkdir -p /etc/pgbackrest/conf.d
sudo touch /etc/pgbackrest/pgbackrest.conf
sudo chmod 640 /etc/pgbackrest/pgbackrest.conf
sudo chown pgbackrest:pgbackrest /etc/pgbackrest/pgbackrest.conf
sudo mkdir -p /var/lib/pgbackrest
sudo chmod 750 /var/lib/pgbackrest
sudo chown pgbackrest:pgbackrest /var/lib/pgbackrest
sudo -u pgbackrest mkdir -m 750 /home/pgbackrest/.ssh
sudo -u pgbackrest ssh-keygen -f /home/pgbackrest/.ssh/id_rsa \ -t rsa -b 4096 -N ""
sudo -u postgres mkdir -m 750 -p /var/lib/postgresql/.ssh
sudo -u postgres ssh-keygen -f /var/lib/postgresql/.ssh/id_rsa \ -t rsa -b 4096 -N ""
(echo -n 'no-agent-forwarding,no-X11-forwarding,no-port-forwarding,' && \ echo -n 'command="/usr/bin/pgbackrest ${SSH_ORIGINAL_COMMAND#* }" ' && \ sudo ssh root@pg-primary cat /var/lib/postgresql/.ssh/id_rsa.pub) | \ sudo -u pgbackrest tee -a /home/pgbackrest/.ssh/authorized_keys
(echo -n 'no-agent-forwarding,no-X11-forwarding,no-port-forwarding,' && \ echo -n 'command="/usr/bin/pgbackrest ${SSH_ORIGINAL_COMMAND#* }" ' && \ sudo ssh root@repository cat /home/pgbackrest/.ssh/id_rsa.pub) | \ sudo -u postgres tee -a /var/lib/postgresql/.ssh/authorized_keys
sudo -u pgbackrest ssh postgres@pg-primary
sudo -u postgres ssh pgbackrest@repository
sudo -u pgbackrest pgbackrest --stanza=demo stanza-create
sudo -u postgres pgbackrest --stanza=demo check
sudo -u pgbackrest pgbackrest --stanza=demo check
sudo -u pgbackrest pgbackrest --stanza=demo backup
P00 WARN: no prior backup exists, incr backup has been changed to full
sudo pg_ctlcluster 15 demo stop
sudo -u postgres pgbackrest --stanza=demo --delta restore
sudo pg_ctlcluster 15 demo start
sudo -u pgbackrest pgbackrest --stanza=demo --type=full backup
sudo -u pgbackrest pgbackrest --stanza=demo --type=full backup
sudo -u pgbackrest pgbackrest info
stanza: demo status: ok cipher: none db (current) wal archive min/max (15): 000000070000000000000024/000000070000000000000026 full backup: 20241216-151135F
timestamp start/stop: 2024-12-16 15:11:35+00 / 2024-12-16 15:11:40+00
wal start/stop: 000000070000000000000024 / 000000070000000000000024 database size: 29.0MB, database backup size: 29.0MB repo1: backup set size: 3.9MB, backup size: 3.9MB full backup: 20241216-151141F
timestamp start/stop: 2024-12-16 15:11:41+00 / 2024-12-16 15:11:46+00
wal start/stop: 000000070000000000000025 / 000000070000000000000026 database size: 29.0MB, database backup size: 29.0MB repo1: backup set size: 3.9MB, backup size: 3.9MB
sudo -u postgres pgbackrest stop
sudo -u pgbackrest pgbackrest --stanza=demo backup
P00 WARN: unable to check pg1: [StopError] raised from remote-0 ssh protocol on 'pg-primary': stop file exists for all stanzas
P00 ERROR: [056]: unable to find primary cluster - cannot proceed HINT: are all available clusters in recovery?
sudo -u postgres pgbackrest stop
P00 WARN: stop file already exists for all stanzas
sudo -u postgres pgbackrest start
sudo -u postgres pgbackrest --stanza=demo stop
sudo -u pgbackrest pgbackrest --stanza=demo backup
P00 WARN: unable to check pg1: [StopError] raised from remote-0 ssh protocol on 'pg-primary': stop file exists for stanza demo
P00 ERROR: [056]: unable to find primary cluster - cannot proceed HINT: are all available clusters in recovery?
sudo -u postgres pgbackrest --stanza=demo start
sudo apt-get install postgresql-client libxml2 libssh2-1
sudo scp build:/build/pgbackrest/src/pgbackrest /usr/bin
sudo chmod 755 /usr/bin/pgbackrest
sudo mkdir -p -m 770 /var/log/pgbackrest
sudo chown postgres:postgres /var/log/pgbackrest
sudo mkdir -p /etc/pgbackrest
sudo mkdir -p /etc/pgbackrest/conf.d
sudo touch /etc/pgbackrest/pgbackrest.conf
sudo chmod 640 /etc/pgbackrest/pgbackrest.conf
sudo chown postgres:postgres /etc/pgbackrest/pgbackrest.conf
sudo -u postgres mkdir -m 750 -p /var/lib/postgresql/.ssh
sudo -u postgres ssh-keygen -f /var/lib/postgresql/.ssh/id_rsa \ -t rsa -b 4096 -N ""
(echo -n 'no-agent-forwarding,no-X11-forwarding,no-port-forwarding,' && \ echo -n 'command="/usr/bin/pgbackrest ${SSH_ORIGINAL_COMMAND#* }" ' && \ sudo ssh root@pg-standby cat /var/lib/postgresql/.ssh/id_rsa.pub) | \ sudo -u pgbackrest tee -a /home/pgbackrest/.ssh/authorized_keys
(echo -n 'no-agent-forwarding,no-X11-forwarding,no-port-forwarding,' && \ echo -n 'command="/usr/bin/pgbackrest ${SSH_ORIGINAL_COMMAND#* }" ' && \ sudo ssh root@repository cat /home/pgbackrest/.ssh/id_rsa.pub) | \ sudo -u postgres tee -a /var/lib/postgresql/.ssh/authorized_keys
sudo -u pgbackrest ssh postgres@pg-standby
sudo -u postgres ssh pgbackrest@repository
sudo pg_createcluster 15 demo
sudo -u postgres pgbackrest --stanza=demo --delta --type=standby restore
sudo -u postgres cat /var/lib/postgresql/15/demo/postgresql.auto.conf
# Do not edit this file manually! # It will be overwritten by the ALTER SYSTEM command. # Recovery settings generated by pgBackRest restore on 2024-12-16 15:09:32 restore_command = 'pgbackrest --stanza=demo archive-get %f "%p"' # Recovery settings generated by pgBackRest restore on 2024-12-16 15:10:03 restore_command = 'pgbackrest --stanza=demo archive-get %f "%p"' # Recovery settings generated by pgBackRest restore on 2024-12-16 15:10:26 restore_command = 'pgbackrest --stanza=demo archive-get %f "%p"' # Removed by pgBackRest restore on 2024-12-16 15:11:05 # recovery_target_time = '2024-12-16 15:10:20.768816+00' # Removed by pgBackRest restore on 2024-12-16 15:11:05 # recovery_target_action = 'promote' # Recovery settings generated by pgBackRest restore on 2024-12-16 15:11:05 restore_command = 'pgbackrest --repo=3 --repo-target-time="2024-12-16 15:10:52+00" --stanza=demo archive-get %f "%p"' # Recovery settings generated by pgBackRest restore on 2024-12-16 15:11:29 restore_command = 'pgbackrest --stanza=demo archive-get %f "%p"' # Recovery settings generated by pgBackRest restore on 2024-12-16 15:12:04 restore_command = 'pgbackrest --stanza=demo archive-get %f "%p"'
sudo pg_ctlcluster 15 demo start
sudo -u postgres cat /var/log/postgresql/postgresql-15-demo.log
[filtered 3 lines of output] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" LOG: database system was interrupted; last known up at 2024-12-16 15:11:41 UTC
LOG: entering standby mode
LOG: starting backup recovery with redo LSN 0/25000028, checkpoint LSN 0/25000060, on timeline ID 7 LOG: restored log file "00000007.history" from archive [filtered 6 lines of output]
sudo -u postgres psql -c " \ begin; \ create table replicated_table (message text); \ insert into replicated_table values ('Important Data'); \ commit; \ select * from replicated_table";
[filtered 4 lines of output] message ----------------
Important Data
(1 row)
sudo -u postgres psql -c "select * from replicated_table;"
ERROR: relation "replicated_table" does not exist
LINE 1: select * from replicated_table; ^
sudo -u postgres psql -c "select *, current_timestamp from pg_switch_wal()";
pg_switch_wal | current_timestamp ---------------+------------------------------- 0/27019A40 | 2024-12-16 15:12:11.380861+00 (1 row)
sudo -u postgres psql -c " \ select *, current_timestamp from replicated_table"
message | current_timestamp ----------------+-------------------------------
Important Data | 2024-12-16 15:12:17.659324+00
(1 row)
sudo -u postgres pgbackrest --stanza=demo --log-level-console=info check
P00 INFO: check command begin 2.54.1: --exec-id=1261-2714b3d2 --log-level-console=info --log-level-file=detail --no-log-timestamp --pg1-path=/var/lib/postgresql/15/demo --repo1-host=repository --stanza=demo P00 INFO: check repo1 (standby)
P00 INFO: switch wal not performed because this is a standby
P00 INFO: check command end: completed successfully
sudo -u postgres psql -c " \ create user replicator password 'jw8s0F4' replication";
CREATE ROLE
sudo -u postgres sh -c 'echo \ "host replication replicator 172.17.0.8/32 md5" \ >> /etc/postgresql/15/demo/pg_hba.conf'
sudo pg_ctlcluster 15 demo reload
sudo -u postgres sh -c 'echo \ "172.17.0.6:*:replication:replicator:jw8s0F4" \ >> /var/lib/postgresql/.pgpass'
sudo -u postgres chmod 600 /var/lib/postgresql/.pgpass
sudo pg_ctlcluster 15 demo stop
sudo -u postgres pgbackrest --stanza=demo --delta --type=standby restore
sudo -u postgres cat /var/lib/postgresql/15/demo/postgresql.auto.conf
# Do not edit this file manually! # It will be overwritten by the ALTER SYSTEM command. # Recovery settings generated by pgBackRest restore on 2024-12-16 15:09:32 restore_command = 'pgbackrest --stanza=demo archive-get %f "%p"' # Recovery settings generated by pgBackRest restore on 2024-12-16 15:10:03 restore_command = 'pgbackrest --stanza=demo archive-get %f "%p"' # Recovery settings generated by pgBackRest restore on 2024-12-16 15:10:26 restore_command = 'pgbackrest --stanza=demo archive-get %f "%p"' # Removed by pgBackRest restore on 2024-12-16 15:11:05 # recovery_target_time = '2024-12-16 15:10:20.768816+00' # Removed by pgBackRest restore on 2024-12-16 15:11:05 # recovery_target_action = 'promote' # Recovery settings generated by pgBackRest restore on 2024-12-16 15:11:05 restore_command = 'pgbackrest --repo=3 --repo-target-time="2024-12-16 15:10:52+00" --stanza=demo archive-get %f "%p"' # Recovery settings generated by pgBackRest restore on 2024-12-16 15:11:29 restore_command = 'pgbackrest --stanza=demo archive-get %f "%p"' # Recovery settings generated by pgBackRest restore on 2024-12-16 15:12:20 primary_conninfo = 'host=172.17.0.6 port=5432 user=replicator' restore_command = 'pgbackrest --stanza=demo archive-get %f "%p"'
sudo pg_ctlcluster 15 demo start
sudo -u postgres cat /var/log/postgresql/postgresql-15-demo.log
[filtered 13 lines of output] LOG: consistent recovery state reached at 0/26000088 LOG: database system is ready to accept read-only connections
LOG: started streaming WAL from primary at 0/28000000 on timeline 7
sudo -u postgres psql -c " \ begin; \ create table stream_table (message text); \ insert into stream_table values ('Important Data'); \ commit; \ select *, current_timestamp from stream_table";
[filtered 4 lines of output] message | current_timestamp ----------------+-------------------------------
Important Data | 2024-12-16 15:12:27.258093+00
(1 row)
sudo -u postgres psql -c " \ select *, current_timestamp from stream_table"
message | current_timestamp ----------------+-------------------------------
Important Data | 2024-12-16 15:12:27.644922+00
(1 row)
sudo apt-get install postgresql-client libxml2 libssh2-1
sudo scp build:/build/pgbackrest/src/pgbackrest /usr/bin
sudo chmod 755 /usr/bin/pgbackrest
sudo mkdir -p -m 770 /var/log/pgbackrest
sudo chown postgres:postgres /var/log/pgbackrest
sudo mkdir -p /etc/pgbackrest
sudo mkdir -p /etc/pgbackrest/conf.d
sudo touch /etc/pgbackrest/pgbackrest.conf
sudo chmod 640 /etc/pgbackrest/pgbackrest.conf
sudo chown postgres:postgres /etc/pgbackrest/pgbackrest.conf
sudo -u postgres mkdir -m 750 -p /var/lib/postgresql/.ssh
sudo -u postgres ssh-keygen -f /var/lib/postgresql/.ssh/id_rsa \ -t rsa -b 4096 -N ""
(echo -n 'no-agent-forwarding,no-X11-forwarding,no-port-forwarding,' && \ echo -n 'command="/usr/bin/pgbackrest ${SSH_ORIGINAL_COMMAND#* }" ' && \ sudo ssh root@pg-alt cat /var/lib/postgresql/.ssh/id_rsa.pub) | \ sudo -u pgbackrest tee -a /home/pgbackrest/.ssh/authorized_keys
(echo -n 'no-agent-forwarding,no-X11-forwarding,no-port-forwarding,' && \ echo -n 'command="/usr/bin/pgbackrest ${SSH_ORIGINAL_COMMAND#* }" ' && \ sudo ssh root@repository cat /home/pgbackrest/.ssh/id_rsa.pub) | \ sudo -u postgres tee -a /var/lib/postgresql/.ssh/authorized_keys
sudo -u pgbackrest ssh postgres@pg-alt
sudo -u postgres ssh pgbackrest@repository
sudo -u postgres /usr/lib/postgresql/15/bin/initdb \ -D /var/lib/postgresql/15/demo -k -A peer
sudo pg_createcluster 15 demo
Configuring already existing cluster (configuration: /etc/postgresql/15/demo, data: /var/lib/postgresql/15/demo, owner: 102:103) Ver Cluster Port Status Owner Data directory Log file 15 demo 5432 down postgres /var/lib/postgresql/15/demo /var/log/postgresql/postgresql-15-demo.log
sudo pg_ctlcluster 15 demo restart
sudo -u postgres pgbackrest --stanza=demo-alt --log-level-console=info stanza-create
P00 INFO: stanza-create command begin 2.54.1: --exec-id=1016-dea26b11 --log-level-console=info --log-level-file=detail --no-log-timestamp --pg1-path=/var/lib/postgresql/15/demo --repo1-host=repository --stanza=demo-alt P00 INFO: stanza-create for stanza 'demo-alt' on repo1
P00 INFO: stanza-create command end: completed successfully
sudo -u postgres pgbackrest --log-level-console=info check
P00 INFO: check command begin 2.54.1: --exec-id=1025-803d5232 --log-level-console=info --log-level-file=detail --no-log-timestamp --repo1-host=repository
P00 INFO: check stanza 'demo-alt'
P00 INFO: check repo1 configuration (primary) P00 INFO: check repo1 archive for WAL (primary)
P00 INFO: WAL segment 000000010000000000000001 successfully archived to '/var/lib/pgbackrest/archive/demo-alt/15-1/0000000100000000/000000010000000000000001-fc59c77815e94111b2b89a533a0c5fc0ac18465a.gz' on repo1
P00 INFO: check command end: completed successfully
sudo -u pgbackrest pgbackrest --log-level-console=info check
P00 INFO: check command begin 2.54.1: --exec-id=1897-8499179b --log-level-console=info --no-log-timestamp --repo1-path=/var/lib/pgbackrest
P00 INFO: check stanza 'demo'
P00 INFO: check repo1 configuration (primary) P00 INFO: check repo1 archive for WAL (primary)
P00 INFO: WAL segment 000000070000000000000028 successfully archived to '/var/lib/pgbackrest/archive/demo/15-1/0000000700000000/000000070000000000000028-c44b2b9149c47766f9bddd65ce69082e49b2bc9c.gz' on repo1 P00 INFO: check stanza 'demo-alt'
P00 INFO: check repo1 configuration (primary) P00 INFO: check repo1 archive for WAL (primary)
P00 INFO: WAL segment 000000010000000000000002 successfully archived to '/var/lib/pgbackrest/archive/demo-alt/15-1/0000000100000000/000000010000000000000002-a569d5d8792e4a2b91bde1c8aecabb2ff35140e0.gz' on repo1
P00 INFO: check command end: completed successfully
sudo mkdir -p -m 750 /var/spool/pgbackrest
sudo chown postgres:postgres /var/spool/pgbackrest
sudo mkdir -p -m 750 /var/spool/pgbackrest
sudo chown postgres:postgres /var/spool/pgbackrest
sudo -u postgres psql -c "alter user replicator password 'bogus'"
ALTER ROLE
sudo pg_ctlcluster 15 demo restart
looking aheadto see which WAL segments are ready to be archived beyond the request that PostgreSQL is currently making via the archive_command. WAL segments are transferred to the archive directly from the pg_xlog/pg_wal directory and success is only returned by the archive_command when the WAL segment has been safely stored in the archive.
sudo -u postgres psql -c " \ select pg_create_restore_point('test async push'); select pg_switch_wal(); \ select pg_create_restore_point('test async push'); select pg_switch_wal(); \ select pg_create_restore_point('test async push'); select pg_switch_wal(); \ select pg_create_restore_point('test async push'); select pg_switch_wal(); \ select pg_create_restore_point('test async push'); select pg_switch_wal();"
sudo -u postgres pgbackrest --stanza=demo --log-level-console=info check
P00 INFO: check command begin 2.54.1: --exec-id=3009-75e7f1f2 --log-level-console=info --log-level-file=detail --no-log-timestamp --pg1-path=/var/lib/postgresql/15/demo --repo1-host=repository --stanza=demo P00 INFO: check repo1 configuration (primary) P00 INFO: check repo1 archive for WAL (primary)
P00 INFO: WAL segment 00000007000000000000002E successfully archived to '/var/lib/pgbackrest/archive/demo/15-1/0000000700000000/00000007000000000000002E-341b22dd1c9d2b31fc31b58bee49b1f931ca17ee.gz' on repo1
P00 INFO: check command end: completed successfully
sudo -u postgres cat /var/log/pgbackrest/demo-archive-push-async.log
-------------------PROCESS START------------------- P00 INFO: archive-push:async command begin 2.54.1: [/var/lib/postgresql/15/demo/pg_wal] --archive-async --exec-id=2996-e31ad64e --log-level-console=off --log-level-file=detail --log-level-stderr=off --no-log-timestamp --pg1-path=/var/lib/postgresql/15/demo --process-max=2 --repo1-host=repository --spool-path=/var/spool/pgbackrest --stanza=demo
P00 INFO: push 1 WAL file(s) to archive: 000000070000000000000029 P01 DETAIL: pushed WAL file '000000070000000000000029' to the archive
P00 INFO: archive-push:async command end: completed successfully -------------------PROCESS START------------------- P00 INFO: archive-push:async command begin 2.54.1: [/var/lib/postgresql/15/demo/pg_wal] --archive-async --exec-id=3013-e55da8fe --log-level-console=off --log-level-file=detail --log-level-stderr=off --no-log-timestamp --pg1-path=/var/lib/postgresql/15/demo --process-max=2 --repo1-host=repository --spool-path=/var/spool/pgbackrest --stanza=demo
P00 INFO: push 5 WAL file(s) to archive: 00000007000000000000002A...00000007000000000000002E P02 DETAIL: pushed WAL file '00000007000000000000002B' to the archive P01 DETAIL: pushed WAL file '00000007000000000000002A' to the archive P02 DETAIL: pushed WAL file '00000007000000000000002C' to the archive P01 DETAIL: pushed WAL file '00000007000000000000002D' to the archive P02 DETAIL: pushed WAL file '00000007000000000000002E' to the archive
P00 INFO: archive-push:async command end: completed successfully
sudo -u postgres cat /var/log/pgbackrest/demo-archive-get-async.log
-------------------PROCESS START------------------- P00 INFO: archive-get:async command begin 2.54.1: [000000070000000000000025, 000000070000000000000026, 000000070000000000000027, 000000070000000000000028, 000000070000000000000029, 00000007000000000000002A, 00000007000000000000002B, 00000007000000000000002C] --archive-async --exec-id=1460-b685b536 --log-level-console=off --log-level-file=detail --log-level-stderr=off --no-log-timestamp --pg1-path=/var/lib/postgresql/15/demo --process-max=2 --repo1-host=repository --spool-path=/var/spool/pgbackrest --stanza=demo P00 INFO: get 8 WAL file(s) from archive: 000000070000000000000025...00000007000000000000002C
P02 DETAIL: found 000000070000000000000026 in the repo1: 15-1 archive P01 DETAIL: found 000000070000000000000025 in the repo1: 15-1 archive P02 DETAIL: found 000000070000000000000027 in the repo1: 15-1 archive P01 DETAIL: found 000000070000000000000028 in the repo1: 15-1 archive
P00 DETAIL: unable to find 000000070000000000000029 in the archive P00 INFO: archive-get:async command end: completed successfully [filtered 14 lines of output] P00 INFO: archive-get:async command begin 2.54.1: [000000070000000000000029, 00000007000000000000002A, 00000007000000000000002B, 00000007000000000000002C, 00000007000000000000002D, 00000007000000000000002E, 00000007000000000000002F, 000000070000000000000030] --archive-async --exec-id=1503-8aaf04f6 --log-level-console=off --log-level-file=detail --log-level-stderr=off --no-log-timestamp --pg1-path=/var/lib/postgresql/15/demo --process-max=2 --repo1-host=repository --spool-path=/var/spool/pgbackrest --stanza=demo P00 INFO: get 8 WAL file(s) from archive: 000000070000000000000029...000000070000000000000030
P02 DETAIL: found 00000007000000000000002A in the repo1: 15-1 archive P01 DETAIL: found 000000070000000000000029 in the repo1: 15-1 archive P02 DETAIL: found 00000007000000000000002B in the repo1: 15-1 archive P01 DETAIL: found 00000007000000000000002C in the repo1: 15-1 archive P02 DETAIL: found 00000007000000000000002D in the repo1: 15-1 archive P01 DETAIL: found 00000007000000000000002E in the repo1: 15-1 archive
P00 DETAIL: unable to find 00000007000000000000002F in the archive P00 INFO: archive-get:async command end: completed successfully [filtered 17 lines of output]
sudo -u postgres psql -c "alter user replicator password 'jw8s0F4'"
ALTER ROLE
sudo -u pgbackrest pgbackrest --stanza=demo --log-level-console=detail backup
[filtered 2 lines of output] P00 INFO: execute non-exclusive backup start: backup begins after the requested immediate checkpoint completes P00 INFO: backup start archive = 000000070000000000000030, lsn = 0/30000028
P00 INFO: wait for replay on the standby to reach 0/30000028 P00 INFO: replay on the standby reached 0/30000028
P00 INFO: check archive for prior segment 00000007000000000000002F
P01 DETAIL: backup file pg-primary:/var/lib/postgresql/15/demo/global/pg_control (8KB, 0.53%) checksum f940bd16ea582ba22c38252194de39189f797c4c
P01 DETAIL: match file from prior backup pg-primary:/var/lib/postgresql/15/demo/pg_logical/replorigin_checkpoint (8B, 0.53%) checksum 347fc8f2df71bd4436e38bd1516ccd7ea0d46532 P02 DETAIL: backup file pg-standby:/var/lib/postgresql/15/demo/base/5/1249 (456KB, 31.18%) checksum 7c8b9cfb1eece7a2397806d3174c468afd13a646 [filtered 1276 lines of output]
sudo pg_ctlcluster 15 demo stop
sudo pg_ctlcluster 15 demo stop
sudo -u postgres /usr/lib/postgresql/16/bin/initdb \ -D /var/lib/postgresql/16/demo -k -A peer
sudo pg_createcluster 16 demo
sudo -u postgres sh -c 'cd /var/lib/postgresql && \ /usr/lib/postgresql/16/bin/pg_upgrade \ --old-bindir=/usr/lib/postgresql/15/bin \ --new-bindir=/usr/lib/postgresql/16/bin \ --old-datadir=/var/lib/postgresql/15/demo \ --new-datadir=/var/lib/postgresql/16/demo \ --old-options=" -c config_file=/etc/postgresql/15/demo/postgresql.conf" \ --new-options=" -c config_file=/etc/postgresql/16/demo/postgresql.conf"'
[filtered 42 lines of output] Checking for extension updates ok
Upgrade Complete
---------------- Optimizer statistics are not transferred by pg_upgrade. [filtered 3 lines of output]
sudo cp /etc/postgresql/15/demo/pg_hba.conf \ /etc/postgresql/16/demo/pg_hba.conf
sudo -u postgres pgbackrest --stanza=demo --no-online \ --log-level-console=info stanza-upgrade
P00 INFO: stanza-upgrade command begin 2.54.1: --exec-id=3419-e7b4f6e6 --log-level-console=info --log-level-file=detail --no-log-timestamp --no-online --pg1-path=/var/lib/postgresql/16/demo --repo1-host=repository --stanza=demo P00 INFO: stanza-upgrade for stanza 'demo' on repo1
P00 INFO: stanza-upgrade command end: completed successfully
sudo pg_ctlcluster 16 demo start
sudo pg_lsclusters
sudo -u postgres pgbackrest --stanza=demo check
sudo pg_dropcluster 15 demo
sudo pg_dropcluster 15 demo
sudo pg_createcluster 16 demo
sudo -u pgbackrest pgbackrest --stanza=demo check
P00 WARN: unable to check pg2: [DbConnectError] raised from remote-0 ssh protocol on 'pg-standby': unable to connect to 'dbname='postgres' port=5432': connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory Is the server running locally and accepting connections on that socket?
sudo -u pgbackrest pgbackrest --stanza=demo --type=full backup
sudo -u postgres pgbackrest --stanza=demo --delta --type=standby restore
sudo pg_ctlcluster 16 demo start
sudo -u postgres pgbackrest --stanza=demo check