pgsql: Fix ALTER TABLE ... SET TABLESPACE for unlogged relations.

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix ALTER TABLE ... SET TABLESPACE for unlogged relations.
Date: 2015-12-12 13:30:03
Message-ID: E1a7kFP-0003gB-3d@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix ALTER TABLE ... SET TABLESPACE for unlogged relations.

Changing the tablespace of an unlogged relation did not WAL log the
creation and content of the init fork. Thus, after a standby is
promoted, unlogged relation cannot be accessed anymore, with errors
like:
ERROR: 58P01: could not open file "pg_tblspc/...": No such file or directory
Additionally the init fork was not synced to disk, independent of the
configured wal_level, a relatively small durability risk.

Investigation of that problem also brought to light that, even for
permanent relations, the creation of !main forks was not WAL logged,
i.e. no XLOG_SMGR_CREATE record were emitted. That mostly turns out not
to be a problem, because these files were created when the actual
relation data is copied; nonexistent files are not treated as an error
condition during replay. But that doesn't work for empty files, and
generally feels a bit haphazard. Luckily, outside init and main forks,
empty forks don't occur often or are not a problem.

Add the required WAL logging and syncing to disk.

Reported-By: Michael Paquier
Author: Michael Paquier and Andres Freund
Discussion: 20151210163230(dot)GA11331(at)alap3(dot)anarazel(dot)de
Backpatch: 9.1, where unlogged relations were introduced

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/f54d0629ec8bc17de932c83fc9872c31bb8da68f

Modified Files
--------------
src/backend/commands/tablecmds.c | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Andres Freund 2015-12-12 13:30:05 pgsql: Fix ALTER TABLE ... SET TABLESPACE for unlogged relations.
Previous Message Michael Paquier 2015-12-12 01:44:14 Re: pgsql: pg_rewind: Don't error if the two clusters are already on the sa