I have a PostgreSQL (9.6.15) two node cluster setup with Patroni. The instances are configured to work in master <-> synchronous standby setup and both run in docker containers with pgdata volume mounted from host. When master is restarted the synchronous standby automatically takes the role of master and master starts operating as synchronous replica.
So it seems that Patroni starts Postgres in two phases. First it starts both instances in standby mode and then, once it establishes who is the leader, it promotes one of the instances. It seems that when promoting a standby to a leader a new timeline is created which causes new WAL file to be created in pg_xlog/. In a result each restart results in a new timeline and a new WAL file. However, nothing cleans up the WAL files stamped with previous timelines. Is there a way to figure out which WAL files can be safely removed?