title: How do I fix a PostgreSQL 9.3 Slave that Cannot Keep Up with the Master?
body: <p>We have a master-slave replication configuration as follows.</p>
  
  <p>On the master:</p>
  
  <p><code>postgresql.conf</code> has replication configured as follows (commented line taken out for brevity):</p>
  
  <pre><code>max_wal_senders = 1            
  wal_keep_segments = 8          
  </code></pre>
  
  <p>On the slave:</p>
  
  <p>Same <code>postgresql.conf</code> as on the master. <code>recovery.conf</code> looks like this:</p>
  
  <pre><code>standby_mode = 'on'
  primary_conninfo = 'host=master1 port=5432 user=replication password=replication'
  trigger_file = '/tmp/postgresql.trigger.5432'
  </code></pre>
  
  <p>When this was initially setup, we performed some simple tests and confirmed the replication was working. However, when we did the initial data load, only some of the data made it to the slave.</p>
  
  <p>Slave's log is now filled with messages that look like this:</p>
  
  <pre><code>&lt; 2015-01-23 23:59:47.241 EST &gt;LOG:  started streaming WAL from primary at F/52000000 on timeline 1
  &lt; 2015-01-23 23:59:47.241 EST &gt;FATAL:  could not receive data from WAL stream: ERROR:  requested WAL segment 000000010000000F00000052 has already been removed
  
  &lt; 2015-01-23 23:59:52.259 EST &gt;LOG:  started streaming WAL from primary at F/52000000 on timeline 1
  &lt; 2015-01-23 23:59:52.260 EST &gt;FATAL:  could not receive data from WAL stream: ERROR:  requested WAL segment 000000010000000F00000052 has already been removed
  
  &lt; 2015-01-23 23:59:57.270 EST &gt;LOG:  started streaming WAL from primary at F/52000000 on timeline 1
  &lt; 2015-01-23 23:59:57.270 EST &gt;FATAL:  could not receive data from WAL stream: ERROR:  requested WAL segment 000000010000000F00000052 has already been removed
  </code></pre>
  
  <p>After some analysis and help on the #postgresql IRC channel, I've come to the conclusion that the slave cannot keep up with the master. My proposed solution is as follows.</p>
  
  <p>On the master:</p>
  
  <ol>
  <li>Set <code>max_wal_senders=5</code></li>
  <li>Set <code>wal_keep_segments=4000</code> . Yes I know it is very high, but I'd like to monitor the situation and see what happens. I have room on the master.</li>
  </ol>
  
  <p>On the slave:</p>
  
  <ol>
  <li>Save configuration files in the data directory (i.e. <code>pg_hba.conf  pg_ident.conf  postgresql.conf  recovery.conf</code>)</li>
  <li>Clear out the data directory (<code>rm -rf /var/lib/pgsql/9.3/data/*</code>) . This seems to be required by <code>pg_basebackup</code>.</li>
  <li>Run the following command:
  <code>pg_basebackup -h master -D /var/lib/pgsql/9.3/data  --username=replication --password</code></li>
  </ol>
  
  <p>Am I missing anything ? Is there a better way to bring the slave up-to-date w/o having to reload all the data ?</p>
  
  <p>Any help is greatly appreciated.</p>