forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commita556549
committed
Improve VACUUM and ANALYZE by avoiding early lock queue
A caller of VACUUM can perform early lookup obtention which can causeother sessions to block on the request done, causing potentially DOSattacks as even a non-privileged user can attempt a vacuum fill of acritical catalog table to block even all incoming connection attempts.Contrary to TRUNCATE, a client could attempt a system-wide VACUUM afterbuilding the list of relations to VACUUM, which can cause vacuum_rel()or analyze_rel() to try to lock the relation but the operation wouldjust block. When the client specifies a list of relations and therelation needs to be skipped, ownership checks are done when buildingthe list of relations to work on, preventing a later lock attempt.vacuum_rel() already had the sanity checks needed, except that thosewere applied too late. This commit refactors the code so as relationskips are checked beforehand, making it safer to avoid too early locks,for both manual VACUUM with and without a list of relations specified.An isolation test is added emulating the fact that early locks do nothappen anymore, issuing a WARNING message earlier if the user callingVACUUM is not a relation owner.When a partitioned table is listed in a manual VACUUM or ANALYZEcommand, its full list of partitions is fetched, all partitions getadded to the list to work on, and then each one of them is processed oneby one, with ownership checks happening at the later phase ofvacuum_rel() or analyze_rel(). Trying to do early ownership checks foreach partition is proving to be tedious as this would result in deadlockrisks with lock upgrades, and skipping all partitions if the listedpartitioned table is not owned would result in a behavior changecompared to how Postgres 10 has implemented vacuum for partitionedtables. The original problem reported related to early lock queue forcritical relations is fixed anyway, so priority is given to avoiding abackward-incompatible behavior.Reported-by: Lloyd Albin, Jeremy SchneiderAuthor: Michael PaquierReviewed by: Nathan Bossart, Kyotaro HoriguchiDiscussion:https://postgr.es/m/152512087100.19803.12733865831237526317@wrigleys.postgresql.orgDiscussion:https://postgr.es/m/20180812222142.GA6097@paquier.xyz1 parent18e5867 commita556549
File tree
6 files changed
+328
-60
lines changed- src
- backend/commands
- include/commands
- test/isolation
- expected
- specs
6 files changed
+328
-60
lines changedLines changed: 9 additions & 19 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
196 | 196 |
| |
197 | 197 |
| |
198 | 198 |
| |
199 |
| - | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
200 | 205 |
| |
201 |
| - | |
202 |
| - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
203 | 209 |
| |
204 |
| - | |
205 |
| - | |
206 |
| - | |
207 |
| - | |
208 |
| - | |
209 |
| - | |
210 |
| - | |
211 |
| - | |
212 |
| - | |
213 |
| - | |
214 |
| - | |
215 |
| - | |
216 |
| - | |
217 |
| - | |
218 |
| - | |
219 |
| - | |
220 | 210 |
| |
221 | 211 |
| |
222 | 212 |
| |
|
Lines changed: 115 additions & 41 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
68 | 68 |
| |
69 | 69 |
| |
70 | 70 |
| |
71 |
| - | |
72 |
| - | |
| 71 | + | |
| 72 | + | |
73 | 73 |
| |
74 | 74 |
| |
75 | 75 |
| |
| |||
257 | 257 |
| |
258 | 258 |
| |
259 | 259 |
| |
260 |
| - | |
| 260 | + | |
261 | 261 |
| |
262 | 262 |
| |
263 | 263 |
| |
264 | 264 |
| |
265 | 265 |
| |
266 | 266 |
| |
267 | 267 |
| |
268 |
| - | |
| 268 | + | |
269 | 269 |
| |
270 | 270 |
| |
271 | 271 |
| |
| |||
408 | 408 |
| |
409 | 409 |
| |
410 | 410 |
| |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
411 | 485 |
| |
412 | 486 |
| |
413 | 487 |
| |
| |||
423 | 497 |
| |
424 | 498 |
| |
425 | 499 |
| |
426 |
| - | |
| 500 | + | |
427 | 501 |
| |
428 | 502 |
| |
429 | 503 |
| |
| |||
457 | 531 |
| |
458 | 532 |
| |
459 | 533 |
| |
460 |
| - | |
461 |
| - | |
462 |
| - | |
463 |
| - | |
464 |
| - | |
465 |
| - | |
466 |
| - | |
467 |
| - | |
468 |
| - | |
469 |
| - | |
470 |
| - | |
| 534 | + | |
| 535 | + | |
471 | 536 |
| |
472 | 537 |
| |
473 | 538 |
| |
474 | 539 |
| |
475 | 540 |
| |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
476 | 556 |
| |
477 | 557 |
| |
478 | 558 |
| |
| |||
481 | 561 |
| |
482 | 562 |
| |
483 | 563 |
| |
484 |
| - | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
485 | 567 |
| |
486 | 568 |
| |
487 | 569 |
| |
| |||
530 | 612 |
| |
531 | 613 |
| |
532 | 614 |
| |
533 |
| - | |
| 615 | + | |
534 | 616 |
| |
535 | 617 |
| |
536 | 618 |
| |
| |||
545 | 627 |
| |
546 | 628 |
| |
547 | 629 |
| |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
548 | 635 |
| |
549 | 636 |
| |
550 | 637 |
| |
| |||
563 | 650 |
| |
564 | 651 |
| |
565 | 652 |
| |
566 |
| - | |
| 653 | + | |
567 | 654 |
| |
568 | 655 |
| |
569 | 656 |
| |
| |||
1436 | 1523 |
| |
1437 | 1524 |
| |
1438 | 1525 |
| |
1439 |
| - | |
1440 |
| - | |
1441 |
| - | |
1442 |
| - | |
1443 |
| - | |
1444 |
| - | |
1445 |
| - | |
1446 |
| - | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
1447 | 1532 |
| |
1448 |
| - | |
1449 |
| - | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
1450 | 1536 |
| |
1451 |
| - | |
1452 |
| - | |
1453 |
| - | |
1454 |
| - | |
1455 |
| - | |
1456 |
| - | |
1457 |
| - | |
1458 |
| - | |
1459 |
| - | |
1460 |
| - | |
1461 |
| - | |
1462 |
| - | |
1463 | 1537 |
| |
1464 | 1538 |
| |
1465 | 1539 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
15 | 15 |
| |
16 | 16 |
| |
17 | 17 |
| |
| 18 | + | |
18 | 19 |
| |
19 | 20 |
| |
20 | 21 |
| |
| |||
185 | 186 |
| |
186 | 187 |
| |
187 | 188 |
| |
| 189 | + | |
| 190 | + | |
188 | 191 |
| |
189 | 192 |
| |
190 | 193 |
| |
|
0 commit comments
Comments
(0)