{"id":37816,"date":"2025-03-28T15:15:06","date_gmt":"2025-03-28T14:15:06","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/?p=37816"},"modified":"2025-03-28T15:15:06","modified_gmt":"2025-03-28T14:15:06","slug":"postgresql-18-swap-mode-for-pg_upgrade","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/postgresql-18-swap-mode-for-pg_upgrade\/","title":{"rendered":"PostgreSQL 18: &#8220;swap&#8221; mode for pg_upgrade"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">When you want to upgrade from one major version of PostgreSQL to another you probably want to go with <a href=\"https:\/\/www.postgresql.org\/docs\/17\/pgupgrade.html\" target=\"_blank\" rel=\"noreferrer noopener\">pg_upgrade<\/a> (or logical replication). There are several modes of operations for this already:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>&#8211;copy: Copy the data files from the old to the new cluster<\/li>\n\n\n\n<li>&#8211;clone: Clone, instead of copying (when the file system supports it)<\/li>\n\n\n\n<li>&#8211;copy-file-range: Use the copy_file_range system call for efficient copying, if the file system supports it<\/li>\n\n\n\n<li>&#8211;link: Use hard links instead of copying files<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">What is best for you, depends on the requirements. We usually go with &#8220;&#8211;link&#8221; as this is pretty fast, but you can only do that if the old and the new cluster are in the same file system. The downside is, that you cannot anymore use the old cluster once the new cluster is started up.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With PostgreSQL 18 there will probably a new option called &#8220;&#8211;swap&#8221;. This mode, instead of linking or copying the files, moves the files from the old to the new cluster and then replaces the catalog files with the ones from the new cluster. The reason for this additional mode (see the link to the commit at the end of this post) is, that this might outperform even &#8220;&#8211;link&#8221; mode (and the others) when a cluster contains many relations.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s see if we can prove this by creating two new PostgreSQL 17 clusters with many relations:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; highlight: [1,3,12,13,16]; title: ; notranslate\" title=\"\">\npostgres@pgbox:\/home\/postgres\/ &#x5B;172] initdb --version\ninitdb (PostgreSQL) 17.2 \npostgres@pgbox:\/home\/postgres\/ &#x5B;172] initdb -D \/var\/tmp\/dummy\/17.2_1 --data-checksums\nThe files belonging to this database system will be owned by user &quot;postgres&quot;.\nThis user must also own the server process.\n...\n\nSuccess. You can now start the database server using:\n\n  pg_ctl -D \/var\/tmp\/17.2 -l logfile start\n\npostgres@pgbox:\/home\/postgres\/ &#x5B;172] echo &quot;port=8888&quot; &gt;&gt; \/var\/tmp\/dummy\/17.2_1\/postgresql.auto.conf \npostgres@pgbox:\/home\/postgres\/ &#x5B;172] pg_ctl --pgdata=\/var\/tmp\/dummy\/17.2_1 start -l \/dev\/null\nwaiting for server to start.... done\nserver started\npostgres@pgbox:\/home\/postgres\/ &#x5B;172] psql -p 8888 -l\n                                                     List of databases\n   Name    |  Owner   | Encoding | Locale Provider |   Collate   |    Ctype    | Locale | ICU Rules |   Access privileges   \n-----------+----------+----------+-----------------+-------------+-------------+--------+-----------+-----------------------\n postgres  | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |        |           | \n template0 | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |        |           | =c\/postgres          +\n           |          |          |                 |             |             |        |           | postgres=CTc\/postgres\n template1 | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |        |           | =c\/postgres          +\n           |          |          |                 |             |             |        |           | postgres=CTc\/postgres\n(3 rows)\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Here is a little script that creates some tables, indexes and a bit of data:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n#!\/bin\/bash\n\nfor i in {1..10000}; do\n    psql -p 8888 -c &quot;create table t${i} ( a int, b text )&quot;\n    psql -p 8888 -c &quot;insert into t${i} select i, i::text from generate_series(1,1000) i;&quot;\n    psql -p 8888 -c &quot;create index i${i} on t${i}(a);&quot;\ndone\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">If we run that against the cluster we&#8217;ll have 10&#8217;000 tables (each containing 1000 rows) and 10&#8217;000 indexes. This should be sufficient &#8220;many relations&#8221; to do a quick test.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We create the second cluster by copying the first one:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; highlight: [1,2,3]; title: ; notranslate\" title=\"\">\npostgres@pgbox:\/home\/postgres\/ &#x5B;172] mkdir \/var\/tmp\/dummy\/17.2_2\/\npostgres@pgbox:\/home\/postgres\/ &#x5B;172] pg_basebackup --port=8888 --pgdata=\/var\/tmp\/dummy\/17.2_2\/ --checkpoint=fast\npostgres@pgbox:\/home\/postgres\/ &#x5B;172] sed -i &#039;s\/8888\/8889\/g&#039; \/var\/tmp\/dummy\/17.2_2\/postgresql.auto.conf\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Now, lets create two  PostgreSQL 18 clusters we will be upgrading to. One of them we will upgrade with &#8220;&#8211;link&#8221; mode, the other with the new &#8220;&#8211;swap&#8221; mode (we&#8217;ll also stop the old cluster):<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; highlight: [1,3,4,5,6,7]; title: ; notranslate\" title=\"\">\npostgres@pgbox:\/home\/postgres\/ &#x5B;pgdev] initdb --version\ninitdb (PostgreSQL) 18devel\npostgres@pgbox:\/home\/postgres\/ &#x5B;pgdev] initdb --pgdata=\/var\/tmp\/dummy\/18link\npostgres@pgbox:\/home\/postgres\/ &#x5B;pgdev] initdb --pgdata=\/var\/tmp\/dummy\/18swap\npostgres@pgbox:\/home\/postgres\/ &#x5B;pgdev] echo &quot;port=9000&quot; &gt;&gt; \/var\/tmp\/dummy\/18link\/postgresql.auto.conf \npostgres@pgbox:\/home\/postgres\/ &#x5B;pgdev] echo &quot;port=9001&quot; &gt;&gt; \/var\/tmp\/dummy\/18swap\/postgresql.auto.conf \npostgres@pgbox:\/home\/postgres\/ &#x5B;pgdev] pg_ctl --pgdata=\/var\/tmp\/dummy\/17.2_1\/ stop\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">A quick check if all seems to be fine for the first upgrade:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; highlight: [1,3,4,5,6,7]; title: ; notranslate\" title=\"\">\npostgres@pgbox:\/home\/postgres\/ &#x5B;pgdev] pg_upgrade --version\npg_upgrade (PostgreSQL) 18devel\npostgres@pgbox:\/home\/postgres\/ &#x5B;pgdev] export PGDATAOLD=\/var\/tmp\/dummy\/17.2_1\/\npostgres@pgbox:\/home\/postgres\/ &#x5B;pgdev] export PGDATANEW=\/var\/tmp\/dummy\/18link\/\npostgres@pgbox:\/home\/postgres\/ &#x5B;pgdev] export PGBINOLD=\/u01\/app\/postgres\/product\/17\/db_2\/bin\npostgres@pgbox:\/home\/postgres\/ &#x5B;pgdev] export PGBINNEW=\/u01\/app\/postgres\/product\/DEV\/db_0\/bin\/\npostgres@pgbox:\/home\/postgres\/ &#x5B;pgdev] pg_upgrade --check\nPerforming Consistency Checks\n-----------------------------\nChecking cluster versions                                     ok\nChecking database connection settings                         ok\nChecking database user is the install user                    ok\nChecking for prepared transactions                            ok\nChecking for contrib\/isn with bigint-passing mismatch         ok\nChecking for valid logical replication slots                  ok\nChecking for subscription state                               ok\nChecking data type usage                                      ok\nChecking for presence of required libraries                   ok\nChecking database user is the install user                    ok\nChecking for prepared transactions                            ok\nChecking for new cluster tablespace directories               ok\n\n*Clusters are compatible*\n\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Time for a test using the &#8220;&#8211;link&#8221; mode:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; highlight: [1]; title: ; notranslate\" title=\"\">\npostgres@pgbox:\/home\/postgres\/ &#x5B;pgdev] time pg_upgrade --link\nPerforming Consistency Checks\n-----------------------------\nChecking cluster versions                                     ok\nChecking database connection settings                         ok\nChecking database user is the install user                    ok\nChecking for prepared transactions                            ok\nChecking for contrib\/isn with bigint-passing mismatch         ok\nChecking for valid logical replication slots                  ok\nChecking for subscription state                               ok\nChecking data type usage                                      ok\nCreating dump of global objects                               ok\nCreating dump of database schemas                             \n                                                              ok\nChecking for presence of required libraries                   ok\nChecking database user is the install user                    ok\nChecking for prepared transactions                            ok\nChecking for new cluster tablespace directories               ok\n\nIf pg_upgrade fails after this point, you must re-initdb the\nnew cluster before continuing.\n\nPerforming Upgrade\n------------------\nSetting locale and encoding for new cluster                   ok\nAnalyzing all rows in the new cluster                         ok\nFreezing all rows in the new cluster                          ok\nDeleting files from new pg_xact                               ok\nCopying old pg_xact to new server                             ok\nSetting oldest XID for new cluster                            ok\nSetting next transaction ID and epoch for new cluster         ok\nDeleting files from new pg_multixact\/offsets                  ok\nCopying old pg_multixact\/offsets to new server                ok\nDeleting files from new pg_multixact\/members                  ok\nCopying old pg_multixact\/members to new server                ok\nSetting next multixact ID and offset for new cluster          ok\nResetting WAL archives                                        ok\nSetting frozenxid and minmxid counters in new cluster         ok\nRestoring global objects in the new cluster                   ok\nRestoring database schemas in the new cluster                 \n                                                              ok\nAdding &quot;.old&quot; suffix to old global\/pg_control                 ok\n\nIf you want to start the old cluster, you will need to remove\nthe &quot;.old&quot; suffix from \/var\/tmp\/dummy\/17.2_1\/global\/pg_control.old.\nBecause &quot;link&quot; mode was used, the old cluster cannot be safely\nstarted once the new cluster has been started.\nLinking user relation files                                   \n                                                              ok\nSetting next OID for new cluster                              ok\nSync data directory to disk                                   ok\nCreating script to delete old cluster                         ok\nChecking for extension updates                                ok\n\nUpgrade Complete\n----------------\nSome optimizer statistics may not have been transferred by pg_upgrade.\nOnce you start the new server, consider running:\n    \/u01\/app\/postgres\/product\/DEV\/db_0\/bin\/vacuumdb --all --analyze-in-stages --missing-stats-only\nRunning this script will delete the old cluster&#039;s data files:\n    .\/delete_old_cluster.sh\n\nreal    0m13.776s\nuser    0m0.654s\nsys     0m1.536s\n\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s do the same test with the new &#8220;swap&#8221; mode:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; highlight: [1,2,3,4,5,23]; title: ; notranslate\" title=\"\">\npostgres@pgbox:\/home\/postgres\/ &#x5B;pgdev] export PGDATAOLD=\/var\/tmp\/dummy\/17.2_2\/\npostgres@pgbox:\/home\/postgres\/ &#x5B;pgdev] export PGDATANEW=\/var\/tmp\/dummy\/18swap\/\npostgres@pgbox:\/home\/postgres\/ &#x5B;pgdev] export PGBINOLD=\/u01\/app\/postgres\/product\/17\/db_2\/bin\npostgres@pgbox:\/home\/postgres\/ &#x5B;pgdev] export PGBINNEW=\/u01\/app\/postgres\/product\/DEV\/db_0\/\npostgres@pgbox:\/home\/postgres\/ &#x5B;pgdev] pg_upgrade --check\nPerforming Consistency Checks\n-----------------------------\nChecking cluster versions                                     ok\nChecking database connection settings                         ok\nChecking database user is the install user                    ok\nChecking for prepared transactions                            ok\nChecking for contrib\/isn with bigint-passing mismatch         ok\nChecking for valid logical replication slots                  ok\nChecking for subscription state                               ok\nChecking data type usage                                      ok\nChecking for presence of required libraries                   ok\nChecking database user is the install user                    ok\nChecking for prepared transactions                            ok\nChecking for new cluster tablespace directories               ok\n\n*Clusters are compatible*\n\npostgres@pgbox:\/home\/postgres\/ &#x5B;pgdev] time pg_upgrade --swap\nPerforming Consistency Checks\n-----------------------------\nChecking cluster versions                                     ok\nChecking database connection settings                         ok\nChecking database user is the install user                    ok\nChecking for prepared transactions                            ok\nChecking for contrib\/isn with bigint-passing mismatch         ok\nChecking for valid logical replication slots                  ok\nChecking for subscription state                               ok\nChecking data type usage                                      ok\nCreating dump of global objects                               ok\nCreating dump of database schemas                             \n                                                              ok\nChecking for presence of required libraries                   ok\nChecking database user is the install user                    ok\nChecking for prepared transactions                            ok\nChecking for new cluster tablespace directories               ok\n\nIf pg_upgrade fails after this point, you must re-initdb the\nnew cluster before continuing.\n\nPerforming Upgrade\n------------------\nSetting locale and encoding for new cluster                   ok\nAnalyzing all rows in the new cluster                         ok\nFreezing all rows in the new cluster                          ok\nDeleting files from new pg_xact                               ok\nCopying old pg_xact to new server                             ok\nSetting oldest XID for new cluster                            ok\nSetting next transaction ID and epoch for new cluster         ok\nDeleting files from new pg_multixact\/offsets                  ok\nCopying old pg_multixact\/offsets to new server                ok\nDeleting files from new pg_multixact\/members                  ok\nCopying old pg_multixact\/members to new server                ok\nSetting next multixact ID and offset for new cluster          ok\nResetting WAL archives                                        ok\nSetting frozenxid and minmxid counters in new cluster         ok\nRestoring global objects in the new cluster                   ok\nRestoring database schemas in the new cluster                 \n                                                              ok\nAdding &quot;.old&quot; suffix to old global\/pg_control                 ok\n\nBecause &quot;swap&quot; mode was used, the old cluster can no longer be\nsafely started.\nSwapping data directories                                     \n                                                              ok\nSetting next OID for new cluster                              ok\nSync data directory to disk                                   ok\nCreating script to delete old cluster                         ok\nChecking for extension updates                                ok\n\nUpgrade Complete\n----------------\nSome optimizer statistics may not have been transferred by pg_upgrade.\nOnce you start the new server, consider running:\n    \/u01\/app\/postgres\/product\/DEV\/db_0\/bin\/vacuumdb --all --analyze-in-stages --missing-stats-only\nRunning this script will delete the old cluster&#039;s data files:\n    .\/delete_old_cluster.sh\n\nreal    0m11.426s\nuser    0m0.600s\nsys     0m0.659s\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">This was around 2 seconds faster, not much, but at least faster. Of course this was a very simple test case and this further needs to be tested further. Please also note the warning in the output:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nBecause &quot;swap&quot; mode was used, the old cluster can no longer be\nsafely started.\nSwapping data directories \n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">This is a consequence of using this mode. Thanks to all involved, details <a href=\"https:\/\/git.postgresql.org\/gitweb\/?p=postgresql.git;a=commitdiff;h=626d7236b65da50423df7de035e86f273cd36b49\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you want to upgrade from one major version of PostgreSQL to another you probably want to go with pg_upgrade (or logical replication). There are several modes of operations for this already: What is best for you, depends on the requirements. We usually go with &#8220;&#8211;link&#8221; as this is pretty fast, but you can only&hellip;&nbsp;<\/p>\n","protected":false},"author":28,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","neve_meta_reading_time":"","_themeisle_gutenberg_block_has_review":false,"footnotes":""},"categories":[4133],"tags":[],"class_list":["post-37816","post","type-post","status-publish","format-standard","category-database"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v28.9 (Yoast SEO v28.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>PostgreSQL 18: &quot;swap&quot; mode for pg_upgrade - dbi services Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/postgresql-18-swap-mode-for-pg_upgrade\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PostgreSQL 18: &quot;swap&quot; mode for pg_upgrade\" \/>\n<meta property=\"og:description\" content=\"When you want to upgrade from one major version of PostgreSQL to another you probably want to go with pg_upgrade (or logical replication). There are several modes of operations for this already: What is best for you, depends on the requirements. We usually go with &#8220;&#8211;link&#8221; as this is pretty fast, but you can only&hellip;&nbsp;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/postgresql-18-swap-mode-for-pg_upgrade\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi services Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/dbiservices\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-03-28T14:15:06+00:00\" \/>\n<meta name=\"author\" content=\"Open source Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@dbiservices\" \/>\n<meta name=\"twitter:site\" content=\"@dbiservices\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Open source Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/postgresql-18-swap-mode-for-pg_upgrade\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/postgresql-18-swap-mode-for-pg_upgrade\\\/\"},\"author\":{\"name\":\"Open source Team\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/person\\\/0b4548362cac3eeff8b3eaf329e3530a\"},\"headline\":\"PostgreSQL 18: &#8220;swap&#8221; mode for pg_upgrade\",\"datePublished\":\"2025-03-28T14:15:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/postgresql-18-swap-mode-for-pg_upgrade\\\/\"},\"wordCount\":405,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/#organization\"},\"articleSection\":[\"Database\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/postgresql-18-swap-mode-for-pg_upgrade\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/postgresql-18-swap-mode-for-pg_upgrade\\\/\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/postgresql-18-swap-mode-for-pg_upgrade\\\/\",\"name\":\"PostgreSQL 18: \\\"swap\\\" mode for pg_upgrade - dbi services Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#website\"},\"datePublished\":\"2025-03-28T14:15:06+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/postgresql-18-swap-mode-for-pg_upgrade\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/postgresql-18-swap-mode-for-pg_upgrade\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/postgresql-18-swap-mode-for-pg_upgrade\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PostgreSQL 18: &#8220;swap&#8221; mode for pg_upgrade\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/\",\"name\":\"dbi services Blog\",\"description\":\"#BeSharing\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/#organization\",\"name\":\"dbi services\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/dbi-services-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/dbi-services-logo.png\",\"width\":512,\"height\":512,\"caption\":\"dbi services\"},\"image\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/dbiservices\\\/\",\"https:\\\/\\\/x.com\\\/dbiservices\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/dbi-services\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/dbiservices\"],\"description\":\"Swiss IT consulting and services company specialized in efficient data infrastructures and platforms: databases, application servers, cloud, DevOps, digitalization, analytics, data quality and monitoring. Headquartered in Del\u00e9mont with offices in Nyon, Basel, Bern and Zurich.\",\"email\":\"info@dbi-services.com\",\"telephone\":\"+41 32 422 96 00\",\"legalName\":\"dbi services SA\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/person\\\/0b4548362cac3eeff8b3eaf329e3530a\",\"name\":\"Open source Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/05\\\/open-source-author.png\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/05\\\/open-source-author.png\",\"contentUrl\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/05\\\/open-source-author.png\",\"caption\":\"Open source Team\"},\"description\":\"Posts published under the Open source Team account are collective contributions by the dbi services open infrastructure consultants. The practice covers open-source databases and platforms, PostgreSQL first of all, along with MySQL, MariaDB, and Linux, from architecture, replication, and high availability to performance tuning and operations under service level agreements, and contributes actively to the PostgreSQL community.\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/author\\\/open-source-team\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"PostgreSQL 18: \"swap\" mode for pg_upgrade - dbi services Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/postgresql-18-swap-mode-for-pg_upgrade\/","og_locale":"en_US","og_type":"article","og_title":"PostgreSQL 18: \"swap\" mode for pg_upgrade","og_description":"When you want to upgrade from one major version of PostgreSQL to another you probably want to go with pg_upgrade (or logical replication). There are several modes of operations for this already: What is best for you, depends on the requirements. We usually go with &#8220;&#8211;link&#8221; as this is pretty fast, but you can only&hellip;&nbsp;","og_url":"https:\/\/www.dbi-services.com\/blog\/postgresql-18-swap-mode-for-pg_upgrade\/","og_site_name":"dbi services Blog","article_publisher":"https:\/\/www.facebook.com\/dbiservices\/","article_published_time":"2025-03-28T14:15:06+00:00","author":"Open source Team","twitter_card":"summary_large_image","twitter_creator":"@dbiservices","twitter_site":"@dbiservices","twitter_misc":{"Written by":"Open source Team","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/postgresql-18-swap-mode-for-pg_upgrade\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/postgresql-18-swap-mode-for-pg_upgrade\/"},"author":{"name":"Open source Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/0b4548362cac3eeff8b3eaf329e3530a"},"headline":"PostgreSQL 18: &#8220;swap&#8221; mode for pg_upgrade","datePublished":"2025-03-28T14:15:06+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/postgresql-18-swap-mode-for-pg_upgrade\/"},"wordCount":405,"commentCount":0,"publisher":{"@id":"https:\/\/www.dbi-services.com\/#organization"},"articleSection":["Database"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/postgresql-18-swap-mode-for-pg_upgrade\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/postgresql-18-swap-mode-for-pg_upgrade\/","url":"https:\/\/www.dbi-services.com\/blog\/postgresql-18-swap-mode-for-pg_upgrade\/","name":"PostgreSQL 18: \"swap\" mode for pg_upgrade - dbi services Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2025-03-28T14:15:06+00:00","breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/postgresql-18-swap-mode-for-pg_upgrade\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/postgresql-18-swap-mode-for-pg_upgrade\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/postgresql-18-swap-mode-for-pg_upgrade\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"PostgreSQL 18: &#8220;swap&#8221; mode for pg_upgrade"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi services Blog","description":"#BeSharing","publisher":{"@id":"https:\/\/www.dbi-services.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.dbi-services.com\/#organization","name":"dbi services","url":"https:\/\/www.dbi-services.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/09\/dbi-services-logo.png","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/09\/dbi-services-logo.png","width":512,"height":512,"caption":"dbi services"},"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/dbiservices\/","https:\/\/x.com\/dbiservices","https:\/\/www.linkedin.com\/company\/dbi-services\/","https:\/\/www.youtube.com\/user\/dbiservices"],"description":"Swiss IT consulting and services company specialized in efficient data infrastructures and platforms: databases, application servers, cloud, DevOps, digitalization, analytics, data quality and monitoring. Headquartered in Del\u00e9mont with offices in Nyon, Basel, Bern and Zurich.","email":"info@dbi-services.com","telephone":"+41 32 422 96 00","legalName":"dbi services SA"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/0b4548362cac3eeff8b3eaf329e3530a","name":"Open source Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/05\/open-source-author.png","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/05\/open-source-author.png","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/05\/open-source-author.png","caption":"Open source Team"},"description":"Posts published under the Open source Team account are collective contributions by the dbi services open infrastructure consultants. The practice covers open-source databases and platforms, PostgreSQL first of all, along with MySQL, MariaDB, and Linux, from architecture, replication, and high availability to performance tuning and operations under service level agreements, and contributes actively to the PostgreSQL community.","url":"https:\/\/www.dbi-services.com\/blog\/author\/open-source-team\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/37816","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/28"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=37816"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/37816\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=37816"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=37816"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=37816"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}