SlideShare una empresa de Scribd logo
1 de 90
Pro Postgres 9




                Robert Treat, JDCon East 2011

Thursday, March 31, 2011
Who Am I? (Why Listen To Me)

               PostgreSQL User Since 6.5.x

               DBA of High Traffic / Large PostgreSQL Instances

               Long Time Contributor to PostgreSQL Project

               Contribute / Maintain Several Open Source Projects

               Co-Author Beginning PHP & PostgreSQL 8 (Apress)

               I like to call it “Postgres”

                                     Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Outline

              What you need to know
              about the project                                        Backups

              Getting Started                                          Replication

              Upgrading                                                Query Tuning

              Configuring Your Server                                   Other stuff you should know
                                                                       about
              Hardware




                                       Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Know Your Way Around The Project




Thursday, March 31, 2011
Know Your Way Around The Project


                                 www.postgresql.org


                           downloads                                   security alerts

                           documentation                               wiki

                           bug reports                                 support companies

                               rss -> news - events - version



                                           Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Know Your Way Around The Project


                                planet.postgresql.org



                           project news
                                                                          helpful tips / examples
                           community news




                                          Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Know Your Way Around The Project

                           www.pgfoundry.org

                                                                URI Type

                                                                SkyTools
          modules
                                                                Npgsql
          programs
                                                                pg_bulkload
          resources
                                                                plpgsql-debugger

                                                                pagila, sample database

                                Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Know Your Way Around The Project

                            git.postgresql.org

                                                                  check_postgres

          modules                                                 edb-installers

          programs                                                website code

          resources                                               json type

          works in progress                                       pg_top

                                                                  user repo’s
                           see also github.com
                                  Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Know Your Way Around The Project


                                 archives.postgresql.org


                               mailing list archives back to 1997

                               full text search via postgresql FTS

                               keyword search suggestions


                           lists for users, developers, regional, user groups


                                            Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Know Your Way Around The Project


                            #postgresql


                           irc.freenode.net

                           real time help

                           pg_docbot - ??help




                               Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Know Your Way Around The Project

                           project management


                                   core team

                                   committers

                                   -hackers

                                   road map

                                   web team


                               Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Get Off To A Good Start




Thursday, March 31, 2011
Get Off To A Good Start

                           Use Package Management


                              Consistent

                              Standardized

                              Simple




                                  Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Get Off To A Good Start

                           Use Package Management


                              Different across systems

                              Upgrades can be a problem

                              Trust your packager?




                                  Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Get Off To A Good Start

                              Use Package Management


                                  Different across systems

                                  Upgrades can be a problem

                                  Trust your packager?




                           Don’t Be Afraid To Roll Your Own

                                      Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Get Off To A Good Start

                           A Note About Versions

                           Just playing? Default packages
                           probably OK, (min 8.2)

                           Any production level work
                           should start on 9.0

                           Any project not due to launch
                           for 6 months, 9.1




                                  Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Get Off To A Good Start

                                So What Do You Get?
                                     pg_control version number:              903
                                     Catalog version number:                 201008051
                                     Database system identifier:             5546136951888795324
                                     Database cluster state:                 in archive recovery
                                     pg_control last modified:               Tue Mar 22 11:50:24 2011
                                     Latest checkpoint location:             7C/1D000058
                                     Prior checkpoint location:              7C/1C000058
                                     Latest checkpoint's REDO location:      7C/1D000020
                                     Latest checkpoint's TimeLineID:         1
                                     Latest checkpoint's NextXID:            0/4924
                                     Latest checkpoint's NextOID:            16608
                                     Latest checkpoint's NextMultiXactId:    1
                                     Latest checkpoint's NextMultiOffset:    0
                                     Latest checkpoint's oldestXID:          654
                                     Latest checkpoint's oldestXID's DB:     1

                   pg_controldata    Latest checkpoint's oldestActiveXID:
                                     Time of latest checkpoint:
                                                                             4924
                                                                             Tue Mar 22 11:46:19 2011
                                     Minimum recovery ending location:       7C/16000000
                                     Backup start location:                  0/0
                                     Current wal_level setting:              hot_standby
                                     Current max_connections setting:        500
                                     Current max_prepared_xacts setting:     0
                                     Current max_locks_per_xact setting:     64
                                     Maximum data alignment:                 8
                                     Database block size:                    8192
                                     Blocks per segment of large relation:   131072
                                     WAL block size:                         8192
                                     Bytes per WAL segment:                  16777216
                                     Maximum length of identifiers:          64
                                     Maximum columns in an index:            32
                                     Maximum size of a TOAST chunk:          1996
                                     Date/time type storage:                 64-bit integers
                                     Float4 argument passing:                by value
                                     Float8 argument passing:                by value


                                       Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Get Off To A Good Start

                                    So What Do You Get?
-rw-------                 1   postgres   postgres              4          Dec    2   12:23   PG_VERSION
drwxr-xr-x                 6   postgres   postgres              6          Dec    2   13:41   base
drwxr-xr-x                 2   postgres   postgres             42          Jan   28   17:49   global
drwxr-xr-x                 2   postgres   postgres              3          Dec    2   12:23   pg_clog
-rw-------                 1   postgres   postgres           3938          Dec   19   11:25   pg_hba.conf
-rw-------                 1   postgres   postgres           1636          Dec   19   11:25   pg_ident.conf
drwxr-xr-x                 3   postgres   postgres            113          Mar   22   00:00   pg_log
drwxr-xr-x                 4   postgres   postgres              4          Dec    2   12:23   pg_multixact
drwxr-xr-x                 2   postgres   postgres              3          Jan   12   14:23   pg_notify
drwxr-xr-x                 2   postgres   postgres              3          Jan   12   14:23   pg_stat_tmp
drwxr-xr-x                 2   postgres   postgres              3          Dec    2   12:23   pg_subtrans
drwxr-xr-x                 2   postgres   postgres              2          Dec    2   12:23   pg_tblspc
drwxr-xr-x                 2   postgres   postgres              2          Dec    2   12:23   pg_twophase
lrwxrwxrwx                 1   postgres   postgres             30          Dec   19   11:13   pg_xlog
-rw-------                 1   postgres   postgres          17915          Mar    3   21:52   postgresql.conf
-rw-------                 1   postgres   postgres             63          Jan   12   14:23   postmaster.opts
-rw-------                 1   postgres   postgres             54          Jan   12   14:23   postmaster.pid
-rw-r--r--                 1   postgres   postgres            336          Dec   20   16:14   recovery.conf



                                               Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Get Off To A Good Start

                                    So What Do You Get?
