Connection failed: FATAL: cannot read pg_class without having selected a database

Application Admin 0 Reputation points
2025-11-10T17:32:33.8666667+00:00

I cannot connect to my postgres db with my Entra authentication and receive the below error:

connection to server at <server_name> <ip address>, port 5432 failed: FATAL: cannot read pg_class without having selected a database

I have confirmed that I am added as a Entra administrator for the database and confirmed the server name is correct private endpoint that I have set up. Also note I am able to connect via PostgresQl Authenication but not via Entra authenication.

I have confirmed that the database does exist and is being requested properly.

Any assistance would be much appreciated.

Azure Database for PostgreSQL
{count} votes

2 answers

Sort by: Most helpful
  1. Q&A Assist
    2025-11-10T17:32:47.9166667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    The error message you're encountering, "FATAL: cannot read pg_class without having selected a database," typically indicates that a database needs to be specified when connecting to PostgreSQL. Since you mentioned that you are able to connect via PostgreSQL authentication but not through Microsoft Entra authentication, it suggests that the connection string or command you are using for Entra authentication may not be specifying the database correctly.

    Here are a few steps to troubleshoot and resolve the issue:

    1. Check Connection String: Ensure that your connection string includes the dbname parameter. For example:
         psql "host=mycluster.[uniqueID].postgres.cosmos.azure.com user=******@tenant.onmicrosoft.com dbname=[db_name] sslmode=require"
      
      Make sure to replace [db_name] with the actual name of your database.
    2. Token Validity: Ensure that the Microsoft Entra ID token you are using is valid and has not expired. Tokens typically have a validity of 5-60 minutes.
    3. Database Role: Verify that the database role you are trying to connect with exists and has the necessary permissions. You can check this by connecting with PostgreSQL authentication and running the command \du to list roles.
    4. Group Membership: If you are connecting as a group member, ensure that the group name matches exactly with the Microsoft Entra group display name and that the pgaadauth.enable_group_sync setting is confirmed.

    If you continue to face issues after these checks, consider reviewing the logs for more detailed error messages or consult the Azure support documentation for further assistance.


    References:

    0 comments No comments

  2. Application Admin 0 Reputation points
    2025-11-24T23:16:29.3633333+00:00

    FYI the issue was that I was using Postgresql version 18 which doesn't support Microsoft Entra ID authentication as this time. I switched to version 17 and I was able to connect.


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.