SlideShare a Scribd company logo
1 of 24
Download to read offline
Rapid Upgrades With Pg_Upgrade
BRUCE MOMJIAN
January, 2015
Pg_Upgrade allows migration between major releases of Postgres
without a data dump/reload. This presentation explains how
pg_upgrade works.
Creative Commons Attribution License http://momjian.us/presentations
1 / 24
PostgreSQL the database…
◮ Open Source Object Relational DBMS since 1996
◮ Distributed under the PostgreSQL License
◮ Similar technical heritage as Oracle, SQL Server & DB2
◮ However, a strong adherence to standards (ANSI-SQL 2008)
◮ Highly extensible and adaptable design
◮ Languages, indexing, data types, etc.
◮ E.g. PostGIS, JSONB, SQL/MED
◮ Extensive use throughout the world for applications and
organizations of all types
◮ Bundled into Red Hat Enterprise Linux, Ubuntu, CentOS
and Amazon Linux
Rapid Upgrades With Pg_Upgrade 2 / 24
PostgreSQL the community…
◮ Independent community led by a Core Team of six
◮ Large, active and vibrant community
◮ www.postgresql.org
◮ Downloads, Mailing lists, Documentation
◮ Sponsors sampler:
◮ Google, Red Hat, VMWare, Skype, Salesforce, HP and
EnterpriseDB
◮ http://www.postgresql.org/community/
Rapid Upgrades With Pg_Upgrade 3 / 24
EnterpriseDB the company…
◮ The worldwide leader of Postgres based products and
services founded in 2004
◮ Customers include 50 of the Fortune 500 and 98 of the
Forbes Global 2000
◮ Enterprise offerings:
◮ PostgreSQL Support, Services and Training
◮ Postgres Plus Advanced Server with Oracle Compatibility
◮ Tools for Monitoring, Replication, HA, Backup & Recovery
Community
◮ Citizenship
◮ Contributor of key features: Materialized Views, JSON, &
more
◮ Nine community members on staff
Rapid Upgrades With Pg_Upgrade 4 / 24
EnterpriseDB the company…
Rapid Upgrades With Pg_Upgrade 5 / 24
Traditional Postgres Upgrade Options
◮ pg_dump (logical dump)/restore
◮ Slony
Rapid Upgrades With Pg_Upgrade 6 / 24
Why Upgrading Postgres Is Complex
◮ New features often require system table changes
◮ However, the internal data format rarely changes
Rapid Upgrades With Pg_Upgrade 7 / 24
Why Pg_Upgrade
◮ Very fast upgrades
◮ Optionally no additional disk space
pg_upgrade installs new system tables while using data files from
the previous Postgres version.
Rapid Upgrades With Pg_Upgrade 8 / 24
How It Works: Initial Setup
1
2
3 6
5
4 7
8
9
pg_class
User Tables and Indexes
15 21 27
262014
13 19 25
241812
17 2311
10 16 22
System Tables and Indexes
clog
Old Cluster
1
2
3 6
5
4 7
8
9
pg_class
User Tables and Indexes
System Tables and Indexes
clog
New Cluster
Rapid Upgrades With Pg_Upgrade 9 / 24
Decouple New Clog Via Freezing
1
2
3 6
5
4 7
8
9
pg_class
User Tables and Indexes
15 21 27
262014
13 19 25
241812
17 2311
10 16 22
System Tables and Indexes
clog
Old Cluster
1
2
3 6
4 7
8
9
pg_class
User Tables and Indexes
System Tables and Indexes
clog
New Cluster
5
Freeze
X X
Rapid Upgrades With Pg_Upgrade 10 / 24
Transfer Clog and XID
1
2
3 6
5
4 7
8
9
pg_class
User Tables and Indexes
15 21 27
262014
13 19 25
241812
17 2311
10 16 22
System Tables and Indexes
clog
Old Cluster
1
2
3 6
5
4 7
8
9
pg_class
User Tables and Indexes
System Tables and Indexes
clog
New Cluster
controldata controldataxid
Rapid Upgrades With Pg_Upgrade 11 / 24
Get Schema Dump
1
2
3 6
5
4 7
8
9
pg_class
User Tables and Indexes
15 21 27
262014
13 19 25
241812
17 2311
10 16 22
System Tables and Indexes
clog
Old Cluster
1
2
3 6
5
4 7
8
9
pg_class
User Tables and Indexes
System Tables and Indexes
clog
New Cluster
pg_dumpall − −schema
Rapid Upgrades With Pg_Upgrade 12 / 24
Restore Schema In New Cluster
1
2
3 6
5
4 7
8
9
pg_class
User Tables and Indexes
15 21 27
262014
13 19 25
241812
17 2311
10 16 22
System Tables and Indexes
clog
Old Cluster
1
2
3 6
5
4 7
8
9
pg_class
User Tables and Indexes
26
System Tables and Indexes
clog
New Cluster
pg_dumpall − −schema
17 23
24
25
27
18
10
11
12
13
14
15
16
19
20
21
22
Rapid Upgrades With Pg_Upgrade 13 / 24
Copy User Heap/Index Files
1
2
3 6
5
4 7
8
9
pg_class
User Tables and Indexes
15 21 27
262014
13 19 25
241812
17 2311
10 16 22
System Tables and Indexes
clog
Old Cluster
1
2
3 6
5
4 7
8
9
pg_class
User Tables and Indexes
26
System Tables and Indexes
clog
New Cluster
1610
11
13
12
14
15
19
20
21
22
23
24
25
27
18
17
Rapid Upgrades With Pg_Upgrade 14 / 24
Complete
1
2
3 6
5
4 7
8
9
pg_class
User Tables and Indexes
15 21 27
262014
13 19 25
241812
17 2311
10 16 22
System Tables and Indexes
clog
Old Cluster
1
2
3 6
5
4 7
8
9
pg_class
User Tables and Indexes
26
System Tables and Indexes
clog
New Cluster
24
25
27
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Rapid Upgrades With Pg_Upgrade 15 / 24
How It Works: In Detail
◮ Check for cluster compatability
◮ locale
◮ encoding
◮ Use pg_dumpall to dump old cluster schema (no data)
◮ Freeze all new cluster rows (remove reference to clog entries)
◮ New cluster uses old xid counter value (see freeze above)
◮ Set system table frozen xids to match the current xid
◮ Create new users/databases
◮ Collect cluster information
◮ Install support functions that call internal backend functions
◮ Create schema in new cluster
◮ Copy or link files from old cluster to new cluster
◮ Warn about any remaining issues, like REINDEX
requirements
Rapid Upgrades With Pg_Upgrade 16 / 24
Sample Run: Performing Consistency Checks
Performing Consistency Checks
-----------------------------
Checking current, bin, and data directories ok
Checking cluster versions ok
Checking database user is a superuser ok
Checking for prepared transactions ok
Checking for reg* system OID user data types ok
Checking for invalid indexes from concurrent index builds ok
Checking for contrib/isn with bigint-passing mismatch ok
Creating catalog dump ok
Checking for presence of required libraries ok
Checking database user is a superuser ok
Checking for prepared transactions ok
If pg_upgrade fails after this point, you must re-initdb the
new cluster before continuing.
Rapid Upgrades With Pg_Upgrade 17 / 24
Sample Run: Performing Migration
Performing Upgrade
------------------
Analyzing all rows in the new cluster ok
Freezing all rows on the new cluster ok
Deleting files from new pg_clog ok
Copying old pg_clog to new server ok
Setting next transaction ID for new cluster ok
Resetting WAL archives ok
Setting frozenxid counters in new cluster ok
Creating databases in the new cluster ok
Adding support functions to new cluster ok
Restoring database schema to new cluster ok
Removing support functions from new cluster ok
Adding ".old" suffix to old global/pg_control ok
If you want to start the old cluster, you will need to remove
the ".old" suffix from /u/pgsql.old/data/global/pg_control.old.
Because "link" mode was used, the old cluster cannot be safely
started once the new cluster has been started.
Linking user relation files
ok
Setting next OID for new cluster ok
Creating script to analyze new cluster okRapid Upgrades With Pg_Upgrade 18 / 24
Sample Run: Completion
Upgrade Complete
----------------
Optimizer statistics are not transferred by pg_upgrade so,
once you start the new server, consider running:
analyze_new_cluster.sh
Running this script will delete the old cluster’s data files:
delete_old_cluster.sh
Rapid Upgrades With Pg_Upgrade 19 / 24
Possible Data
Format Changes
Change Conversion Method
clog none
heap page header, including bitmask convert to new page format on read
tuple header, including bitmask convert to new page format on read
data value format create old data type in new cluster
index page format reindex, or recreate index methods
TOAST page format convert to new page format on read
Rapid Upgrades With Pg_Upgrade 20 / 24
Speed Comparison
Migration Method Minutes
dump/restore 300.0
dump with parallel restore 180.0
pg_upgrade in copy mode 44.0
pg_upgrade in link mode 0.7
Database size: 150GB, 850 tables
The last duration is 44 seconds.
Timings courtesy of
Stefan Kaltenbrunner
(mastermind on IRC)
Rapid Upgrades With Pg_Upgrade 21 / 24
Release History
◮ 9.0 focused on stability
◮ 9.1 focused on performance for databases with many
relations
◮ 9.2 focused on improved debugging and reliability for
non-standard configurations
◮ 9.3 focused on performance via parallelism and reduced
fsync activity
◮ 9.4 dramatically reduced memory usage
Rapid Upgrades With Pg_Upgrade 22 / 24
Additional Resources…
◮ Postgres Downloads:
◮ www.enterprisedb.com/downloads
◮ Product and Services information:
◮ info@enterprisedb.com
Rapid Upgrades With Pg_Upgrade 23 / 24
Conclusion
http://momjian.us/presentations
Rapid Upgrades With Pg_Upgrade 24 / 24

