Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Â
Pitr Made Easy
1. PITR made easy
Joshua Drake
United States PostgreSQL
Software in the Public Interest
Command Prompt, Inc.
Creative Commons Attribution-Share Alike 3.0 United States License
5. Why is PITR hard?
It was written by open source engineers.
6. Uses the many tools to one solution
rsync?
nfs?
walmgr?
scp?
Push or pull?
Something else?
7. What makes PITR easy?
PITR tools
BSD Licensed
Written in Python
(theoretically cross platform)
8. What is PITRTools
A simple wrapper around all the utilities you
already have.
ssh,rsync,pg_standby,postgresql
Designed by a consultant (KISS)
9. PITRTools Features?
Warm standby
Cold Storage
Fail over (actionable)
Arbitrary alerts (monitoring)
Single protocol (security)
10. How does it work?
success
Master Slave
else
Queue
11. The process on the archiver/master
On the archiver/Master:
â Configure ssh key for postgres user to
standby/slave
â Configure archiver.ini
â cmd_archiver -C /path/to/archiver.ini -I
12. The archiver
The archiver calls cmd_archive.py which calls rsync to âpushâ the
file to the slave or queue.
Usage: cmd_archiver [options] arg1 arg2
Options:
-h, --help show this help message and exit
-F FILE, --file=FILE Archive file
-C FILE, --config=FILE
the name of the archiver config file
-f, --flush Flush all remaining archives to slave
-I, --init Initialize master environment
13. The archiver config file
Useful but obvious parameters
[DEFAULT]
state: online
pgdata: /var/lib/postgresql/8.3/main
rsync_bin: /usr/bin/rsync
rsync_version = 2 # Because RH ships old software
user: postgres
timeout: 10
debug: on
ssh_debug: off
15. Configuring archiver with pitrtools
Edit the postgresql.conf change:
â
â archive_mode to on
â archive_command to:
â cmd_archiver -C /path/to/archiver.ini -F %p
â restart postgresql
â apply cmd_standby.sql to database of pitr user
(usually postgres)
â psql -U postgres < /path/to/cmd_standby/sql
16. cmd_standby.py
Works in conjunction with pg_standby
î¸
Supports failover
î¸
Supports recovery to a point in time
î¸
Included with 8.3, available for 8.1 and 8.2 (8.1
î¸
is flaky)
17. The process on the slave/standby
On the standby/slave:
â Configure SSH key for postgres user to master
â Configure cmd_standby.ini
20. Start the standby
Usage: cmd_standby [options] arg1 arg2
Options:
-h, --help show this help message and exit
-A start|stop, --action=start|stop|stop_basebackup
Start or Stop PostgreSQL
-B, --basebackup Start/Stop a base backup
-C FILE, --config=FILE
Name of the archiver config file
-F VALUE, --failover=VALUE
If you are serious, set -F999
-I, --dbinit Use before -B
-P, --ping Is my master alive?
-R TIMESTAMP, --recovertotime=TIMESTAMP
To restore to a specific point in time
-S, --standby Enter standby mode
24. How do I?
Use PITRTools to simplify backups?
î¸
Take the archiver offline?
î¸
Configure send_nsca (nagios) for alerts
î¸
Get PITRTools
î¸
Donate to PostgreSQL?
î¸
25. Simplify backups
On the standby/slave:
î¸
cmd_standby -C
î¸
/var/lib/postgresql/etc/cmd_standby.ini -Astop
tar -czvf /backups/database.`date +%a`.tar.gz
î¸
/var/lib/pgsql/data
cmd_standby -C
î¸
/var/lib/postgresql/etc/cmd_standby.ini -S
You could also use rsync with a network volume to make
the backup more efficient (after stopping the standby)
26. Take the archiver offline
Edit /var/lib/postgresql/etc/cmd_archiver.ini
î¸
[DEFAULT]
; online or offline
state: offline
When you are ready to bring it back online, just
change to online. No restarts on archiver or
standby required.
27. Configure send_nsca
Example ok.sh for send_nsca
î¸
#!/bin/sh
echo quot;shoggoth;CMD_ARCHIVER;0;Archived to Yuggquot;|
/usr/sbin/send_nsca -to 10 -H monitor -d ';' -c /etc/
nagios/send_nsca.cfg
29. Donate to PostgreSQL
For United States PostgreSQL:
î¸
î¸ https://www.postgresql.us/donate
For PostgreSQL Generally:
î¸
î¸ http://www.postgresql.org/about/donate