forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit6cc6619
committed
Improve memory handling across SQL-callable backup functions
Since pg_backup_start() and pg_backup_stop() exist, the tablespace mapdata and the backup state data (backup_label string until7d70809) havebeen allocated in the TopMemoryContext. This approach would causememory leaks in the session calling these functions if failures happenbefore pg_backup_stop() ends, leaking more memory on repeated failures.Both things need little memory so that would not be really noticeablefor most users, except perhaps connection poolers with long-livedconnections able to trigger backup failures with these functions.This commit improves the logic in this area by not allocating anymorethe backup-related data that needs to travel across the SQL-callablebackup functions in TopMemoryContext, by using instead a dedicatedmemory context child of TopMemoryContext. The memory context is createdin pg_backup_start() and deleted when finishing pg_backup_stop(). Inthe event of an in-flight failure, this memory context gets reset in thefollow-up pg_backup_start() call, so as we are sure that only one runworth of data is leaked at any time. Some cleanup was already done forthe backup data on a follow-up call of pg_backup_start(), but using amemory context makes the whole simpler.BASE_BACKUP commands are executed in isolation, relying on the memorycontext created for replication commands, hence these do not need suchan extra logic.Author: Bharath RupireddyReviewed-by: Robert Haas, Alvaro Herrera, Cary Huang, Michael PaquierDiscussion:https://postgr.es/m/CALj2ACXqvfKF2B0beQ=aJMdWnpNohmBPsRg=EDQj_6y1t2O8mQ@mail.gmail.com1 parent1f0c4fa commit6cc6619
1 file changed
+22
-19
lines changedLines changed: 22 additions & 19 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
45 | 45 |
| |
46 | 46 |
| |
47 | 47 |
| |
| 48 | + | |
| 49 | + | |
| 50 | + | |
48 | 51 |
| |
49 | 52 |
| |
50 | 53 |
| |
| |||
72 | 75 |
| |
73 | 76 |
| |
74 | 77 |
| |
75 |
| - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
76 | 82 |
| |
77 |
| - | |
78 |
| - | |
79 |
| - | |
80 |
| - | |
81 |
| - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
82 | 89 |
| |
83 |
| - | |
84 |
| - | |
85 |
| - | |
86 |
| - | |
87 |
| - | |
88 |
| - | |
89 |
| - | |
90 | 90 |
| |
91 |
| - | |
92 |
| - | |
| 91 | + | |
93 | 92 |
| |
| 93 | + | |
94 | 94 |
| |
95 | 95 |
| |
| 96 | + | |
| 97 | + | |
96 | 98 |
| |
97 | 99 |
| |
98 | 100 |
| |
| |||
157 | 159 |
| |
158 | 160 |
| |
159 | 161 |
| |
160 |
| - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
161 | 165 |
| |
162 |
| - | |
163 |
| - | |
164 | 166 |
| |
165 |
| - | |
| 167 | + | |
| 168 | + | |
166 | 169 |
| |
167 | 170 |
| |
168 | 171 |
| |
|
0 commit comments
Comments
(0)