wal_keep_segments can be estimated as the average number of new WAL segments per minute in the pg_xlog directory times the number of minutes you want to be safe in. Keep in mind that this speed is expected to increase after wal_level changes from its default value of minimal to archive or hot_standby . The only cost is disk space, which by default is 16 MB per segment.
Usually I use permissions 2 as values. At a speed of about 1 segment per minute, a value of 256 gives me about 4 hours to set up standby mode.
Alternatively, you can use the WAL streaming using pg_basebackup . This corresponds to the --xlog-method=stream option. Unfortunately, at least since 2013, for a discussion on the PostgreSQL mailing list , setting wal_keep_segments to a non-zero value can still be recommended - this is to prevent the risk that the thread will not keep up with the times. If you are using pg_basebackup , but also do not forget --checkpoint=fast .
source share