Skip to content

Archive Queue Max doesn't apply when archiving failed #1848

Closed

Description

@slardiere

Please provide the following information when submitting an issue (feature requests or general comments can skip this):

  1. pgBackRest version: 2.39

  2. PostgreSQL version: 10.21

  3. Operating system/version : Debian GNU/Linux 11 (bullseye)

  4. Did you install pgBackRest from source or from a package? Debian PGDG packages

  5. Please attach the following as applicable:

    • pgbackrest.conf file(s) pgbackrest.txt
    • postgresql.conf settings applicable to pgBackRest (archive_command, archive_mode, listen_addresses, max_wal_senders, wal_level, port)
archive_mode = on
archive_command = 'pgbackrest --stanza=lsi archive-push %p'
  1. Describe the issue:

Using pgbackrest to backup and archive PostgreSQL 10 to S3 (at scaleway), I setup archive-push-queue-max=200GiB to limit the queue, because of the large amount of transaction every morning, which are slow to archive because of S3, which can fill the PG local storage. It works well, sometime I got that in : 

2022-08-21 08:41:08.380 P00   WARN: dropped WAL file '000000030000AF05000000FC' because archive queue exceeded 200GB

But yesterday, there was a problem is S3, which return 500 Internal error :

2022-08-22 11:59:09.521 P02   WARN: could not push WAL file '000000030000AF980000009A' to the archive (will be retried): [104] raised from local-2 protocol: archive-push command encountered error(s):
                                    repo1: [ServiceError] [500] Internal Server Error
                                    [CommandError] on retry after 0ms

Problem : I thought that the queue will be full, then WAL file will be drop, but no, this morning, the disk was full and PG stop.

Now, the S3 error is fixed, and it works, but I think it's not OK that pgbackrest does not apply archive-push-queue-max when there is a problem with the archive system (S3 here)

It is normal ? do I miss something ?

