none
Postgresql database connection randomly times out RRS feed

  • Question

  • I didn't have any issues until today, for some reason which I don't understand my web app on azure is giving random timeout exception when connecting to a postgresql server:

    PHP Warning: pg_connect(): Unable to connect to Postgresql server: could not connect to server: Connection timed out.

    Is the server running on host "IP" and accepting TCP/IP connections on port 5432?

    I initially thought it was because azure server changed the ip and I was blocking through postgresql allowed host configuration but after I've opened everything it still doesn't work.

    If I use other servers we have to query the DB there are no issues including my local machine, and the azure web app only times out sometimes others is really quick to respond.

    Wednesday, August 7, 2019 8:04 AM

All replies

  • Thanks for asking Question! Just to confirm if you are using PAAS for PostgreSQL. If so, you may refer to Troubleshoot connection issues to Azure Database for PostgreSQL - Single Server

    Thursday, August 8, 2019 5:30 AM
  • I had already checked that page.

    It's not a heavy request web app yet we are still migrating our services to azure web app so none of the recommendations should apply.

    The postgresql server is running on our (soon to be replaced by azure if it works) server in a datacenter. I have no timeout issues in any other server using the DB, including when I run my app locally on my pc.

    I did a snapshot recover and it started working again but today the timeouts slowly started coming back again. Can it bee to many connections opened ? If so why is it happening only on azure ? Shouldn't php close them automatically? Can I somehow check opened outbound connections ?

    Friday, August 9, 2019 9:27 AM
  • I cannot really comment on the scenario without knowledge of your code.

    It is recommended that you dispose the connections by using pg_close ([ resource $connection ] ) after the database call as non-persistent open connections are closed only at the end of the script.

    You can monitor the active connections using the Metrics blade on your PostgreSQL database.

    We would like to have you on board Azure database for PostgreSQL.

    Please let us know if you need any further help to make this happen.


    Tuesday, August 13, 2019 8:17 AM
    Owner