pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: pgsql-bugs@postgresql.org
Cc: Alvaro Herrera <alvherre@commandprompt.com>
Cc: Greg Sabino Mullane <greg@endpoint.com>
Subject: Re: Unlogged tables cannot be truncated twice
Date: Tue, 31 May 2011 01:28:37 +0200
Message-ID: <201105310128.37288.andres@anarazel.de> (raw)
In-Reply-To: <1306790274-sup-6596@alvh.no-ip.org>
References: <20110530160043.GC3012@core.home>
	<1306790274-sup-6596@alvh.no-ip.org>

On Monday, May 30, 2011 11:18:20 PM Alvaro Herrera wrote:
> Excerpts from Greg Sabino Mullane's message of lun may 30 12:00:43 -0400 
2011:
> > Wow, this one took a bit to narrow down. Here's the failing case:
> > 
> > # create unlogged table foo (a text);
> > CREATE TABLE
> > # begin;
> > BEGIN
> > #* truncate table foo;
> > TRUNCATE TABLE
> > #* truncate table foo;
> > ERROR:  could not create file "base/19131/19183_init": File exists
> > 
> > Very reproducible. The column types matter: if the only column
> > is an INT, for example, the problem does not occur.
> 
> So 19183 is the toast table OID?
Nope. Its any index.

You can provoke it with:
begin;create unlogged table foo (a int primary key);truncate foo;rollback;
or
begin;create unlogged table foo (a text);truncate foo;rollback;


The problem is this tidbit from tablecmds.c's ExecuteTruncate:

		/*
		 * Normally, we need a transaction-safe truncation here.  However, if
		 * the table was either created in the current (sub)transaction or has
		 * a new relfilenode in the current (sub)transaction, then we can just
		 * truncate it in-place, because a rollback would cause the whole
		 * table or the current physical file to be thrown away anyway.
		 */
		if (rel->rd_createSubid == mySubid ||
			rel->rd_newRelfilenodeSubid == mySubid)
		{
			/* Immediate, non-rollbackable truncation is OK */
			heap_truncate_one_rel(rel);
		}

in combination with index.c's index_build:


	/*
	 * If this is an unlogged index, we need to write out an init fork for it.
	 */
	if (heapRelation->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED)
	{
		RegProcedure ambuildempty = indexRelation->rd_am->ambuildempty;

		RelationOpenSmgr(indexRelation);
		smgrcreate(indexRelation->rd_smgr, INIT_FORKNUM, false);
		OidFunctionCall1(ambuildempty, PointerGetDatum(indexRelation));
	}

Andres



view thread (16+ messages)  latest in thread

Message-ID: <201105310128.37288.andres@anarazel.de>
Permalink:  ../201105310128.37288.andres@anarazel.de/
Also on:    postgresql.org/message-id/201105310128.37288.andres@anarazel.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: andres@anarazel.de, alvherre@commandprompt.com, greg@endpoint.com
  Subject: Re: Unlogged tables cannot be truncated twice
  In-Reply-To: <201105310128.37288.andres@anarazel.de>
  References: <20110530160043.GC3012@core.home> <1306790274-sup-6596@alvh.no-ip.org> <201105310128.37288.andres@anarazel.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox