I have reading about difference between logical replication slots and phyiscal replication slots in Postgres. I am confused about some paramters and how they are used.

  1. For a replication slot, we have two parameters wal_sender_timeout and wal_keep_segments. For first one postgres disconnects a replication slot if replication connection is idle for more than wal_sender_timeout. Suppose, we have a logical replication slot and we have wal_keep_segments set to 0, all the older wal logs will be deleted from the server, so if the replication server disconnects and try to get wal logs again, will it be able to recover/start the replication again? Will the same thing will happen in physical replication slot as well or wal_sender_timeout is application only for logical replication slots?

  2. I have hosted a CloudSQL(Google Cloud managed) database instance and I have created a read-replica which uses a physical replication slot. Parameters which are set over there are wal_sender_timeout=60000 in ms and wal_keep_segments=0. So, I expect read-replica to not able to recover if it loses connection to master server for some time. But I think I am missing something here, since, it has happened that there was network outage for some time but still replication was happening normally after the network outage.

Can some one clear it out. I am reading online resources but able to distinguish when people are talking about logical replication and when about physical replication.

I know I can use continuous archiving to handle all the above problems but I just want to understand it from these parameters perspective.

1 Answer 1


WAL is retained until both all valid slots are satisfied and wal_keep_segments/wal_keep_size is satisfied. If all of your replication needs use slots, then wal_keep_size serves no purpose and should be zero.

If the wal receiver becomes disconnected, the WAL is still maintained (unless max_slot_wal_keep_size is set and is exceeded) waiting for it to reconnect.

For physical replication, use of slots is optional. If you don't use slots, then you can instead use wal_keep_segments/wal_keep_size to give replicas a chance to catch up if they ever fall behind. If they fail to keep up within that amount of WAL, then they will be cut lose and will have to be reestablished from scratch to get them back online. The specified amount of WAL is always retained, even if no replicas actually need it.

For logical replication, use of slots is mandatory. For that reason, wal_keep_segments serves no purpose.

On the newest version (v13) max_slot_wal_keep_size was implemented, this allows a logical replica to be cut loose once it falls behind by a certain amount. With this system, the max amount of WAL is retained only if something actually needs it. Without this setting and without careful monitoring, the master might fill up its storage and stop working if a replica should be permanently disconnected or just fall behind by an unbounded amount.

  • Thanks for your response. I am using Postgres 11 and my current database is on Google CloudSQL(Google managed) and it does not allow to change wal_sender_timeout which is default set to 60000 ms. It is suggested everywhere to set it to 0(for logical replication) so that even if the replication connection is disconnected for some time, I can resume it after some time. So, I was wondering if it is safe to do so? Also, does wal_sender_timeout affect physical replication slots as well, i.e. close them if they are unreachable for some period of time?
    – hardik24
    Jun 14, 2021 at 22:25
  • 1
    If you have a replication slot, the primary will always retain the required WAL, and you don't have to worry. Jun 15, 2021 at 2:15
  • @LaurenzAlbe Exactly but what I am wondering is whether wal_sender_timeout will terminate replication connection slot? Both in case of logical replication slot and in case of physical replication slot
    – hardik24
    Jun 15, 2021 at 9:03
  • 1
    A replication slot cannot be terminated. wal_sender_timeout may terminate the replication connection, but the replication slot (and the WAL) will stay in place. Jun 15, 2021 at 9:06

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.