Angry Bits

Words on bytes and bits

PostgreSQL WAL archiving on Rackspace

Viralize is now hosted on Rackspace. During the change I had to setup PostgreSQL master-slave replication and I had to write a simple script for WAL archiving.

I've put the code on Github, hopefully it will help other people:

https://github.com/duilio/pg_raxarchive/

How does it work?

pg_raxarchive is designed to be easy to integrate with PostgreSQL.

First install pg_raxarchive using pip on both master and slave:

$ pip install pg_raxarchive

Configure your Rackspace API credentials writing them on /etc/pg_raxarchive.ini:

[rackspace_cloud]
username = YOUR_USERNAME_HERE
api_key = YOUR_API_KEY_HERE

Then enable WAL logs on your your postgresql.conf master:

wal_level = hot_standby
max_wal_senders = 5
hot_standby = on
wal_keep_segments = 32

archive_mode = on
archive_command = 'pg_raxarchive upload %p %f'

Setup your slave the same way you would do for streaming replica and use the following lines into recovery.conf:

restore_command = 'pg_raxarchive download %f %p'
archive_cleanup_command = 'pg_raxarchive cleanup %r'

Here it is. ;-)

Please, feel free to contribute and submit issues.

Comments