Part of Managed PostgresPostgres · Upgrades

Upgrade Postgres to a new major version: pg_upgrade, dump and restore, or logical replication.

There are three ways to move Postgres to a new major version. Dump and restore is the simplest and the slowest. pg_upgrade carries the catalog over and reuses the data files, so it is much faster. Logical replication keeps the old server live until a switch of seconds, but leaves out schema changes and sequences.

Facts checked

The three methods side by side

Minor releases (17.5 to 17.6) only need new binaries and a restart. A major version (17 to 18) changes the on-disk format of the system catalogs, so the data has to be moved, rewritten or replicated. What separates the methods is how long the database is unavailable and how you get back if something goes wrong.

  • Under a few gigabytes: dump and restore. It is one command each way and also cleans up bloat.
  • Bigger, and a few minutes offline is fine: pg_upgrade, in copy mode if the disk has room for a second copy, so the old cluster survives.
  • Bigger, and minutes offline is not fine: logical replication, after a rehearsal.
MethodDowntimeWhat carries overThe way back
Dump and restore (pg_dump / pg_restore) † †Writes stopped for the whole dump and restore; grows with the data sizeOne database per pg_dump. Roles and tablespaces need pg_dumpall --globals-onlyThe old server is untouched
pg_upgrade --copy (the default) †Both servers stopped while files are copiedThe whole cluster: roles, grants, extensions, and in Postgres 18 most planner statisticsThe old cluster is left unmodified
pg_upgrade --link †Much shorter: no data files are copiedSame as aboveNone once the new server has started: the old cluster is unusable, restore from backup
pg_upgrade --clone †As fast as linkSame as aboveThe old cluster stays usable. Needs Btrfs or XFS on Linux, or APFS on macOS
Logical replication † †“Only several seconds” at the switchTable rows only. Not the schema or later DDL, not sequence values, not large objectsKeep the old server until you are sure

† Competitor details come from each vendor’s own published pages on the dates shown; prices and plans change, so check the vendor before you decide. Dump and restore (`pg_dump` / `pg_restore`) (2026-10-29) · Dump and restore (`pg_dump` / `pg_restore`) (2026-10-29) · `pg_upgrade --copy` (the default) (2026-10-29) · `pg_upgrade --link` (2026-10-29) · `pg_upgrade --clone` (2026-10-29) · Logical replication (2026-10-29) · Logical replication (2026-10-29)

Before you start

Whatever the method, restore a recent backup onto the target version first and run your test suite against it. Most upgrade problems are one of these:

CheckWhy it matters
How long your version has left †Each major version is supported for 5 years. Postgres 13 reached end of life on November 13, 2025; 14 follows on November 12, 2026.
Data checksums (going to 18) †initdb in Postgres 18 enables checksums by default, and pg_upgrade requires both clusters to match. An old cluster without checksums needs a new one created with --no-data-checksums.
Optimizer statistics (going to 18) †pg_upgrade now keeps most of them, so queries are not slow for the first minutes. Extended statistics (CREATE STATISTICS) are not kept.
MD5 passwords †Deprecated in 18: CREATE ROLE and ALTER ROLE warn when setting one, and a later major version will remove them. Move roles to SCRAM while you are at it.
Extensions †The new server needs each extension’s files (vector.so, PostGIS) built for the new version. Don’t run CREATE EXTENSION on it before pg_upgrade; the old definitions are carried over.

† Competitor details come from each vendor’s own published pages on the dates shown; prices and plans change, so check the vendor before you decide. How long your version has left (2026-10-29) · Data checksums (going to 18) (2026-10-29) · Optimizer statistics (going to 18) (2026-10-29) · MD5 passwords (2026-10-29) · Extensions (2026-10-29)

Dump and restore

Stop writes first: put the app in maintenance mode or stop it. pg_dump takes a consistent snapshot without blocking anyone, but whatever is written after the snapshot starts is not in the dump. Use the dump tools from the new version, which is what the Postgres docs recommend.

# Use the NEWER version's client tools: they read servers back to 9.2
# 1. Roles and other cluster-wide objects (pg_dump never includes them)
pg_dumpall --globals-only -h old-host -U postgres > globals.sql

# 2. The database, in directory format so both sides can run in parallel
pg_dump -h old-host -U postgres -Fd -j 4 -f app.dir app

# 3. Into the new server
psql -h new-host -U postgres -f globals.sql
createdb -h new-host -U postgres app
pg_restore -h new-host -U postgres -d app -j 4 app.dir

# 4. Fresh planner statistics before you send traffic
vacuumdb -h new-host -U postgres --all --analyze-in-stages

pg_upgrade

pg_upgrade creates the new version’s system catalogs from the old ones and moves the data files as they are. Both servers must be stopped, both versions’ binaries installed, and the new cluster freshly created with initdb using the same settings (checksums, encoding, locale).

  • Always run `--check` with the same mode flag you will use. It catches missing extension libraries and incompatible settings while nothing has changed yet.
  • Link mode is fast because it is one-way. Once the new server starts, the old one is no longer safe to start, so take a backup first.
  • Logical replication slots and standbys need their own steps; the pg_upgrade docs point to a separate procedure for them.
# Dry run first: reports problems, changes nothing
pg_upgrade --check \
  -b /usr/lib/postgresql/17/bin -B /usr/lib/postgresql/18/bin \
  -d /var/lib/postgresql/17/main -D /var/lib/postgresql/18/main

# The real thing, both servers stopped. --copy is the default and leaves the old cluster intact.
pg_upgrade --copy -b ... -B ... -d ... -D ... --jobs 4

# After starting the new server: Postgres 18 carries most statistics over;
# this fills in what it didn't (extended statistics, for one)
vacuumdb --all --analyze-in-stages --missing-stats-only
vacuumdb --all --analyze-only

Logical replication: seconds of downtime, more steps

Logical replication works between different major versions, so a new server can follow the old one, row by row, until you switch. The switch is short; the preparation is not. The schema has to exist on the new side first, and anything replication skips has to be handled by hand.

  • Freeze migrations from the moment you copy the schema until the switch. A new column on the old server won’t show up on the new one and the subscription stops applying changes.
  • Give every table a primary key before you publish it (see the error below), or set REPLICA IDENTITY FULL on the few that can’t have one. FULL works, but each update makes the subscriber search for the whole row.
  • At the switch: stop writes on the old server, wait until nothing is left to apply, copy the sequence values, point the app at the new server, then DROP SUBSCRIPTION.
-- On the OLD server (needs wal_level = logical, which takes a restart)
CREATE PUBLICATION upgrade_pub FOR ALL TABLES;

-- Copy the schema across first; DDL is not replicated
--   pg_dump --schema-only -h old-host app | psql -h new-host app

-- On the NEW server
CREATE SUBSCRIPTION upgrade_sub
  CONNECTION 'host=old-host dbname=app user=replicator password=...'
  PUBLICATION upgrade_pub;

-- Every table should reach state 'r' (ready) before you switch
SELECT srrelid::regclass, srsubstate FROM pg_subscription_rel;

-- At the switch, with writes stopped on the old server: copy the sequences.
-- Run this on the OLD server and execute its output on the NEW one.
SELECT format('SELECT setval(%L, %s, true);',
              format('%I.%I', schemaname, sequencename), last_value)
FROM pg_sequences WHERE last_value IS NOT NULL;

Errors you are likely to meet

MessageWhereFix
Your installation references loadable libraries that are missing from the new installation. † †pg_upgrade --checkInstall the extension’s package for the new version, or drop the extension on the old server. The list is in loadable_libraries.txt.
cannot update table "orders" because it does not have a replica identity and publishes updates † †The OLD server, on every UPDATE, as soon as the table is in a publicationALTER TABLE orders ADD PRIMARY KEY (...), or REPLICA IDENTITY FULL. INSERT keeps working, so this can hide until the first update.
Duplicate key errors on the new server right after the switch †Your appThe sequences still hold their start values. Run the setval output from above.
Subscription stops applying changes †The NEW server’s logA schema change on the old server that was not repeated on the new one. Apply the same DDL on the new side; replication resumes.

