BUG: Orphaned roles cannot be dropped on Azure DB for PostgreSQL v16

Thuerriedl, Reinhard 20 Reputation points
2025-04-18T06:34:47.33+00:00

With Azure Database for PostgreSQL Flexible Server V16 it is not possible to drop orphaned roles with the cloud provider admin account azure_pg_admin.

Only actual DB superusers can manage orphaned roles in PG V16. The community is aware of the problem and discussing if they should provide a "fix" or declare it a "feature". See https://www.postgresql.org/message-id/flat/CAE9k0PmwJxFcajwnouQECsRWhtGSe0OeXP-BK%3DG%2Bn1umjuqEBw%40mail.gmail.com

Steps to reproduce

Create chain of roles

postgres=> SELECT CURRENT_USER;
 current_user 
--------------
 postgres
(1 row)

postgres=> CREATE ROLE grandpa CREATEROLE;
GRANT grandpa TO CURRENT_USER; -- not needed on native PG and AWS
SET ROLE grandpa;
CREATE ROLE papa CREATEROLE;
GRANT papa TO CURRENT_USER; -- not needed on native PG and AWS
SET ROLE papa;
CREATE ROLE son;

-- output
CREATE ROLE
GRANT ROLE
SET
CREATE ROLE
GRANT ROLE
SET
CREATE ROLE

postgres=> \drg
                              List of role grants
   Role name    |          Member of          |       Options       | Grantor  
----------------+-----------------------------+---------------------+----------
 azure_pg_admin | pg_checkpoint               | ADMIN, INHERIT, SET | azuresu
 azure_pg_admin | pg_create_subscription      | ADMIN, INHERIT, SET | azuresu
 azure_pg_admin | pg_monitor                  | ADMIN, INHERIT, SET | azuresu
 azure_pg_admin | pg_read_all_data            | ADMIN, INHERIT, SET | azuresu
 azure_pg_admin | pg_read_all_settings        | ADMIN, INHERIT, SET | azuresu
 azure_pg_admin | pg_read_all_stats           | ADMIN, INHERIT, SET | azuresu
 azure_pg_admin | pg_signal_autovacuum_worker | ADMIN, INHERIT, SET | azuresu
 azure_pg_admin | pg_signal_backend           | ADMIN, INHERIT, SET | azuresu
 azure_pg_admin | pg_stat_scan_tables         | ADMIN, INHERIT, SET | azuresu
 grandpa        | papa                        | ADMIN               | azuresu
 grandpa        | papa                        | INHERIT, SET        | grandpa
 papa           | son                         | ADMIN               | azuresu
 postgres       | azure_pg_admin              | ADMIN, INHERIT, SET | azuresu
 postgres       | grandpa                     | ADMIN               | azuresu
 postgres       | grandpa                     | INHERIT, SET        | postgres
 postgres       | pg_read_all_settings        | ADMIN, INHERIT, SET | azuresu
 postgres       | pg_read_all_stats           | ADMIN, INHERIT, SET | azuresu
 postgres       | pg_stat_scan_tables         | ADMIN, INHERIT, SET | azuresu
 replication    | pg_use_reserved_connections | INHERIT, SET        | azuresu
(19 rows)

Create orphan and try to drop it

postgres=> SET ROLE grandpa;
DROP ROLE papa;
SET
DROP ROLE
postgres=> DROP ROLE son;
ERROR:  permission denied to drop role
DETAIL:  Only roles with the CREATEROLE attribute and the ADMIN option on role "son" may drop this role.

postgres=> SET ROLE postgres;
SET
postgres=> DROP ROLE son;
ERROR:  permission denied to drop role
DETAIL:  Only roles with the CREATEROLE attribute and the ADMIN option on role "son" may drop this role.

postgres=> SET ROLE azure_pg_admin;
SET
postgres=> DROP ROLE son;
ERROR:  permission denied to drop role
DETAIL:  Only roles with the CREATEROLE attribute and the ADMIN option on the target roles may drop roles.

No available user (including the admin account azure_pg_admin) can drop the orphaned role anymore!

At least on Azure. It is possible to drop the orphaned role with the AWS (Aurora-PostgreSQL) and GCP (Cloud SQL for PostgreSQL) managed PostgreSQL v16 databases.

Azure Database for PostgreSQL
{count} votes

1 answer

Sort by: Most helpful
  1. PratikLad 1,125 Reputation points Microsoft External Staff Moderator
    2025-04-30T13:13:22.9466667+00:00

    Hi Thuerriedl, Reinhard,

    We have some limitation on Postgres 16, please check the below document.

    Previously roles with CREATEROLE privileges could change many aspects of any non-superuser role. Such changes, including adding members, now require the role requesting the change to have ADMIN OPTION permission. For example, they can now change the CREATEDB, REPLICATION, and BYPASSRLS properties only if they also have those permissions.

    https://www.postgresql.org/docs/16/release-16.html

    To delete a non-superuser role in PostgreSQL, a user needs:

    • They must have the CREATEROLE privilege, which grants general permission to manage roles (including creating and deleting them).
    • They must also have been granted the ADMIN OPTION for the specific role they want to remove, which means they have explicit authority to manage that particular role.

    I hope this answer your question.

    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.