Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to write a script to check for gaps in my archived WAL files, but I can't find any documentation of the numbering scheme. It looks fairly straightforward, but I'd like to base my script off of some official documentation so that I don't miss any hidden complexity with rolling over, etc.

share|improve this question

2 Answers 2

This is not really easy to do from the filesystem. The file name is actually three parts (8-characters each, hex values): Timeline, Logical XLOG, Physical Segment. In order to know what the "next" file is you really need to know what's happened to the underlying database (new xlog, new timeline, etc.).

A better solution if you're archiving transaction logs is to have your archive command also append the name of the file being archived to a list somewhere -- Postgres passes the name to your archive script so you don't have to worry about figuring it out yourself, and if all the files on that list are present you have no gaps.
(This doesn't solve the problem of being sure you have no gaps before you implemented this solution, so you should take a base backup in accordance with 24.3.2 in the Postgres manual after you implement this solution...

share|improve this answer

There's no documentation outside of the source code. There's a walkthrough of that code that explains it as well as anything I know of, trying to solve the same problem you are. Count the last two digits upward in hex until they reach FE, then rollover to 0 and increment the second log number field in the middle. The notes at Understanding WAL nomenclature are helpful here too.

One of the reason it's not documented is that you can change it at compile time; in practice no one does. The other problem is that once you active a standby system or do something else to change the timeline id, all guarantees of sequence are gone. That's also not a problem in practice for most people. If that happens, you'll want to check the monitoring, too, anyway.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.