† Competitor details come from each vendor’s own published pages on the dates shown; prices and plans change, so check the vendor before you decide. `Your installation references loadable libraries that are missing from the new installation.` (2026-10-29) · `Your installation references loadable libraries that are missing from the new installation.` (2026-10-29) · `cannot update table "orders" because it does not have a replica identity and publishes updates` (2026-10-29) · `cannot update table "orders" because it does not have a replica identity and publishes updates` (2026-10-29) · Duplicate key errors on the new server right after the switch (2026-10-29) · Subscription stops applying changes (2026-10-29)

On Canner

Canner offers Postgres 17 (the default) and 18. A database stays on the version it was created with until you choose to move it, and the Database tab shows the exact running version, such as 17.9.

  • A database on shared hosting moves with canner db pg-version (or from the Database tab). It is a dump and restore: open connections are closed, the app can’t reach the database while it runs (seconds for a small database, longer for a large one), and the connection string does not change. It is not available yet while the database has groups or logins you created in SQL.
  • A dedicated instance ($9 a month per project) upgrades as a whole with pg_upgrade in copy mode. Every database, role, grant, policy and extension carries over and connection strings stay the same. Every database on the instance is offline for a few minutes; if the upgrade fails, the instance is left as it was. The previous version is kept for 7 days for a rollback.
  • The check refuses while logical replication is on, while a backup or restore is running, while a previous upgrade is still open, or when an installed extension isn’t offered on the new version, with messages like Postgres 18 does not offer: <extension>. Drop it before upgrading.
  • Point-in-time recovery starts a fresh window after the upgrade. WAL numbering restarts at a major version, so you can’t recover to a moment before the upgrade on the new version. Take a backup just before you run it.
  • Coming from another provider on an older version? A dedicated instance can follow any publicly reachable Postgres server by logical replication (canner db subscriptions), which is an upgrade and a move in one step. See migrating to Canner Postgres.
# Shared hosting: move one database to the other version (dump + restore)
canner db pg-version primary 18 --yes

# Dedicated instance: what would stop an upgrade, then do it (pg_upgrade, in place)
canner db instance upgrade
canner db instance upgrade run --pg 18 --yes

# Within 7 days: go back (loses what was written since), or let the old version go
canner db instance upgrade rollback --yes
canner db instance upgrade finish --yes

When Canner is the wrong fit for this

An upgrade of a database already on Canner always has some downtime: the shared-hosting move is a dump and restore, and the instance upgrade takes every database on it offline for a few minutes. If your app can’t be unavailable for that long, even in a planned window at night, you need a provider that runs a replica-based upgrade with a switch measured in seconds. Canner does not offer one today.

Questions

Is pg_upgrade faster than pg_dump?

Usually by a lot on a large database: pg_upgrade moves the data files instead of re-inserting every row and rebuilding every index. In link or clone mode it does not copy the data files at all.

Can I upgrade Postgres with no downtime?

Close to none, with logical replication: a new server follows the old one and the switch takes seconds. You have to copy the schema first, freeze schema changes, give tables a primary key and copy sequence values at the switch.

Do I need to run ANALYZE after pg_upgrade?

From Postgres 18, pg_upgrade keeps most planner statistics, so run vacuumdb --all --analyze-in-stages --missing-stats-only to fill in the rest. Upgrading to 17 or earlier, analyze everything, or queries plan badly until autovacuum catches up.

Can I skip major versions, say 14 to 18?

Yes. pg_upgrade, dump and restore, and logical replication can all go across several major versions in one step. Read the release notes of every version in between for incompatibilities.

How do I upgrade a Canner database to Postgres 18?

On shared hosting, canner db pg-version <name> 18 --yes (a dump and restore). On a dedicated instance, canner db instance upgrade to check, then canner db instance upgrade run --pg 18 --yes. Connection strings don’t change in either case.

Postgres 17 and 18, in Montréal.

Upgrades in place on the dedicated instance, with a 7-day way back. See the Postgres plans.