I am trying to use user assigned identity for connecting postgres flexible server but getting failed: FATAL: password authentication failed for user

Prasanna Sai Kommineni 90 Reputation points
2026-08-06T14:21:09.1433333+00:00

I am trying to use user assigned identity for connecting postgres flexible server but getting failed: FATAL: password authentication failed for user

Azure Database for PostgreSQL
0 comments No comments

Answer accepted by question author
Nithin 330 Reputation points
2026-08-06T15:07:19.18+00:00

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:

  1. Log in to PostgreSQL using the Azure Entra Admin account (or primary admin user).
  2. 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";
  1. 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!

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

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