diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2024-03-11 09:08:02 +0200 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2024-03-11 09:08:02 +0200 |
commit | af0e7deb4a1c369bb8154ac55f085d6a93fe5c35 (patch) | |
tree | 0096a3a99c8225f78d90a00cefde3d3b60ec95ab /src/backend | |
parent | e629846472255c7a636c453a522755ef05489c90 (diff) | |
download | postgresql-af0e7deb4a1c369bb8154ac55f085d6a93fe5c35.tar.gz postgresql-af0e7deb4a1c369bb8154ac55f085d6a93fe5c35.zip |
Don't destroy SMgrRelations at relcache invalidation
With commit 21d9c3ee4e, SMgrRelations remain valid until end of
transaction (or longer if they're "pinned"). Relcache invalidation can
happen in the middle of a transaction, so we must not destroy them at
relcache invalidation anymore.
This was revealed by failures in the 'constraints' test in buildfarm
animals using -DCLOBBER_CACHE_ALWAYS. That started failing with commit
8af2565248, which was the first commit that started to rely on an
SMgrRelation living until end of transaction.
Diagnosed-by: Tomas Vondra, Thomas Munro
Reviewed-by: Thomas Munro
Discussion: https://www.postgresql.org/message-id/CA%2BhUKGK%2B5DOmLaBp3Z7C4S-Yv6yoROvr1UncjH2S1ZbPT8D%2BZg%40mail.gmail.com
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/storage/smgr/smgr.c | 2 | ||||
-rw-r--r-- | src/backend/utils/cache/relcache.c | 10 |
2 files changed, 3 insertions, 9 deletions
diff --git a/src/backend/storage/smgr/smgr.c b/src/backend/storage/smgr/smgr.c index a5b18328b89..62226d5dca7 100644 --- a/src/backend/storage/smgr/smgr.c +++ b/src/backend/storage/smgr/smgr.c @@ -348,8 +348,6 @@ smgrdestroyall(void) /* * smgrreleaseall() -- Release resources used by all objects. - * - * This is called for PROCSIGNAL_BARRIER_SMGRRELEASE. */ void smgrreleaseall(void) diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 7ad6a35a50e..2cd19d603fb 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -2985,9 +2985,6 @@ RelationCacheInvalidate(bool debug_discard) { relation = idhentry->reldesc; - /* Must close all smgr references to avoid leaving dangling ptrs */ - RelationCloseSmgr(relation); - /* * Ignore new relations; no other backend will manipulate them before * we commit. Likewise, before replacing a relation's relfilelocator, @@ -3039,11 +3036,10 @@ RelationCacheInvalidate(bool debug_discard) } /* - * Now zap any remaining smgr cache entries. This must happen before we - * start to rebuild entries, since that may involve catalog fetches which - * will re-open catalog files. + * We cannot destroy the SMgrRelations as there might still be references + * to them, but close the underlying file descriptors. */ - smgrdestroyall(); + smgrreleaseall(); /* Phase 2: rebuild the items found to need rebuild in phase 1 */ foreach(l, rebuildFirstList) |