Dealing with the timelines

Timelines are an important concept you have to be aware of, especially when you are planning a large scale setup.

So, what is a timeline? In fact, it is a certain branch of the XLOG. Normally a database instance that has been freshly set up is utilizing timeline number 1. Let us assume that we are starting to replicate our master database to a slave system. The slave will also operate in timeline 1. At some point, your master might die and your slave will be promoted to be a new master. This is the time when a timeline switch happens. The new master will create transaction log of its own now. Logically, we want to make sure that its XLOG is not mixed up with some other XLOG made in good old times.

How can we figure out that the timeline has advanced? Let us take a look at the XLOG directory of a system that was just turned into a master:

00000002.history
000000020000000000000006
000000020000000000000007
000000020000000000000008

The first part of the XLOG files is the interesting thing. You can observe that up to now, there was always a 1 in our filename. This is not so anymore. By checking the first part of the XLOG filename, you can see that the number has changed over time (after turning the slave into a master, we have reached timeline number 2).

It is important to mention that (as of PostgreSQL 9.2) you cannot simply pump the XLOG of timeline 5 into a database instance that is already at timeline 9. It is simply not possible, it does not go together.

In PostgreSQL 9.3, we are able to handle those timelines a little more flexibly. This means that timeline changes will be put to the transaction log and a slave can follow a timeline shift easily.

Tip

Timelines are especially something to be aware of when cascading replication and working with many slaves. After all, you have to connect your slaves to some server if your master fails.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.51.36