Running Postgresql 9.5 on a Windows 2012 R2 server in Azure
When I run some boot tests in my application, I get errors when it is not possible to connect to the postgres server. In postgres logs, I get the following message:
Failed to receive data from the client: the connection could not be completed because the target machine actively refused it.
This only happens when loadtest moves on to the next script, falling into another part of the code. Therefore, new database connections are needed. But after 10-20 seconds, the rest of the script works flawlessly, without hitting any other hiccups. So the problem is with tcp connection. (My code retries several times, but it is not possible to retry within 20 seconds)
I use the following settings in configuration files
postgresql.conf
listen_addresses = '*' max_connections = 500 shared_buffers = 1024MB temp_buffers = 2MB work_mem = 2MB maintenance_work_mem = 128MB
pg_hba.conf
host all all 0.0.0.0/0 trust host all all ::/0 trust
I know, I know. You cannot accept connections from everyone, but this is only for testing purposes and to ensure that these settings do not block any connection. So this answer is invalid
I track the number of connections on the server and under load it is stable at 75. Postgres uses about 350 MB of RAM. Therefore, given the configuration and specifications of vm (7gb ram), there should be enough space to create more connections. However, when the following scenario unfolds, the number of connections does not increase, it remains at the level and starts issuing these log messages about the impossibility of connection.
What could be the problem?