-rw-------                 1   postgres   postgres              4          Dec    2   12:23   PG_VERSION
drwxr-xr-x                 6   postgres   postgres              6          Dec    2   13:41   base
drwxr-xr-x                 2   postgres   postgres             42          Jan   28   17:49   global
drwxr-xr-x                 2   postgres   postgres              3          Dec    2   12:23   pg_clog
-rw-------                 1   postgres   postgres           3938          Dec   19   11:25   pg_hba.conf
-rw-------                 1   postgres   postgres           1636          Dec   19   11:25   pg_ident.conf
drwxr-xr-x                 3   postgres   postgres            113          Mar   22   00:00   pg_log
drwxr-xr-x                 4   postgres   postgres              4          Dec    2   12:23   pg_multixact
drwxr-xr-x                 2   postgres   postgres              3          Jan   12   14:23   pg_notify
drwxr-xr-x                 2   postgres   postgres              3          Jan   12   14:23   pg_stat_tmp
drwxr-xr-x                 2   postgres   postgres              3          Dec    2   12:23   pg_subtrans
drwxr-xr-x                 2   postgres   postgres              2          Dec    2   12:23   pg_tblspc
drwxr-xr-x                 2   postgres   postgres              2          Dec    2   12:23   pg_twophase
lrwxrwxrwx                 1   postgres   postgres             30          Dec   19   11:13   pg_xlog
-rw-------                 1   postgres   postgres          17915          Mar    3   21:52   postgresql.conf
-rw-------                 1   postgres   postgres             63          Jan   12   14:23   postmaster.opts
-rw-------                 1   postgres   postgres             54          Jan   12   14:23   postmaster.pid
-rw-r--r--                 1   postgres   postgres            336          Dec   20   16:14   recovery.conf



                                               Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Get Off To A Good Start

                                    So What Do You Get?
-rw-------                 1   postgres   postgres              4          Dec    2   12:23   PG_VERSION
drwxr-xr-x                 6   postgres   postgres              6          Dec    2   13:41   base
drwxr-xr-x                 2   postgres   postgres             42          Jan   28   17:49   global
drwxr-xr-x                 2   postgres   postgres              3          Dec    2   12:23   pg_clog
-rw-------                 1   postgres   postgres           3938          Dec   19   11:25   pg_hba.conf
-rw-------                 1   postgres   postgres           1636          Dec   19   11:25   pg_ident.conf
drwxr-xr-x                 3   postgres   postgres            113          Mar   22   00:00   pg_log
drwxr-xr-x                 4   postgres   postgres              4          Dec    2   12:23   pg_multixact
drwxr-xr-x                 2   postgres   postgres              3          Jan   12   14:23   pg_notify
drwxr-xr-x                 2   postgres   postgres              3          Jan   12   14:23   pg_stat_tmp
drwxr-xr-x                 2   postgres   postgres              3          Dec    2   12:23   pg_subtrans
drwxr-xr-x                 2   postgres   postgres              2          Dec    2   12:23   pg_tblspc
drwxr-xr-x                 2   postgres   postgres              2          Dec    2   12:23   pg_twophase
lrwxrwxrwx                 1   postgres   postgres             30          Dec   19   11:13   pg_xlog
-rw-------                 1   postgres   postgres          17915          Mar    3   21:52   postgresql.conf
-rw-------                 1   postgres   postgres             63          Jan   12   14:23   postmaster.opts
-rw-------                 1   postgres   postgres             54          Jan   12   14:23   postmaster.pid
-rw-r--r--                 1   postgres   postgres            336          Dec   20   16:14   recovery.conf



                                               Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Get Off To A Good Start

                                    Configure Your Logging

                                       $PGDATA/pg_log

                                       /var/log/postgresql

                                       when in doubt...
                                       (postgresql.conf)

                                       separate disk


                                      Logging is often overlooked,
                           but it is the first step toward troubleshooting!

                                            Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Get Off To A Good Start

                           Configure Authentication


                           most systems have different defaults

                           firewalls / selinux (FATAL?)

                           rtfm (pg_hba.conf, grant, revoke)




                                     Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Get Off To A Good Start

                           Authentication Methods


                                        TRUST

                                        md5

                                        IDENT




                                 Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Get Off To A Good Start

                                            /contrib

                           Trust these more than your own code

                           package dependent

                           use different schemas (when able)

                           pgcrypto




                                          Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Get Off To A Good Start

                              Additional Supplied Modules

                           “contrib”

                           Trust these more than your own code

                           package dependent

                           use different schemas (when able)

                           pgcrypto, pg_upgrade



      http://www.postgresql.org/docs/current/interactive/contrib.html

                                          Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Let’s Talk About Upgrades




Thursday, March 31, 2011
Let’s Talk About Upgrades

                                 Versioning


                           First Digit (7.4.16 -> 8.2.0)

                           Second Digit (8.3.6 -> 8.4.0)

                           Third Digit (9.0.0 -> 9.0.2)




                                  Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Let’s Talk About Upgrades

                                 Versioning


                           First Digit (7.4.16 -> 8.2.0)

                           Second Digit (8.3.6 -> 8.4.0)

                           Third Digit (9.0.0 -> 9.0.2)




                                  Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Let’s Talk About Upgrades

                                   Achtung!!

                           Make Backups!

                           Read the Release Notes!

                           Read the Commit Logs!

                           Test!




                                   Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Let’s Talk About Upgrades


                           pg_dump/pg_restore


                           simple

                           -Fc is your friend

                           dump with new version of pg_dump

                           pitfalls: (time, hdd)




                                    Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Let’s Talk About Upgrades


                            the “slony” method


                           not simple

                           create slave on new version

                           switchover (switch back?)

                           pitfalls: (initial synch, compatibility)




                                   Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Let’s Talk About Upgrades


                                 pg_upgrade


                           in place upgrades

                           rewrites system catalog info

                           no way to go back (fs snapshots)

                           first official release was 9.0




                                   Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Let’s Talk About Upgrades


                             upgrading legacy databases


                           < 8.2 is no longer supported (upgrade now!)

                           pg_upgrade only works on 8.3 or greater

                           older slony can work back to 7.3ish

                           pre-7.3 ?




                                        Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Let’s Talk About Upgrades


                                       is it worth it?



                           any database with significant transaction
                           workload (read or write) >= 8.3 (vxid)

                           most systems will want at least 8.4 (fsm)

                           replication is nice too though...




                                         Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Let’s Talk About Upgrades

                                 Versioning


                           First Digit (7.4.16 -> 8.2.0)

                           Second Digit (8.3.6 -> 8.4.0)

                           Third Digit (9.0.0 -> 9.0.2)




                                  Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Let’s Talk About Upgrades

                                 minor release versioning policy

                           drop in replacement

                           no feature changes

                           bug fixes only (includes security fixes)

                           sometimes involves extra steps

                           also referred to as service packs, hot fixes, fix packs, etc...



               It is considered more dangerous to not upgrade!
                                                Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Figure Your Configure




Thursday, March 31, 2011
Figure Your Configure

                           the basics: performance


                              shared_buffers

                              effective_cache_size

                              work_mem

                              checkpoint_segments




                                Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Figure Your Configure

                                the basics: logging



                           stderr/pg_log vs. syslog/eventlog

                           log_min_duration_statement

                           log_line_prefix (%t, %p, %d, %u, %r)




                                    Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Figure Your Configure

                           other stuff worth looking at


                            maintenance_work_mem

                            max_prepared_transactions

                            wal_buffers

                            checkpoint_completion_target

                            autovacuum_freeze_max_age




                                     Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Figure Your Configure

                              the basics: replication



                           primary: wal_level = ‘hot_standby’

                           primary: max_wal_senders = n

                           slave: hot_standby = on




                                    Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Hardware For Software




