An Azure managed PostgreSQL database service for app development and deployment.
Hi Prasanna,
This error occurs because creating a User-Assigned Managed Identity in Entra ID does not automatically create the corresponding database user role inside PostgreSQL.
PostgreSQL Flexible Server requires Microsoft Entra ID authentication to be explicitly mapped to a database role before accepting access tokens.
Here is how to fix it:
- Log in to PostgreSQL using the Azure Entra Admin account (or primary admin user).
- Create the DB role matching your User-Assigned Managed Identity name:
SET aad_validate_oids = off;
CREATE USER "your-user-assigned-identity-name" IN ROLE azure_ad_user;
GRANT ALL PRIVILEGES ON DATABASE your_db TO "your-user-assigned-identity-name";
- Get Entra Token for PostgreSQL: Ensure your application requests a token specifically for
https://ossrdbms-aad.database.windows.net/.default(not Management API scope) when passing it as the password.
Once the Entra identity is mapped as a DB user role, authentication will succeed!
Ref: Use Microsoft Entra ID authentication in Azure Database for PostgreSQL Flexible Server
If this resolves your authentication error, please mark as Accept Answer!