postgresql/src/include/storage
Andres Freund 43b491a817 Introduce durable_rename() and durable_link_or_rename().
Renaming a file using rename(2) is not guaranteed to be durable in face
of crashes; especially on filesystems like xfs and ext4 when mounted
with data=writeback. To be certain that a rename() atomically replaces
the previous file contents in the face of crashes and different
filesystems, one has to fsync the old filename, rename the file, fsync
the new filename, fsync the containing directory.  This sequence is not
generally adhered to currently; which exposes us to data loss risks. To
avoid having to repeat this arduous sequence, introduce
durable_rename(), which wraps all that.

Also add durable_link_or_rename(). Several places use link() (with a
fallback to rename()) to rename a file, trying to avoid replacing the
target file out of paranoia. Some of those rename sequences need to be
durable as well. There seems little reason extend several copies of the
same logic, so centralize the link() callers.

This commit does not yet make use of the new functions; they're used in
a followup commit.

Author: Michael Paquier, Andres Freund
Discussion: 56583BDD.9060302@2ndquadrant.com
Backpatch: All supported branches
2016-03-09 18:53:54 -08:00
..
backendid.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
barrier.h Use "mb" not the nonexistent "rmb" for pg_read_barrier() on Alpha. 2015-08-29 16:34:30 -04:00
block.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
buf.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
buf_internals.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
buffile.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
bufmgr.h Fix bug leading to restoring unlogged relations from empty files. 2015-12-10 16:29:26 +01:00
bufpage.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
checksum.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
checksum_impl.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
copydir.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
dsm.h "Pin", rather than "keep", dynamic shared memory mappings and segments. 2014-10-30 11:44:22 -04:00
dsm_impl.h "Pin", rather than "keep", dynamic shared memory mappings and segments. 2014-10-30 11:44:22 -04:00
fd.h Introduce durable_rename() and durable_link_or_rename(). 2016-03-09 18:53:54 -08:00
freespace.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
fsm_internals.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
indexfsm.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
ipc.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
item.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
itemid.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
itemptr.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
large_object.h Add defenses against running with a wrong selection of LOBLKSIZE. 2014-06-05 11:31:06 -04:00
latch.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
lmgr.h Setup error context callback for transaction lock waits 2014-03-19 15:10:36 -03:00
lock.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
lwlock.h Fix calculation of PREDICATELOCK_MANAGER_LWLOCK_OFFSET. 2014-06-19 08:52:16 -05:00
off.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_sema.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
pg_shmem.h On Windows, ensure shared memory handle gets closed if not being used. 2015-10-13 11:21:33 -04:00
pmsignal.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pos.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
predicate.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
predicate_internals.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
proc.h Don't skip SQL backends in logical decoding for visibility computation. 2014-12-02 23:52:44 +01:00
procarray.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
procsignal.h Export set_latch_on_sigusr1 symbol for Windows. 2014-01-17 12:48:23 -05:00
reinit.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
relfilenode.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
s_lock.h Fix s_lock.h PPC assembly code to be compatible with native AIX assembler. 2015-08-29 16:09:25 -04:00
shm_mq.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
shm_toc.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
shmem.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
sinval.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
sinvaladt.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
smgr.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
spin.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
standby.h Logging running transactions every 15 seconds. 2014-01-15 12:41:20 -05:00