Thursday, March 31, 2011
Hardware for Software People

                                    cpu and you


                           connections, autovacuum, bgwriter,
                           stats collector, replication

                           Multiple CPU’s work wonders, up
                           to 32 processors

                           http://tweakers.net




                                     Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Hardware for Software People

                                     disk does and don’ts


                           Put WAL on it’s own disk (RAID 1)

                           Put DATA directory on it’s own disk (RAID 10)

                           More Spindles is Good

                           More Controllers Even Gooder (tablespaces)

                           Battery Backed Controllers, Write Cache Enabled




                                          Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Hardware for Software People

                                    disk don’ts



                           NFS == Not Fully Safe!

                           RAID 5

                           Beware disks / controllers that lie




                                    Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Can You Back That Up?




Thursday, March 31, 2011
Can You Back That Up?

                                        types of backups




                           logical (sql export)

                           physical (files on disk)




                                            Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Can You Back That Up?

                                            logical backups


                           slow to create

                           slow to restore

                           “pure”, no system level corruption

                           susceptible to database level corruption


                                  pg_dump is your friend
                                  pg_dumpall for globals

                                             Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Can You Back That Up?

                               physical backups



                           replication / failover machine

                           “tarball” (pitr)

                           filesystem snapshots (pitr)




                                  Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Can You Back That Up?

                           replication / failover node


                             good idea, but... offsite? fragile?

                             we’ll talk more in replication
                             section :-)




                                    Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Can You Back That Up?

                                  “tarball” (pitr)

                           basic idea is to copy all database
                           files and relevant xlogs

                           use multiple machines if able

                           use rsync if able

                           copy the slave if able!!




                                    Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Can You Back That Up?

                           filesystem snapshots (pitr)

                           basic idea is to copy all database
                           files and relevant xlogs

                           use multiple machines if able

                           use rsync if able

                           copy the slave if able!!




                                    Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Replication, Replication




Thursday, March 31, 2011
Replication, Replication

                           9.0 “Introduced” Replication In Postgres

                                    Built In Solution

                                    Based on WAL replay

                                    True Binary Replication

                                    1st Cut, Still A Little Rough




                                          Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Replication, Replication

                           However, There Are Lots Of Alternatives!

                               Most Are Trigger Based:

                                 Slony,

                                 Bucardo,

                                 Londiste,

                                 RubyRep,

                                 etc...

                               Statement Based (PGPoolII)


                                             Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Replication, Replication

                              Quick Rundown: Slony

                           Trigger Based

                           Asynchronous

                           Master -> (Multiple, Cascading) Slave

                           Switchover

                           “A Pain To Work With”




                                     Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Replication, Replication

                            Quick Rundown: Londiste

                           Trigger Based

                           Asynchronous

                           Master -> (Multiple) Slave

                           Switchover

                           “I Don’t Like Slony”




                                     Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Replication, Replication

                            Quick Rundown: Bucardo

                           Trigger Based

                           Asynchronous

                           Master -> (Multiple) Slave

                           Master -> Master

                           “Small Community”




                                     Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Replication, Replication

                           Quick Rundown: Ruby Rep

                           Trigger Based

                           Asynchronous

                           Master -> Slave

                           Master -> Master

                           “Huh?”




                                     Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Replication, Replication

                           Determine Your Needs: Failover


                           Simple 2 Server Setup?

                             9.0 Streaming Replication

                           Multiple Slaves?

                             Slony




                                       Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Replication, Replication

                           Determine Your Needs: Switchover
                              Master -> Slave

                                Slony

                                Londiste

                              Master -> Master

                                Bucardo

                                Ruby Rep




                                        Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Replication, Replication

                           Determine Your Needs: Single Read Slave



                                   Postgres Streaming Replication

                                     no changes to the slave

                                   Any of the Trigger Based Solutions




                                          Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Replication, Replication

                       Determine Your Needs: Multiple Read Slaves


                                 Slony (Cascading)

                                 Bucardo (Split)

                                 Londiste (meh)




                                        Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Replication, Replication

                           A Note On Scaling Writes



                           Scaling Writes Is A Hard Problem

                           Bucardo/RubyRep Help IF CPU Bound




           If you are bound on write i/o, you probably need to
                         federate your database

                                     Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Query Your Queries




Thursday, March 31, 2011
Query Your Queries

                              finding slow queries:
                           log_min_duration_statement


                                   -1, 0, n

                                   superuser only

                                   alter user




       LOG: duration: 5005.273ms statement: select pg_sleep(5);


                                  Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Query Your Queries

                               finding slow queries:
                                   log analyzers


                           command line
                           tools
                                                                 i/o load
                           generate
                           reports                               cpu load

                           archive reports




                                      Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Query Your Queries

                           finding slow queries:
                               log analyzers


                              pqa

                              pgfouine

                              maatkit (percona)

                              pgsi (endpoint)




                               Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Query Your Queries

                           fixing slow queries:
                              explain analyze

                           universal tool

                           good for specific queries

                           “explain” for large queries

                           could be it’s own talk




                               Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Query Your Queries

                           fixing slow queries:
                              explain analyze

                           universal tool

                           good for specific queries

                           “explain” for large queries

                           could be it’s own talk



            http://wiki.postgresql.org/Using_EXPLAIN

                               Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Query Your Queries

                                    fixing slow queries:
                                      indexing (basic)


                           use explain to find large sequential reads

                           use pg_stat_* tables to find numerous reads

                           use btree (gist/gin)

                           dual column vs. single column




                                          Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Query Your Queries

                                    fixing slow queries:
                                      indexing (partial)


                           restrain index to rows that matter

                           can give significant speed improvements

                           where clause of index should match where
                           clause of query


                           create index address_ba_part_idx
                                 on address (district)
                           where district = ‘Buenos Aires’;

                                         Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Query Your Queries

                                      fixing slow queries:
                                        indexing (partial)


                             restrain index to rows that matter

                             can give significant speed improvements

                             where clause of index should match where
                             clause of query


                           create index customer_active_part_idx
                                 on customer (customer_id)
                                   where active is true;

                                           Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Query Your Queries

                                       fixing slow queries:
                                       indexing (functional)




                           some people prefer to call these expressional indexes




                                            Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Query Your Queries

                                        fixing slow queries:
                                       indexing (expressional)

                           push expensive functions into your index

                           system sees just WHERE indexedcolumn = ‘constant’

                           expression of index should match expression of queries

                           narrow scope, but nice gains




   create unique index one_true_email_xidx on customer (lower(email));


                                             Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Query Your Queries

                                        fixing slow queries:
                                       indexing (expressional)

                           push expensive functions into your index

                           system sees just WHERE indexedcolumn = ‘constant’

                           expression of index should match expression of queries

                           narrow scope, but nice gains




  create index fullname_xidx on customer ((firstname||’ ‘||lastname));


                                             Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Query Your Queries

                                        fixing slow queries:
                                       indexing (expressional)

                           push expensive functions into your index

                           system sees just WHERE indexedcolumn = ‘constant’

                           expression of index should match expression of queries

                           narrow scope, but nice gains




  create index fullname_xidx on customer ((firstname||’ ‘||lastname));


                                             Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Other Stuff I Should Mention