More Related Content

What's hot

A Deep Dive into Stateful Stream Processing in Structured Streaming with Tath...
A Deep Dive into Stateful Stream Processing in Structured Streaming with Tath...A Deep Dive into Stateful Stream Processing in Structured Streaming with Tath...
A Deep Dive into Stateful Stream Processing in Structured Streaming with Tath...Databricks
 
Kettleetltool 090522005630-phpapp01
Kettleetltool 090522005630-phpapp01Kettleetltool 090522005630-phpapp01
Kettleetltool 090522005630-phpapp01jade_22
 
Bluecat Iceberg Journey by Cory Darby
Bluecat Iceberg Journey by Cory DarbyBluecat Iceberg Journey by Cory Darby
Bluecat Iceberg Journey by Cory DarbyBrian Olsen
 
January 2016 Flink Community Update & Roadmap 2016
January 2016 Flink Community Update & Roadmap 2016January 2016 Flink Community Update & Roadmap 2016
January 2016 Flink Community Update & Roadmap 2016Robert Metzger
 
Delta: Building Merge on Read
Delta: Building Merge on ReadDelta: Building Merge on Read
Delta: Building Merge on ReadDatabricks
 
Containerized Stream Engine to Build Modern Delta Lake
Containerized Stream Engine to Build Modern Delta LakeContainerized Stream Engine to Build Modern Delta Lake
Containerized Stream Engine to Build Modern Delta LakeDatabricks
 
Java High Level Stream API
Java High Level Stream APIJava High Level Stream API
Java High Level Stream APIApache Apex
 
Apache CarbonData+Spark to realize data convergence and Unified high performa...
Apache CarbonData+Spark to realize data convergence and Unified high performa...Apache CarbonData+Spark to realize data convergence and Unified high performa...
Apache CarbonData+Spark to realize data convergence and Unified high performa...Tech Triveni
 
Relational databases for BigData
Relational databases for BigDataRelational databases for BigData
Relational databases for BigDataAlexander Tokarev
 
TPT connection Implementation in Informatica
TPT connection Implementation in InformaticaTPT connection Implementation in Informatica
TPT connection Implementation in InformaticaYagya Sharma
 
Introducing Apache Carbon Data - Hadoop Native Columnar Data Format
Introducing Apache Carbon Data - Hadoop Native Columnar Data FormatIntroducing Apache Carbon Data - Hadoop Native Columnar Data Format
Introducing Apache Carbon Data - Hadoop Native Columnar Data FormatVimal Das Kammath
 
Apache Spark for Library Developers with William Benton and Erik Erlandson
 Apache Spark for Library Developers with William Benton and Erik Erlandson Apache Spark for Library Developers with William Benton and Erik Erlandson
Apache Spark for Library Developers with William Benton and Erik ErlandsonDatabricks
 
Intro to Apache Apex - Next Gen Native Hadoop Platform - Hackac
Intro to Apache Apex - Next Gen Native Hadoop Platform - HackacIntro to Apache Apex - Next Gen Native Hadoop Platform - Hackac
Intro to Apache Apex - Next Gen Native Hadoop Platform - HackacApache Apex
 
DataTorrent Presentation @ Big Data Application Meetup
DataTorrent Presentation @ Big Data Application MeetupDataTorrent Presentation @ Big Data Application Meetup
DataTorrent Presentation @ Big Data Application MeetupThomas Weise
 
Common Strategies for Improving Performance on Your Delta Lakehouse
Common Strategies for Improving Performance on Your Delta LakehouseCommon Strategies for Improving Performance on Your Delta Lakehouse
Common Strategies for Improving Performance on Your Delta LakehouseDatabricks
 
Oracle 12.2 Domain Services Cluster
Oracle 12.2 Domain Services ClusterOracle 12.2 Domain Services Cluster
Oracle 12.2 Domain Services ClusterMarkus Flechtner
 
Bucketing 2.0: Improve Spark SQL Performance by Removing Shuffle
Bucketing 2.0: Improve Spark SQL Performance by Removing ShuffleBucketing 2.0: Improve Spark SQL Performance by Removing Shuffle
Bucketing 2.0: Improve Spark SQL Performance by Removing ShuffleDatabricks
 
Spark Summit EU talk by Ram Sriharsha and Vlad Feinberg
Spark Summit EU talk by Ram Sriharsha and Vlad FeinbergSpark Summit EU talk by Ram Sriharsha and Vlad Feinberg
Spark Summit EU talk by Ram Sriharsha and Vlad FeinbergSpark Summit
 
Working with informtiaca teradata parallel transporter
Working with informtiaca teradata parallel transporterWorking with informtiaca teradata parallel transporter
Working with informtiaca teradata parallel transporterAnjaneyulu Gunti
 
Real-time Stream Processing with Apache Flink
Real-time Stream Processing with Apache FlinkReal-time Stream Processing with Apache Flink
Real-time Stream Processing with Apache FlinkDataWorks Summit
 

What's hot (20)

A Deep Dive into Stateful Stream Processing in Structured Streaming with Tath...
A Deep Dive into Stateful Stream Processing in Structured Streaming with Tath...A Deep Dive into Stateful Stream Processing in Structured Streaming with Tath...
A Deep Dive into Stateful Stream Processing in Structured Streaming with Tath...
 
Kettleetltool 090522005630-phpapp01
Kettleetltool 090522005630-phpapp01Kettleetltool 090522005630-phpapp01
Kettleetltool 090522005630-phpapp01
 
Bluecat Iceberg Journey by Cory Darby
Bluecat Iceberg Journey by Cory DarbyBluecat Iceberg Journey by Cory Darby
Bluecat Iceberg Journey by Cory Darby
 
January 2016 Flink Community Update & Roadmap 2016
January 2016 Flink Community Update & Roadmap 2016January 2016 Flink Community Update & Roadmap 2016
January 2016 Flink Community Update & Roadmap 2016
 
Delta: Building Merge on Read
Delta: Building Merge on ReadDelta: Building Merge on Read
Delta: Building Merge on Read
 
Containerized Stream Engine to Build Modern Delta Lake
Containerized Stream Engine to Build Modern Delta LakeContainerized Stream Engine to Build Modern Delta Lake
Containerized Stream Engine to Build Modern Delta Lake
 
Java High Level Stream API
Java High Level Stream APIJava High Level Stream API
Java High Level Stream API
 
Apache CarbonData+Spark to realize data convergence and Unified high performa...
Apache CarbonData+Spark to realize data convergence and Unified high performa...Apache CarbonData+Spark to realize data convergence and Unified high performa...
Apache CarbonData+Spark to realize data convergence and Unified high performa...
 
Relational databases for BigData
Relational databases for BigDataRelational databases for BigData
Relational databases for BigData
 
TPT connection Implementation in Informatica
TPT connection Implementation in InformaticaTPT connection Implementation in Informatica
TPT connection Implementation in Informatica
 
Introducing Apache Carbon Data - Hadoop Native Columnar Data Format
Introducing Apache Carbon Data - Hadoop Native Columnar Data FormatIntroducing Apache Carbon Data - Hadoop Native Columnar Data Format
Introducing Apache Carbon Data - Hadoop Native Columnar Data Format
 
Apache Spark for Library Developers with William Benton and Erik Erlandson
 Apache Spark for Library Developers with William Benton and Erik Erlandson Apache Spark for Library Developers with William Benton and Erik Erlandson
Apache Spark for Library Developers with William Benton and Erik Erlandson
 
Intro to Apache Apex - Next Gen Native Hadoop Platform - Hackac
Intro to Apache Apex - Next Gen Native Hadoop Platform - HackacIntro to Apache Apex - Next Gen Native Hadoop Platform - Hackac
Intro to Apache Apex - Next Gen Native Hadoop Platform - Hackac
 
DataTorrent Presentation @ Big Data Application Meetup
DataTorrent Presentation @ Big Data Application MeetupDataTorrent Presentation @ Big Data Application Meetup
DataTorrent Presentation @ Big Data Application Meetup
 
Common Strategies for Improving Performance on Your Delta Lakehouse
Common Strategies for Improving Performance on Your Delta LakehouseCommon Strategies for Improving Performance on Your Delta Lakehouse
Common Strategies for Improving Performance on Your Delta Lakehouse
 
Oracle 12.2 Domain Services Cluster
Oracle 12.2 Domain Services ClusterOracle 12.2 Domain Services Cluster
Oracle 12.2 Domain Services Cluster
 
Bucketing 2.0: Improve Spark SQL Performance by Removing Shuffle
Bucketing 2.0: Improve Spark SQL Performance by Removing ShuffleBucketing 2.0: Improve Spark SQL Performance by Removing Shuffle
Bucketing 2.0: Improve Spark SQL Performance by Removing Shuffle
 
Spark Summit EU talk by Ram Sriharsha and Vlad Feinberg
Spark Summit EU talk by Ram Sriharsha and Vlad FeinbergSpark Summit EU talk by Ram Sriharsha and Vlad Feinberg
Spark Summit EU talk by Ram Sriharsha and Vlad Feinberg
 
Working with informtiaca teradata parallel transporter
Working with informtiaca teradata parallel transporterWorking with informtiaca teradata parallel transporter
Working with informtiaca teradata parallel transporter
 
Real-time Stream Processing with Apache Flink
Real-time Stream Processing with Apache FlinkReal-time Stream Processing with Apache Flink
Real-time Stream Processing with Apache Flink
 

Viewers also liked

Making.postgres.central.2015
Making.postgres.central.2015Making.postgres.central.2015
Making.postgres.central.2015EDB
 
Making the Most of Your Postgres Rollout
Making the Most of Your Postgres RolloutMaking the Most of Your Postgres Rollout
Making the Most of Your Postgres RolloutEDB
 
Which Postgres is Right for You?
Which Postgres is Right for You? Which Postgres is Right for You?
Which Postgres is Right for You? EDB
 
Non-Relational Postgres
Non-Relational PostgresNon-Relational Postgres
Non-Relational PostgresEDB
 
Which Postgres is Right for You? Part 3
Which Postgres is Right for You? Part 3Which Postgres is Right for You? Part 3
Which Postgres is Right for You? Part 3EDB
 
Best Practices for a Complete Postgres Enterprise Architecture Setup
Best Practices for a Complete Postgres Enterprise Architecture SetupBest Practices for a Complete Postgres Enterprise Architecture Setup
Best Practices for a Complete Postgres Enterprise Architecture SetupEDB
 
EDB Postgres with Containers
EDB Postgres with ContainersEDB Postgres with Containers
EDB Postgres with ContainersEDB
 
Mémoire - L’influence des programmes de customisation proposés par les marques
Mémoire - L’influence des programmes de customisation proposés par les marquesMémoire - L’influence des programmes de customisation proposés par les marques
Mémoire - L’influence des programmes de customisation proposés par les marquesAthomedia
 
Les chiffres clés de l'E-Mailing
Les chiffres clés de l'E-MailingLes chiffres clés de l'E-Mailing
Les chiffres clés de l'E-Mailingnextia
 

Viewers also liked (9)

Making.postgres.central.2015
Making.postgres.central.2015Making.postgres.central.2015
Making.postgres.central.2015
 
Making the Most of Your Postgres Rollout
Making the Most of Your Postgres RolloutMaking the Most of Your Postgres Rollout
Making the Most of Your Postgres Rollout
 
Which Postgres is Right for You?
Which Postgres is Right for You? Which Postgres is Right for You?
Which Postgres is Right for You?
 
Non-Relational Postgres
Non-Relational PostgresNon-Relational Postgres
Non-Relational Postgres
 
Which Postgres is Right for You? Part 3
Which Postgres is Right for You? Part 3Which Postgres is Right for You? Part 3
Which Postgres is Right for You? Part 3
 
Best Practices for a Complete Postgres Enterprise Architecture Setup
Best Practices for a Complete Postgres Enterprise Architecture SetupBest Practices for a Complete Postgres Enterprise Architecture Setup
Best Practices for a Complete Postgres Enterprise Architecture Setup
 
EDB Postgres with Containers
EDB Postgres with ContainersEDB Postgres with Containers
EDB Postgres with Containers
 
Mémoire - L’influence des programmes de customisation proposés par les marques
Mémoire - L’influence des programmes de customisation proposés par les marquesMémoire - L’influence des programmes de customisation proposés par les marques
Mémoire - L’influence des programmes de customisation proposés par les marques
 
Les chiffres clés de l'E-Mailing
Les chiffres clés de l'E-MailingLes chiffres clés de l'E-Mailing
Les chiffres clés de l'E-Mailing
 

Similar to Rapidly Upgrade Postgres with Pg_Upgrade

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
 
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...PostgreSQL-Consulting
 
Avi Apelbaum - RAC
Avi Apelbaum - RAC Avi Apelbaum - RAC
Avi Apelbaum - RAC gridcontrol
 
Checklist for Upgrades and Migrations
Checklist for Upgrades and MigrationsChecklist for Upgrades and Migrations
Checklist for Upgrades and MigrationsMarkus Flechtner
 
SAP Migration Overview
SAP Migration OverviewSAP Migration Overview
SAP Migration OverviewSitaram Kotnis
 
Moving Towards Better Upgrades in Kafka Streams
Moving Towards Better Upgrades in Kafka StreamsMoving Towards Better Upgrades in Kafka Streams
Moving Towards Better Upgrades in Kafka StreamsHostedbyConfluent
 
What's New in Postgres 9.4
What's New in Postgres 9.4What's New in Postgres 9.4
What's New in Postgres 9.4EDB
 
OSMC 2023 | What’s new with Grafana Labs’s Open Source Observability stack by...
OSMC 2023 | What’s new with Grafana Labs’s Open Source Observability stack by...OSMC 2023 | What’s new with Grafana Labs’s Open Source Observability stack by...
OSMC 2023 | What’s new with Grafana Labs’s Open Source Observability stack by...NETWAYS
 
Zero Downtime Schema Changes - Galera Cluster - Best Practices
Zero Downtime Schema Changes - Galera Cluster - Best PracticesZero Downtime Schema Changes - Galera Cluster - Best Practices
Zero Downtime Schema Changes - Galera Cluster - Best PracticesSeveralnines
 
2013_protect_presentation
2013_protect_presentation2013_protect_presentation
2013_protect_presentationJeff Holland
 
NoCOUG_201411_Patel_Managing_a_Large_OLTP_Database
NoCOUG_201411_Patel_Managing_a_Large_OLTP_DatabaseNoCOUG_201411_Patel_Managing_a_Large_OLTP_Database
NoCOUG_201411_Patel_Managing_a_Large_OLTP_DatabaseParesh Patel
 
Trivadis TechEvent 2017 PostgreSQL für die (Orakel) DBA by Ludovico Caldara
Trivadis TechEvent 2017 PostgreSQL für die (Orakel) DBA by Ludovico CaldaraTrivadis TechEvent 2017 PostgreSQL für die (Orakel) DBA by Ludovico Caldara
Trivadis TechEvent 2017 PostgreSQL für die (Orakel) DBA by Ludovico CaldaraTrivadis
 
CDC patterns in Apache Kafka®
CDC patterns in Apache Kafka®CDC patterns in Apache Kafka®
CDC patterns in Apache Kafka®confluent
 
Webinar - MariaDB Temporal Tables: a demonstration
Webinar - MariaDB Temporal Tables: a demonstrationWebinar - MariaDB Temporal Tables: a demonstration
Webinar - MariaDB Temporal Tables: a demonstrationFederico Razzoli
 
Steps for upgrading the database to 10g release 2
Steps for upgrading the database to 10g release 2Steps for upgrading the database to 10g release 2
Steps for upgrading the database to 10g release 2nesmaddy
 

Similar to Rapidly Upgrade Postgres with Pg_Upgrade (20)

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
 
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
 
Avi Apelbaum - RAC
Avi Apelbaum - RAC Avi Apelbaum - RAC
Avi Apelbaum - RAC
 
Checklist for Upgrades and Migrations
Checklist for Upgrades and MigrationsChecklist for Upgrades and Migrations
Checklist for Upgrades and Migrations
 
SAP Migration Overview
SAP Migration OverviewSAP Migration Overview
SAP Migration Overview
 
IUG ATL PC 9.5
IUG ATL PC 9.5IUG ATL PC 9.5
IUG ATL PC 9.5
 
Moving Towards Better Upgrades in Kafka Streams
Moving Towards Better Upgrades in Kafka StreamsMoving Towards Better Upgrades in Kafka Streams
Moving Towards Better Upgrades in Kafka Streams
 
What's New in Postgres 9.4
What's New in Postgres 9.4What's New in Postgres 9.4
What's New in Postgres 9.4
 
OSMC 2023 | What’s new with Grafana Labs’s Open Source Observability stack by...
OSMC 2023 | What’s new with Grafana Labs’s Open Source Observability stack by...OSMC 2023 | What’s new with Grafana Labs’s Open Source Observability stack by...
OSMC 2023 | What’s new with Grafana Labs’s Open Source Observability stack by...
 
Zero Downtime Schema Changes in Galera Cluster
Zero Downtime Schema Changes in Galera ClusterZero Downtime Schema Changes in Galera Cluster
Zero Downtime Schema Changes in Galera Cluster
 
Zero Downtime Schema Changes - Galera Cluster - Best Practices
Zero Downtime Schema Changes - Galera Cluster - Best PracticesZero Downtime Schema Changes - Galera Cluster - Best Practices
Zero Downtime Schema Changes - Galera Cluster - Best Practices
 
2013_protect_presentation
2013_protect_presentation2013_protect_presentation
2013_protect_presentation
 
NoCOUG_201411_Patel_Managing_a_Large_OLTP_Database
NoCOUG_201411_Patel_Managing_a_Large_OLTP_DatabaseNoCOUG_201411_Patel_Managing_a_Large_OLTP_Database
NoCOUG_201411_Patel_Managing_a_Large_OLTP_Database
 
Trivadis TechEvent 2017 PostgreSQL für die (Orakel) DBA by Ludovico Caldara
Trivadis TechEvent 2017 PostgreSQL für die (Orakel) DBA by Ludovico CaldaraTrivadis TechEvent 2017 PostgreSQL für die (Orakel) DBA by Ludovico Caldara
Trivadis TechEvent 2017 PostgreSQL für die (Orakel) DBA by Ludovico Caldara
 
Upgrading 11i E-business Suite to R12 E-business Suite
Upgrading 11i E-business Suite to R12 E-business SuiteUpgrading 11i E-business Suite to R12 E-business Suite
Upgrading 11i E-business Suite to R12 E-business Suite
 
Learning postgresql
Learning postgresqlLearning postgresql
Learning postgresql
 
CDC patterns in Apache Kafka®
CDC patterns in Apache Kafka®CDC patterns in Apache Kafka®
CDC patterns in Apache Kafka®
 
Webinar - MariaDB Temporal Tables: a demonstration
Webinar - MariaDB Temporal Tables: a demonstrationWebinar - MariaDB Temporal Tables: a demonstration
Webinar - MariaDB Temporal Tables: a demonstration
 
