Postgresql, write archive file over mount, secure against simultaneous access? I am using Postgres 9.2.1 and am saving my archivable WAL over a NFS share.

I just use the basic command, given as an example in the postgresql.conf

test ! -f /mnt/server/archivedir/%f &amp;&amp; cp %p /mnt/server/archivedir/%f

Does the cp command somehow secure that my backup server, which reads the WAL archives, doesn't read half copied WAL files? Do I have to manually define a cp command that lets the file end with .tmp and then call rename afterwards to give it its proper name?

Has someone got a example of an save archive_command?
Neither NFS nor cp will protect you from partial write. The usual way of mitigating problems with write atomicity is to use a temporary file and a mv after copying (or writing) is complete.  You might use something like:

    test ! -f /mnt/server/archivedir/%f &amp;&amp; cp %p /mnt/server/archivedir/tmp/%f &amp;&amp; \
    mv /mnt/server/archivedir/tmp/%f /mnt/server/archivedir/%f