I have a Postgres 9.3 database server with this configuration:

# grep archive_ postgresql.conf
archive_mode = on            # allows archiving to be done
archive_command = 'rsync -a %p postgres@backupserver:9.3/standby/archive/%f'            # command to use to archive a logfile segment                                                                                                                      
archive_timeout = 300            # force a logfile segment switch after this

and another server that follows in hot standby mode.

I expect a WAL packet to be sent when it becomes full or 5 minutes (300 seconds).

If I run this query in the hot standby:

WHEN pg_last_xlog_receive_location() = pg_last_xlog_replay_location() THEN 0
ELSE EXTRACT (EPOCH FROM now() - pg_last_xact_replay_timestamp())

Then I get a mean value of about 1500 seconds, that is about 5 times bigger than the configured 300 seconds.


In other servers with a lot of traffic the delay is small.

Related questions: - When will PostgreSQL execute archive_command to archive wal files?

  • 1
    pg_last_xlog_receive_location() is for streaming replication. Try replacing that with pg_current_xlog_location() from the primary. I posted a version of the seconds and MB lag queries a while back at dba.stackexchange.com/a/157698/24393, for reference.
    – bma
    Nov 13, 2017 at 15:28

1 Answer 1


In other servers with a lot of traffic the delay is small.

By this statement, I am assuming that this server does not have a lot of traffic.

If there are no transactions to replay, then the value of pg_last_xact_replay_timestamp() will not advance merely due to the passage of time. Also, archive_timeout will only kick in when there is something to archive. If there is no new WAL data since the last archive switch, then the existing WAL file (which is empty except for the initial header) will not be archived just because 5 minutes have passed.

A possible work around is to set checkpoint_timeout to 300 seconds as well. In 9.3 with this setting, the checkpoint will create records to be archived, and the archival will create work to be checkpointed, so you will generate a nearly empty file every 5 minutes on an idle server. Most people consider this to be a bug, but perhaps it is a feature for you.

  • Thanks for your explanation. Now I understand what is really happening. I'd like simply to detect anomalies and the standby server doesn't follow the master. Nov 15, 2017 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.