Flush unlogged table's buffers when copying or moving databases.
authorAndres Freund
Mon, 20 Oct 2014 21:43:46 +0000 (23:43 +0200)
committerAndres Freund
Mon, 20 Oct 2014 21:45:31 +0000 (23:45 +0200)
commitd7624e5621aefe76c31798f79db47e952240225d
tree8b8150a4aa6f5f312c085f1f813d892f8c867cc1
parent4e54685d0bcc74b840fdeff54c79c343941d3681
Flush unlogged table's buffers when copying or moving databases.

CREATE DATABASE and ALTER DATABASE .. SET TABLESPACE copy the source
database directory on the filesystem level. To ensure the on disk
state is consistent they block out users of the affected database and
force a checkpoint to flush out all data to disk. Unfortunately, up to
now, that checkpoint didn't flush out dirty buffers from unlogged
relations.

That bug means there could be leftover dirty buffers in either the
template database, or the database in its old location. Leading to
problems when accessing relations in an inconsistent state; and to
possible problems during shutdown in the SET TABLESPACE case because
buffers belonging files that don't exist anymore are flushed.

This was reported in bug #10675 by Maxim Boguk.

Fix by Pavan Deolasee, modified somewhat by me. Reviewed by MauMau and
Fujii Masao.

Backpatch to 9.1 where unlogged tables were introduced.
src/backend/access/transam/xlog.c
src/backend/commands/dbcommands.c
src/backend/storage/buffer/bufmgr.c
src/include/access/xlog.h