15

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

6 Answers 6

11

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, how can I find out which user created a cluster?
You would do that with SELECT rolname FROM pg_roles WHERE oid = 10, but it is not necessary. Just drop the new cluster and recreate it with -U dimid.
Thanks, that did the trick. Out of curiosity, what does 10 refer to?
That's the hard-coded Oid for the bootstrap superuser. Search the source for BOOTSTRAP_SUPERUSERID.
Note: if you're using postgres.app, it seems two roles are installed: $USER and 'postgres'. This will also choke pg_upgrade (which expects a single non-system role), so you should run: DROP DATABASE $USER; DROP ROLE $USER
5

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

2 Comments

for a lot of others the user may be postgres so just use that instead if this error message comes up with your name as not the install user
Yes, 'postgres' is the preferred install user as that is the default, and thus what users (like me) will try first. Using $USER for the initial initdb as described in this answer is specific to homebrew installations of PostgreSQL on OSX / MacOS.
3

For users of macOS Postgres App:

The upgrade script checks if $USER has the oid 10 in the old database, if this user does not exist – it responds with a 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.

P.S.: 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.

2 Comments

Today noticed exactly same problem. In our db was postgres role renamed to x. And was created a new postgres role. I don't know was earlier a tool which made this... or not? We must re-rename the roles... You can't rename logged role! Must consider next time how can you login! indent or password :)
In our postgres9.3 postgres user was renamed and new postgres user was created. This caused our upgrade error.
1

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.

Comments

0

check initdb.log for both clusters, check from which older cluster (pg11) was initialized. We need to initialize new cluster with the same user, and there should be no other user created other than the initialized cluster user at target (pg14)

Comments

0

During the pg_upgrade process, a check is run to make sure pg_catalog.pg_roles has only a single non pg_* user, typically this is just 'postgres'. If this check fails, the error message is "Only the install user can be defined in the new cluster."; This message implies the user executing pg_upgrade must match the the rolsuper in pg_catalog.pg_roles.

1 Comment

What is a pg_* user? What is rolsuper?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.