Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
The behavior difference between local and Azure Container Apps indicates a connectivity or resource issue between the container app environment and Azure Database for PostgreSQL (with built-in PgBouncer), not with the database itself.
Use the following focused checks and mitigations:
- Verify the app is actually using PgBouncer (port 6432)
- Built-in PgBouncer is enabled on port 6432 and uses the same host name as the PostgreSQL server.
- In the container app connection string, ensure the port is 6432 (PgBouncer) rather than 5432 if PgBouncer is intended:
- Example test from a shell:
psql "host=myPgServer.postgres.database.azure.com port=6432 dbname=postgres user=myUser password=<password> sslmode=require"
- Example test from a shell:
- If 6432 is unreachable from the container, the app may hang until timeout.
- Check for transient connectivity issues from the container app
- Azure Database for PostgreSQL can have transient errors (brief disconnects) due to maintenance, scaling, or infrastructure events.
- Applications must implement retry logic and handle short connection losses instead of failing after a single long wait.
- From the app logs, check if timeouts correlate with maintenance windows or scaling events.
- Check for persistent connectivity issues (network/firewall)
- From the container app environment:
- Confirm outbound connectivity to the database host and port (5432 or 6432, depending on what is used).
- Validate:
- The server firewall for Azure Database for PostgreSQL allows the container app’s outbound IP or VNet/subnet.
- Any client-side firewall or network appliance between Container Apps and the database allows outbound traffic on port 5432 and/or 6432.
- If local connections succeed but the container app times out, this often indicates a firewall or networking rule missing for the container environment.
- From the container app environment:
- Confirm PgBouncer configuration and limits
- PgBouncer is enabled/controlled via server parameters:
-
pgbouncer.enabledmust betrueto use it. -
pgbouncer.max_client_connandpgbouncer.default_pool_sizecontrol how many connections are allowed.
-
- If the container app opens many connections or there are multiple apps, PgBouncer may hit limits and queue connections until the app times out.
- In the Azure portal → PostgreSQL server → Parameters, review:
-
pgbouncer.max_client_conn(default 5000) -
pgbouncer.default_pool_size(default 50 per user/database pair)
-
- If the app is highly concurrent, consider tuning these values.
- PgBouncer is enabled/controlled via server parameters:
- Monitor PgBouncer from the server side
- Connect to the PgBouncer admin console and inspect pools and stats:
psql "host=myPgServer.postgres.database.azure.com port=6432 dbname=pgbouncer user=myUser password=<password> sslmode=require" - Run:
-
SHOW POOLS;to see active/idle/waiting connections. -
SHOW DATABASES;to see connection limits per database. -
SHOW STATS;to see traffic and request stats.
-
- If many clients are waiting or pools are saturated, the app’s requests may be blocked until they hit the 35s timeout.
- Connect to the PgBouncer admin console and inspect pools and stats:
- Check for resource limits and long-running queries
- If the server is near its resource limits (CPU, connections, I/O), connections and queries can appear to hang.
- Use PostgreSQL monitoring (e.g.,
pg_stat_activity) and Azure metrics to see if connections are piling up or queries are long-running.
- Ensure proper retry and timeout strategy in the app
- For cloud databases, implement:
- Shorter connect timeouts with retry logic for transient failures.
- Reasonable query timeouts so a single slow query does not block the health endpoint for 35 seconds.
- The health/ready endpoint should perform a lightweight query to minimize latency.
- For cloud databases, implement:
- If issues persist beyond ~60 seconds or recur frequently
- If timeouts continue or last longer than typical transient events, and resource/network checks look healthy, open an Azure support request via Get Support so the platform team can check backend logs and regional health.
References: