1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-09 00:45:49 +02:00
Commit Graph

118 Commits

Author SHA1 Message Date
922e9f0775 Verify recovery target timeline.
If the user picks an invalid timeline (or the default is invalid) they will not discover it until after the restore is complete and recovery starts. In that case they'll receive a message like this:

FATAL:  requested timeline 2 is not a child of this server's history
DETAIL:  Latest checkpoint is at 0/7000028 on timeline 1, but in the history of the requested timeline, the server forked off from that timeline at 0/600AA20.

This message generally causes confusion unless one is familiar with it. In this case 1) a standby was promoted creating a new timeline 2) a new backup was made from the primary 3) the new backup was restored but could not follow the new timeline because the backup was made after the new timeline forked off. Since PostgreSQL 12 following the latest timeline has been the default so this error has become common in split brain situations.

Improve pgBackRest to read the history files and provide better error messages. Now this error is thrown before the restore starts:

ERROR: [058]: target timeline 2 forked from backup timeline 1 at 0/600aa20 which is before backup lsn of 0/7000028
       HINT: was the target timeline created by accidentally promoting a standby?
       HINT: was the target timeline created by testing a restore without --archive-mode=off?
       HINT: was the backup made after the target timeline was created?

This saves time since it happens before the restore and gives more information about what has gone wrong.

If the backup timeline is not an ancestor of the target timeline the error message is:

ERROR: [058]: backup timeline 6, lsn 0/4ffffff is not in the history of target timeline B
       HINT: was the target timeline created by promoting from a timeline < latest?

This situation should be rare but can happen during complex recovery scenarios where the user is explicitly setting the target time.
2025-02-04 10:06:17 -05:00
d5cefb7290 Fix error reporting for queries with no results.
If a query that expected no results returned an error then it would incorrectly report that no results were expected because the error was interpreted as a result.

Switch the order of the checks so that an error is reported instead and add a test to prevent regression.
2025-01-29 13:48:26 -05:00
e625ed8be2 Caveat --tablespace-map-all regarding tablespace creation.
If a tablespace is created after the backup starts then it cannot be mapped using --tablespace-map-all since there is no record of it in the manifest.

This would be extremely complex to fix but it can be documented.
2025-01-28 09:14:30 -05:00
6776940c3b Use three part version in development builds.
This makes the versioning more consistent and is required by a subsequent commit that will separate the version components.
2025-01-23 14:55:44 -05:00
6fbb28fa2d Do not set recovery_target_timeline=current for PostgreSQL < 12.
PostgreSQL < 12 defaults recovery_target_timeline to current but if current is explicitly set it behaves as if latest was set. Since current is not handled in the PostgreSQL code it looks as if there should be an error during the integer conversion but that doesn't happen due to incorrect strtoul() usage (not checking endptr).

Handle this by omitting recovery_target_timeline from recovery.conf when it is explicitly set by the user to current.
2025-01-23 07:58:41 -05:00
931435c017 Allow backup command to operate on remote repositories.
The backup command has always been limited to working only when the repository is local. This was due to some limitations in storage (addressed in 01b81f9) and the protocol helper (addressed in 4a94b6be).

Now that there a no limitations preventing this feature it makes sense to enable it. This allows for more flexibility in where backups are run.
2025-01-21 11:45:50 -05:00
23bd392bdc Improve hex encode performance with bytewise lookup.
Previously, hex encode looked up each nibble of the input separately. Instead use a larger lookup table containing the two-byte encoding of every possible input byte, resulting in a 1/3 reduction in encoding time.

Inspired by and mostly cribbed from PostgreSQL commit e24d7708.
2025-01-20 14:09:54 -05:00
713f6657d3 Merge v2.54.2 release. 2025-01-20 10:57:27 -05:00
7a33d6168b Replace constant version with macro in backup test module. 2025-01-14 13:10:32 -05:00
13f23f2168 Fix issue after disabling bundling with block incremental enabled.
When bundling and block incremental are both enabled the bundleRaw flag is set to indicate that headers are omitted (whenever possible) for encryption and compression. This is intended to save space, especially when there are very large numbers of small files.

If bundling is disabled this flag needs to be preserved so that existing bundles from prior backups are read correctly. However, the prior code was only saving the flag when bundling was enabled, which caused prior backups to be unreadable if bundling was disabled.

Fix so that the flag is preserved and backups are not broken.
2024-12-26 12:01:59 -05:00
48ecbe422d Clarify behavior of multiple configuration files. 2024-12-19 13:52:59 -05:00
005c7e974f Merge v2.54.1 release. 2024-12-16 12:04:21 -05:00
5c8296df06 Remove reference to disabling network compression in the documentation.
Previously setting compress-level-network=0 would disable compression. This worked because gzip disables compression at this level but still transmits the data in gz format.

lz4 does not provide similar functionality so we would need to disable the compression filter entirely. This does not seem worth it however since lz4 compression is very efficient and 0 is the default fast mode.
2024-12-10 11:22:45 -05:00
cad595f9f8 Full/incremental backup method.
This backup method does a preliminary copy of all files that were last modified prior to a defined interval before calling pg_backup_start(). Then the backup is started as usual and the remainder of the files are copied. The advantage is that generally a smaller set of WAL will be required to make the backup consistent, provided there are some files that have not been recently modified.

The length of the prior full backup is used to determine the interval used for the preliminary copy since any files modified within this interval will likely be modified again during the backup. If no prior full backup exists then the interval is set to one day.

This feature is being committed as internal-only for the time being.
2024-11-26 11:23:43 -05:00
0577b03016 Use lz4 for protocol compression.
lz4 provides much better compression speed and gives similar compression ratios to gz when used at low levels (the gz default was 3).
2024-11-26 11:03:27 -05:00
4af42d93b2 Update release notes for PostgreSQL 17 support.
Accurately reflect when different versions of PostgreSQL were supported since an update was required for beta3.
2024-11-25 10:38:37 -05:00
274bb24a5a Stabilize async archiving in integration tests.
The integration tests could fail if:

1. After restoring the PostgreSQL instance the recovery process starts, which calls asynchronous archive-get.
2. After archive-get checks the existence of the queue directory, but before writing the WAL file, there are restores when the next test is begun, which leads to the deletion of the queue directory.
3. Since the directory no longer exists, writing the WAL file will fail, and archive-get will write the error file to the queue.
4. A new PostgreSQL instance will start and the recovery process will begin, which requests the WAL file.
5. The new archive-get looks into the queue directory, finds the error file, and throws out the error, after which the PostgreSQL recovery fails because the previous archive-get background process has not finished yet.

This patch fixes the problem by using a separate spool directory for each test.
2024-11-13 09:56:42 -05:00
c9c73ede9d Fix issue with version/help commands attempting to load pgbackrest.conf.
8d6bceb5 refactored version/help to operate more like regular commands in part to simplify the implementation of --version and --help. Unfortunately this had the side effect of these commands also loading pgbackrest.conf which would lead to an error if the file could not be read or parsed.

Add a filter to prevent version or help from loading pgbackrest.conf. Also prevent reads from the env to stop any warnings or errors from that source.
2024-11-07 10:30:16 -05:00
48f511dad3 Remove support for PostgreSQL 9.4.
Per our policy to support five EOL versions of PostgreSQL, 9.4 is no longer supported by pgBackRest. Remove all logic associated with 9.4 and update the tests.

This includes a small fix in infoPg.c to allow backup.info files with old versions to be saved. This allows expire to function when old versions are present. Even though those older versions cannot be used, they can be expired.

Tests for 9.4 are left in the expire/info tests to demonstrate that these commands work with old versions present.
2024-10-21 13:56:04 +03:00
89c9baba72 Remove autoconf/make build.
2.54.0 is the last release to support the autoconf/make build. Remove the autoconf/make build to reduce maintenance going forward.
2024-10-21 13:32:35 +03:00
4125f726a8 Begin v2.55.0 development. 2024-10-21 09:11:49 +03:00
1e5f46b7d9 v2.54.0: Target Time for Versioned Storage
NOTE TO PACKAGERS: This is last feature release to support the autoconf/make build. Please migrate to meson if you have not already done so. 2.54.X patch releases (if any) will continue to support autoconf/make.

Bug Fixes:

* Fix PostgreSQL query performance for large datasets. (Fixed by Thibault Vincent, David Steele. Reviewed by David Christensen, Antoine Millet. Reported by Antoine Millet.)

Features:

* Allow repositories on versioned storage to be read at a target time. (Reviewed by Stefan Fercot, David Christensen.)
* Allow requested standby backup to proceed with no standby. (Reviewed by Stefan Fercot.)

Improvements:

* Summarize backup reference list for info command text output. (Contributed by Stefan Fercot. Reviewed by David Steele.)
* Refresh web-id token for each S3 authentication. (Contributed by Brent Graveland. Reviewed by David Steele.)
* Correctly display current values for indexed options in help. (Reviewed by David Christensen.)
* Save backup.info only when contents have changed. (Reviewed by Stefan Fercot.)
* Remove limitation on reading files in parallel during restore. (Reviewed by David Christensen.)
* Improve SFTP error messages. (Contributed by Reid Thompson. Reviewed by David Steele.)

Documentation Features:

* Add performance tuning section to user guide. (Reviewed by Stefan Fercot.)

Documentation Improvements:

* Clarify source for data_directory. (Contributed by Stefan Fercot. Reviewed by David Steele. Suggested by Matthias.)
* Better logic for deciding when a summary should be lower-cased. (Suggested by Daniel Westermann.)
2024-10-21 08:57:43 +03:00
9ba2db0173 Clarify source for data_directory. 2024-10-16 12:41:26 +03:00
70bda2cfb2 Improve SFTP error messages.
The numbers by themselves weren't very informative and required looking into the libssh2_sftp.h header file for the definition.
2024-10-10 11:17:35 +03:00
c8ccaaa755 Fix PostgreSQL query performance for large datasets.
The asynchronous logic used to implement the query timeout was misusing PQisBusy(), which caused the wait handler to throttle the consumption of command results. It could introduce a large delay on a query up to `db-timeout` because of the back-off sequence.

Following the recommendation of libpq, fix by polling the client socket for data availability and then continue consuming results and checking for command busyness.
2024-10-10 09:48:43 +03:00
b3ca2e3482 Correctly display current values for indexed options in help.
The current value for an indexed option was always for the first index, e.g. pg1-path. This is likely legacy from before indexing was added (and faithfully copied over from Perl, apparently).

Fix this by enumerating the current values in the option help and displaying <multi> in the option list when more than one value exists.
2024-10-05 09:41:50 +03:00
278319eba3 Add performance tuning section to user guide.
We frequently tell users to enable to these options but they are spread through the documentation and not at all obvious. Hopefully putting them in the quick start will make them more visible and also provide an easy place to link.
2024-09-20 15:49:26 +03:00
b19134dccd Allow repositories on versioned storage to be read at a target time.
This feature allows the archive-get, info, repo-get, repo-ls, restore, and verify commands to operate at a point-in-time on versioned buckets in Azure, GCS, and S3. This allows recovery even if a repository has been accidentally or maliciously deleted or corrupted.
2024-09-17 10:51:21 +03:00
46c1297be3 Remove limitation on reading files in parallel during restore.
This restriction prevented multiple files being read from a remote simultaneously, which was not supported by the protocol. Although the limitation only applied to remotes, it was applied in all cases for testing purposes and because we planned to fix it.

Protocol command multiplexing added in df8cbc91 allows files to be read simultaneously from a remote so this restriction is no longer required.

Note that there is a test for this condition since the prior code had coverage. It might be tricky to ensure that test doesn't go away, but in general we should have enough tests in place to ensure simultaneous reads function as expected.
2024-09-09 15:47:23 +03:00
a42629f87a Allow requested standby backup to proceed with no standby.
Add a "prefer" value to the backup-standby option to allow the backup to proceed when no standby is found. Note that this will not help if the standby is responding but fails to sync with the primary after the backup has started.

