forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitab7dbd6
committed
Update FSM on WAL replay of page all-visible/frozen
We aren't very strict about keeping FSM up to date on WAL replay,because per-page freespace values aren't critical in replicas (can'twrite to heap in a replica; and if the replica is promoted, the valueswould be updated by VACUUM anyway). However, VACUUM since 9.6 can skipprocessing pages marked all-visible or all-frozen, and if such pages arerecorded in FSM with wrong values, those values are blindly propagatedto FSM's upper layers by VACUUM's FreeSpaceMapVacuum. (This rationaleassumes that crashes are not very frequent, because those would causeoutdated FSM to occur in the primary.)Even when the FSM is outdated in standby, things are not too badnormally, because, most per-page FSM values will be zero (other thanthose propagated with the base-backup that created the standby); onlyonce the remaining free space is less than 0.2*BLCKSZ the per-page valueis maintained by WAL replay of heap ins/upd/del. However, ifwal_log_hints=on causes complete FSM pages to be propagated to a standbyvia full-page images, many too-optimistic per-page values can end upbeing registered in the standby.Incorrect per-page values aren't critical in most cases, since aninserter that is given a page that doesn't actually contain the claimedfree space will update FSM with the correct value, and retry until itfinds a usable page. However, if there are many such updates to do, aninserter can spend a long time doing them before a usable page is found;in a heavily trafficked insert-only table with many concurrent insertersthis has been observed to cause several second stalls, causing visibleapplication malfunction.To fix this problem, it seems sufficient to have heap_xlog_visible(replay of setting all-visible and all-frozen VM bits for a heap page)update the FSM value for the page being processed. This fixes theper-page counters together with making the page skippable to vacuum, sowhen vacuum does FreeSpaceMapVacuum, the values propagated to FSM upperlayers are the correct ones, avoiding the problem.While at it, apply the same fix to heap_xlog_clean (replay of tupleremoval by HOT pruning and vacuum). This makes any space freed by thecleaning available earlier than the next vacuum in the promoted replica.Backpatch to 9.6, where this problem was diagnosed on an insert-onlytable with all-frozen pages, which were introduced as a concept in thatrelease. Theoretically it could apply with all-visible pages to olderbranches, but there's been no report of that and it doesn't backpatchcleanly anyway.Author: Álvaro Herrera <alvherre@alvh.no-ip.org>Discussion:https://postgr.es/m/20180802172857.5skoexsilnjvgruk@alvherre.pgsql1 parentcc4f6b7 commitab7dbd6
1 file changed
+40
-12
lines changedLines changed: 40 additions & 12 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
8172 | 8172 |
| |
8173 | 8173 |
| |
8174 | 8174 |
| |
8175 |
| - | |
| 8175 | + | |
8176 | 8176 |
| |
8177 | 8177 |
| |
8178 | 8178 |
| |
8179 | 8179 |
| |
8180 | 8180 |
| |
8181 | 8181 |
| |
8182 | 8182 |
| |
8183 |
| - | |
8184 | 8183 |
| |
8185 | 8184 |
| |
8186 | 8185 |
| |
| |||
8232 | 8231 |
| |
8233 | 8232 |
| |
8234 | 8233 |
| |
8235 |
| - | |
8236 |
| - | |
8237 | 8234 |
| |
8238 | 8235 |
| |
8239 | 8236 |
| |
| |||
8242 | 8239 |
| |
8243 | 8240 |
| |
8244 | 8241 |
| |
| 8242 | + | |
8245 | 8243 |
| |
| 8244 | + | |
| 8245 | + | |
| 8246 | + | |
8246 | 8247 |
| |
8247 | 8248 |
| |
8248 |
| - | |
8249 |
| - | |
8250 |
| - | |
8251 |
| - | |
8252 |
| - | |
8253 |
| - | |
8254 |
| - | |
8255 |
| - | |
| 8249 | + | |
| 8250 | + | |
| 8251 | + | |
| 8252 | + | |
| 8253 | + | |
| 8254 | + | |
| 8255 | + | |
| 8256 | + | |
| 8257 | + | |
8256 | 8258 |
| |
| 8259 | + | |
8257 | 8260 |
| |
8258 | 8261 |
| |
8259 | 8262 |
| |
| |||
8326 | 8329 |
| |
8327 | 8330 |
| |
8328 | 8331 |
| |
| 8332 | + | |
8329 | 8333 |
| |
| 8334 | + | |
| 8335 | + | |
| 8336 | + | |
8330 | 8337 |
| |
8331 | 8338 |
| |
| 8339 | + | |
| 8340 | + | |
| 8341 | + | |
| 8342 | + | |
| 8343 | + | |
| 8344 | + | |
| 8345 | + | |
| 8346 | + | |
| 8347 | + | |
| 8348 | + | |
| 8349 | + | |
| 8350 | + | |
| 8351 | + | |
| 8352 | + | |
| 8353 | + | |
| 8354 | + | |
| 8355 | + | |
| 8356 | + | |
| 8357 | + | |
| 8358 | + | |
| 8359 | + | |
8332 | 8360 |
| |
8333 | 8361 |
| |
8334 | 8362 |
| |
|
0 commit comments
Comments
(0)