From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Tue, 31 Aug 2004 15:56:39 +0000 (+0000)
Subject: copy_relation_data was mistakenly assuming that the source relation
X-Git-Tag: REL8_0_0BETA3~176
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=556110f4e0fa70e90647886ad4c157471fee53d7;p=postgresql

copy_relation_data was mistakenly assuming that the source relation
would always be already open at the smgr level.  Per bug report from
Fabien Coelho.
---

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index ab0d659dc5..d14fb35ca3 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.129 2004/08/29 05:06:41 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.130 2004/08/31 15:56:39 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -5434,7 +5434,7 @@ ATExecSetTableSpace(Oid tableOid, Oid newTableSpace)
 static void
 copy_relation_data(Relation rel, SMgrRelation dst)
 {
-	SMgrRelation src = rel->rd_smgr;
+	SMgrRelation src;
 	bool		use_wal;
 	BlockNumber nblocks;
 	BlockNumber blkno;
@@ -5457,6 +5457,9 @@ copy_relation_data(Relation rel, SMgrRelation dst)
 	use_wal = XLogArchivingActive() && !rel->rd_istemp;
 
 	nblocks = RelationGetNumberOfBlocks(rel);
+	/* RelationGetNumberOfBlocks will certainly have opened rd_smgr */
+	src = rel->rd_smgr;
+
 	for (blkno = 0; blkno < nblocks; blkno++)
 	{
 		smgrread(src, blkno, buf);