aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2014-11-04 13:24:14 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2014-11-04 13:24:14 -0500
commitf88300168b1c5786c4b167de17e1a0bbb252337e (patch)
treec0601a4d3b7e103fd4a7d4a1ed92327f6e2c1160 /src
parentd233f0a52f1a0a0b3b8654fd8b93b00a9e77563e (diff)
downloadpostgresql-f88300168b1c5786c4b167de17e1a0bbb252337e.tar.gz
postgresql-f88300168b1c5786c4b167de17e1a0bbb252337e.zip
Drop no-longer-needed buffers during ALTER DATABASE SET TABLESPACE.
The previous coding assumed that we could just let buffers for the database's old tablespace age out of the buffer arena naturally. The folly of that is exposed by bug #11867 from Marc Munro: the user could later move the database back to its original tablespace, after which any still-surviving buffers would match lookups again and appear to contain valid data. But they'd be missing any changes applied while the database was in the new tablespace. This has been broken since ALTER SET TABLESPACE was introduced, so back-patch to all supported branches.
Diffstat (limited to 'src')
-rw-r--r--src/backend/commands/dbcommands.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 8a591dc93de..29a50cfd498 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -1141,6 +1141,23 @@ movedb(const char *dbname, const char *tblspcname)
| CHECKPOINT_FLUSH_ALL);
/*
+ * Now drop all buffers holding data of the target database; they should
+ * no longer be dirty so DropDatabaseBuffers is safe.
+ *
+ * It might seem that we could just let these buffers age out of shared
+ * buffers naturally, since they should not get referenced anymore. The
+ * problem with that is that if the user later moves the database back to
+ * its original tablespace, any still-surviving buffers would appear to
+ * contain valid data again --- but they'd be missing any changes made in
+ * the database while it was in the new tablespace. In any case, freeing
+ * buffers that should never be used again seems worth the cycles.
+ *
+ * Note: it'd be sufficient to get rid of buffers matching db_id and
+ * src_tblspcoid, but bufmgr.c presently provides no API for that.
+ */
+ DropDatabaseBuffers(db_id);
+
+ /*
* Check for existence of files in the target directory, i.e., objects of
* this database that are already in the target tablespace. We can't
* allow the move in such a case, because we would need to change those