Hi Nikhil Pant,
Welcome to the Microsoft Q&A Platform! Thank you for asking your question here.
Is your PostgreSQL, single server or flexible server?
Since the application is working locally on the Azure VM hosting the database, I think the issue might be the network or connectivity problem.
Can you check the PostgreSQL logs for errors related to connections or performance issues.
Run a ping
command from the application VM to the database VM to check network connectivity.
Please check this Are you running into Postgres connection issues on Azure?
Connection timeout issue on Azure PostgreSQL Single Server
For more trouble shooting steps, please check Troubleshoot connection issues to Azure Database for PostgreSQL - Single Server
Troubleshoot connection issues to Azure Database for PostgreSQL - Flexible Server
If you have any further queries, please do let us know.