Gg steps
Gg stepsGg steps
Gg steps
 
Steps for upgrading the database to 10g release 2
Steps for upgrading the database to 10g release 2Steps for upgrading the database to 10g release 2
Steps for upgrading the database to 10g release 2
 

More from EDB

Cloud Migration Paths: Kubernetes, IaaS, or DBaaS
Cloud Migration Paths: Kubernetes, IaaS, or DBaaSCloud Migration Paths: Kubernetes, IaaS, or DBaaS
Cloud Migration Paths: Kubernetes, IaaS, or DBaaSEDB
 
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr UnternehmenDie 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr UnternehmenEDB
 
Migre sus bases de datos Oracle a la nube
Migre sus bases de datos Oracle a la nube Migre sus bases de datos Oracle a la nube
Migre sus bases de datos Oracle a la nube EDB
 
EFM Office Hours - APJ - July 29, 2021
EFM Office Hours - APJ - July 29, 2021EFM Office Hours - APJ - July 29, 2021
EFM Office Hours - APJ - July 29, 2021EDB
 
Benchmarking Cloud Native PostgreSQL
Benchmarking Cloud Native PostgreSQLBenchmarking Cloud Native PostgreSQL
Benchmarking Cloud Native PostgreSQLEDB
 
Las Variaciones de la Replicación de PostgreSQL
Las Variaciones de la Replicación de PostgreSQLLas Variaciones de la Replicación de PostgreSQL
Las Variaciones de la Replicación de PostgreSQLEDB
 
NoSQL and Spatial Database Capabilities using PostgreSQL
NoSQL and Spatial Database Capabilities using PostgreSQLNoSQL and Spatial Database Capabilities using PostgreSQL
NoSQL and Spatial Database Capabilities using PostgreSQLEDB
 
Is There Anything PgBouncer Can’t Do?
Is There Anything PgBouncer Can’t Do?Is There Anything PgBouncer Can’t Do?
Is There Anything PgBouncer Can’t Do?EDB
 
Data Analysis with TensorFlow in PostgreSQL
Data Analysis with TensorFlow in PostgreSQLData Analysis with TensorFlow in PostgreSQL
Data Analysis with TensorFlow in PostgreSQLEDB
 
Practical Partitioning in Production with Postgres
Practical Partitioning in Production with PostgresPractical Partitioning in Production with Postgres
Practical Partitioning in Production with PostgresEDB
 
A Deeper Dive into EXPLAIN
A Deeper Dive into EXPLAINA Deeper Dive into EXPLAIN
A Deeper Dive into EXPLAINEDB
 
IOT with PostgreSQL
IOT with PostgreSQLIOT with PostgreSQL
IOT with PostgreSQLEDB
 
A Journey from Oracle to PostgreSQL
A Journey from Oracle to PostgreSQLA Journey from Oracle to PostgreSQL
A Journey from Oracle to PostgreSQLEDB
 
Psql is awesome!
Psql is awesome!Psql is awesome!
Psql is awesome!EDB
 
EDB 13 - New Enhancements for Security and Usability - APJ
EDB 13 - New Enhancements for Security and Usability - APJEDB 13 - New Enhancements for Security and Usability - APJ
EDB 13 - New Enhancements for Security and Usability - APJEDB
 
Comment sauvegarder correctement vos données
Comment sauvegarder correctement vos donnéesComment sauvegarder correctement vos données
Comment sauvegarder correctement vos donnéesEDB
 
Cloud Native PostgreSQL - Italiano
Cloud Native PostgreSQL - ItalianoCloud Native PostgreSQL - Italiano
Cloud Native PostgreSQL - ItalianoEDB
 
New enhancements for security and usability in EDB 13
New enhancements for security and usability in EDB 13New enhancements for security and usability in EDB 13
New enhancements for security and usability in EDB 13EDB
 
Best Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQLBest Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQLEDB
 
Cloud Native PostgreSQL - APJ
Cloud Native PostgreSQL - APJCloud Native PostgreSQL - APJ
Cloud Native PostgreSQL - APJEDB
 

More from EDB (20)

Cloud Migration Paths: Kubernetes, IaaS, or DBaaS
Cloud Migration Paths: Kubernetes, IaaS, or DBaaSCloud Migration Paths: Kubernetes, IaaS, or DBaaS
Cloud Migration Paths: Kubernetes, IaaS, or DBaaS
 
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr UnternehmenDie 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
 
Migre sus bases de datos Oracle a la nube
Migre sus bases de datos Oracle a la nube Migre sus bases de datos Oracle a la nube
Migre sus bases de datos Oracle a la nube
 
EFM Office Hours - APJ - July 29, 2021
EFM Office Hours - APJ - July 29, 2021EFM Office Hours - APJ - July 29, 2021
EFM Office Hours - APJ - July 29, 2021
 
Benchmarking Cloud Native PostgreSQL
Benchmarking Cloud Native PostgreSQLBenchmarking Cloud Native PostgreSQL
Benchmarking Cloud Native PostgreSQL
 
Las Variaciones de la Replicación de PostgreSQL
Las Variaciones de la Replicación de PostgreSQLLas Variaciones de la Replicación de PostgreSQL
Las Variaciones de la Replicación de PostgreSQL
 
NoSQL and Spatial Database Capabilities using PostgreSQL
NoSQL and Spatial Database Capabilities using PostgreSQLNoSQL and Spatial Database Capabilities using PostgreSQL
NoSQL and Spatial Database Capabilities using PostgreSQL
 
Is There Anything PgBouncer Can’t Do?
Is There Anything PgBouncer Can’t Do?Is There Anything PgBouncer Can’t Do?
Is There Anything PgBouncer Can’t Do?
 
Data Analysis with TensorFlow in PostgreSQL
Data Analysis with TensorFlow in PostgreSQLData Analysis with TensorFlow in PostgreSQL
Data Analysis with TensorFlow in PostgreSQL
 
Practical Partitioning in Production with Postgres
Practical Partitioning in Production with PostgresPractical Partitioning in Production with Postgres
Practical Partitioning in Production with Postgres
 
A Deeper Dive into EXPLAIN
A Deeper Dive into EXPLAINA Deeper Dive into EXPLAIN
A Deeper Dive into EXPLAIN
 
IOT with PostgreSQL
IOT with PostgreSQLIOT with PostgreSQL
IOT with PostgreSQL
 
A Journey from Oracle to PostgreSQL
A Journey from Oracle to PostgreSQLA Journey from Oracle to PostgreSQL
A Journey from Oracle to PostgreSQL
 
Psql is awesome!
Psql is awesome!Psql is awesome!
Psql is awesome!
 
EDB 13 - New Enhancements for Security and Usability - APJ
EDB 13 - New Enhancements for Security and Usability - APJEDB 13 - New Enhancements for Security and Usability - APJ
EDB 13 - New Enhancements for Security and Usability - APJ
 
Comment sauvegarder correctement vos données
Comment sauvegarder correctement vos donnéesComment sauvegarder correctement vos données
Comment sauvegarder correctement vos données
 
Cloud Native PostgreSQL - Italiano
Cloud Native PostgreSQL - ItalianoCloud Native PostgreSQL - Italiano
Cloud Native PostgreSQL - Italiano
 
New enhancements for security and usability in EDB 13
New enhancements for security and usability in EDB 13New enhancements for security and usability in EDB 13
New enhancements for security and usability in EDB 13
 
Best Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQLBest Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQL
 
Cloud Native PostgreSQL - APJ
Cloud Native PostgreSQL - APJCloud Native PostgreSQL - APJ
Cloud Native PostgreSQL - APJ
 

