SlideShare uma empresa Scribd logo
1 de 31
Baixar para ler offline
An ultimate guide to
upgrading your
PostgreSQL
installation
Ilya Kosmodemiansky
ik@dataegret.com
2 Why this talk?
Upgrading your PostgreSQL is not a rocket science!
• ...but there are lots of small details
• Unsuccessful upgrade can ruin your data
• Or at least cause an unacceptable downtime
• Upgrade requires good knowledge of your system and substantial
preparation time
dataegret.com
3 Because of that
• DBAs do not like upgrades
• They are attached to outdated versions
• They manage to screw up an upgrade when they finally decide to perform
one
dataegret.com
4 Why do you need to upgrade?
• Bugfixes, security fixes
• Many performance improvements and new features over the last years
• Upgrading on time makes it easier
• Running 7.* in 2017 would make consultants too happy
dataegret.com
5 PostgreSQL version numbering
<= 9.6.*
9.4.3Major
Major
Minor
dataegret.com
5 PostgreSQL version numbering
> 9.6.*
10.2
Major Minor
dataegret.com
6 Types of upgrades
• Minor
New versions’ binaries can run on old version datafiles
• Major
New versions’ binaries can run on old version datafiles, but require new
system tables and internal data format may change
• Major with special requirements
dataegret.com
7 Before any upgrade
• Read carefully version specific release notes
• Play with chosen upgrade method in test environment
• Align with your application development team
• Make a backup and check it by test recovery
dataegret.com
8 Minor upgrades are easy
• You simply install new binaries and start new database server on the old
data directory
• There are no new features between minor versions
• Still - keep an eye on updating all PostgreSQL-related packages you use
dataegret.com
9 Major upgrade prerequisites
• Install new versions for all PostgreSQL-related packages
• Read carefully all release notes
• Know your PostgreSQL installation
• Choose the method and carefully read the documentation for this method
• Align with your application development team
• Do a backup and check it by doing a test recovery
dataegret.com
10 Check which PostgreSQL-related packages you use
your_server:~$ sudo dpkg -l *postgres*
||/ Name Version
+++-=================================================-=============================
ii postgresql-9.3 9.3.15-1.pgdg14.04+1
ii postgresql-client-9.3 9.3.15-1.pgdg14.04+1
ii postgresql-client-common 182.pgdg14.04+1
ii postgresql-common 182.pgdg14.04+1
ii postgresql-contrib-9.3 9.3.15-1.pgdg14.04+1
ii postgresql-plperl-9.3 9.3.15-1.pgdg14.04+1
ii postgresql-server-dev-9.3 9.3.15-1.pgdg14.04+1
your_server:~$ sudo dpkg -l *pg*
||/ Name Version
+++-=================================================-=============================
ii libdbd-pg-perl 2.19.3-2
ii pgbouncer 1.5.4-4
ii pgdg-keyring 2014.1
dataegret.com
11 Major upgrade methods
• Good old dump/restore
• pg_upgrade
• Replication-based methods
dataegret.com
12 Major upgrade using pg_dump
• Difficult to make without downtime if you have a large, heavyloaded
database
• Requires additional disk space
• Works with any PostgreSQL version since 7.0
• pg_dump -Fc - custom format, -Z - compression
• pg_dump -Fd –jobs can be a good option in terms of speed and downtime
• But if using -j you can’t do things like that: pg_dumpall -p 5432 | psql -d
postgres -p 5433
• If your installation can be upgraded easily by dump/restore, you are lucky!
dataegret.com
13 Major upgrade using pg_dump - procedure
• Install new binaries
• Initialize new cluster. Don’t forget about locale
• Change config files appropriately
• It can be a good idea to use newer version of pg_dump, but be careful if
running on pre-9.2 server
• Restore the dump, try to figure out if everything looks good
• Switch your application to the new cluster
dataegret.com
14 pg_upgrade - outline
• How it works?
• Procedure
Simple case - standalone server
How to minimize downtime?
Upgrading hot-standby cluster
• Details
dataegret.com
15 pg_upgrade - How it works?
user data
pg_clog
pg_catalog
pg_clog
pg_catalog
old
new
user data
pg_clog
pg_catalog
pg_clog
pg_catalog
freeze
user data
pg_clog
pg_catalog
pg_clog
pg_catalog
pg_clog and pg_control
user data
pg_clog
pg_catalog
pg_clog
pg_catalog
user data
dupm/restore of schema
and
cp or relink of datafiles
dataegret.com
15 pg_upgrade - How it works?
• Decouple pg_clog (pg_xact) from new cluster
• Couple old pg_clog to a new cluster and set xid
• Restore schema
• Copy or link datafiles from old cluster to a new one
dataegret.com
16 pg_upgrade - procedure
• Create empty database for new version of PostgreSQL
• Stop database with old PostgreSQL version
• Start upgrade procedure with pg_upgrade command
• Start database that runs on new PostgreSQL version
• Start collecting statistics (pg_upgrade does not transfer optimizer
statistics)
• When statistic collection started, you can open database for your
application
• Depending on your database, you can achieve 1-10 min downtime target
dataegret.com
17 pg_upgrade - minimizing downtime
• Use pgbouncer
PAUSE/RESUME
Issue CHECKPOINT; on old server before you start, to make shutdown
process faster
• Use -k (–link) to use hard links instead of copy (but carefully!)
dataegret.com
18 pg_upgrade - hot-standby replica
• Upgrade master as a standalone server
• Keep replica intact to failover if something goes wrong
• Reinstantiate your replica
• Procedure
Pause pgbouncer on standby or stop it
Clone a replica from upgraded master using pg_basebackup
Start replica with new binaries
Resume pgbouncer connections or start pgbouncer.
dataegret.com
19 pg_upgrade - Details
• pg_upgrade does not transfer optimizer statistics
• instead, it generates a script ./analyze_new_cluster.sh
It basically runs vacuumdb –all –analyze-in-stages
In some cases it is better to run vacuumdb –all –analyze-only
Since 9.5 you can vacuumdb run in parallel (-j)
We usually use vacuumdb –all –analyze-in-stages and open database for
application after medium optimizer statistics (10 targets) are generated
dataegret.com
20 pg_upgrade - Details
• Documentation suggests to use rsync to reinstantiate standby
• rsync –archive –delete –hard-links –size-only old_pgdata new_pgdata
remote_dir
• rsync allows you to save a lot of network traffic in that case
• ...and provides lots of opportunities to shoot yourself in the foot
dataegret.com
21 pg_upgrade - Details
• Debian/Ubuntu follow their own way
• Wrappers, like pg_ctlcluster are designed to manipulate PostgreSQL cluster
in a Debian way
• pg_upgradecluster -v 9.5 9.3 main1 -m upgrade -k supposed to be a
make-me-happy button for a DBA
• It even takes care of converting postgresql.conf parameters for you
• But I strongly recommend to do this manually
dataegret.com
22 pg_upgrade - Details
• Extensions can surprise you
• pg_upgrade keeps old versions of extensions
• We advise to cycle through all extensions and perform alter extension
EXTENSION_NAME update;
• Some extensions need special care: for example PostGIS should be
updated before an upgrade
dataegret.com
23 Using replication to upgrade PostgreSQL
• Streaming replication doesn’t work between versions
• But some replication methods can do that
Logical replication
Slony-I
Londiste
• Procedure
Setup new database cluster
Setup replication from old one to a new one
Perform failover
dataegret.com
24 Logical replication
• New promising method
• Allows you to upgrade from 9.4 to a newer version
• It can be tricky:
Check documentation carefully
If you have a complex schema, you may need some wrapper, like
https://github.com/rtshome/pgrepup
Check what you replicate using pglogical.replication_set
Don’t forget about sequences
dataegret.com
25 Slony-I
• Old and bulletproof
• Can be used with old versions
• Failover can be done really fast
• Drawbacks
Trigger based - can cause heavy load on old cluster
Extra disk space is needed
dataegret.com
26 Londiste
• I’am not a big fan of Londiste
• Same drawbacks as with Slony, but without Slony’s robustness
• Lots of bugs (compared to Slony)
• Tool was designed for a different purpose
dataegret.com
27 Conclusion
Method downtime extra disk space complexity riskiness
dump/restore high double low low
pg_upgrade (copy) high double high low
pg_upgrade (link) low low high very high
Logical replication low double high low
Slony-I low double medium low
Londiste low double medium low
dataegret.com
28 Reading list
• http://momjian.us/main/writings/pgsql/pg_upgrade.pdf
• https://blog.2ndquadrant.com/untangling-the-postgresql-upgrade/
• http://blog.endpoint.com/2016/12/postgres-statistics-and-pain-of-
analyze.html
• https://www.depesz.com/2016/11/08/major-version-upgrading-with-
minimal-downtime/
dataegret.com
29 Questions?
ik@dataegret.com
dataegret.com

