- Notifications
You must be signed in to change notification settings - Fork4.9k
Commitb24e6ca
committed
Fix race condition with toast table access from a stale syscache entry.
If a tuple in a syscache contains an out-of-line toasted field, and wetry to fetch that field shortly after some other transaction has committedan update or deletion of the tuple, there is a race condition: vacuumcould come along and remove the toast tuples before we can fetch them.This leads to transient failures like "missing chunk number 0 for toastvalue NNNNN in pg_toast_2619", as seen in recent reports from AndrewHammond and Tim Uckun.The design idea of syscache is that access to stale syscache entriesshould be prevented by relation-level locks, but that fails for at leasttwo cases where toasted fields are possible: ANALYZE updates pg_statisticrows without locking out sessions that might want to plan queries on thesame table, and CREATE OR REPLACE FUNCTION updates pg_proc rows withoutany meaningful lock at all.The least risky fix seems to be an idea that Heikki suggested when wewere dealing with a related problem back in August: forcibly detoast anyout-of-line fields before putting a tuple into syscache in the first place.This avoids the problem because at the time we fetch the parent tuple fromthe catalog, we should be holding an MVCC snapshot that will preventremoval of the toast tuples, even if the parent tuple is outdatedimmediately after we fetch it. (Note: I'm not convinced that thisstatement holds true at every instant where we could be fetching a syscacheentry at all, but it does appear to hold true at the times where we couldfetch an entry that could have a toasted field. We will need to be a bitwary of adding toast tables to low-level catalogs that don't have themalready.) An additional benefit is that subsequent uses of the syscacheentry should be faster, since they won't have to detoast the field.Back-patch to all supported versions. The problem is significantly harderto reproduce in pre-9.0 releases, because of their willingness to flushevery entry in a syscache whenever the underlying catalog is vacuumed(cf CatalogCacheFlushRelation); but there is still a window for trouble.1 parent5b297de commitb24e6ca
File tree
3 files changed
+105
-1
lines changed- src
- backend
- access/heap
- utils/cache
- include/access
3 files changed
+105
-1
lines changedLines changed: 78 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
809 | 809 |
| |
810 | 810 |
| |
811 | 811 |
| |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
812 | 890 |
| |
813 | 891 |
| |
814 | 892 |
| |
|
Lines changed: 18 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
17 | 17 |
| |
18 | 18 |
| |
19 | 19 |
| |
| 20 | + | |
20 | 21 |
| |
21 | 22 |
| |
22 | 23 |
| |
| |||
1634 | 1635 |
| |
1635 | 1636 |
| |
1636 | 1637 |
| |
| 1638 | + | |
1637 | 1639 |
| |
1638 | 1640 |
| |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
1639 | 1653 |
| |
1640 | 1654 |
| |
1641 | 1655 |
| |
1642 | 1656 |
| |
1643 | 1657 |
| |
1644 |
| - | |
| 1658 | + | |
1645 | 1659 |
| |
1646 | 1660 |
| |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
1647 | 1664 |
| |
1648 | 1665 |
| |
1649 | 1666 |
| |
|
Lines changed: 9 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
112 | 112 |
| |
113 | 113 |
| |
114 | 114 |
| |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
115 | 124 |
| |
116 | 125 |
| |
117 | 126 |
| |
|
0 commit comments
Comments
(0)