Rapidly Upgrade Postgres with Pg_Upgrade

  • 1. Rapid Upgrades With Pg_Upgrade BRUCE MOMJIAN January, 2015 Pg_Upgrade allows migration between major releases of Postgres without a data dump/reload. This presentation explains how pg_upgrade works. Creative Commons Attribution License http://momjian.us/presentations 1 / 24
  • 2. PostgreSQL the database… ◮ Open Source Object Relational DBMS since 1996 ◮ Distributed under the PostgreSQL License ◮ Similar technical heritage as Oracle, SQL Server & DB2 ◮ However, a strong adherence to standards (ANSI-SQL 2008) ◮ Highly extensible and adaptable design ◮ Languages, indexing, data types, etc. ◮ E.g. PostGIS, JSONB, SQL/MED ◮ Extensive use throughout the world for applications and organizations of all types ◮ Bundled into Red Hat Enterprise Linux, Ubuntu, CentOS and Amazon Linux Rapid Upgrades With Pg_Upgrade 2 / 24
  • 3. PostgreSQL the community… ◮ Independent community led by a Core Team of six ◮ Large, active and vibrant community ◮ www.postgresql.org ◮ Downloads, Mailing lists, Documentation ◮ Sponsors sampler: ◮ Google, Red Hat, VMWare, Skype, Salesforce, HP and EnterpriseDB ◮ http://www.postgresql.org/community/ Rapid Upgrades With Pg_Upgrade 3 / 24
  • 4. EnterpriseDB the company… ◮ The worldwide leader of Postgres based products and services founded in 2004 ◮ Customers include 50 of the Fortune 500 and 98 of the Forbes Global 2000 ◮ Enterprise offerings: ◮ PostgreSQL Support, Services and Training ◮ Postgres Plus Advanced Server with Oracle Compatibility ◮ Tools for Monitoring, Replication, HA, Backup & Recovery Community ◮ Citizenship ◮ Contributor of key features: Materialized Views, JSON, & more ◮ Nine community members on staff Rapid Upgrades With Pg_Upgrade 4 / 24
  • 5. EnterpriseDB the company… Rapid Upgrades With Pg_Upgrade 5 / 24
  • 6. Traditional Postgres Upgrade Options ◮ pg_dump (logical dump)/restore ◮ Slony Rapid Upgrades With Pg_Upgrade 6 / 24
  • 7. Why Upgrading Postgres Is Complex ◮ New features often require system table changes ◮ However, the internal data format rarely changes Rapid Upgrades With Pg_Upgrade 7 / 24
  • 8. Why Pg_Upgrade ◮ Very fast upgrades ◮ Optionally no additional disk space pg_upgrade installs new system tables while using data files from the previous Postgres version. Rapid Upgrades With Pg_Upgrade 8 / 24
  • 9. How It Works: Initial Setup 1 2 3 6 5 4 7 8 9 pg_class User Tables and Indexes 15 21 27 262014 13 19 25 241812 17 2311 10 16 22 System Tables and Indexes clog Old Cluster 1 2 3 6 5 4 7 8 9 pg_class User Tables and Indexes System Tables and Indexes clog New Cluster Rapid Upgrades With Pg_Upgrade 9 / 24
  • 10. Decouple New Clog Via Freezing 1 2 3 6 5 4 7 8 9 pg_class User Tables and Indexes 15 21 27 262014 13 19 25 241812 17 2311 10 16 22 System Tables and Indexes clog Old Cluster 1 2 3 6 4 7 8 9 pg_class User Tables and Indexes System Tables and Indexes clog New Cluster 5 Freeze X X Rapid Upgrades With Pg_Upgrade 10 / 24
  • 11. Transfer Clog and XID 1 2 3 6 5 4 7 8 9 pg_class User Tables and Indexes 15 21 27 262014 13 19 25 241812 17 2311 10 16 22 System Tables and Indexes clog Old Cluster 1 2 3 6 5 4 7 8 9 pg_class User Tables and Indexes System Tables and Indexes clog New Cluster controldata controldataxid Rapid Upgrades With Pg_Upgrade 11 / 24
  • 12. Get Schema Dump 1 2 3 6 5 4 7 8 9 pg_class User Tables and Indexes 15 21 27 262014 13 19 25 241812 17 2311 10 16 22 System Tables and Indexes clog Old Cluster 1 2 3 6 5 4 7 8 9 pg_class User Tables and Indexes System Tables and Indexes clog New Cluster pg_dumpall − −schema Rapid Upgrades With Pg_Upgrade 12 / 24
  • 13. Restore Schema In New Cluster 1 2 3 6 5 4 7 8 9 pg_class User Tables and Indexes 15 21 27 262014 13 19 25 241812 17 2311 10 16 22 System Tables and Indexes clog Old Cluster 1 2 3 6 5 4 7 8 9 pg_class User Tables and Indexes 26 System Tables and Indexes clog New Cluster pg_dumpall − −schema 17 23 24 25 27 18 10 11 12 13 14 15 16 19 20 21 22 Rapid Upgrades With Pg_Upgrade 13 / 24
  • 14. Copy User Heap/Index Files 1 2 3 6 5 4 7 8 9 pg_class User Tables and Indexes 15 21 27 262014 13 19 25 241812 17 2311 10 16 22 System Tables and Indexes clog Old Cluster 1 2 3 6 5 4 7 8 9 pg_class User Tables and Indexes 26 System Tables and Indexes clog New Cluster 1610 11 13 12 14 15 19 20 21 22 23 24 25 27 18 17 Rapid Upgrades With Pg_Upgrade 14 / 24
  • 15. Complete 1 2 3 6 5 4 7 8 9 pg_class User Tables and Indexes 15 21 27 262014 13 19 25 241812 17 2311 10 16 22 System Tables and Indexes clog Old Cluster 1 2 3 6 5 4 7 8 9 pg_class User Tables and Indexes 26 System Tables and Indexes clog New Cluster 24 25 27 10 11 12 13 14 15 16 17 18 19 20 21 22 23 Rapid Upgrades With Pg_Upgrade 15 / 24
  • 16. How It Works: In Detail ◮ Check for cluster compatability ◮ locale ◮ encoding ◮ Use pg_dumpall to dump old cluster schema (no data) ◮ Freeze all new cluster rows (remove reference to clog entries) ◮ New cluster uses old xid counter value (see freeze above) ◮ Set system table frozen xids to match the current xid ◮ Create new users/databases ◮ Collect cluster information ◮ Install support functions that call internal backend functions ◮ Create schema in new cluster ◮ Copy or link files from old cluster to new cluster ◮ Warn about any remaining issues, like REINDEX requirements Rapid Upgrades With Pg_Upgrade 16 / 24
  • 17. Sample Run: Performing Consistency Checks Performing Consistency Checks ----------------------------- Checking current, bin, and data directories ok Checking cluster versions ok Checking database user is a superuser ok Checking for prepared transactions ok Checking for reg* system OID user data types ok Checking for invalid indexes from concurrent index builds ok Checking for contrib/isn with bigint-passing mismatch ok Creating catalog dump ok Checking for presence of required libraries ok Checking database user is a superuser ok Checking for prepared transactions ok If pg_upgrade fails after this point, you must re-initdb the new cluster before continuing. Rapid Upgrades With Pg_Upgrade 17 / 24
  • 18. Sample Run: Performing Migration Performing Upgrade ------------------ Analyzing all rows in the new cluster ok Freezing all rows on the new cluster ok Deleting files from new pg_clog ok Copying old pg_clog to new server ok Setting next transaction ID for new cluster ok Resetting WAL archives ok Setting frozenxid counters in new cluster ok Creating databases in the new cluster ok Adding support functions to new cluster ok Restoring database schema to new cluster ok Removing support functions from new cluster ok Adding ".old" suffix to old global/pg_control ok If you want to start the old cluster, you will need to remove the ".old" suffix from /u/pgsql.old/data/global/pg_control.old. Because "link" mode was used, the old cluster cannot be safely started once the new cluster has been started. Linking user relation files ok Setting next OID for new cluster ok Creating script to analyze new cluster okRapid Upgrades With Pg_Upgrade 18 / 24
  • 19. Sample Run: Completion Upgrade Complete ---------------- Optimizer statistics are not transferred by pg_upgrade so, once you start the new server, consider running: analyze_new_cluster.sh Running this script will delete the old cluster’s data files: delete_old_cluster.sh Rapid Upgrades With Pg_Upgrade 19 / 24
  • 20. Possible Data Format Changes Change Conversion Method clog none heap page header, including bitmask convert to new page format on read tuple header, including bitmask convert to new page format on read data value format create old data type in new cluster index page format reindex, or recreate index methods TOAST page format convert to new page format on read Rapid Upgrades With Pg_Upgrade 20 / 24
  • 21. Speed Comparison Migration Method Minutes dump/restore 300.0 dump with parallel restore 180.0 pg_upgrade in copy mode 44.0 pg_upgrade in link mode 0.7 Database size: 150GB, 850 tables The last duration is 44 seconds. Timings courtesy of Stefan Kaltenbrunner (mastermind on IRC) Rapid Upgrades With Pg_Upgrade 21 / 24
  • 22. Release History ◮ 9.0 focused on stability ◮ 9.1 focused on performance for databases with many relations ◮ 9.2 focused on improved debugging and reliability for non-standard configurations ◮ 9.3 focused on performance via parallelism and reduced fsync activity ◮ 9.4 dramatically reduced memory usage Rapid Upgrades With Pg_Upgrade 22 / 24
  • 23. Additional Resources… ◮ Postgres Downloads: ◮ www.enterprisedb.com/downloads ◮ Product and Services information: ◮ info@enterprisedb.com Rapid Upgrades With Pg_Upgrade 23 / 24