Postgresql pg_upgrade failed : role <XXX> unknown
Rédigé par gorki Aucun commentaireProblem :
When migrating a database, pg_upgrade failed with “could not connect, role <XXX> is unknown”.
My database was created with another user (postgresql)
Then transfered to another user (let's call it john)
The login authentication was password only until upgrade, where I put local to trust for upgrade.
The new destination database was created by john.
Solution :
The pg_upgrade can not use :
- an old database with super role postgres
- a new database with super role john
The option “-U <username>” is applied to the both, so there is always one which is wrong.
So rename the old database super role to john (thanks to internet).
- start the old database, pg_upgrade give the command in the log but !!
- Be careful ! there is a hidden option “-b” which prevent any modification :) remove it and all is ok
"/home/myuser/postgresql-9.6.2/bin/pg_ctl" -w -D "/home/myuser/database-introscope-9.6" -o "-p 50432 -c listen_addresses='' -c unix_socket_permissions=0700 -c unix_socket_directories='/home/myuser'" start
Connect with :
/home/myuser/postgresql-9.6.2/bin/psql -p 50432 -h /home/myuser -U postgres -d postgres
Check the super user role name :
SELECT rolname FROM pg_roles WHERE oid = 10;
Create another super user
CREATE ROLE spiderman SUPERUSER LOGIN PASSWORD 'moreSecurePass';
Quit, connect with spideman, still on postgres database
/home/myuser/postgresql-9.6.2/bin/psql -p 50432 -h /home/myuser -U spideman -d postgres
Rename the original role :
alter role postgres rename to john;
Check the connection :
/home/myuser/postgresql-9.6.2/bin/psql -p 50432 -h /home/myuser -U john -d postgres
Drop spiderman role :
DROP ROLE spiderman;
I learn to side tricks here :
-h
<path> : give the path to the unix socket connection-b
option : use for binary upgrade mode on pg_ctl (didn't see the option in the documentation)- Owner role has value OID=10