This article is contributed. See the original author and article here.


We see customers were not able to delete the AD Admin user in Azure database for PostgreSQL, and after triggering the operation , the request keep running forever without any error message or it fails with error like:

‘The user name conflict with an existing database user name’ is not a valid name because it contains invalid characters.



In this scenario, most properly the operation stuck because there is a dependent objects on the AAD role, so you will need to remove these dependencies first , so log in with your server admin user and check the object dependency using the following query:



— make sure to run this query against all databases.

— Replace ### with AAD admin User or group.


WITH myconstants (MyUser, ExcludeUser) AS (
    values ('', 'azure_superuser')
    n.nspname AS schema_name,
    c.relname AS rel_name,
    c.relkind AS rel_kind,
    pg_get_userbyid(c.relowner) AS owner_name
  FROM myconstants, pg_class c
  JOIN pg_namespace n ON n.oid = c.relnamespace
        pg_get_userbyid(c.relowner) NOT LIKE concat('%',ExcludeUser,'%')
        pg_get_userbyid(c.relowner) LIKE concat('%',MyUser,'%')
    n.nspname AS schema_name,
 FROM myconstants, pg_proc p
  JOIN pg_namespace n ON n.oid = p.pronamespace
        pg_get_userbyid(p.proowner) NOT LIKE concat ('%',ExcludeUser,'%')
        pg_get_userbyid(p.proowner) LIKE concat('%',MyUser,'%')


To mitigate this issue, you will need to change the ownership of these object to other new/existing user and retry the operation:


REASSIGN OWNED BY "###" TO "local database user";





For more details, please check out PostgreSQL documentation:

PostgreSQL: Documentation: 11: REASSIGN OWNED

In case, after you cleaned the dependences to AAD Admin and you want to set the AD Admin again but it fails again with error


'The user name conflict with an existing database user name' is not a valid name because it contains invalid characters.


As a workaround, you can assign the AAD admin role to another AAD admin user and then you will be able to do the override. by then you should be able to reset the AAD admin once again.


I hope you find this article helpful. If you have any feedback please do not hesitate to provide it in the comment section below.


Ahmed S. Mazrouh

Brought to you by Dr. Ware, Microsoft Office 365 Silver Partner, Charleston SC.

%d bloggers like this: