forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitcec2edf

Amit Kapila
Add logical_decoding_work_mem to limit ReorderBuffer memory usage.
Instead of deciding to serialize a transaction merely based on thenumber of changes in that xact (toplevel or subxact), this makesthe decisions based on amount of memory consumed by the changes.The memory limit is defined by a new logical_decoding_work_mem GUC,so for example we can do this SET logical_decoding_work_mem = '128kB'to reduce the memory usage of walsenders or set the higher value toreduce disk writes. The minimum value is 64kB.When adding a change to a transaction, we account for the size intwo places. Firstly, in the ReorderBuffer, which is then used todecide if we reached the total memory limit. And secondly in thetransaction the change belongs to, so that we can pick the largesttransaction to evict (and serialize to disk).We still use max_changes_in_memory when loading changes serializedto disk. The trouble is we can't use the memory limit directly asthere might be multiple subxact serialized, we need to read all ofthem but we don't know how many are there (and which subxact toread first).We do not serialize the ReorderBufferTXN entries, so if there is atransaction with many subxacts, most memory may be in this type ofobjects. Those records are not included in the memory accounting.We also do not account for INTERNAL_TUPLECID changes, which arekept in a separate list and not evicted from memory. Transactionswith many CTID changes may consume significant amounts of memory,but we can't really do much about that.The current eviction algorithm is very simple - the transaction ispicked merely by size, while it might be useful to also consider age(LSN) of the changes for example. With the new Generational memoryallocator, evicting the oldest changes would make it more likelythe memory gets actually pfreed.The logical_decoding_work_mem can be set in postgresql.conf, in whichcase it serves as the default for all publishers on that instance.Author: Tomas Vondra, with changes by Dilip Kumar and Amit KapilaReviewed-by: Dilip Kumar and Amit KapilaTested-By: Vignesh CDiscussion:https://postgr.es/m/688b0b7f-2f6c-d827-c27b-216a8e3ea700@2ndquadrant.com1 parent2110f71 commitcec2edf
File tree
6 files changed
+333
-12
lines changed- contrib/test_decoding
- doc/src/sgml
- src
- backend
- replication/logical
- utils/misc
- include/replication
6 files changed
+333
-12
lines changedLines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1 | 1 |
| |
2 | 2 |
| |
| 3 | + |
Lines changed: 21 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1732 | 1732 |
| |
1733 | 1733 |
| |
1734 | 1734 |
| |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
1735 | 1756 |
| |
1736 | 1757 |
| |
1737 | 1758 |
| |
|
0 commit comments
Comments
(0)