Accidentaldbalinuxcon 130102190320 Phpapp02
Accidentaldbalinuxcon 130102190320 Phpapp02
a guide for
the perplexed
Do
n 't P
ani
c
Josh Berkus
PostgreSQL Experts, Inc.
LinuxCon NA 2012
“Jonathan quit.
You're in charge of
the Postgres servers
now.”
covered in this talk
● PostgreSQL ● MySQL
● installation ● (covered
● configuration yesterday)
● connections ● no time for
● backup ● replication
● monitoring ● indexes
● slow queries ● schema design
● migrations
9.2rc1 Out Now!
“DevOps”
“Cloud”
Y U no DBA?
1.limited budgets
2.shortage of operational staff
3.cheaper OSS databases
Want RAAAAAAAM
killing zombies
● pg_cancel_backend(pid)
● kills running queries with sigINT
● like CTRL-C
● pg_terminate_backend(pid)
● kills bad connections, idle
transactions
● can cause DB to restart
EXPLAIN
Nested Loop (cost=792.00..828.08 rows=1422317 width=99)
-> HashAggregate (cost=792.00..792.00 rows=1 width=4)
-> Index Scan using
index_player_summaries_on_player_id on player_summaries
ps (cost=0.00..791.80 rows=403 width=4)
Index Cond: (player_id = 21432312)
-> Index Scan using index_player_summaries_on_match_id
on player_summaries (cost=0.00..33.98 rows=600 width=99)
Index Cond: (match_id = ps.match_id)
EXPLAIN ANALYZE
Nested Loop (cost=792.00..828.08 rows=1422317
width=99) (actual time=9928.869..20753.723
rows=13470 loops=1)
-> HashAggregate (cost=792.00..792.00 rows=1 width=4)
(actual time=9895.105..9897.096 rows=1347 loops=1)
-> Index Scan using
index_player_summaries_on_player_id on player_summaries
ps (cost=0.00..791.80 rows=403 width=4) (actual
time=27.413..9890.887 rows=1347 loops=1)
Index Cond: (player_id = 21432312)
-> Index Scan using index_player_summaries_on_match_id
on player_summaries (cost=0.00..33.98 rows=600 width=99)
(actual time=7.375..8.037 rows=10 loops=1347)
Index Cond: (match_id = ps.match_id)
Total runtime: 20764.371 ms"
explain.depesz.com
what to look for
● “seq scan” on large table
● maybe index needed
● cartesian joins
● really bad row estimates
● ANALYZE needed?
Do
n't
P ani
c
backups
2012-01-27 18:00:44 MSK FATAL:
invalid page header in block
311757 of relation
base/26976/27977
2012-01-27 18:00:44 MSK CONTEXT:
xlog redo insert:
rel 1663/26976/27977;
tid 311757/44
2012-01-27 18:00:44 MSK LOG:
startup process (PID 392)
exited with exit code 1
2012-01-27 18:00:44 MSK LOG:
aborting startup due
to startup process failure
pg_dump
● “logical” backup
● portable
● compressed
● works for upgrades
● good for small databases
● use -Fc
● custom binary format
PITR
● “Point-In-Time Recovery”
● “binary” and “continuous” backup
● take snapshot of DB files
● accumulate logfile copies
● good for large databases
● can combine with replication
PITR - PITA
● can be difficult to set up & monitor
● use tools:
● RepMgr
● OmniPITR
● WAL-E (for AWS)
Do
n't
P ani
c
monitoring
use your favorite tool
ganglia, collectd, Hyperic, OpenNMS,
OpenView, whatever ....
● nagios check_postgres.pl
&
upgrades
major vs. minor
9.2 == a major version
● requires an upgrade from 9.1.4
● contains features not in 9.1
● requires testing and planned downtime
9.1.5 == a minor version
● is a minor “update” from 9.1.4.
● can (and should) be applied immediately
minor updates
● come out ~ every 2 months
● contain only bugfixes
● security hole patches
● data loss prevention
● fix server crashes
● no new or changed features
● occasional documented breakage
update procedure
1.schedule 5 minute downtime
2.download packages
3.shut down postgresql
4.install packages
5.restart postgresql
6.restart application
major upgrades
● come out once per year
● have many new features
● and sometimes break stuff which used to
work
● require extensive testing with your
application
● require significant downtime to
upgrade
upgrade procedures
● dump & reload
● use pg_dump & pg_restore on database
● most reliable way
● “cleans up” database in process
● best with small databases
● can take a long, long time
upgrade procedures
● pgUpgrade
● upgrade “in place”
● much faster
● does not “clean up” database
● sometimes doesn't work
EOL after
5 years
Getting Help
● docs
● postgresql.org/docs/
● postgresguide.org
● wiki.postgresql.org
● books
● PostgreSQL Up and Running (O'Reilly)
● PostgreSQL 9.0 High Performance (Packt)
Getting Help
● mailing lists
● postgresql.org/community/lists
– pgsql-novice, pgsql-general
● chat
● irc.freenode.net, #postgresql
● web
● dba.stackexchange.com
● planet.postgresql.org
questions?
● Josh Berkus
● josh@pgexperts.com
● PGX: www.pgexperts.com
● Blog: www.databasesoup.com
● Upcoming Events
● Postgres Open: Chicago, Sept 17-19
● LISA: San Diego, Dec 5-8
Copyright 2012 PostgreSQL Experts Inc. Released under the Creative Commons
Attribution License. All images are the property of their respective owners. The
Don't Panic slogan and logo is property of the BBC, and the Dilbert image belongs
to Scott Adams and is used here as parody.