After Postgresql flexible migration from version 11 to version 16 admin user cannot change ownership of database

Ryszard Sikora 0 Reputation points
2025-03-20T07:55:33.05+00:00

Since the migration of the PostgreSQL Flexible version I am unable to ALTER ROLE and change database owner (ALTER DATABASE db OWNER TO new_role;)

When running this command:

ALTER DATABASE db1 OWNER TO new_role;

I am getting the following error:

ERROR: must be owner of database prefectdb SQL state: 42501

Moreover, I'm also unable to grant my admin user permissions to the old owner. When trying this command:
grant old_role to admin_user;

I am getting the following error:

ERROR: permission denied to grant role "prefect" Only roles with the ADMIN option on role "prefect" may grant this role. SQL state: 42501 Detail: Only roles with the ADMIN option on role "prefect" may grant this role.

The problem is that we cannot modify this role or change the owner of the database nor rollback to earlier version of PostgreSQL. Do you have solution for that problem?

Azure Database for PostgreSQL
{count} votes

2 answers

Sort by: Most helpful
  1. Ryszard Sikora 0 Reputation points
    2025-04-04T13:05:48.1533333+00:00

    The support has fixed my problem

    0 comments No comments

  2. PratikLad 1,825 Reputation points Microsoft External Staff Moderator
    2025-04-07T06:42:36.6066667+00:00

    Hi @Ryszard Sikora

    Current admin user is emtrailsadmin as it has ADMIN OPTION on azure_pg_admin.

    To add another admin user: log in as an admin user (e.g., emtrailsadmin).

    Execute below command:

    GRANT azure_pg_admin TO new_admin_user WITH ADMIN OPTION;
    

    To grant a member role to another role, the current logged in user must have admin option on the member role. So for example if you are trying to execute GRANT role_a TO role_b; and you are logged in as role_c, role_c MUST have been granted role_a WITH ADMIN OPTION.

    • Admin users can grant themselves any new role with ADMIN OPTION
    • To change ownership of the databases
      • Log in as emtrailsadmin
      • Ensure emtrailsadmin has ADMIN OPTION on the role you are changing the database ownership to. Can add this using GRANT role TO emtrailsadmin WITH ADMIN OPTION;
      • Execute ALTER DATABASE database OWNER TO role;

    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.