Postgresql: No connection could be made because the target machine actively refused it
It does sound like this isn't really a Postgres problem (hence no changes in DB stats you're checking), rather that the traffic is being stopped by the server. Possibly because traffic on that port is saturated while handling your load testing queries?
It doesn't sound like you're hitting any of the Azure resource limits (including the database limits if that applies to your setup?), but without more detail on your load tests it's hard to say exactly what is needed.
Solutions from around the web and other SO answers suggest:
- Disable TCP autotuning and tweak the TCP/IP registry keys on the server, e.g. set
TcpAckFrequency
- see this article for details - Make TCP setting adjustments (like WinsockListenBacklog) - which may be affected by whether connection pooling is in use or not - see this MS support article, which is for SQL Server 2005 but has some great tips on troubleshooting rejected TCP/IP connections (using Network Monitor, but applies to newer tools)
- Faster request processing if you have enough control of the server - source
- Disabling network proxying (in your load testing app):
<defaultProxy> <proxy usesystemdefault="False"/> </defaultProxy>
- source
Most possible reason is a Firewall/Anti-virus:
- Software/Personal Firewall Settings
- Multiple Software/Personal Firewalls
- Anti-virus Software
- LSP Layer
- (Virtual) Router Firmware
Does your current Azure infrastructure contain Firewall or Anti-virus ?
Additionally on doing some additional searches, it looks like this is a standard Windows "connection refused" message, which suggests that PostgreSQL is trying to connect to something and being refused.
Also possible that one network element in your network - assuming that you are still connected to the server - will delay or drop somes DB login/authentication network packets (considered for example as a fake auth.replay) ...
You may also use a packet analyzer (like Wireshark) to record/inspect network flow when the error appear.
Regards