Postgres Database server migration

All we need is an easy explanation of the problem, so here it is.

We need to migrate our existing database server (PG 12) to a new server.
I followed this [https://www.postgresql.org/docs/8.1/app-pg-dumpall.html] article and created the dump as

pg_dumpall > alldb.sql

then copied the file alldb.sql to the new system and tried to restore using

psql -f alldb.sql postgres

and it failed with the following error messages

psql:allbackup.sql:314: ERROR: option "locale" not recognized LINE 1:
…3103" WITH TEMPLATE = template0 ENCODING = ‘UTF8’ LOCALE = ‘…
^ psql:allbackup.sql:317: ERROR: database "XXXXX" does not exist
psql:allbackup.sql:319: error: \connect: FATAL: database "XXXXX"
does not exist

What could be the issue?

  • Ubuntu 20.04
  • Postgres version 12

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

The CREATE DATABASE statement did not accept a LOCALE parameter until PostgreSQL version 13. It fails in your case because the target server is version 12.

The pg_dumpall command put that parameter because its version is newer than 12, so it considers that you’re going to restore into a version newer than 12. You can check the version with pg_dumpall --version

The solution is to use the same version of pg_dumpall than your target server. On Ubuntu, you might have several versions installed. Check if you have /usr/lib/postgresql/12/bin/pg_dumpall, and if you do, call it directly with that full path.

If it’s not installed, it can be installed with the postgresql-client-12 package.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply