The error that you're facing "invalid authorization specification" might be because of the fact that Azure Database for PostgreSQL requires SSL connections by default. If the client (Heroku app or Azure Data Studio) is not explicitly configured to use SSL, the server will reject the connection even if the credentials are correct.
Kindly follow the mentioned steps to troubleshoot the error:
- Confirm SSL is required by your Azure PostgreSQL server:
- Go to "Connection Security" in your Azure Database for PostgreSQL
- Ensure that “Enforce SSL connection” is enabled.
- Update the
DATABASE_URL
with SSL mode:
- If your connection string doesn’t include SSL settings, update it to:
postgres://username:******@yourserver.postgres.database.azure.com:5432/dbname?sslmode=require
For Heroku:
heroku config:set DATABASE_URL="postgres://username:******@yourserver.postgres.database.azure.com:5432/dbname?sslmode=require"
- Configure Azure Data Studio to use SSL:
If you’re connecting using Azure Data Studio, make a "New Connection"
- Enter your connection details (Server name, Username, Password and DB name)
- Click "Advanced" tab
- Set
sslmode
:require
- If your app requires strict SSL validation, you may need to add a root certificate.
Download the official Azure CA certificate from:
https://learn.microsoft.com/en-us/azure/postgresql/concepts-ssl-connection-security#ca-certificate
Kindly verify the same at your end. Hope it helps. Kindly accept the answer by clicking on Accept answer
button. Thankyou