Repository navigation
Commit f421bf8
Make autoprewarm yield to conflicting lock requests.
The autoprewarm worker opens every relation it has recorded
blocks for and holds AccessShareLock on it until all of those
blocks have been read back into shared buffers. On a large
relation that takes a long time, and anything that needs a
conflicting lock in the meantime, TRUNCATE or DROP for instance,
waits behind the worker for the whole of it. Nothing bounds that
wait, and it buys nothing, since prewarming is best-effort work
done for the benefit of later queries.
Fix this by having the worker check from time to time whether a
conflicting request is waiting on the relation, and give the
relation up when one is. It closes the relation, which releases
the lock, and moves on to the next one rather than coming back to
finish later, because once a conflicting strong lock has been
taken the blocks recorded for that relation may no longer be the
ones worth reading. Heap truncation in VACUUM already yields to
waiters the same way. The check is throttled by both a block
count and a time interval, so it costs nothing measurable while
nobody is waiting.
Note that the pg_prewarm() function is left as it is. Its caller
asked for a bounded amount of work and is waiting on the result,
which is the same reason a foreground VACUUM does not
deprioritize itself.
Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Co-authored-by: Satyanarayana Narlapuram <satyanarlapuram@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Palak Chaturvedi <chaturvedipalak1911@gmail.com>
Discussion: https://postgr.es/m/CAHg+QDfdoR=7iqEAvLW9qtzV0Sx1wp2FuALeamqcCdiVEmMF-Q@mail.gmail.com1 parent 404affb commit f421bf8
1 file changed
Lines changed: 89 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| 43 | + | |
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
| |||
52 | 54 | | |
53 | 55 | | |
54 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
55 | 65 | | |
56 | 66 | | |
57 | 67 | | |
| |||
493 | 503 | | |
494 | 504 | | |
495 | 505 | | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
496 | 573 | | |
497 | 574 | | |
498 | 575 | | |
| |||
577 | 654 | | |
578 | 655 | | |
579 | 656 | | |
580 | | - | |
581 | | - | |
582 | 657 | | |
583 | 658 | | |
584 | 659 | | |
| |||
627 | 702 | | |
628 | 703 | | |
629 | 704 | | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | 705 | | |
641 | | - | |
642 | | - | |
643 | | - | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
644 | 709 | | |
645 | | - | |
| 710 | + | |
646 | 711 | | |
647 | | - | |
648 | | - | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
649 | 720 | | |
650 | 721 | | |
651 | | - | |
652 | | - | |
653 | 722 | | |
654 | 723 | | |
655 | 724 | | |
| |||
0 commit comments