[PATCH] Report no unpinned buffers as insufficient resources
[PATCH] Report no unpinned buffers as insufficient resources
Hi,
StrategyGetBuffer() currently reports "no unpinned buffers available"
using elog(ERROR). As a result, clients receive SQLSTATE XX000
(internal_error), and the message is not translatable.
Although this condition is uncommon, it can occur in user environments,
for example when shared_buffers is configured unusually low. GitLab
encountered this error with a shared_buffers setting of 1 MB:
The analogous local-buffer error, "no empty local buffer available",
is already reported using ERRCODE_INSUFFICIENT_RESOURCES.
This patch changes the shared-buffer error to use ereport() with
ERRCODE_INSUFFICIENT_RESOURCES.
I also considered adding a hint suggesting an increase to
shared_buffers. However, a small shared_buffers setting is not the
only possible cause of this error, so I left the hint out of this
version. I'd welcome thoughts on whether such a hint would be useful.
Best regards,
Xueting Ma
Re: [PATCH] Report no unpinned buffers as insufficient resources
От:
Pierre Forstmann <pierre.forstmann@gmail.com>
Дата:
The following review has been posted through the commitfest application: make installcheck-world: tested, passed Implements feature: tested, passed Spec compliant: not tested Documentation: not tested Hello, I have used following scenario to trigger "no unpinned buffers available": 1. set following parameters in postgresql.conf: shared_buffers = 128kB log_error_verbosity = verbose 2. stop and restart PG server 3. use pgbench: pgbench -i -s 10 postgres dropping old tables... creating tables... generating data (client-side)... vacuuming... creating primary keys... done in 8.98 s (drop tables 0.01 s, create tables 0.02 s, client-side generate 8.14 s, vacuum 0.31 s, primary keys 0.50 s). $ pgbench -c 16 -j 16 -T 60 postgres pgbench (20devel) starting vacuum...end. pgbench: error: pgbench: error: pgbench:client 8 script 0 aborted in command 5 query 0: ERROR: no unpinned buffers available pgbench:pgbench:client 5 script 0 aborted in command 5 query 0: ERROR: no unpinned buffers available pgbench: error: error: client 4 script 0 aborted in command 5 query 0: ERROR: no unpinned buffers available error: client 7 script 0 aborted in command 5 query 0: ERROR: no unpinned buffers available I have checked PG log: grep 53000 $PGDATA/log/pg.log 2026-09-26 13:23:28.504 CEST [66095] ERROR: 53000: no unpinned buffers available 2026-09-26 13:23:28.504 CEST [66102] ERROR: 53000: no unpinned buffers available 2026-09-26 13:23:28.504 CEST [66089] ERROR: 53000: no unpinned buffers available 2026-09-26 13:23:28.504 CEST [66103] ERROR: 53000: no unpinned buffers available 2026-09-26 13:23:28.504 CEST [66094] ERROR: 53000: no unpinned buffers available 2026-09-26 13:23:28.504 CEST [66092] ERROR: 53000: no unpinned buffers available 2026-09-26 13:23:28.504 CEST [66088] ERROR: 53000: no unpinned buffers available 2026-09-26 13:23:28.504 CEST [66098] ERROR: 53000: no unpinned buffers available 2026-09-26 13:23:28.505 CEST [66091] ERROR: 53000: no unpinned buffers available We have expected PG error code class: Class 53 — Insufficient Resources Patch looks good to me. Regards, PF. The new status of this patch is: Ready for Committer
Re: [PATCH] Report no unpinned buffers as insufficient resources
От:
Matthias van de Meent <boekewurm+postgres@gmail.com>
Дата:
On Thu, 24 Sept 2026 at 07:26, Ma Xueting wrote: > > Hi, > > StrategyGetBuffer() currently reports "no unpinned buffers available" > using elog(ERROR). As a result, clients receive SQLSTATE XX000 > (internal_error), and the message is not translatable. > > Although this condition is uncommon, it can occur in user environments, > for example when shared_buffers is configured unusually low. GitLab > encountered this error with a shared_buffers setting of 1 MB: With the recent drive to read vectorization and AIO, backends are holding more buffers pinned than ever before, so we've increased the likelyhood someone will eventually hit this limit. Making the error message more descriptive is definitely useful. > The analogous local-buffer error, "no empty local buffer available", > is already reported using ERRCODE_INSUFFICIENT_RESOURCES. > > This patch changes the shared-buffer error to use ereport() with > ERRCODE_INSUFFICIENT_RESOURCES. Yep, LGTM. > I also considered adding a hint suggesting an increase to > shared_buffers. However, a small shared_buffers setting is not the > only possible cause of this error, so I left the hint out of this > version. I'd welcome thoughts on whether such a hint would be useful. I think it could be useful, but indeed the issue can be caused by various different issues (misbehaving code leaking buffer pins, too-high connection counts, bad plans, bad plan nodes, etc.). If we're adding an errdetail/errhint, then the ereport in GetLocalVictimBuffer should probably also be updated accordingly. Kind regards, Matthias van de Meent Databricks (https://www.databricks.com)
Re: [PATCH] Report no unpinned buffers as insufficient resources
От:
solai v <solai.cdac@gmail.com>
Дата:
Hi, I tested the patch by reproducing the issue before and after applying the changes. Before applying the patch, I was able to reproduce the issue by setting shared_buffers = 128kB and running pgbench with 16 clients and 16 threads. The server reported no unpinned buffers available with SQLSTATE XX000. After applying the patch, I repeated the same test and confirmed that the error was reported with SQLSTATE 53000 (insufficient resources), as expected. I also ran the regression tests, and all tests passed. git diff --check reported no issues. The patch looks good to me. It reports the error with the appropriate SQLSTATE while keeping the existing error message unchanged. Thanks for the patch. Regards, solai
Re: [PATCH] Report no unpinned buffers as insufficient resources
От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Thu, Sep 24, 2026 at 2:26 PM Ma Xueting wrote: > The analogous local-buffer error, "no empty local buffer available", > is already reported using ERRCODE_INSUFFICIENT_RESOURCES. Isn't it better to add "shared" to the error message to clarify which buffers are involved, as the local-buffer message does? For example, "no unpinned shared buffers available" or "could not find an unpinned shared buffer". BTW, I prefer the latter because "could not" describes the failed attempt more clearly. If we adopt this, for consistency, it might be better to also change the local-buffer message to something like "could not find an unpinned local buffer". Regards, -- Fujii Masao
Re: [PATCH] Report no unpinned buffers as insufficient resources
fujii-san,
Thank you for the suggestion.
Isn't it better to add "shared" to the error message to clarifywhich buffers are involved, as the local-buffer message does?
I agree that explicitly mentioning shared buffers makes the error clearer.
I prefer the latter because "could not" describes the failed attemptmore clearly. If we adopt this, for consistency, it might be betterto also change the local-buffer message.
Agreed. I changed the messages in v2 to:
could not find an unpinned shared buffer
could not find an unpinned local buffer
I also updated the regression test expected output accordingly.
Best regards,
Xueting Ma
Re: [PATCH] Report no unpinned buffers as insufficient resources
От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Fri, Oct 16, 2026 at 1:44 PM Ma Xueting wrote: > Agreed. I changed the messages in v2 to: > > could not find an unpinned shared buffer > could not find an unpinned local buffer > > I also updated the regression test expected output accordingly. Thanks for updating the patch! LGTM. Barring any objections, I will commit the patch. Regards, -- Fujii Masao
Re: [PATCH] Report no unpinned buffers as insufficient resources
От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Tue, Oct 20, 2026 at 5:16 PM Fujii Masao wrote: > Thanks for updating the patch! LGTM. > Barring any objections, I will commit the patch. I've pushed the patch. Thanks! Regards, -- Fujii Masao