Thursday, March 31, 2011
Other Stuff I Should Mention

                                 pgcrypto



                           cryptography

                           /contrib (export issues)

                           md5, sha1, blowfish, many more




                                   Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Other Stuff I Should Mention

                                            dblink


                           pgsql -> pgsql connections

                           /contrib (still under development)

                           can have performance issues on large queries

                           make it live in it’s own schema

                           may be replaced by foreign data wrappers



                                            Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Other Stuff I Should Mention

                                             *-link


                           heterogenous connections for postgresql

                           db specific and db independent options

                           any pl/u language can implement this

                           similar performance issue as dblink

                           dblink-tds, dbi-link, oralink, odbclink



                                             Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Other Stuff I Should Mention

                             autonomous logging tool


                           persistent logging for postgresql functions

                           built on top of dblink

                           make it live in it’s own schema




              https://labs.omniti.com/trac/pgtreats
                                          Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Other Stuff I Should Mention

                                   check_postgres


                           nagios oriented monitoring script

                           comprehensive list of items for alterting

                           adapted for other systems, some trending




                     http://bucardo.org/check_postgres
                                          Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Other Stuff I Should Mention

                                    phpPgAdmin


                           web based gui for postgresql

                           remote administration of multiple servers

                           implements much of postgresql functionality




                   http://phppgadmin.sourceforge.net/
                                         Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Other Stuff I Should Mention

                                        omnipitr

                           advanced WAL file management scripts

                           pitr archiving, pitr restore

                           complete filesystem based backup

                           can create backups from a slave server




              https://labs.omniti.com/trac/pgtreats
                                          Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Other Stuff I Should Mention

                                            books



                           PostgreSQL 9.0 High Performance, by Greg Smith

                           PostgreSQL 9.0 Admin Cookbook, by Simon Riggs




                                            Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Other Stuff I Should Mention

                                            books



                           PostgreSQL 9.0 High Performance, by Greg Smith

                           PostgreSQL 9.0 Admin Cookbook, by Simon Riggs




                                            Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Other Stuff I Should Mention


                            we’re hiring :-)


                             Database Operations

                                 Big Systems

                            High Volume Workloads

                                 Keggerator!




                                 Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
Other Stuff I Should Mention


                            we’re hiring :-)


                             Database Operations

                                 Big Systems

                            High Volume Workloads

                                 Keggerator!




                                 Robert Treat | Pro Postgres 9
Thursday, March 31, 2011
El Fin




                Thanks For Coming!

Thursday, March 31, 2011

Más contenido relacionado

La actualidad más candente

Oracle db performance tuning
Oracle db performance tuningOracle db performance tuning
Oracle db performance tuning
Simon Huang
 

La actualidad más candente (20)

PostgreSQL Replication Tutorial
PostgreSQL Replication TutorialPostgreSQL Replication Tutorial
PostgreSQL Replication Tutorial
 
Why oracle data guard new features in oracle 18c, 19c
Why oracle data guard new features in oracle 18c, 19cWhy oracle data guard new features in oracle 18c, 19c
Why oracle data guard new features in oracle 18c, 19c
 
Postgresql database administration volume 1
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1
 
PostgreSQL replication
PostgreSQL replicationPostgreSQL replication
PostgreSQL replication
 
The consequences of sync_binlog != 1
The consequences of sync_binlog != 1The consequences of sync_binlog != 1
The consequences of sync_binlog != 1
 
PostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability MethodsPostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability Methods
 
PostgreSQL Streaming Replication Cheatsheet
PostgreSQL Streaming Replication CheatsheetPostgreSQL Streaming Replication Cheatsheet
PostgreSQL Streaming Replication Cheatsheet
 
Thrift vs Protocol Buffers vs Avro - Biased Comparison
Thrift vs Protocol Buffers vs Avro - Biased ComparisonThrift vs Protocol Buffers vs Avro - Biased Comparison
Thrift vs Protocol Buffers vs Avro - Biased Comparison
 
Oracle db performance tuning
Oracle db performance tuningOracle db performance tuning
Oracle db performance tuning
 
Apache Spark Data Source V2 with Wenchen Fan and Gengliang Wang
Apache Spark Data Source V2 with Wenchen Fan and Gengliang WangApache Spark Data Source V2 with Wenchen Fan and Gengliang Wang
Apache Spark Data Source V2 with Wenchen Fan and Gengliang Wang
 
Your tuning arsenal: AWR, ADDM, ASH, Metrics and Advisors
Your tuning arsenal: AWR, ADDM, ASH, Metrics and AdvisorsYour tuning arsenal: AWR, ADDM, ASH, Metrics and Advisors
Your tuning arsenal: AWR, ADDM, ASH, Metrics and Advisors
 
Oracle RAC 19c: Best Practices and Secret Internals
Oracle RAC 19c: Best Practices and Secret InternalsOracle RAC 19c: Best Practices and Secret Internals
Oracle RAC 19c: Best Practices and Secret Internals
 
Spark shuffle introduction
Spark shuffle introductionSpark shuffle introduction
Spark shuffle introduction
 
What is NoSQL and CAP Theorem
What is NoSQL and CAP TheoremWhat is NoSQL and CAP Theorem
What is NoSQL and CAP Theorem
 
Postgresql tutorial
Postgresql tutorialPostgresql tutorial
Postgresql tutorial
 
PostgreSQL Administration for System Administrators
PostgreSQL Administration for System AdministratorsPostgreSQL Administration for System Administrators
PostgreSQL Administration for System Administrators
 
Oracle Performance Tools of the Trade
Oracle Performance Tools of the TradeOracle Performance Tools of the Trade
Oracle Performance Tools of the Trade
 
Troubleshooting PostgreSQL Streaming Replication
Troubleshooting PostgreSQL Streaming ReplicationTroubleshooting PostgreSQL Streaming Replication
Troubleshooting PostgreSQL Streaming Replication
 
Postgresql 12 streaming replication hol
Postgresql 12 streaming replication holPostgresql 12 streaming replication hol
Postgresql 12 streaming replication hol
 
Backup and-recovery2
Backup and-recovery2Backup and-recovery2
Backup and-recovery2
 

Destacado

Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)
Denish Patel
 
PostgreSQL Disaster Recovery with Barman
PostgreSQL Disaster Recovery with BarmanPostgreSQL Disaster Recovery with Barman
PostgreSQL Disaster Recovery with Barman
Gabriele Bartolini
 

Destacado (20)

The Essential PostgreSQL.conf
The Essential PostgreSQL.confThe Essential PostgreSQL.conf
The Essential PostgreSQL.conf
 
Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)
 
PostgreSQL Disaster Recovery with Barman
PostgreSQL Disaster Recovery with BarmanPostgreSQL Disaster Recovery with Barman
PostgreSQL Disaster Recovery with Barman
 
Scaling postgres
Scaling postgresScaling postgres
Scaling postgres
 
Inaugural Addresses
Inaugural AddressesInaugural Addresses
Inaugural Addresses
 
Teaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & TextspeakTeaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & Textspeak
 
UX, ethnography and possibilities: for Libraries, Museums and Archives
UX, ethnography and possibilities: for Libraries, Museums and ArchivesUX, ethnography and possibilities: for Libraries, Museums and Archives
UX, ethnography and possibilities: for Libraries, Museums and Archives
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
 
Designing Teams for Emerging Challenges
Designing Teams for Emerging ChallengesDesigning Teams for Emerging Challenges
Designing Teams for Emerging Challenges
 
Visual Design with Data
Visual Design with DataVisual Design with Data
Visual Design with Data
 
3 Things Every Sales Team Needs to Be Thinking About in 2017
3 Things Every Sales Team Needs to Be Thinking About in 20173 Things Every Sales Team Needs to Be Thinking About in 2017
3 Things Every Sales Team Needs to Be Thinking About in 2017
 
How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your Niche
 
Vert.x
Vert.xVert.x
Vert.x
 
High performance network programming on the jvm oscon 2012
High performance network programming on the jvm   oscon 2012 High performance network programming on the jvm   oscon 2012
High performance network programming on the jvm oscon 2012
 
Advanced WAL File Management With OmniPITR
Advanced WAL File Management With OmniPITRAdvanced WAL File Management With OmniPITR
Advanced WAL File Management With OmniPITR
 
Think_your_Postgres_backups_and_recovery_are_safe_lets_talk.pptx
Think_your_Postgres_backups_and_recovery_are_safe_lets_talk.pptxThink_your_Postgres_backups_and_recovery_are_safe_lets_talk.pptx
Think_your_Postgres_backups_and_recovery_are_safe_lets_talk.pptx
 
Managing PostgreSQL with PgCenter
Managing PostgreSQL with PgCenterManaging PostgreSQL with PgCenter
Managing PostgreSQL with PgCenter
 
Nine Pages You Should Optimize on Your Blog and How
Nine Pages You Should Optimize on Your Blog and HowNine Pages You Should Optimize on Your Blog and How
Nine Pages You Should Optimize on Your Blog and How
 
Backups
BackupsBackups
Backups
 
Analytics Trends 2016: The next evolution
Analytics Trends 2016: The next evolutionAnalytics Trends 2016: The next evolution
Analytics Trends 2016: The next evolution
 

Similar a Pro Postgres 9

Situated learning among open source software developers
Situated learning among open source software developersSituated learning among open source software developers
Situated learning among open source software developers
Josef Hardi
 
Blackhat Workshop
Blackhat WorkshopBlackhat Workshop
Blackhat Workshop
wremes
 
Monitoring is easy, why are we so bad at it presentation
Monitoring is easy, why are we so bad at it  presentationMonitoring is easy, why are we so bad at it  presentation
Monitoring is easy, why are we so bad at it presentation
Theo Schlossnagle
 
ThePythonPapersVolume2Issue3
ThePythonPapersVolume2Issue3ThePythonPapersVolume2Issue3
ThePythonPapersVolume2Issue3
webuploader
 

Similar a Pro Postgres 9 (11)

Situated learning among open source software developers
Situated learning among open source software developersSituated learning among open source software developers
Situated learning among open source software developers
 
Cc index
Cc indexCc index
Cc index
 
Complete placement guide(technical)
Complete placement guide(technical)Complete placement guide(technical)
Complete placement guide(technical)
 
Python in 15 minutes
Python in 15 minutesPython in 15 minutes
Python in 15 minutes
 
RunDeck
RunDeckRunDeck
RunDeck
 
PostgreSQL Development Today: 9.0
PostgreSQL Development Today: 9.0PostgreSQL Development Today: 9.0
PostgreSQL Development Today: 9.0
 
Blackhat Workshop
Blackhat WorkshopBlackhat Workshop
Blackhat Workshop
 
Chris Brew - TR Discover: A Natural Language Interface for Exploring Linked D...
Chris Brew - TR Discover: A Natural Language Interface for Exploring Linked D...Chris Brew - TR Discover: A Natural Language Interface for Exploring Linked D...
Chris Brew - TR Discover: A Natural Language Interface for Exploring Linked D...
 
Become a Better Developer with Debugging Techniques for Drupal (and more!)
Become a Better Developer with Debugging Techniques for Drupal (and more!)Become a Better Developer with Debugging Techniques for Drupal (and more!)
Become a Better Developer with Debugging Techniques for Drupal (and more!)
 
Monitoring is easy, why are we so bad at it presentation
Monitoring is easy, why are we so bad at it  presentationMonitoring is easy, why are we so bad at it  presentation
Monitoring is easy, why are we so bad at it presentation
 
ThePythonPapersVolume2Issue3
ThePythonPapersVolume2Issue3ThePythonPapersVolume2Issue3
ThePythonPapersVolume2Issue3
 

Más de Robert Treat

Less Alarming Alerts!
Less Alarming Alerts!Less Alarming Alerts!
Less Alarming Alerts!
Robert Treat
 
Managing Databases In A DevOps Environment
Managing Databases In A DevOps EnvironmentManaging Databases In A DevOps Environment
Managing Databases In A DevOps Environment
Robert Treat
 
Scaling with Postgres (Highload++ 2010)
Scaling with Postgres (Highload++ 2010)Scaling with Postgres (Highload++ 2010)
Scaling with Postgres (Highload++ 2010)
Robert Treat
 
Intro to Postgres 9 Tutorial
Intro to Postgres 9 TutorialIntro to Postgres 9 Tutorial
Intro to Postgres 9 Tutorial
Robert Treat
 

Más de Robert Treat (20)

Advanced Int->Bigint Conversions
Advanced Int->Bigint ConversionsAdvanced Int->Bigint Conversions
Advanced Int->Bigint Conversions
 
Explaining Explain
Explaining ExplainExplaining Explain
Explaining Explain
 
the-lost-art-of-plpgsql
the-lost-art-of-plpgsqlthe-lost-art-of-plpgsql
the-lost-art-of-plpgsql
 
Managing Chaos In Production: Testing vs Monitoring
Managing Chaos In Production: Testing vs MonitoringManaging Chaos In Production: Testing vs Monitoring
Managing Chaos In Production: Testing vs Monitoring
 
Managing Databases In A DevOps Environment 2016
Managing Databases In A DevOps Environment 2016Managing Databases In A DevOps Environment 2016
Managing Databases In A DevOps Environment 2016
 
Less Alarming Alerts - SRECon 2016
Less Alarming Alerts - SRECon 2016 Less Alarming Alerts - SRECon 2016
Less Alarming Alerts - SRECon 2016
 
What Ops Can Learn From Design
What Ops Can Learn From DesignWhat Ops Can Learn From Design
What Ops Can Learn From Design
 
Postgres 9.4 First Look
Postgres 9.4 First LookPostgres 9.4 First Look
Postgres 9.4 First Look
 
Less Alarming Alerts!
Less Alarming Alerts!Less Alarming Alerts!
Less Alarming Alerts!
 
Past, Present, and Pachyderm - All Things Open - 2013
Past, Present, and Pachyderm - All Things Open - 2013Past, Present, and Pachyderm - All Things Open - 2013
Past, Present, and Pachyderm - All Things Open - 2013
 
Big Bad "Upgraded" Postgres
Big Bad "Upgraded" PostgresBig Bad "Upgraded" Postgres
Big Bad "Upgraded" Postgres
 
Managing Databases In A DevOps Environment
Managing Databases In A DevOps EnvironmentManaging Databases In A DevOps Environment
Managing Databases In A DevOps Environment
 
Scaling with Postgres (Highload++ 2010)
Scaling with Postgres (Highload++ 2010)Scaling with Postgres (Highload++ 2010)
Scaling with Postgres (Highload++ 2010)
 
Intro to Postgres 9 Tutorial
Intro to Postgres 9 TutorialIntro to Postgres 9 Tutorial
Intro to Postgres 9 Tutorial
 
Check Please!
Check Please!Check Please!
Check Please!
 
Database Scalability Patterns
Database Scalability PatternsDatabase Scalability Patterns
Database Scalability Patterns
 
A Guide To PostgreSQL 9.0
A Guide To PostgreSQL 9.0A Guide To PostgreSQL 9.0
A Guide To PostgreSQL 9.0
 
Scaling With Postgres
Scaling With PostgresScaling With Postgres
Scaling With Postgres
 
Intro to Postgres 8.4 Tutorial
Intro to Postgres 8.4 TutorialIntro to Postgres 8.4 Tutorial
Intro to Postgres 8.4 Tutorial
 
Intro to pl/PHP Oscon2007
Intro to pl/PHP Oscon2007Intro to pl/PHP Oscon2007
Intro to pl/PHP Oscon2007
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

