You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Archive Queue Max doesn't apply when archiving failed #1848
archive_mode = on
archive_command = 'pgbackrest --stanza=lsi archive-push %p'
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 :
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)
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.
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.
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.
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:
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?
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)
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.
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?
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.
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.
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
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
Activity
dwsteele commentedon Aug 30, 2022
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.
slardiere commentedon Aug 31, 2022
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 :
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.
slardiere commentedon Aug 31, 2022
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:
I got that :
It could be interesting to catch it, at least in DEBUG or TRACE mode.
Full log : s3cmd.txt
dwsteele commentedon Aug 31, 2022
Just debug will be fine. Try compressing it and attaching to this issue and see if that works.
dwsteele commentedon Aug 31, 2022
One thing to note, if
archive-push-queue-maxis 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.
slardiere commentedon Sep 1, 2022
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.
dwsteele commentedon Sep 2, 2022
When exactly did the WAL volume fill up on the primary? I can see the errors starting here:
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:
That doesn't happen until the next morning:
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?slardiere commentedon Sep 5, 2022
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)
dwsteele commentedon Sep 5, 2022
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?
pgstef commentedon Sep 6, 2022
Hm, I agree we should continue archiving beyond an error. But stop trying after 3 errors seems reasonable to me 👍
sfrost commentedon Sep 6, 2022
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?
dwsteele commentedon Sep 6, 2022
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.
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.
sfrost commentedon Sep 7, 2022
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.
1053531172 commentedon Aug 22, 2025
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
jw1u1 commentedon Mar 27, 2026
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
dwsteele commentedon Jul 2, 2026
Closing since there is a proposed fix for this in PR #2802.