Introduce a new option modifier, bool-like, that allows a boolean option to be converted to a string or string-id option while still allowing the option to act like a boolean on the command-line, e.g. --no-backup-standby.
2024-09-09 12:56:52 +03:00
b454b9e403 Save backup.info only when contents have changed.
This prevents backup.info from being saved again when expire does not make any changes.

More importantly, as we look to support versioning on object stores, it will be much easier to determine a good point-in-time to use for restore if there are no extraneous saves of backup.info.
2024-09-05 11:38:42 +03:00
95a4b9e10a Refresh web-id token for each S3 authentication.
The token file pointed to by the AWS_WEB_IDENTITY_TOKEN_FILE environment variable was read once at startup, but for long operations the token might expire before completion.

Instead read the token on each S3 authentication so the current token is always used.
2024-09-01 11:21:56 +07:00
f6aaa3672b Merge v2.53.1 release. 2024-08-20 11:03:24 +07:00
60f96429b8 Fix segfault on delayed connection errors.
Connection errors could cause a segfault if the error was delayed enough to pass the initial call to sckClientOpenWait() and the error was instead thrown by a subsequent call to sckClientOpenWait(), which was not correctly initializing a variable required for error handling.

While this can be produced fairly easily in a test environment, I was unable to craft a unit test to hit this exact condition, probably due to timing. The new code still has full coverage and I added several comments to help prevent regressions.
2024-08-16 10:56:07 +07:00
04ef43d9ed Skip local repository duplicate check for SFTP.
This check does not make sense for SFTP since the repository will never be local.
2024-08-13 13:45:24 +08:00
80c9b3001c PostgreSQL 17beta3 support.
This release changed the control and WAL format, which is very unusual for a beta. Update control and WAL versions/structs to match.
2024-08-13 11:53:12 +08:00
ed9b0c260a Fix permissions when restore run as root user.
When restore was run as the root user the pg_control file would end up with root permissions. This bug was introduced in e634fd8. Fix this by directly overwriting the pg_control temp file rather than doing an atomic write that updates permissions. Also update other parameters to more closely match similar calls.

There was also an adjacent error where restore as the root user would fail if the base path did not exist. Fix this by ignoring the missing path since it will be created later and this logic is just trying to find an alternate user for permissions if the user in the manifest does not exist.
2024-08-13 11:43:05 +08:00
b306f83493 Summarize backup reference list for info command text output.
The backup reference list can be very long so it seems better to summarize the list by default for text output and keep the full list when --set is specified.
2024-07-31 18:53:02 +07:00
df8cbc91c3 Protocol command multiplexing.
Previously it was not possible to read or write two files at the same time on the same remote because the protocol was entirely taken over by the read or write command. Multiple reads are required to make restores efficient when a list of bundled files is being read but blocks need to be retrieved from a separate file or a different part of the same file.

Improve that situation with sessions that allow related commands to be run with shared state. Also break read/write into separate requests (rather than pushing all data at once) so they can be multiplexed.

The disadvantage for read/write is that they now require more back and forth to transfer a file. This is mitigated by sending asynchronous read/write requests to keep both server and client as busy as possible. Reads that can fit into a single buffer are optimized to transfer in a single command. Reads that transfer the entire file can also skip the close command since it is implicit on end-of-file.

These changes allow the protocol to be simplified to provide one response per request, which makes the data end message obsolete. Any data sent for the request is now added to the parameters so no data needs to be sent separately to the server outside the request parameters.

Also update the Db protocol to use the new sessions. Previously this code had tracked its own sessions.
2024-07-22 11:48:32 +07:00
e7f4e8d800 Begin v2.54 development. 2024-07-22 09:42:33 +07:00
6e8a45f650 v2.53: Concurrent Backups
IMPORTANT NOTE: The log-level-stderr option default has been changed from warn to off. This makes it easier to capture errors when only redirecting stdout. To preserve the prior behavior set log-level-stderr=warn.

NOTE TO PACKAGERS: The lz4 library is now required by the meson build.

NOTE TO PACKAGERS: Compiler support for __builtin_clzl() and __builtin_bswap64() is now required by the meson build.

Bug Fixes:

* Fix SFTP renaming failure when file already exists. (Fixed by Reid Thompson. Reviewed by David Steele. Reported by ahmed112212.)