Mais conteúdo relacionado

Mais procurados

PostgreSQL major version upgrade using built in Logical Replication
PostgreSQL major version upgrade using built in Logical ReplicationPostgreSQL major version upgrade using built in Logical Replication
PostgreSQL major version upgrade using built in Logical Replication
Atsushi Torikoshi
 

Mais procurados (20)

PostgreSQL Deep Internal
PostgreSQL Deep InternalPostgreSQL Deep Internal
PostgreSQL Deep Internal
 
Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.
 
Introduction VAUUM, Freezing, XID wraparound
Introduction VAUUM, Freezing, XID wraparoundIntroduction VAUUM, Freezing, XID wraparound
Introduction VAUUM, Freezing, XID wraparound
 
DOAG Oracle Unified Audit in Multitenant Environments
DOAG Oracle Unified Audit in Multitenant EnvironmentsDOAG Oracle Unified Audit in Multitenant Environments
DOAG Oracle Unified Audit in Multitenant Environments
 
PostgreSQL Administration for System Administrators
PostgreSQL Administration for System AdministratorsPostgreSQL Administration for System Administrators
PostgreSQL Administration for System Administrators
 
PostgreSQL : Introduction
PostgreSQL : IntroductionPostgreSQL : Introduction
PostgreSQL : Introduction
 
Long live to CMAN!
Long live to CMAN!Long live to CMAN!
Long live to CMAN!
 
Tanel Poder - Performance stories from Exadata Migrations
Tanel Poder - Performance stories from Exadata MigrationsTanel Poder - Performance stories from Exadata Migrations
Tanel Poder - Performance stories from Exadata Migrations
 
PostgreSQL major version upgrade using built in Logical Replication
PostgreSQL major version upgrade using built in Logical ReplicationPostgreSQL major version upgrade using built in Logical Replication
PostgreSQL major version upgrade using built in Logical Replication
 
The Oracle RAC Family of Solutions - Presentation
The Oracle RAC Family of Solutions - PresentationThe Oracle RAC Family of Solutions - Presentation
The Oracle RAC Family of Solutions - Presentation
 
PostgreSQL Replication Tutorial
PostgreSQL Replication TutorialPostgreSQL Replication Tutorial
PostgreSQL Replication Tutorial
 
UKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tipsUKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tips
 
10 things, an Oracle DBA should care about when moving to PostgreSQL
10 things, an Oracle DBA should care about when moving to PostgreSQL10 things, an Oracle DBA should care about when moving to PostgreSQL
10 things, an Oracle DBA should care about when moving to PostgreSQL
 
Oracle Multitenant meets Oracle RAC - IOUG 2014 Version
Oracle Multitenant meets Oracle RAC - IOUG 2014 VersionOracle Multitenant meets Oracle RAC - IOUG 2014 Version
Oracle Multitenant meets Oracle RAC - IOUG 2014 Version
 
Backup and-recovery2
Backup and-recovery2Backup and-recovery2
Backup and-recovery2
 
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdfOracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
 
Oracle Performance Tools of the Trade
Oracle Performance Tools of the TradeOracle Performance Tools of the Trade
Oracle Performance Tools of the Trade
 
10 ways to improve your rman script
10 ways to improve your rman script10 ways to improve your rman script
10 ways to improve your rman script
 
5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance
 
Looking ahead at PostgreSQL 15
Looking ahead at PostgreSQL 15Looking ahead at PostgreSQL 15
Looking ahead at PostgreSQL 15
 

Semelhante a Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installation PGConf.EU

Operating PostgreSQL at Scale with Kubernetes
Operating PostgreSQL at Scale with KubernetesOperating PostgreSQL at Scale with Kubernetes
Operating PostgreSQL at Scale with Kubernetes
Jonathan Katz
 
Rapid Upgrades With Pg_Upgrade, Bruce Momjian
Rapid Upgrades With Pg_Upgrade, Bruce MomjianRapid Upgrades With Pg_Upgrade, Bruce Momjian
Rapid Upgrades With Pg_Upgrade, Bruce Momjian
Fuenteovejuna
 
Pg upgrade employer
Pg upgrade employerPg upgrade employer
Pg upgrade employer
EDB
 
Openstack hk-summit-upgrades-talk
Openstack hk-summit-upgrades-talkOpenstack hk-summit-upgrades-talk
Openstack hk-summit-upgrades-talk
Buvanesh Kumar
 
ProstgreSQLFailoverConfiguration
ProstgreSQLFailoverConfigurationProstgreSQLFailoverConfiguration
ProstgreSQLFailoverConfiguration
Suyog Shirgaonkar
 

Semelhante a Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installation PGConf.EU (20)

The Accidental DBA
The Accidental DBAThe Accidental DBA
The Accidental DBA
 
Operating PostgreSQL at Scale with Kubernetes
Operating PostgreSQL at Scale with KubernetesOperating PostgreSQL at Scale with Kubernetes
Operating PostgreSQL at Scale with Kubernetes
 
Rapid Upgrades With Pg_Upgrade, Bruce Momjian
Rapid Upgrades With Pg_Upgrade, Bruce MomjianRapid Upgrades With Pg_Upgrade, Bruce Momjian
Rapid Upgrades With Pg_Upgrade, Bruce Momjian
 
Best Practices: Migrating a Postgres Production Database to the Cloud
Best Practices: Migrating a Postgres Production Database to the CloudBest Practices: Migrating a Postgres Production Database to the Cloud
Best Practices: Migrating a Postgres Production Database to the Cloud
 
Pg upgrade employer
Pg upgrade employerPg upgrade employer
Pg upgrade employer
 
Using PostgreSQL With Docker & Kubernetes - July 2018
Using PostgreSQL With Docker & Kubernetes - July 2018Using PostgreSQL With Docker & Kubernetes - July 2018
Using PostgreSQL With Docker & Kubernetes - July 2018
 
Upgrade to MySQL 5.6 without downtime
Upgrade to MySQL 5.6 without downtimeUpgrade to MySQL 5.6 without downtime
Upgrade to MySQL 5.6 without downtime
 
Database upgradation
Database upgradationDatabase upgradation
Database upgradation
 
What's New in PostgreSQL 9.3
What's New in PostgreSQL 9.3What's New in PostgreSQL 9.3
What's New in PostgreSQL 9.3
 
TechEvent PostgreSQL Best Practices
TechEvent PostgreSQL Best PracticesTechEvent PostgreSQL Best Practices
TechEvent PostgreSQL Best Practices
 
Overview of Postgres Utility Processes
Overview of Postgres Utility ProcessesOverview of Postgres Utility Processes
Overview of Postgres Utility Processes
 
Webinar: Best Practices for Upgrading to MongoDB 3.2
Webinar: Best Practices for Upgrading to MongoDB 3.2Webinar: Best Practices for Upgrading to MongoDB 3.2
Webinar: Best Practices for Upgrading to MongoDB 3.2
 
Postgre sql best_practices
Postgre sql best_practicesPostgre sql best_practices
Postgre sql best_practices
 
Postgre sql best_practices
Postgre sql best_practicesPostgre sql best_practices
Postgre sql best_practices
 
Openstack hk-summit-upgrades-talk
Openstack hk-summit-upgrades-talkOpenstack hk-summit-upgrades-talk
Openstack hk-summit-upgrades-talk
 
Checklist for Upgrades and Migrations
Checklist for Upgrades and MigrationsChecklist for Upgrades and Migrations
Checklist for Upgrades and Migrations
 
ProstgreSQLFailoverConfiguration
ProstgreSQLFailoverConfigurationProstgreSQLFailoverConfiguration
ProstgreSQLFailoverConfiguration
 
Running PostgreSQL in a Kubernetes cluster: CloudNativePG
Running PostgreSQL in a Kubernetes cluster: CloudNativePGRunning PostgreSQL in a Kubernetes cluster: CloudNativePG
Running PostgreSQL in a Kubernetes cluster: CloudNativePG
 
What's coming in Airflow 2.0? - NYC Apache Airflow Meetup
What's coming in Airflow 2.0? - NYC Apache Airflow MeetupWhat's coming in Airflow 2.0? - NYC Apache Airflow Meetup
What's coming in Airflow 2.0? - NYC Apache Airflow Meetup
 
Best And Worst Practices Deploying IBM Connections
Best And Worst Practices Deploying IBM ConnectionsBest And Worst Practices Deploying IBM Connections
Best And Worst Practices Deploying IBM Connections
 

Mais de PostgreSQL-Consulting

How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
PostgreSQL-Consulting
 

Mais de PostgreSQL-Consulting (12)

Linux IO internals for database administrators (SCaLE 2017 and PGDay Nordic 2...
Linux IO internals for database administrators (SCaLE 2017 and PGDay Nordic 2...Linux IO internals for database administrators (SCaLE 2017 and PGDay Nordic 2...
Linux IO internals for database administrators (SCaLE 2017 and PGDay Nordic 2...
 
PostgreSQL worst practices, version FOSDEM PGDay 2017 by Ilya Kosmodemiansky
PostgreSQL worst practices, version FOSDEM PGDay 2017 by Ilya KosmodemianskyPostgreSQL worst practices, version FOSDEM PGDay 2017 by Ilya Kosmodemiansky
PostgreSQL worst practices, version FOSDEM PGDay 2017 by Ilya Kosmodemiansky
 
Linux internals for Database administrators at Linux Piter 2016
Linux internals for Database administrators at Linux Piter 2016Linux internals for Database administrators at Linux Piter 2016
Linux internals for Database administrators at Linux Piter 2016
 
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 Vienna
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 ViennaAutovacuum, explained for engineers, new improved version PGConf.eu 2015 Vienna
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 Vienna
 
PostgreSQL Meetup Berlin at Zalando HQ
PostgreSQL Meetup Berlin at Zalando HQPostgreSQL Meetup Berlin at Zalando HQ
PostgreSQL Meetup Berlin at Zalando HQ
 
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
 
Pgconfru 2015 kosmodemiansky
Pgconfru 2015 kosmodemianskyPgconfru 2015 kosmodemiansky
Pgconfru 2015 kosmodemiansky
 
Как PostgreSQL работает с диском
Как PostgreSQL работает с дискомКак PostgreSQL работает с диском
Как PostgreSQL работает с диском
 
Kosmodemiansky wr 2013
Kosmodemiansky wr 2013Kosmodemiansky wr 2013
Kosmodemiansky wr 2013
 
Максим Богук. Postgres-XC
Максим Богук. Postgres-XCМаксим Богук. Postgres-XC
Максим Богук. Postgres-XC
 
Иван Фролков. Tricky SQL
Иван Фролков. Tricky SQLИван Фролков. Tricky SQL
Иван Фролков. Tricky SQL
 
Илья Космодемьянский. Использование очередей асинхронных сообщений с PostgreSQL
Илья Космодемьянский. Использование очередей асинхронных сообщений с PostgreSQLИлья Космодемьянский. Использование очередей асинхронных сообщений с PostgreSQL
Илья Космодемьянский. Использование очередей асинхронных сообщений с PostgreSQL
 

Último

FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 

Último (20)

FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 

Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installation PGConf.EU

  • 1. An ultimate guide to upgrading your PostgreSQL installation Ilya Kosmodemiansky ik@dataegret.com
  • 2. 2 Why this talk? Upgrading your PostgreSQL is not a rocket science! • ...but there are lots of small details • Unsuccessful upgrade can ruin your data • Or at least cause an unacceptable downtime • Upgrade requires good knowledge of your system and substantial preparation time dataegret.com
  • 3. 3 Because of that • DBAs do not like upgrades • They are attached to outdated versions • They manage to screw up an upgrade when they finally decide to perform one dataegret.com
  • 4. 4 Why do you need to upgrade? • Bugfixes, security fixes • Many performance improvements and new features over the last years • Upgrading on time makes it easier • Running 7.* in 2017 would make consultants too happy dataegret.com
  • 5. 5 PostgreSQL version numbering <= 9.6.* 9.4.3Major Major Minor dataegret.com
  • 6. 5 PostgreSQL version numbering > 9.6.* 10.2 Major Minor dataegret.com
  • 7. 6 Types of upgrades • Minor New versions’ binaries can run on old version datafiles • Major New versions’ binaries can run on old version datafiles, but require new system tables and internal data format may change • Major with special requirements dataegret.com
  • 8. 7 Before any upgrade • Read carefully version specific release notes • Play with chosen upgrade method in test environment • Align with your application development team • Make a backup and check it by test recovery dataegret.com
  • 9. 8 Minor upgrades are easy • You simply install new binaries and start new database server on the old data directory • There are no new features between minor versions • Still - keep an eye on updating all PostgreSQL-related packages you use dataegret.com
  • 10. 9 Major upgrade prerequisites • Install new versions for all PostgreSQL-related packages • Read carefully all release notes • Know your PostgreSQL installation • Choose the method and carefully read the documentation for this method • Align with your application development team • Do a backup and check it by doing a test recovery dataegret.com
  • 11. 10 Check which PostgreSQL-related packages you use your_server:~$ sudo dpkg -l *postgres* ||/ Name Version +++-=================================================-============================= ii postgresql-9.3 9.3.15-1.pgdg14.04+1 ii postgresql-client-9.3 9.3.15-1.pgdg14.04+1 ii postgresql-client-common 182.pgdg14.04+1 ii postgresql-common 182.pgdg14.04+1 ii postgresql-contrib-9.3 9.3.15-1.pgdg14.04+1 ii postgresql-plperl-9.3 9.3.15-1.pgdg14.04+1 ii postgresql-server-dev-9.3 9.3.15-1.pgdg14.04+1 your_server:~$ sudo dpkg -l *pg* ||/ Name Version +++-=================================================-============================= ii libdbd-pg-perl 2.19.3-2 ii pgbouncer 1.5.4-4 ii pgdg-keyring 2014.1 dataegret.com
  • 12. 11 Major upgrade methods • Good old dump/restore • pg_upgrade • Replication-based methods dataegret.com
  • 13. 12 Major upgrade using pg_dump • Difficult to make without downtime if you have a large, heavyloaded database • Requires additional disk space • Works with any PostgreSQL version since 7.0 • pg_dump -Fc - custom format, -Z - compression • pg_dump -Fd –jobs can be a good option in terms of speed and downtime • But if using -j you can’t do things like that: pg_dumpall -p 5432 | psql -d postgres -p 5433 • If your installation can be upgraded easily by dump/restore, you are lucky! dataegret.com
  • 14. 13 Major upgrade using pg_dump - procedure • Install new binaries • Initialize new cluster. Don’t forget about locale • Change config files appropriately • It can be a good idea to use newer version of pg_dump, but be careful if running on pre-9.2 server • Restore the dump, try to figure out if everything looks good • Switch your application to the new cluster dataegret.com
  • 15. 14 pg_upgrade - outline • How it works? • Procedure Simple case - standalone server How to minimize downtime? Upgrading hot-standby cluster • Details dataegret.com
  • 16. 15 pg_upgrade - How it works? user data pg_clog pg_catalog pg_clog pg_catalog old new user data pg_clog pg_catalog pg_clog pg_catalog freeze user data pg_clog pg_catalog pg_clog pg_catalog pg_clog and pg_control user data pg_clog pg_catalog pg_clog pg_catalog user data dupm/restore of schema and cp or relink of datafiles dataegret.com
  • 17. 15 pg_upgrade - How it works? • Decouple pg_clog (pg_xact) from new cluster • Couple old pg_clog to a new cluster and set xid • Restore schema • Copy or link datafiles from old cluster to a new one dataegret.com
  • 18. 16 pg_upgrade - procedure • Create empty database for new version of PostgreSQL • Stop database with old PostgreSQL version • Start upgrade procedure with pg_upgrade command • Start database that runs on new PostgreSQL version • Start collecting statistics (pg_upgrade does not transfer optimizer statistics) • When statistic collection started, you can open database for your application • Depending on your database, you can achieve 1-10 min downtime target dataegret.com
  • 19. 17 pg_upgrade - minimizing downtime • Use pgbouncer PAUSE/RESUME Issue CHECKPOINT; on old server before you start, to make shutdown process faster • Use -k (–link) to use hard links instead of copy (but carefully!) dataegret.com
  • 20. 18 pg_upgrade - hot-standby replica • Upgrade master as a standalone server • Keep replica intact to failover if something goes wrong • Reinstantiate your replica • Procedure Pause pgbouncer on standby or stop it Clone a replica from upgraded master using pg_basebackup Start replica with new binaries Resume pgbouncer connections or start pgbouncer. dataegret.com
  • 21. 19 pg_upgrade - Details • pg_upgrade does not transfer optimizer statistics • instead, it generates a script ./analyze_new_cluster.sh It basically runs vacuumdb –all –analyze-in-stages In some cases it is better to run vacuumdb –all –analyze-only Since 9.5 you can vacuumdb run in parallel (-j) We usually use vacuumdb –all –analyze-in-stages and open database for application after medium optimizer statistics (10 targets) are generated dataegret.com
  • 22. 20 pg_upgrade - Details • Documentation suggests to use rsync to reinstantiate standby • rsync –archive –delete –hard-links –size-only old_pgdata new_pgdata remote_dir • rsync allows you to save a lot of network traffic in that case • ...and provides lots of opportunities to shoot yourself in the foot dataegret.com
  • 23. 21 pg_upgrade - Details • Debian/Ubuntu follow their own way • Wrappers, like pg_ctlcluster are designed to manipulate PostgreSQL cluster in a Debian way • pg_upgradecluster -v 9.5 9.3 main1 -m upgrade -k supposed to be a make-me-happy button for a DBA • It even takes care of converting postgresql.conf parameters for you • But I strongly recommend to do this manually dataegret.com
  • 24. 22 pg_upgrade - Details • Extensions can surprise you • pg_upgrade keeps old versions of extensions • We advise to cycle through all extensions and perform alter extension EXTENSION_NAME update; • Some extensions need special care: for example PostGIS should be updated before an upgrade dataegret.com
  • 25. 23 Using replication to upgrade PostgreSQL • Streaming replication doesn’t work between versions • But some replication methods can do that Logical replication Slony-I Londiste • Procedure Setup new database cluster Setup replication from old one to a new one Perform failover dataegret.com
  • 26. 24 Logical replication • New promising method • Allows you to upgrade from 9.4 to a newer version • It can be tricky: Check documentation carefully If you have a complex schema, you may need some wrapper, like https://github.com/rtshome/pgrepup Check what you replicate using pglogical.replication_set Don’t forget about sequences dataegret.com
  • 27. 25 Slony-I • Old and bulletproof • Can be used with old versions • Failover can be done really fast • Drawbacks Trigger based - can cause heavy load on old cluster Extra disk space is needed dataegret.com
  • 28. 26 Londiste • I’am not a big fan of Londiste • Same drawbacks as with Slony, but without Slony’s robustness • Lots of bugs (compared to Slony) • Tool was designed for a different purpose dataegret.com
  • 29. 27 Conclusion Method downtime extra disk space complexity riskiness dump/restore high double low low pg_upgrade (copy) high double high low pg_upgrade (link) low low high very high Logical replication low double high low Slony-I low double medium low Londiste low double medium low dataegret.com
  • 30. 28 Reading list • http://momjian.us/main/writings/pgsql/pg_upgrade.pdf • https://blog.2ndquadrant.com/untangling-the-postgresql-upgrade/ • http://blog.endpoint.com/2016/12/postgres-statistics-and-pain-of- analyze.html • https://www.depesz.com/2016/11/08/major-version-upgrading-with- minimal-downtime/ dataegret.com