title: Postgres Continuous Archiving and Point-in-Time Recovery (PITR)
body: <p>I am trying to setup Continuous Archiving and Point-in-Time Recovery (PITR) in Postgres. When I go through the <a href="https://www.postgresql.org/docs/current/static/continuous-archiving." rel="nofollow noreferrer">documentation</a> it says:</p>
  
  <blockquote>
    <p>The archive command should generally be designed to refuse to overwrite any pre-existing archive file. This is an important safety feature to preserve the integrity of your archive in case of administrator error (such as sending the output of two different servers to the same archive directory).</p>
  </blockquote>
  
  <p>But I see that the same WAL file is changing multiple times when I open a connection and do some changes time to time. So for example, when I first connect the database and do some changes (like deleting or inserting some rows), it creates a WAL file named <strong>000000010000000000000090</strong> and my archive_command is immediately run. My archive_command is </p>
  
  <pre><code>test ! -f /mnt/server/archivedir/%f &amp;&amp; cp %p /mnt/server/archivedir/%f
  </code></pre>
  
  <p>This is based on the documentation, which checks if the file already exists in the archive directory, if exists, it doesn't copy and copies only if the file doesn't exist. So the first time the condition passes and the file is copied, but when I am doing some more changes with the same connection (I am even having the same issue when I reconnect from the same PC) the original WAL file is being changed. But the next time the copy doesn't work because the file already exists. </p>
  
  <p>If this is allowed to happen, we may lose some changes in the backup. Anyone knows about any solution, so it creates a new file for every change instead of modifying the old file?</p>
  
  <blockquote>
    <p>I am using Postgres version 10.2 on my local computer (Mac).</p>
  </blockquote>