简体   繁体   中英

timelines and history files postgresql 9.1

Can someone explain me the purpose of timelines and history files and the setting 'recovery_target_timeline' in recovery.conf.

The vague understanding I got from the postgresql 9.1 documentation is that when the slave completes recovery it switches to a new timeline to prevent overwriting of WALs of a previous timeline. I am not clear how this is used in a recovery scenario and the purpose of the .history file and the 'recovery_target_timeline' setting to 'latest'.

I am trying to understand what happens when I promote the slave to become the new master. It recovers and starts a new timeline before accepting read/write queries.

Now if I setup a new slave since I promoted the existing slave to master, does it need/use the history file generated by the previous slave (new master) to read the new WALs generated (by the new master) for continuous archiving/log shipping.

Thanks much.

To understand timelines what you have to understand is that they are to avoid problems with MVCC and diverging timelines. A good way to think about this is in the context of replication. In Master/Slave streaming replication you don't want someone to bring the slave up as a master insert a bunch of information and then turn it back into a slave. If you do this, the binary logs of the WAL segments can no longer run properly and you will get db corruption.

When you recover a slave to a new master it completes "recovery" and starts its own timeline. From this point on, it is now the master and can not go back to being the slave without a rebuild. This poses some issues for failover and fail back but the way to do this is to periodically fail back and forth with the old master rebuilding the db (using pg_basebackup ) as a new slave. This means each failover/failback is a new timeline.

Yes, this does impact failing over multiple servers, as the slaves have to change timelines.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM