Do we need wal_keep_segments when we have archive_command? I'm trying to clarify some concepts about how archive_command in conjunction with wal_keep_segments

Please correct me if I'm wrong.

wal_keep_segments: if slaves fall behind wal_keep_segments then downstream connections will fail and we have to recovery all downsteam connections (slaves)

archive_command: if slaves lag behind wal_keep_segments (excess) then pg start to purge oldest segment in pg_wall/to archive/

If two above statements are correct, does pg always wait for wal_keep_segments excess before doing purge segment to archive_command? that mean downstreams need to always failed.

in recovery.conf, I have:

restore_command = 'cp /var/lib/postgresql/11/main/archive/%f %p'


does that mean I don't need to set wal_keep_segments if I've set archive_command?

Edit: I need to clarify some questions:


does file under archive/ folder auto rotate by pg? or we need crontab to clean it up?
in case of disaster, we can manually recovery from archive/, I wonder does we really need to set wal_keep_segments to non-zero number? (or keep it default to zero so all segments will be put in archive?
if we set both wal_keep_segments and archive_command, does pg wait till segments excess wal_keep_segments before purging to archive/ or does it purge immediately?
No, wal_keep_segments and archive_command are independent from each other.

As soon as a WAL segment is finished, it will be archived, no matter how wal_keep_segments is set. wal_keep_segments keeps the file from being deleted at the next checkpoint after it has been archived.