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.