mirror of
https://github.com/postgres/postgres.git
synced 2025-06-11 20:28:21 +03:00
Fix memory counter update in ReorderBuffer.
Commit 5bec1d6bc5
changed the memory usage updates of the
ReorderBufferTXN to zero all at once by subtracting txn->size, rather
than updating it for each change. However, if TOAST reconstruction
data remained in the transaction when freeing it, there were cases
where it further subtracted the memory counter from zero, resulting in
an assertion failure.
This change calculates the memory size for each change and updates the
memory usage to precisely the amount that has been freed.
Backpatch to v17, where this was introducd.
Reviewed-by: Amit Kapila, Shlok Kyal
Discussion: https://postgr.es/m/CAD21AoAqkNUvicgKPT_dXzNoOwpPkVTg0QPPxEcWmzT0moCJ1g%40mail.gmail.com
Backpatch-through: 17
This commit is contained in:
@ -44,5 +44,20 @@ toasted-123456789012345678901234567890123456789012345678901234567890123456789012
|
||||
|
||||
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL,NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
|
||||
|
||||
/*
|
||||
* Test concurrent abort with toast data. When streaming the second insertion, we
|
||||
* detect that the subtransaction was aborted, and reset the transaction while having
|
||||
* the TOAST changes in memory, resulting in deallocating both decoded changes and
|
||||
* TOAST reconstruction data. Memory usage counters must be updated correctly.
|
||||
*/
|
||||
BEGIN;
|
||||
INSERT INTO stream_test SELECT repeat(string_agg(to_char(g.i, 'FM0000'), ''), 50) FROM generate_series(1, 500) g(i);
|
||||
ALTER TABLE stream_test ADD COLUMN i INT;
|
||||
SAVEPOINT s1;
|
||||
INSERT INTO stream_test(data, i) SELECT repeat(string_agg(to_char(g.i, 'FM0000'), ''), 50), 1 FROM generate_series(1, 500) g(i);
|
||||
ROLLBACK TO s1;
|
||||
COMMIT;
|
||||
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
|
||||
|
||||
DROP TABLE stream_test;
|
||||
SELECT pg_drop_replication_slot('regression_slot');
|
||||
|
Reference in New Issue
Block a user