aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>1999-05-17 06:38:41 +0000
committerBruce Momjian <bruce@momjian.us>1999-05-17 06:38:41 +0000
commit184dd28d5c2c8067d2336398a03f04a8b989e52e (patch)
tree90d51a5b57794ffca9484fafc7b72333669a8c8e /src
parent1125c5e4c5882f02b4152b2993bc9add4849ea7e (diff)
downloadpostgresql-184dd28d5c2c8067d2336398a03f04a8b989e52e.tar.gz
postgresql-184dd28d5c2c8067d2336398a03f04a8b989e52e.zip
This is actually more of a fundamental problem with mdtruncate. It
looks like someone just didn't add support for multiple segments for truncation. The following patch seems to do the right thing, for me at least. It passed my tests, my data looks right(no data that shouldn't be in there) and regression is ok. Ole Gjerde
Diffstat (limited to 'src')
-rw-r--r--src/backend/storage/smgr/md.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
index 8d7e4c864b1..84fd67510dc 100644
--- a/src/backend/storage/smgr/md.c
+++ b/src/backend/storage/smgr/md.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.42 1999/04/05 22:25:11 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.43 1999/05/17 06:38:41 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -711,15 +711,26 @@ mdtruncate(Relation reln, int nblocks)
MdfdVec *v;
#ifndef LET_OS_MANAGE_FILESIZE
- int curnblk;
+ int curnblk,
+ i,
+ oldsegno,
+ newsegno;
+ char fname[NAMEDATALEN];
+ char tname[NAMEDATALEN + 10];
curnblk = mdnblocks(reln);
- if (curnblk / RELSEG_SIZE > 0)
- {
- elog(NOTICE, "Can't truncate multi-segments relation %s",
- reln->rd_rel->relname.data);
- return curnblk;
- }
+ oldsegno = curnblk / RELSEG_SIZE;
+ newsegno = nblocks / RELSEG_SIZE;
+
+ StrNCpy(fname, RelationGetRelationName(reln)->data, NAMEDATALEN);
+
+ if (newsegno < oldsegno) {
+ for (i = (newsegno + 1);; i++) {
+ sprintf(tname, "%s.%d", fname, i);
+ if (FileNameUnlink(tname) < 0)
+ break;
+ }
+ }
#endif
fd = RelationGetFile(reln);