SlideShare a Scribd company logo
1 of 31
Download to read 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

More Related Content

What's hot

Monitoring Oracle Database Instances with Zabbix
Monitoring Oracle Database Instances with ZabbixMonitoring Oracle Database Instances with Zabbix
Monitoring Oracle Database Instances with ZabbixGerger
 
YugaByte DB Internals - Storage Engine and Transactions
YugaByte DB Internals - Storage Engine and Transactions YugaByte DB Internals - Storage Engine and Transactions
YugaByte DB Internals - Storage Engine and Transactions Yugabyte
 
PostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized WorldPostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized WorldJignesh Shah
 
Deep Dive on Amazon Aurora PostgreSQL Performance Tuning (DAT428-R1) - AWS re...
Deep Dive on Amazon Aurora PostgreSQL Performance Tuning (DAT428-R1) - AWS re...Deep Dive on Amazon Aurora PostgreSQL Performance Tuning (DAT428-R1) - AWS re...
Deep Dive on Amazon Aurora PostgreSQL Performance Tuning (DAT428-R1) - AWS re...Amazon Web Services
 
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the CloudAmazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the CloudNoritaka Sekiyama
 
Connection Pooling in PostgreSQL using pgbouncer
Connection Pooling in PostgreSQL using pgbouncer Connection Pooling in PostgreSQL using pgbouncer
Connection Pooling in PostgreSQL using pgbouncer Sameer Kumar
 
How to Manage Scale-Out Environments with MariaDB MaxScale
How to Manage Scale-Out Environments with MariaDB MaxScaleHow to Manage Scale-Out Environments with MariaDB MaxScale
How to Manage Scale-Out Environments with MariaDB MaxScaleMariaDB plc
 
Parquet performance tuning: the missing guide
Parquet performance tuning: the missing guideParquet performance tuning: the missing guide
Parquet performance tuning: the missing guideRyan Blue
 
Postgresql database administration volume 1
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1Federico Campoli
 
The Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization OpportunitiesThe Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization OpportunitiesDatabricks
 
Fundamentals of Apache Kafka
Fundamentals of Apache KafkaFundamentals of Apache Kafka
Fundamentals of Apache KafkaChhavi Parasher
 
私はここでつまづいた! Oracle database 11g から 12cへのアップグレードと Oracle Database 12c の新機能@201...
私はここでつまづいた! Oracle database 11g から 12cへのアップグレードと Oracle Database 12c の新機能@201...私はここでつまづいた! Oracle database 11g から 12cへのアップグレードと Oracle Database 12c の新機能@201...
私はここでつまづいた! Oracle database 11g から 12cへのアップグレードと Oracle Database 12c の新機能@201...yoshimotot
 
MongoDB Internals
MongoDB InternalsMongoDB Internals
MongoDB InternalsSiraj Memon
 
Postgresql Database Administration- Day3
Postgresql Database Administration- Day3Postgresql Database Administration- Day3
Postgresql Database Administration- Day3PoguttuezhiniVP
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL AdministrationEDB
 

What's hot (20)

Monitoring Oracle Database Instances with Zabbix
Monitoring Oracle Database Instances with ZabbixMonitoring Oracle Database Instances with Zabbix
Monitoring Oracle Database Instances with Zabbix
 
YugaByte DB Internals - Storage Engine and Transactions
YugaByte DB Internals - Storage Engine and Transactions YugaByte DB Internals - Storage Engine and Transactions
YugaByte DB Internals - Storage Engine and Transactions
 
PostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized WorldPostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized World
 
Deep Dive on Amazon Aurora PostgreSQL Performance Tuning (DAT428-R1) - AWS re...
Deep Dive on Amazon Aurora PostgreSQL Performance Tuning (DAT428-R1) - AWS re...Deep Dive on Amazon Aurora PostgreSQL Performance Tuning (DAT428-R1) - AWS re...
Deep Dive on Amazon Aurora PostgreSQL Performance Tuning (DAT428-R1) - AWS re...
 
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the CloudAmazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
 
ORC Deep Dive 2020
ORC Deep Dive 2020ORC Deep Dive 2020
ORC Deep Dive 2020
 
Connection Pooling in PostgreSQL using pgbouncer
Connection Pooling in PostgreSQL using pgbouncer Connection Pooling in PostgreSQL using pgbouncer
Connection Pooling in PostgreSQL using pgbouncer
 
How to Manage Scale-Out Environments with MariaDB MaxScale
How to Manage Scale-Out Environments with MariaDB MaxScaleHow to Manage Scale-Out Environments with MariaDB MaxScale
How to Manage Scale-Out Environments with MariaDB MaxScale
 
5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance
 
Parquet performance tuning: the missing guide
Parquet performance tuning: the missing guideParquet performance tuning: the missing guide
Parquet performance tuning: the missing guide
 
Get to know PostgreSQL!
Get to know PostgreSQL!Get to know PostgreSQL!
Get to know PostgreSQL!
 
PostgreSQL replication
PostgreSQL replicationPostgreSQL replication
PostgreSQL replication
 
Postgresql database administration volume 1
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1
 
The Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization OpportunitiesThe Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization Opportunities
 
Fundamentals of Apache Kafka
Fundamentals of Apache KafkaFundamentals of Apache Kafka
Fundamentals of Apache Kafka
 
私はここでつまづいた! Oracle database 11g から 12cへのアップグレードと Oracle Database 12c の新機能@201...
私はここでつまづいた! Oracle database 11g から 12cへのアップグレードと Oracle Database 12c の新機能@201...私はここでつまづいた! Oracle database 11g から 12cへのアップグレードと Oracle Database 12c の新機能@201...
私はここでつまづいた! Oracle database 11g から 12cへのアップグレードと Oracle Database 12c の新機能@201...
 
MongoDB Internals
MongoDB InternalsMongoDB Internals
MongoDB Internals
 
Postgresql Database Administration- Day3
Postgresql Database Administration- Day3Postgresql Database Administration- Day3
Postgresql Database Administration- Day3
 
Deep Dive on Amazon Aurora
Deep Dive on Amazon AuroraDeep Dive on Amazon Aurora
Deep Dive on Amazon Aurora
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL Administration
 

Similar to 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 KubernetesJonathan 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 MomjianFuenteovejuna
 
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 CloudEDB
 
Pg upgrade employer
Pg upgrade employerPg upgrade employer
Pg upgrade employerEDB
 
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 2018Jonathan Katz
 
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 downtimeOlivier DASINI
 
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.3EDB
 
TechEvent PostgreSQL Best Practices
TechEvent PostgreSQL Best PracticesTechEvent PostgreSQL Best Practices
TechEvent PostgreSQL Best PracticesTrivadis
 
Overview of Postgres Utility Processes
Overview of Postgres Utility ProcessesOverview of Postgres Utility Processes
Overview of Postgres Utility ProcessesEDB
 
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.2Dana Elisabeth Groce
 
Postgre sql best_practices
Postgre sql best_practicesPostgre sql best_practices
Postgre sql best_practicesJacques Kostic
 
Openstack hk-summit-upgrades-talk
Openstack hk-summit-upgrades-talkOpenstack hk-summit-upgrades-talk
Openstack hk-summit-upgrades-talkBuvanesh Kumar
 
Checklist for Upgrades and Migrations
Checklist for Upgrades and MigrationsChecklist for Upgrades and Migrations
Checklist for Upgrades and MigrationsMarkus Flechtner
 
ProstgreSQLFailoverConfiguration
ProstgreSQLFailoverConfigurationProstgreSQLFailoverConfiguration
ProstgreSQLFailoverConfigurationSuyog Shirgaonkar
 
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: CloudNativePGNick Ivanov
 
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 MeetupKaxil Naik
 
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 ConnectionsLetsConnect
 

Similar to 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
 

More from PostgreSQL-Consulting

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-Consulting
 
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 KosmodemianskyPostgreSQL-Consulting
 
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 2016PostgreSQL-Consulting
 
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 PostgreSQLPostgreSQL-Consulting
 
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 ViennaPostgreSQL-Consulting
 
PostgreSQL Meetup Berlin at Zalando HQ
PostgreSQL Meetup Berlin at Zalando HQPostgreSQL Meetup Berlin at Zalando HQ
PostgreSQL Meetup Berlin at Zalando HQPostgreSQL-Consulting
 
Как PostgreSQL работает с диском
Как PostgreSQL работает с дискомКак PostgreSQL работает с диском
Как PostgreSQL работает с дискомPostgreSQL-Consulting
 
Максим Богук. Postgres-XC
Максим Богук. Postgres-XCМаксим Богук. Postgres-XC
Максим Богук. Postgres-XCPostgreSQL-Consulting
 
Илья Космодемьянский. Использование очередей асинхронных сообщений с PostgreSQL
Илья Космодемьянский. Использование очередей асинхронных сообщений с PostgreSQLИлья Космодемьянский. Использование очередей асинхронных сообщений с PostgreSQL
Илья Космодемьянский. Использование очередей асинхронных сообщений с PostgreSQLPostgreSQL-Consulting
 

More from 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
 
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
 
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
 
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
 

Recently uploaded

Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Comparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization TechniquesComparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization Techniquesugginaramesh
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 

Recently uploaded (20)

Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Comparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization TechniquesComparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization Techniques
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 

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