Activity

  1. self-assigned this
    on Aug 30, 2022
  2. dwsteele commented on Aug 30, 2022

    @dwsteele
    Member

    I'm not seeing anything obvious that would cause this. Dropping files from the queue is pretty early on an I can't see any S3 accesses before this.

    Can we see the archive-push async logs after the first warning? It would be good to see what the process was doing after that.

  3. slardiere commented on Aug 31, 2022

    @slardiere
    Author

    While trying to understand the problem, I setted up the log level to DEBUG then TRACE to get the detailed error message from the S3 provider (which is not logged by pgbackrest, but that's another problem).

    I'm not sure that's something interesting, but this message is present :

    2022-08-22 18:39:38.599 P00  DEBUG:     storage/storage::storageInfo: (buffer full - parameters not available)
    2022-08-22 18:39:38.599 P00  DEBUG:     storage/storage::storageInfo: => {StorageInfo}
    

    I don't think that, at this moment, the queue was full, but, probably, I was too confident at this moment. I can provide the full log with DEBUG and TRACE, but probably not here, because it's a 200MB file.

  4. slardiere commented on Aug 31, 2022

    @slardiere
    Author

    So, another problem is that the detailed error message provided by the S3 provider (scaleway here) isn't traced by pgbackrest.

    While trying to understand the problem with s3cmd:

    s3cmd -v -d put 000000030000AFFB000000AA s3://db-pgbackrest-data/backups/archive/lsi/10-1/000000030000AF98/
    

    I got that : 

    DEBUG: Response:
    {'data': b"<?xml version='1.0' encoding='UTF-8'?>\n<Error><Code>InternalErro"
             b'r</Code><Message>Proxified error: No Cluster Leader  /builds/storage'
             b'/storage/common/src/hive/backends/s3/shard_reference/mpu_create.c:er'
             b'ror (redirect 0/20 try 27/20) (HTTP 503)</Message><RequestId>txdc27b'
             b'6a562704dcaa5064-006304848c</RequestId></Error>',
     'headers': {'content-type': 'application/xml',
                 'date': 'Tue, 23 Aug 2022 07:41:40 GMT',
                 'transfer-encoding': 'chunked',
                 'x-amz-id-2': 'txdc27b6a562704dcaa5064-006304848c',
                 'x-amz-request-id': 'txdc27b6a562704dcaa5064-006304848c'},
     'reason': 'Internal Server Error',
     'status': 500}
    

    It could be interesting to catch it, at least in DEBUG or TRACE mode.

    Full log : s3cmd.txt

  5. dwsteele commented on Aug 31, 2022

    @dwsteele
    Member

    I can provide the full log with DEBUG

    Just debug will be fine. Try compressing it and attaching to this issue and see if that works.

  6. dwsteele commented on Aug 31, 2022

    @dwsteele
    Member

    One thing to note, if archive-push-queue-max is exactly the size of the storage allocated to WAL (or even close), then it may not work as expected. We only check the queue at the beginning of each async run, so it is possible for the queue to fill up while we are working. This is especially true during failures since retries can take a lot of time.

    Definitely an area for improvement, but I wonder if that is what is going on here.

  7. slardiere commented on Sep 1, 2022

    @slardiere
    Author

    Here's the full log, without TRACE : lsi-archive-push-async.log.gz

    The queue size is lower than the free space, about a half only. But one of the problem is the large number of WAL by batch, about 8000 in the morning (not anymore, this problem is fixed).

    The « error 500 » problem on S3 first occurs at 12h00, when the large mornig batch is not yet finished, so maybe pgbackrest keep running on this batch ? But i kill pgbackrest async batch to change some config, so the queue size max should have been re-evaluated.

  8. dwsteele commented on Sep 2, 2022

    @dwsteele
    Member

    When exactly did the WAL volume fill up on the primary? I can see the errors starting here:

    2022-08-22 11:53:39.055 P03   WARN: could not push WAL file '000000030000AF9800000094' to the archive (will be retried): [104] raised from local-3 protocol: archive-push command encountered error(s):
                                        repo1: [ServiceError] [500] Internal Server Error
                                        [CommandError] on retry after 0ms
    

    And it chugs along on retries for the next 6 hours (and it looks like you killed it). But the next run has not accumulated enough WAL to force any drops:

    2022-08-22 18:39:38.597 P00   INFO: push 6931 WAL file(s) to archive: 000000030000AF9800000094...000000030000AFB3000000A6
    

    That doesn't happen until the next morning:

    2022-08-23 08:39:23.031 P00   INFO: push 18568 WAL file(s) to archive: 000000030000AFB2000000F0...000000030000AFFB00000077
    

    When they do get dropped. So, as far as I can see everything is working as expected. Did you remove some files manually after killing the process before 2022-08-22 18:39:38.597?

  9. slardiere commented on Sep 5, 2022

    @slardiere
    Author

    Actually, the volume was filled up the 2022-08-23 at 08:27 (PG was stopped) ; Then I had to drop some « old WAL » to restart, and remove archiving setup until S3 came back to work.

    During the preceding day (2022-08-22), i had to kill pgbackrest archiving job to change the log level (to DEBUG then TRACE).

    So, can i say that the problem is caused by the large size of the pgbackrest batch ( about 8000 WALs at once ) ? 

    If so, could it be a good idea to add a max batch size setting ? (I don't know if it's easy to do)

  10. dwsteele commented on Sep 5, 2022

    @dwsteele
    Member

    Limiting the batch size would be pretty easy, I think, but I'm worried that lots of retries could still present a problem even for smaller batch sizes since each one takes 60 seconds (or more depending on configuration).

    Perhaps it would be better to stop async processing after a certain number of errors. We don't do this now because the idea is that it is good to archive beyond an error so that when the error is fixed it will be faster to cleanup all the WAL that has already been archived. But, since PostgreSQL can't cleanup anything after the errored segment, it doesn't help with the immediate problem of the disk filling up.

    It would be pretty easy to stop after three errors and let the async process get spawned again, which would do any queue cleanup needed. This would also keep us from creating thousands of error files for all the WAL that could not be archived.

    Thoughts, @sfrost @pgstef?

  11. pgstef commented on Sep 6, 2022

    @pgstef
    Member

    Thoughts, @sfrost @pgstef?

    Hm, I agree we should continue archiving beyond an error. But stop trying after 3 errors seems reasonable to me 👍

  12. sfrost commented on Sep 6, 2022

    @sfrost
    Contributor

    Generally agreed on limiting the number of errors before giving up on a given run as it's pretty likely that whatever is causing the failure will persist for a while longer after 3 errors and immediately trying again isn't going to be helpful.

    Another thought though is to perhaps review the queue size after the first error as we have some idea that it probably took a while for the error to come back and therefore it might make sense to check the WAL size and do cleanup then (or maybe just exit the run?).

    A third thought- how expensive is it for us to calculate where we are in terms of the queue depth? Notionally, PG should be calling us for the 'oldest' WAL and we can query PG for the current WAL position and gauge the depth that way and maybe do something different when we get called by PG via archive_command? Signal the async process that's running somehow? Just immediately go into cleanup mode because we want to push hard on avoiding the out-of-disk-space issue?

  13. dwsteele commented on Sep 6, 2022

    @dwsteele
    Member

    Another thought though is to perhaps review the queue size after the first error as we have some idea that it probably took a while for the error to come back and therefore it might make sense to check the WAL size and do cleanup then (or maybe just exit the run?).

    Well, exiting would be easy, but I'm not sure that exiting after one error is a good idea. In particular I'm worried about duplicate WAL segments, though that's enough of an edge case that maybe we shouldn't worry about it too much.

    We can reprocess the queue but that can be very expensive depending on the number of WAL that have accumulated. In general I am not excited about trying to do cleanup while local workers are still running since you'd get multiple processes manipulating the same status files.

    Essentially, we'd need to stop the run to do cleanup safely so we may as well just exit for and make it easy.

    A third thought- how expensive is it for us to calculate where we are in terms of the queue depth?

    Could be very expensive, depending. Right now we stat each file in pg_wal, which seems like a bad idea in any case. We should probably just stat the first file and then project that all the rest will be the same size. There are some edge cases where that might not be true (e.g. pg_reset_wal), but I think it is OK to ignore them for this case.

  14. sfrost commented on Sep 7, 2022

    @sfrost
    Contributor

    Seems like we should consider moving away from stat'ing every file every time. stat'ing the file that PG asked us to archive to get the size and then asking PG where it's at in WAL (through a query or maybe just peek'ing at pg_control?) and then doing a bit of math sure seems like it'd get us an answer very quickly and I'm not sure there's any reason to think that answer would be way off. I agree that we can probably ignore really odd edge cases that aren't going to happen in normal usage.

  15. 1053531172 commented on Aug 22, 2025

    @1053531172

    Can this issue be resolved by adjusting the archive-push-queue-max parameter? For instance, setting it to 1T? Is there any other impact if it is set too high, besides causing the wal log of the primary database to expand

  16. jw1u1 commented on Mar 27, 2026

    @jw1u1

    pgBackRest 2.58.0

    Archive Queue Max doesn't apply when archiving hangs.
    Due to an S3 issue, we had a hanging archiving process.
    Archive Queue Max kicked in only after killing pgbackrest.

    Expected behavior: Archive Queue Max should be checked asynchronously

    2026-03-26 16:17:54.342 P00 INFO: push 639 WAL file(s) to archive: 00000004000079A70000003B...00000004000079A9000000B9
    terminated on signal SIGTERM

    -------------------PROCESS START-------------------
    2026-03-26 17:46:41.363 P00 INFO: archive-push:async command begin 2.58.0: [/var/lib/pgsql/data/16/cdrqm_cl/pg_wal] --archive-async --archive-push-queue-max=23530291KB --exec-id=3133533-8125eee9 --io-timeout=300 --log-level-console=off --log-level-stderr=off --pg2-host=foo.lan --pg1-path=/var/lib/pgsql/data/16/cdrqm_cl --pg2-path=/var/lib/pgsql/data/16/cdrqm_cl --process-max=2 --repo1-path=/repo --repo1-s3-bucket=drqm --repo1-s3-endpoint=s301.lan --repo1-s3-key= --repo1-s3-key-secret= --repo1-s3-region=us-east-1 --repo1-storage-port=443 --repo1-storage-upload-chunk-size=64MiB --repo1-type=s3 --spool-path=/var/lib/pgsql/wals/spool --stanza=cdrqm
    2026-03-26 17:46:41.367 P00 INFO: push 2852 WAL file(s) to archive: 00000004000079A8000000A1...00000004000079B3000000D9
    2026-03-26 17:46:41.368 P00 WARN: dropped WAL file '00000004000079A8000000A1' because archive queue exceeded 22.4GB
    2026-03-26 17:46:41.369 P00 WARN: dropped WAL file '00000004000079A8000000B7' because archive queue exceeded 22.4GB
    2026-03-26 17:46:41.370 P00 WARN: dropped WAL file '00000004000079A8000000B8' because archive queue exceeded 22.4GB
    2026-03-26 17:46:41.370 P00 WARN: dropped WAL file '00000004000079A8000000B9' because archive queue exceeded 22.4GB
    2026-03-26 17:46:41.371 P00 WARN: dropped WAL file '00000004000079A8000000BA' because archive queue exceeded 22.4GB

  17. linked a pull request that will close this issueExit async archive-push on first error. #2802on Jul 2, 2026
  18. added this to the 2.59 milestone on Jul 2, 2026
  19. dwsteele commented on Jul 2, 2026

    @dwsteele
    Member

    Closing since there is a proposed fix for this in PR #2802.

  20. locked and limited conversation to collaborators on Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions