Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgresql: No connection could be made because the target machine actively refused it

Running Postgresql 9.5 on a windows server 2012 R2 in Azure

While running some loadtests on my application, I get errors on not being able to connect to the postgres server. In the logs of postgres I get the following message:

could not receive data from client: No connection could be made because the target machine actively refused it.

This only happens when the loadtest goes to the next scenario, hitting a different part of the code. So new connections to the database are required. But after 10-20 seconds the rest of the scenario works flawlessly without hitting any other hiccups. So the problem seems to be the tcp connections. (My code retries a couple of times but it is not feasible to let it retry for 20 seconds)

I'm using the following settings in the config 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.. It is not save to accept connections from everyone, but this is just for testing purposes and to make sure these settings are not blocking any connection. So this answer is void

I've been monitoring the number of connection on the server and under the load it is stable at 75. Postgres is using around 350mb of RAM. So given the config and the vm specs (7gb ram) there should be plenty of space to create more connections. However when the next scenario is spinning up the number of connections does not increase, it stays level and starts giving these log messages about no connection could be made.

What could be the problem here?

like image 493
P. Gramberg Avatar asked Aug 02 '16 20:08

P. Gramberg


People also ask

How do you fix no connection could be made because target machine actively refused it?

You can try below solution: You might have a firewall rule in the way, or are trying to run it through a proxy without having the proxy up and running. The easiest way to check would be to disable your firewall or proxy and try again. Disable proxy at web.

How do you fix no connection could be made because the target machine actively refused it 10061?

Try running netstat -anb from the command line to see if there's anything listening on the port you were entered. If you get nothing, try changing your port number and see if that works for you. In Windows operating systems, you can use the netstat services via the command line (cmd.exe) .

Can't connect to target machine actively refused it?

​If no connection could be made because the target machine actively refused it, this indicates that the Source or Destination system blocked the connection. This is likely due to firewall or web server settings. In some cases, an IP restriction may be in place.

Why PostgreSQL connection could not be made?

8 Postgresql: No connection could be made because the target machine actively refused it 4 Send text string via TCP? 4 No connection could be made because the target machine actively refused it 127.0.0.1:57240 at System.Net.Sockets.Socket

Why no connection could be made to the target machine?

No connection could be made because the target machine actively refused it 127.0.0.1:57240 at System.Net.Sockets.Socket See more linked questions Related 7 WebException: Unable to connect to the remote server

Can PowerBI desktop connect to postgre database?

I did a connection with a postgre database and all works fine in powerbi desktop. When i did publish the .pbix on app.powerbi.com with use the same configuration parameters to the database, i receive the error: No connections could be made because the target machine actively refused them Não é possível conectar à fonte de dados undefined.

Why does my local computer refuse to connect to remote server?

Any chance when you create a website or desktop application trying to reach remote web server or web API, your local computer prompts "No connection could be made because the target machine actively refused it 127.0.0.1:8888". Local host always referred as 127.0.0.1


2 Answers

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
like image 148
brichins Avatar answered Sep 29 '22 01:09

brichins


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

like image 21
A STEFANI Avatar answered Sep 29 '22 00:09

A STEFANI