Features:

* Allow backups to run concurrently on different repositories. (Reviewed by Reid Thompson, Stefan Fercot.)
* Support IP-based SANs for TLS certificate validation. (Contributed by David Christensen. Reviewed by David Steele.)

Improvements:

* Default log-level-stderr option to off. (Reviewed by Greg Sabino Mullane, Stefan Fercot.)
* Allow alternative WAL segment sizes for PostgreSQL ≤ 10. (Contributed by Viktor Kurilko. Reviewed by David Steele.)
* Add hint to check SFTP authorization log. (Contributed by Vitalii Zurian. Reviewed by Reid Thompson, David Steele.)

Documentation Improvements:

* Clarify archive-push multi-repo behavior. (Reviewed by Stefan Fercot.)
2024-07-22 09:33:31 +07:00
ec3e387bb7 Clarify archive-push multi-repo behavior.
Clarify that archive-push will not be able to push ahead in other repositories if one is failing unless archive-async in enabled.
2024-07-18 11:19:25 +07:00
dfb620b0b8 Support IP-based SANs for TLS certificate validation.
The prior SAN code only recognized DNS-based SANs, which meant that it would not properly validate if using an IP-based SAN. 

Add support for IPv4 and IPv6 SANs with exact matching only.

This simplifies testing when certificate generation tools have trouble generating a DNS:1.2.3.4-style SAN, preferring to include the SAN as IP:1.2.3.4.
2024-07-11 10:54:20 +07:00
ccae609402 Add hint to check SFTP authorization log.
In the case of authorization failures there many be valuable information in the log.
2024-07-09 11:34:13 +07:00
d6f0bf88af Fix SFTP renaming failure when file already exists.
Update error handling for libssh2_sftp_rename_ex() in storageWriteSftpClose() when a file already exists. 

The SFTP servers used during development and testing never returned LIBSSH2_FX_FILE_ALREADY_EXISTS, rather they returned LIBSSH2_FX_FAILURE when a file already existed. However, it is clear that some SFTP servers use LIBSSH2_FX_FILE_ALREADY_EXISTS so add support.
2024-07-04 16:53:07 +07:00
edd61636a9 Allow backups to run concurrently on different repositories.
The prior locking only allowed one backup per stanza, which was required by PostgreSQL <= 9.5 and didn't present a problem when only one stanza could be created.

Now that multiple stanzas are allowed relax this restriction so that backups can run concurrently for PostgreSQL > 9.5. To do this, update the locking to be per stanza and repo rather than per stanza. Remotes are not aware of the repos that require locking so send an explicit list of files to be locked to the remote. Also remove the advisory lock for PostgreSQL > 9.5.

For info output the running backups are combined for progress output in order to avoid changing the JSON format. It definitely makes sense to have per repo progress as well but that will be left for a future commit.
2024-07-04 16:22:17 +07:00
7d54073094 Default log-level-stderr option to off.
Writing warnings and errors to stderr by default leads to error messages being lost when the user does not correctly redirect stderr while generating logs for analysis. This happens so often that it seems worth changing the default to increase the quality of the logs we receive.

If the user has explicitly set log-level-stderr then there is no change in behavior.
2024-06-25 16:45:47 +08:00
1094aecab5 Require compiler support for __builtin_clzl() and __builtin_bswap64().
These functions will be useful for optimizing varint-128 functions.

Require them in the meson build before adding new code in case there are problems with packaging.
2024-06-25 16:16:55 +08:00
0c32757fd9 Require the lz4 library in the meson build.
We would like to use lz4 for protocol compression instead of gz but first we need to make sure this is not going to cause a problem for packaging.

To do this make lz4 required in meson but make no changes to the code so this is an easy revert for packagers if there is an issue.
2024-06-25 16:04:02 +08:00
cfb8aa202e Add remote locks for stanza commands missed in 31c7824a.
31c7824a should have added remote locks when the commands were modified to run remotely. This is unlikely to have caused issues since these commands are generally not run concurrently with backup/expire but having the locks is safer.
2024-06-21 13:29:17 +08:00