I'm trying to upgrade postgres from 9.5 to 9.6. brew upgrade postgresql
succeeds, but when running
pg_upgrade -b /usr/local/Cellar/postgresql/9.5.3/bin/ -B /usr/local/Cellar/postgresql/9.6.1/bin/ -d /usr/local/var/postgres -D /usr/local/var/postgres9.6 -U postgres
I get an error
Performing Consistency Checks
-----------------------------
Checking cluster versions ok
Checking database user is the install user
database user "postgres" is not the install user
Failure, exiting
when trying without -U postgres
at the end it gets even weirder
Performing Consistency Checks
-----------------------------
Checking cluster versions ok
Checking database user is the install user ok
Checking database connection settings ok
Checking for prepared transactions ok
Checking for reg* system OID user data types ok
Checking for contrib/isn with bigint-passing mismatch ok
Checking for roles starting with 'pg_' ok
Creating dump of global objects ok
Creating dump of database schemas
ok
Checking for presence of required libraries ok
Checking database user is the install user
database user "dimid" is not the install user
So how come
Checking database user is the install user ok
The old PostgreSQL cluster was obviously created with
initdb -U dimid
but the new cluster was istalled with a different superuser.
You have to create the new cluster with the same superuser name as the old one.
Specifically for homebrew postgresql installations, the default user for initdb is $USER -- so if you just followed the instructions initially and did something like
initdb /usr/local/var/postgres -E utf8
the install user is your Unix username. In my case it is 'rob', so just adding '-U rob' to the pg_upgrade works as well:
pg_upgrade -b /usr/local/Cellar/postgresql/9.5.4_1/bin -B /usr/local/Cellar/postgresql/9.6.2/bin -d /usr/local/var/postgres95 -D /usr/local/var/postgres -U rob
I was getting this because the target database contained an extra user.
This was previously part of my install and upgrade init script. I removed it from the upgrade initdb and the upgrade completed successfully.
For users of macOS Postgres App:
The upgrade script checks if $USER has the oid 10
in the old database, if not it exists with an corresponding error message. Consult https://support.hashicorp.com/hc/en-us/articles/1500005343202-PostgreSQL-12-Upgrade-Error-database-user-hashicorp-is-not-the-install-user on how to work around this issue.
In my case:
psql postgres -U postgres
SELECT rolname, oid FROM pg_roles;
# check which role has oid 10, in my case role `postgres`
# – as we are postgres right now we have to create an temp user, continue with that:
CREATE ROLE "temp" WITH SUPERUSER CREATEDB CREATEROLE REPLICATION BYPASSRLS LOGIN PASSWORD 'temp';
exit # or Ctrl + D
psql postgres -U temp
ALTER ROLE $USER RENAME TO "$USER_";
ALTER ROLE postgres RENAME TO $USER;
CREATE ROLE "postgres" WITH SUPERUSER CREATEDB CREATEROLE REPLICATION BYPASSRLS;
Depending on your own databases you have to adapt these queries as described in the linked article.
PS: Be aware that upgrading old databases with an still installed postgis extension is not really worth the hassle, you have to either uninstall the extension or could another upgrade path as described in https://postgresapp.com/documentation/migrating-data.html .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.