1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

Report shared buffer exhaustion as insufficient resources

When all shared buffers examined are pinned, a query can fail with
"no unpinned buffers available". This can happen when shared_buffers
is too small for the workload, but the error was reported as an internal
error, making a resource shortage look like a server bug.

Replace elog() with ereport() to report this condition with SQLSTATE
53000 (insufficient_resources) instead of XX000 (internal_error),
matching the corresponding local-buffer error. Reword both messages
to clarify whether shared or local buffers are involved.

Author: Ma Xueting <ma@sraoss.co.jp>
Reviewed-by: Pierre Forstmann <pierre.forstmann@gmail.com>
Reviewed-by: Matthias van de Meent <boekewurm+postgres@gmail.com>
Reviewed-by: solai v <solai.cdac@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/TYWP286MB2571C92032EE9D1B8F2BFACFEF812@TYWP286MB2571.JPNP286.PROD.OUTLOOK.COM
This commit is contained in:
Fujii Masao
2026-10-21 23:40:46 +09:00
parent 54f38d8115
commit 4b97fd15fb
3 changed files with 6 additions and 4 deletions

View File

@@ -271,7 +271,9 @@ StrategyGetBuffer(BufferAccessStrategy strategy, uint64 *buf_state, bool *from_r
* one eventually, but it's probably better to fail than
* to risk getting stuck in an infinite loop.
*/
elog(ERROR, "no unpinned buffers available");
ereport(ERROR,
errcode(ERRCODE_INSUFFICIENT_RESOURCES),
errmsg("could not find an unpinned shared buffer"));
}
break;
}

View File

@@ -271,7 +271,7 @@ GetLocalVictimBuffer(void)
else if (--trycounter == 0)
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_RESOURCES),
errmsg("no empty local buffer available")));
errmsg("could not find an unpinned local buffer")));
}
/*

View File

@@ -456,7 +456,7 @@ SELECT test_temp_pin(0, 9);
-- should fail, too many buffers pinned
SELECT test_temp_pin(10, 105);
ERROR: no empty local buffer available
ERROR: could not find an unpinned local buffer
ROLLBACK;
BEGIN;
-- have some working cursors to test after errors
@@ -475,7 +475,7 @@ FETCH NEXT FROM c_3;
-- exhaust buffer pins in subtrans, check things work after
SAVEPOINT rescue_me;
SELECT test_temp_pin(10, 105);
ERROR: no empty local buffer available
ERROR: could not find an unpinned local buffer
ROLLBACK TO SAVEPOINT rescue_me;
-- pre-subtrans cursors continue to work
FETCH NEXT FROM c_3;