diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-08-13 04:50:28 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-08-13 04:50:28 +0000 |
commit | d785841f831fd9bc9cf11ed62d8571910a71bd0c (patch) | |
tree | 936e4b7ef05364fbfbebd6627432af658697ebdd /src | |
parent | ae449122cf093cc8890a47770b13a8cc75912386 (diff) | |
download | postgresql-d785841f831fd9bc9cf11ed62d8571910a71bd0c.tar.gz postgresql-d785841f831fd9bc9cf11ed62d8571910a71bd0c.zip |
Change order of operations in ALTER TABLE SET TABLESPACE so that we
don't hold an open file reference to the original table at the end.
This is a good thing in any case, particularly so on Windows which
cannot drop the table file otherwise.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/commands/tablecmds.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index bc5339a91bf..87a2fb4856d 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.124 2004/08/04 20:53:53 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.125 2004/08/13 04:50:28 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -5379,21 +5379,20 @@ ATExecSetTableSpace(Oid tableOid, Oid newTableSpace) dstrel = smgropen(newrnode); smgrcreate(dstrel, rel->rd_istemp, false); + /* copy relation data to the new physical file */ + copy_relation_data(rel, dstrel); + /* schedule unlinking old physical file */ if (rel->rd_smgr == NULL) rel->rd_smgr = smgropen(rel->rd_node); smgrscheduleunlink(rel->rd_smgr, rel->rd_istemp); - - /* copy relation data to the new physical file */ - copy_relation_data(rel, dstrel); + rel->rd_smgr = NULL; /* - * Now drop smgr references. We need not smgrclose() the old file, - * since it will be dropped anyway at commit by the pending unlink. - * We do need to get rid of relcache's reference to it, however. + * Now drop smgr references. The source was already dropped by + * smgrscheduleunlink. */ smgrclose(dstrel); - rel->rd_smgr = NULL; /* update the pg_class row */ rd_rel->reltablespace = (newTableSpace == MyDatabaseTableSpace) ? InvalidOid : newTableSpace; |