[PATCH] Report no unpinned buffers as insufficient resources

Started by Ma Xueting2 months ago8 messageshackers
Jump to latest
#1Ma Xueting
ma@sraoss.co.jp

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:

https://gitlab.com/gitlab-org/omnibus-gitlab/-/work_items/8682

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

Attachments:

t253914_1
0001-Report-no-unpinned-buffers-as-insufficient-resources.patchapplication/octet-stream; name=0001-Report-no-unpinned-buffers-as-insufficient-resources.patchDownload+3-2
#2Pierre Forstmann
pierre.forstmann@gmail.com
In reply to: Ma Xueting (#1)
Re: [PATCH] Report no unpinned buffers as insufficient resources

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

#3Matthias van de Meent
boekewurm+postgres@gmail.com
In reply to: Ma Xueting (#1)
Re: [PATCH] Report no unpinned buffers as insufficient resources

On Thu, 24 Sept 2026 at 07:26, Ma Xueting <ma@sraoss.co.jp> 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)

#4solai v
solai.cdac@gmail.com
In reply to: Matthias van de Meent (#3)
Re: [PATCH] Report no unpinned buffers as insufficient resources

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

#5Fujii Masao
masao.fujii@gmail.com
In reply to: Ma Xueting (#1)
Re: [PATCH] Report no unpinned buffers as insufficient resources

On Thu, Sep 24, 2026 at 2:26 PM Ma Xueting <ma@sraoss.co.jp> 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

#6Ma Xueting
ma@sraoss.co.jp
In reply to: Fujii Masao (#5)
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 clarify
which 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 attempt
more clearly. If we adopt this, for consistency, it might be better
to 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

Attachments:

t253914_6
v2-0001-Report-unpinned-buffer-errors-as-insufficient-res.patchapplication/octet-stream; name=v2-0001-Report-unpinned-buffer-errors-as-insufficient-res.patchDownload+6-5
#7Fujii Masao
masao.fujii@gmail.com
In reply to: Ma Xueting (#6)
Re: [PATCH] Report no unpinned buffers as insufficient resources

On Fri, Oct 16, 2026 at 1:44 PM Ma Xueting <ma@sraoss.co.jp> 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

#8Fujii Masao
masao.fujii@gmail.com
In reply to: Fujii Masao (#7)
Re: [PATCH] Report no unpinned buffers as insufficient resources

On Tue, Oct 20, 2026 at 5:16 PM Fujii Masao <masao.fujii@gmail.com> wrote:

Thanks for updating the patch! LGTM.
Barring any objections, I will commit the patch.

I've pushed the patch. Thanks!

Regards,

--
Fujii Masao