Pro Postgres 9

  • 1. Pro Postgres 9 Robert Treat, JDCon East 2011 Thursday, March 31, 2011
  • 2. Who Am I? (Why Listen To Me) PostgreSQL User Since 6.5.x DBA of High Traffic / Large PostgreSQL Instances Long Time Contributor to PostgreSQL Project Contribute / Maintain Several Open Source Projects Co-Author Beginning PHP & PostgreSQL 8 (Apress) I like to call it “Postgres” Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 3. Outline What you need to know about the project Backups Getting Started Replication Upgrading Query Tuning Configuring Your Server Other stuff you should know about Hardware Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 4. Know Your Way Around The Project Thursday, March 31, 2011
  • 5. Know Your Way Around The Project www.postgresql.org downloads security alerts documentation wiki bug reports support companies rss -> news - events - version Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 6. Know Your Way Around The Project planet.postgresql.org project news helpful tips / examples community news Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 7. Know Your Way Around The Project www.pgfoundry.org URI Type SkyTools modules Npgsql programs pg_bulkload resources plpgsql-debugger pagila, sample database Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 8. Know Your Way Around The Project git.postgresql.org check_postgres modules edb-installers programs website code resources json type works in progress pg_top user repo’s see also github.com Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 9. Know Your Way Around The Project archives.postgresql.org mailing list archives back to 1997 full text search via postgresql FTS keyword search suggestions lists for users, developers, regional, user groups Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 10. Know Your Way Around The Project #postgresql irc.freenode.net real time help pg_docbot - ??help Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 11. Know Your Way Around The Project project management core team committers -hackers road map web team Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 12. Get Off To A Good Start Thursday, March 31, 2011
  • 13. Get Off To A Good Start Use Package Management Consistent Standardized Simple Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 14. Get Off To A Good Start Use Package Management Different across systems Upgrades can be a problem Trust your packager? Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 15. Get Off To A Good Start Use Package Management Different across systems Upgrades can be a problem Trust your packager? Don’t Be Afraid To Roll Your Own Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 16. Get Off To A Good Start A Note About Versions Just playing? Default packages probably OK, (min 8.2) Any production level work should start on 9.0 Any project not due to launch for 6 months, 9.1 Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 17. Get Off To A Good Start So What Do You Get? pg_control version number: 903 Catalog version number: 201008051 Database system identifier: 5546136951888795324 Database cluster state: in archive recovery pg_control last modified: Tue Mar 22 11:50:24 2011 Latest checkpoint location: 7C/1D000058 Prior checkpoint location: 7C/1C000058 Latest checkpoint's REDO location: 7C/1D000020 Latest checkpoint's TimeLineID: 1 Latest checkpoint's NextXID: 0/4924 Latest checkpoint's NextOID: 16608 Latest checkpoint's NextMultiXactId: 1 Latest checkpoint's NextMultiOffset: 0 Latest checkpoint's oldestXID: 654 Latest checkpoint's oldestXID's DB: 1 pg_controldata Latest checkpoint's oldestActiveXID: Time of latest checkpoint: 4924 Tue Mar 22 11:46:19 2011 Minimum recovery ending location: 7C/16000000 Backup start location: 0/0 Current wal_level setting: hot_standby Current max_connections setting: 500 Current max_prepared_xacts setting: 0 Current max_locks_per_xact setting: 64 Maximum data alignment: 8 Database block size: 8192 Blocks per segment of large relation: 131072 WAL block size: 8192 Bytes per WAL segment: 16777216 Maximum length of identifiers: 64 Maximum columns in an index: 32 Maximum size of a TOAST chunk: 1996 Date/time type storage: 64-bit integers Float4 argument passing: by value Float8 argument passing: by value Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 18. Get Off To A Good Start So What Do You Get? -rw------- 1 postgres postgres 4 Dec 2 12:23 PG_VERSION drwxr-xr-x 6 postgres postgres 6 Dec 2 13:41 base drwxr-xr-x 2 postgres postgres 42 Jan 28 17:49 global drwxr-xr-x 2 postgres postgres 3 Dec 2 12:23 pg_clog -rw------- 1 postgres postgres 3938 Dec 19 11:25 pg_hba.conf -rw------- 1 postgres postgres 1636 Dec 19 11:25 pg_ident.conf drwxr-xr-x 3 postgres postgres 113 Mar 22 00:00 pg_log drwxr-xr-x 4 postgres postgres 4 Dec 2 12:23 pg_multixact drwxr-xr-x 2 postgres postgres 3 Jan 12 14:23 pg_notify drwxr-xr-x 2 postgres postgres 3 Jan 12 14:23 pg_stat_tmp drwxr-xr-x 2 postgres postgres 3 Dec 2 12:23 pg_subtrans drwxr-xr-x 2 postgres postgres 2 Dec 2 12:23 pg_tblspc drwxr-xr-x 2 postgres postgres 2 Dec 2 12:23 pg_twophase lrwxrwxrwx 1 postgres postgres 30 Dec 19 11:13 pg_xlog -rw------- 1 postgres postgres 17915 Mar 3 21:52 postgresql.conf -rw------- 1 postgres postgres 63 Jan 12 14:23 postmaster.opts -rw------- 1 postgres postgres 54 Jan 12 14:23 postmaster.pid -rw-r--r-- 1 postgres postgres 336 Dec 20 16:14 recovery.conf Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 19. Get Off To A Good Start So What Do You Get? -rw------- 1 postgres postgres 4 Dec 2 12:23 PG_VERSION drwxr-xr-x 6 postgres postgres 6 Dec 2 13:41 base drwxr-xr-x 2 postgres postgres 42 Jan 28 17:49 global drwxr-xr-x 2 postgres postgres 3 Dec 2 12:23 pg_clog -rw------- 1 postgres postgres 3938 Dec 19 11:25 pg_hba.conf -rw------- 1 postgres postgres 1636 Dec 19 11:25 pg_ident.conf drwxr-xr-x 3 postgres postgres 113 Mar 22 00:00 pg_log drwxr-xr-x 4 postgres postgres 4 Dec 2 12:23 pg_multixact drwxr-xr-x 2 postgres postgres 3 Jan 12 14:23 pg_notify drwxr-xr-x 2 postgres postgres 3 Jan 12 14:23 pg_stat_tmp drwxr-xr-x 2 postgres postgres 3 Dec 2 12:23 pg_subtrans drwxr-xr-x 2 postgres postgres 2 Dec 2 12:23 pg_tblspc drwxr-xr-x 2 postgres postgres 2 Dec 2 12:23 pg_twophase lrwxrwxrwx 1 postgres postgres 30 Dec 19 11:13 pg_xlog -rw------- 1 postgres postgres 17915 Mar 3 21:52 postgresql.conf -rw------- 1 postgres postgres 63 Jan 12 14:23 postmaster.opts -rw------- 1 postgres postgres 54 Jan 12 14:23 postmaster.pid -rw-r--r-- 1 postgres postgres 336 Dec 20 16:14 recovery.conf Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 20. Get Off To A Good Start So What Do You Get? -rw------- 1 postgres postgres 4 Dec 2 12:23 PG_VERSION drwxr-xr-x 6 postgres postgres 6 Dec 2 13:41 base drwxr-xr-x 2 postgres postgres 42 Jan 28 17:49 global drwxr-xr-x 2 postgres postgres 3 Dec 2 12:23 pg_clog -rw------- 1 postgres postgres 3938 Dec 19 11:25 pg_hba.conf -rw------- 1 postgres postgres 1636 Dec 19 11:25 pg_ident.conf drwxr-xr-x 3 postgres postgres 113 Mar 22 00:00 pg_log drwxr-xr-x 4 postgres postgres 4 Dec 2 12:23 pg_multixact drwxr-xr-x 2 postgres postgres 3 Jan 12 14:23 pg_notify drwxr-xr-x 2 postgres postgres 3 Jan 12 14:23 pg_stat_tmp drwxr-xr-x 2 postgres postgres 3 Dec 2 12:23 pg_subtrans drwxr-xr-x 2 postgres postgres 2 Dec 2 12:23 pg_tblspc drwxr-xr-x 2 postgres postgres 2 Dec 2 12:23 pg_twophase lrwxrwxrwx 1 postgres postgres 30 Dec 19 11:13 pg_xlog -rw------- 1 postgres postgres 17915 Mar 3 21:52 postgresql.conf -rw------- 1 postgres postgres 63 Jan 12 14:23 postmaster.opts -rw------- 1 postgres postgres 54 Jan 12 14:23 postmaster.pid -rw-r--r-- 1 postgres postgres 336 Dec 20 16:14 recovery.conf Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 21. Get Off To A Good Start Configure Your Logging $PGDATA/pg_log /var/log/postgresql when in doubt... (postgresql.conf) separate disk Logging is often overlooked, but it is the first step toward troubleshooting! Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 22. Get Off To A Good Start Configure Authentication most systems have different defaults firewalls / selinux (FATAL?) rtfm (pg_hba.conf, grant, revoke) Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 23. Get Off To A Good Start Authentication Methods TRUST md5 IDENT Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 24. Get Off To A Good Start /contrib Trust these more than your own code package dependent use different schemas (when able) pgcrypto Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 25. Get Off To A Good Start Additional Supplied Modules “contrib” Trust these more than your own code package dependent use different schemas (when able) pgcrypto, pg_upgrade http://www.postgresql.org/docs/current/interactive/contrib.html Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 26. Let’s Talk About Upgrades Thursday, March 31, 2011
  • 27. Let’s Talk About Upgrades Versioning First Digit (7.4.16 -> 8.2.0) Second Digit (8.3.6 -> 8.4.0) Third Digit (9.0.0 -> 9.0.2) Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 28. Let’s Talk About Upgrades Versioning First Digit (7.4.16 -> 8.2.0) Second Digit (8.3.6 -> 8.4.0) Third Digit (9.0.0 -> 9.0.2) Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 29. Let’s Talk About Upgrades Achtung!! Make Backups! Read the Release Notes! Read the Commit Logs! Test! Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 30. Let’s Talk About Upgrades pg_dump/pg_restore simple -Fc is your friend dump with new version of pg_dump pitfalls: (time, hdd) Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 31. Let’s Talk About Upgrades the “slony” method not simple create slave on new version switchover (switch back?) pitfalls: (initial synch, compatibility) Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 32. Let’s Talk About Upgrades pg_upgrade in place upgrades rewrites system catalog info no way to go back (fs snapshots) first official release was 9.0 Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 33. Let’s Talk About Upgrades upgrading legacy databases < 8.2 is no longer supported (upgrade now!) pg_upgrade only works on 8.3 or greater older slony can work back to 7.3ish pre-7.3 ? Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 34. Let’s Talk About Upgrades is it worth it? any database with significant transaction workload (read or write) >= 8.3 (vxid) most systems will want at least 8.4 (fsm) replication is nice too though... Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 35. Let’s Talk About Upgrades Versioning First Digit (7.4.16 -> 8.2.0) Second Digit (8.3.6 -> 8.4.0) Third Digit (9.0.0 -> 9.0.2) Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 36. Let’s Talk About Upgrades minor release versioning policy drop in replacement no feature changes bug fixes only (includes security fixes) sometimes involves extra steps also referred to as service packs, hot fixes, fix packs, etc... It is considered more dangerous to not upgrade! Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 38. Figure Your Configure the basics: performance shared_buffers effective_cache_size work_mem checkpoint_segments Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 39. Figure Your Configure the basics: logging stderr/pg_log vs. syslog/eventlog log_min_duration_statement log_line_prefix (%t, %p, %d, %u, %r) Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 40. Figure Your Configure other stuff worth looking at maintenance_work_mem max_prepared_transactions wal_buffers checkpoint_completion_target autovacuum_freeze_max_age Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 41. Figure Your Configure the basics: replication primary: wal_level = ‘hot_standby’ primary: max_wal_senders = n slave: hot_standby = on Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 43. Hardware for Software People cpu and you connections, autovacuum, bgwriter, stats collector, replication Multiple CPU’s work wonders, up to 32 processors http://tweakers.net Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 44. Hardware for Software People disk does and don’ts Put WAL on it’s own disk (RAID 1) Put DATA directory on it’s own disk (RAID 10) More Spindles is Good More Controllers Even Gooder (tablespaces) Battery Backed Controllers, Write Cache Enabled Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 45. Hardware for Software People disk don’ts NFS == Not Fully Safe! RAID 5 Beware disks / controllers that lie Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 46. Can You Back That Up? Thursday, March 31, 2011
  • 47. Can You Back That Up? types of backups logical (sql export) physical (files on disk) Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 48. Can You Back That Up? logical backups slow to create slow to restore “pure”, no system level corruption susceptible to database level corruption pg_dump is your friend pg_dumpall for globals Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 49. Can You Back That Up? physical backups replication / failover machine “tarball” (pitr) filesystem snapshots (pitr) Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 50. Can You Back That Up? replication / failover node good idea, but... offsite? fragile? we’ll talk more in replication section :-) Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 51. Can You Back That Up? “tarball” (pitr) basic idea is to copy all database files and relevant xlogs use multiple machines if able use rsync if able copy the slave if able!! Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 52. Can You Back That Up? filesystem snapshots (pitr) basic idea is to copy all database files and relevant xlogs use multiple machines if able use rsync if able copy the slave if able!! Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 54. Replication, Replication 9.0 “Introduced” Replication In Postgres Built In Solution Based on WAL replay True Binary Replication 1st Cut, Still A Little Rough Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 55. Replication, Replication However, There Are Lots Of Alternatives! Most Are Trigger Based: Slony, Bucardo, Londiste, RubyRep, etc... Statement Based (PGPoolII) Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 56. Replication, Replication Quick Rundown: Slony Trigger Based Asynchronous Master -> (Multiple, Cascading) Slave Switchover “A Pain To Work With” Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 57. Replication, Replication Quick Rundown: Londiste Trigger Based Asynchronous Master -> (Multiple) Slave Switchover “I Don’t Like Slony” Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 58. Replication, Replication Quick Rundown: Bucardo Trigger Based Asynchronous Master -> (Multiple) Slave Master -> Master “Small Community” Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 59. Replication, Replication Quick Rundown: Ruby Rep Trigger Based Asynchronous Master -> Slave Master -> Master “Huh?” Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 60. Replication, Replication Determine Your Needs: Failover Simple 2 Server Setup? 9.0 Streaming Replication Multiple Slaves? Slony Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 61. Replication, Replication Determine Your Needs: Switchover Master -> Slave Slony Londiste Master -> Master Bucardo Ruby Rep Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 62. Replication, Replication Determine Your Needs: Single Read Slave Postgres Streaming Replication no changes to the slave Any of the Trigger Based Solutions Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 63. Replication, Replication Determine Your Needs: Multiple Read Slaves Slony (Cascading) Bucardo (Split) Londiste (meh) Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 64. Replication, Replication A Note On Scaling Writes Scaling Writes Is A Hard Problem Bucardo/RubyRep Help IF CPU Bound If you are bound on write i/o, you probably need to federate your database Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 66. Query Your Queries finding slow queries: log_min_duration_statement -1, 0, n superuser only alter user LOG: duration: 5005.273ms statement: select pg_sleep(5); Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 67. Query Your Queries finding slow queries: log analyzers command line tools i/o load generate reports cpu load archive reports Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 68. Query Your Queries finding slow queries: log analyzers pqa pgfouine maatkit (percona) pgsi (endpoint) Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 69. Query Your Queries fixing slow queries: explain analyze universal tool good for specific queries “explain” for large queries could be it’s own talk Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 70. Query Your Queries fixing slow queries: explain analyze universal tool good for specific queries “explain” for large queries could be it’s own talk http://wiki.postgresql.org/Using_EXPLAIN Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 71. Query Your Queries fixing slow queries: indexing (basic) use explain to find large sequential reads use pg_stat_* tables to find numerous reads use btree (gist/gin) dual column vs. single column Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 72. Query Your Queries fixing slow queries: indexing (partial) restrain index to rows that matter can give significant speed improvements where clause of index should match where clause of query create index address_ba_part_idx on address (district) where district = ‘Buenos Aires’; Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 73. Query Your Queries fixing slow queries: indexing (partial) restrain index to rows that matter can give significant speed improvements where clause of index should match where clause of query create index customer_active_part_idx on customer (customer_id) where active is true; Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 74. Query Your Queries fixing slow queries: indexing (functional) some people prefer to call these expressional indexes Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 75. Query Your Queries fixing slow queries: indexing (expressional) push expensive functions into your index system sees just WHERE indexedcolumn = ‘constant’ expression of index should match expression of queries narrow scope, but nice gains create unique index one_true_email_xidx on customer (lower(email)); Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 76. Query Your Queries fixing slow queries: indexing (expressional) push expensive functions into your index system sees just WHERE indexedcolumn = ‘constant’ expression of index should match expression of queries narrow scope, but nice gains create index fullname_xidx on customer ((firstname||’ ‘||lastname)); Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 77. Query Your Queries fixing slow queries: indexing (expressional) push expensive functions into your index system sees just WHERE indexedcolumn = ‘constant’ expression of index should match expression of queries narrow scope, but nice gains create index fullname_xidx on customer ((firstname||’ ‘||lastname)); Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 78. Other Stuff I Should Mention Thursday, March 31, 2011
  • 79. Other Stuff I Should Mention pgcrypto cryptography /contrib (export issues) md5, sha1, blowfish, many more Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 80. Other Stuff I Should Mention dblink pgsql -> pgsql connections /contrib (still under development) can have performance issues on large queries make it live in it’s own schema may be replaced by foreign data wrappers Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 81. Other Stuff I Should Mention *-link heterogenous connections for postgresql db specific and db independent options any pl/u language can implement this similar performance issue as dblink dblink-tds, dbi-link, oralink, odbclink Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 82. Other Stuff I Should Mention autonomous logging tool persistent logging for postgresql functions built on top of dblink make it live in it’s own schema https://labs.omniti.com/trac/pgtreats Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 83. Other Stuff I Should Mention check_postgres nagios oriented monitoring script comprehensive list of items for alterting adapted for other systems, some trending http://bucardo.org/check_postgres Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 84. Other Stuff I Should Mention phpPgAdmin web based gui for postgresql remote administration of multiple servers implements much of postgresql functionality http://phppgadmin.sourceforge.net/ Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 85. Other Stuff I Should Mention omnipitr advanced WAL file management scripts pitr archiving, pitr restore complete filesystem based backup can create backups from a slave server https://labs.omniti.com/trac/pgtreats Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 86. Other Stuff I Should Mention books PostgreSQL 9.0 High Performance, by Greg Smith PostgreSQL 9.0 Admin Cookbook, by Simon Riggs Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 87. Other Stuff I Should Mention books PostgreSQL 9.0 High Performance, by Greg Smith PostgreSQL 9.0 Admin Cookbook, by Simon Riggs Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 88. Other Stuff I Should Mention we’re hiring :-) Database Operations Big Systems High Volume Workloads Keggerator! Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 89. Other Stuff I Should Mention we’re hiring :-) Database Operations Big Systems High Volume Workloads Keggerator! Robert Treat | Pro Postgres 9 Thursday, March 31, 2011
  • 90. El Fin Thanks For Coming! Thursday, March 31, 2011