Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
postgresql_pgbackrest_configuration [2025/05/12 15:48] – created andonovj | postgresql_pgbackrest_configuration [2025/05/19 06:22] (current) – [Restore] andonovj | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | https://www.scaleway.com/en/docs/tutorials/backup-postgresql-pgbackrest-s3/ | + | =====Overview===== |
+ | I find pgbackrest, way more " | ||
+ | You have a pgbackrest executable, which checks the config file, it generates the postgresql.auto.conf file and the server STILL restores till the last WAL files when you try to do PITR. But I guess I will return to this section, when I am smarter and know how to use it. | ||
+ | Either case, let's get into it. Unlike Barman, pgbackrest REQUIRES passwordless connection for the backup / restore to the server and unlike Barman in REQUIRES you to archive the WAL Files to a common repo or global repo. P.S. Barman doesn' | ||
+ | |||
+ | Either case, so in general. My setup is. 1 central backup server, 1 NFS on that backup server, which is mounted on the data nodes and the data nodes push the WAL Files to that repo using pgbackrest. Simple as that. | ||
+ | |||
+ | =====Setup===== | ||
+ | After you install pgbackrest on all servers: data nodes + backup server. You can set the archive command as follows: | ||
+ | |||
+ | |||
+ | < | ||
+ | archive_command: | ||
+ | restore_command: | ||
+ | </Code> | ||
+ | |||
+ | |||
+ | After that, you can configure the /etc/ | ||
+ | |||
+ | < | ||
+ | [global] | ||
+ | repo1-path=/ | ||
+ | repo1-retention-full=14 | ||
+ | repo1-retention-full-type=time | ||
+ | repo1-host-user=pgbackrest | ||
+ | archive-check=n | ||
+ | process-max=2 | ||
+ | log-level-console=info | ||
+ | log-path=/ | ||
+ | log-level-file=debug | ||
+ | start-fast=y (performs a checkpoint) | ||
+ | delta=y | ||
+ | |||
+ | [cluster_backup] | ||
+ | pg1-path=/ | ||
+ | </ | ||
+ | |||
+ | After that, we need to create the Stanza (Configuration of server and a backup). That is done from the backup server. | ||
+ | |||
+ | ===Create Stanza=== | ||
+ | < | ||
+ | pgbackrest --stanza=cluster_backup stanza-create | ||
+ | </Code> | ||
+ | |||
+ | That command will create you the stanza and then the archive command from the data nodes will work. You can also manually archive a file as follows, ran from the data node. | ||
+ | |||
+ | < | ||
+ | pgbackrest --stanza=cluster_backup archive-push | ||
+ | </ | ||
+ | |||
+ | |||
+ | =====Backup===== | ||
+ | Now, pgbackrest has the following backups: | ||
+ | |||
+ | - Full | ||
+ | - Differential (What has changed since FULL) | ||
+ | - Incremental (What has changed since FULL or Differential) | ||
+ | |||
+ | I know, it is the opposite of Oracle, but hey, we cannot live in perfect world. If you try to make DIfferential or Incremental without Full, pgbackrest is " | ||
+ | |||
+ | < | ||
+ | [postgres@backup ~]$ pgbackrest | ||
+ | 2025-05-17 04: | ||
+ | 2025-05-17 04: | ||
+ | 2025-05-17 04: | ||
+ | 2025-05-17 04: | ||
+ | 2025-05-17 04: | ||
+ | 2025-05-17 04: | ||
+ | 2025-05-17 04: | ||
+ | 2025-05-17 04: | ||
+ | 2025-05-17 04: | ||
+ | 2025-05-17 04: | ||
+ | 2025-05-17 04: | ||
+ | </ | ||
+ | |||
+ | After that we can create an incremental or differential backup: | ||
+ | |||
+ | |||
+ | < | ||
+ | # | ||
+ | pgbackrest --stanza=cluster_backup --type=incr --log-level-console=info backup | ||
+ | |||
+ | # | ||
+ | pgbackrest --stanza=cluster_backup --type=diff --log-level-console=info backup | ||
+ | </Code> | ||
+ | |||
+ | |||
+ | With that at hand, we can drop and delete all database: | ||
+ | |||
+ | |||
+ | =====Restore===== | ||
+ | Now, the restore can be: | ||
+ | |||
+ | - Complete | ||
+ | - PITR: Time, LSN, Checkpoint, Transactions, | ||
+ | |||
+ | Don't forget that you need also the WAL Files in either case. The cluster has to be consistent after all. So make the difference between: | ||
+ | |||
+ | * Restore (Moving the data files from backup to the data dir) | ||
+ | * Recover (Applying the WAL Files, until we are consistent state and/or until we are told (recovery_target_time) | ||
+ | |||
+ | These are important concepts. To restore a backup we can use the following command. | ||
+ | |||
+ | < | ||
+ | pgbackrest --stanza=cluster_backup restore --type=immediate | ||
+ | </ | ||
+ | |||
+ | Or we can restore only to a PITR (using time) | ||
+ | |||
+ | < | ||
+ | pgbackrest --stanza=cluster_backup \ | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | |||
+ | Despite, whatever you chose, MY BIGGEST PROBLEM was that Patroni continued to apply the WAL Files, despite what I was telling him. So my HUMBLE opinion. After restore with pgbackrest, DO NOT START IT WITH PATRONI, BUT start it outside of Patroni: | ||
+ | |||
+ | < | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | |||
+ | Check if that is the correct state and if you are happy. Then promote it and THEN stop it: | ||
+ | |||
+ | < | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | After that, you can start it from patroni and maybe failover: | ||
+ | |||
+ | < | ||
+ | service patroni start | ||
+ | su - postgres | ||
+ | patronictl -c / | ||
+ | </ | ||
+ | |||
+ | That is how I was able to make it work. I am 99.(9)8% (Math nerds here), sure I do something wrong, but still. If you cannot get it work with patroni initially, that way works. | ||
+ |