aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/sequence.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-12-17 20:15:32 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2012-12-17 20:15:32 -0500
commit6919b7e3294702adc39effd16634b2715d04f012 (patch)
tree0931f18ad031305d4e15944960d94a719098c0e5 /src/backend/commands/sequence.c
parentc299477229559d4ee7db68720d86d3fb391db761 (diff)
downloadpostgresql-6919b7e3294702adc39effd16634b2715d04f012.tar.gz
postgresql-6919b7e3294702adc39effd16634b2715d04f012.zip
Fix failure to ignore leftover temp tables after a server crash.
During crash recovery, we remove disk files belonging to temporary tables, but the system catalog entries for such tables are intentionally not cleaned up right away. Instead, the first backend that uses a temp schema is expected to clean out any leftover objects therein. This approach requires that we be careful to ignore leftover temp tables (since any actual access attempt would fail), *even if their BackendId matches our session*, if we have not yet established use of the session's corresponding temp schema. That worked fine in the past, but was broken by commit debcec7dc31a992703911a9953e299c8d730c778 which incorrectly removed the rd_islocaltemp relcache flag. Put it back, and undo various changes that substituted tests like "rel->rd_backend == MyBackendId" for use of a state-aware flag. Per trouble report from Heikki Linnakangas. Back-patch to 9.1 where the erroneous change was made. In the back branches, be careful to add rd_islocaltemp in a spot in the struct that was alignment padding before, so as not to break existing add-on code.
Diffstat (limited to 'src/backend/commands/sequence.c')
-rw-r--r--src/backend/commands/sequence.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c
index 634ce3f7188..5583e721ead 100644
--- a/src/backend/commands/sequence.c
+++ b/src/backend/commands/sequence.c
@@ -553,7 +553,7 @@ nextval_internal(Oid relid)
RelationGetRelationName(seqrel))));
/* read-only transactions may only modify temp sequences */
- if (seqrel->rd_backend != MyBackendId)
+ if (!seqrel->rd_islocaltemp)
PreventCommandIfReadOnly("nextval()");
if (elm->last != elm->cached) /* some numbers were cached */
@@ -846,7 +846,7 @@ do_setval(Oid relid, int64 next, bool iscalled)
RelationGetRelationName(seqrel))));
/* read-only transactions may only modify temp sequences */
- if (seqrel->rd_backend != MyBackendId)
+ if (!seqrel->rd_islocaltemp)
PreventCommandIfReadOnly("setval()");
/* lock page' buffer and read tuple */