How to fix Connection to localhost:5432 refused in postgres installed on CentOS 7? - spring

I have a digitalocean droplet and I'm trying to install my Java web-application, on CentOS 7, which is using postgres database. I've successfully installed Java, tomcat and postgres database. I am able to connect to my droplet's postgres database from my local machine using pgadmin as well as from local eclipse. But when I am deploying the web application on server I'm getting the following error:
org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
I've added listen_addresses = '*' to postgresql.conf
This is the code from pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
host all all 0.0.0.0/0 md5
Is there any firewall issue? Do I need to provide any special permission? The port which I am using to connect is 5432. I've not made any changes to the port.
I deleted the droplet and installed ubuntu 18 on it, I was successfully able to connect to the database properly. Again, I installed CentOS 7 and it gives the same problem.
Here's the output of iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: enforcing
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 31

For some reason my tomcat 8 server just did that the same thing this morning, when it was working previously. I looked at the selinux logs in /var/log/audit and found the following got me back working again:
sudo setsebool -P tomcat_can_network_connect_db true
Edited: added -P flag to stick between reboots.

Related

Docker PostgreSQL: cannot connect to the server on Windows 7

I run on Windows 10
docker run -it --rm -e POSTGRES_PASSWORD=postgres -p5401:5432 postgres:12.3-alpine
it works fine. I can connect to PostgreSQL, create database etc, all is ok.
But when I run the same docker on my 2nd machine Windows 7 I receive
Could not connect to server: Connection refused (0x0000274D/10061) Is
the server running on host "localhost" (::1) and accepting TCP/IP
connections on port 5401?
What may be the reason? what to check?
That is pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
host all all all md5
I would say the possible issues are:
1) The server has not actually been started in the Docker server.
Verify server is running.
2) Port 5401 is not visible to the client that is trying to connect.
Ping the port. Could be a firewall issue.

postgres: client could not connect to server

For clarification, please note that I have found several similar questions on stackoverflow, but I could not fix my issue.
psql: could not connect to server: Connection refused” Error when connecting to remote database
psql: How to Allow Remote Access to PostgreSQL database
I am trying to connect to a postgres DB installed in a remote server.
To create a connection from the client I am using QGIS plugin (Add PostGIS Layer):
The error that occurs is:
could not connect to server: Connection refused (0x0000274D/10061) is the server running on host "localhost" (::1) and accepting TCP/IP connection on port 5432
Additionally I added the host's IP Adress in the Host field, but then another error message occurs:
could not connect to server: Connection timed out (0x0000274C/10060) Is the server running on host "hosts_ip_adress" and accepting TCP/IP connections on port 5432?
My settings are:
Postgres installed version is 10.0 with PostGIS extension
Host operating System: Windows 7
Client operating System: Windows 7
I edited pg_hba.conf to:
host all all 0.0.0.0/0 md5
and changes listen parameter in 'postgresql.conf' to:
listen_addresses = '*'
both files are located in C:\Program Files\PostgreSQL\10\data
restartet pgAdmin4
My devices are in the same network. Each one is connected via LAN cable.
I suppose that a firewall is preventing the connection?

debugging remote websphere application from eclipse

I've configured my server to run with the following flags:
Server--> Server Types --> WebSphere application servers --> Additional Properties --> Debugging Service:
JVM Debug Arguments= -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8888
JVM Port= 8888
I configured eclipse debug configuration with the server ip (verified that ip is reachable with the ping command) and port
To be sure i increased the debugger timeout as well .
I've got: Failed to connect to remote VM. Connection refused.
Connection refused: connect
so i did a port scan on the server with (nmap xxx.xxx.xxx.xxx -p 8888) and the port seems:
PORT STATE SERVICE
8888/tcp closed sun-answerbook
moreover looking at the section Server--> Server Types --> WebSphere application servers --> Communications-->Ports of WebSphere admin consolle
i don't see the port 8888 in the list.
what do i need to do?
open the port on the machine? (how?)
add the port in the list of the above mentioned section?
other?
###### EDITED ########
ADDITIONAL CHECKS
netstat -na | grep 8888 --->no listening port/doesn't show me nothing
----------------------------------------------------------------------------
[root#dmgr ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
----------------------------------------------------------------------------
C:\Users\alex>nmap 192.168.115.235 -p 8888
Starting Nmap 7.60 ( https://nmap.org ) at 2018-02-23 10:58 ora solare Europa occidentale
Nmap scan report for xxxx.xxxxxxxxxxxx.com (192.168.115.235)
Host is up (0.0018s latency).
PORT STATE SERVICE
7777/tcp closed cbt
Nmap done: 1 IP address (1 host up) scanned in 4.59 seconds
so, no listening port on 8888, no iptables rules that deny the connection, how to investigate further?
You are almost there :-)
On the Debugging Service page where you set the port and arguments, there is a checkbox - Enable service at server startup - ensure that it is checked.
If not, check, and restart the server.
After that you should see the debugging port open. You can check it for example via netstat -an.
If the port is open and you still cannot connect then it is probably the firewall issue.
Here some more details about setting the debug - Starting the application server in debug mode

Windows 8 VMWare guest under Ubuntu 16.04 host doesn't have access to the internet

I have Ubuntu 16.04 host machine with WMWare Player and Windows 8 guest. The problem is that the guest Windows machine doesn't have access to the internet.
Host Ubuntu 16.04 configuration:
>>> grep VERSION= /etc/*-release
/etc/os-release:VERSION="16.04.3 LTS (Xenial Xerus)"
>>> sudo iptables --list
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
>>> sudo ufw status
Status: inactive
VMWare configuration:
> vmware --version
VMware Workstation 12.1.0 build-3272444
Windows guest machine:
Testing:
Notes:
Note the ping is ok and nslookup hangs. Looks like host machine is stopping the traffic.
I tried ssh into host - ok.
I tried ssh into other machine within the Local lo network of the host - ok
The gateway in the network config is set to 172.16.223.2. I tried to change that to the IP of the host (172.16.223.1) - same results.
My case was really simple. For some reason VMWare hasn't picked up proper DNS's of the host and 8.8.8.8 and 8.8.4.4 are blocked within the internal network. Setting DNS servers manually within Windows to the IPs that are allowed within internal network fixed the issue.
I am marking the question as resolved, but if smb posts a solution to fix the VMWare to pick-up the DNS's of the host, I will switch to his answer.

Vagrant port fowarding on macOS?

I'm running postgresql on a Vagrant centos 7.2 box on macOS. I have confirmed postgres is up and running on the Vagrant box on port 5432 by connecting to it using psql on the box itself. I am attempting to forward port 5432 on the Vagrant box to port 10001 on my host machine as follows:
config.vm.define "acc_db" do | acc_db |
acc_db.vm.box = "bento/centos-7.2"
acc_db.vm.hostname = "acc.db"
acc_db.vm.network :forwarded_port, guest: 5432, host: 10001
acc_db.vm.provision "shell",
inline: "yum upgrade -y -q --nogpgcheck"
acc_db.vm.provision "shell",
path: "install_postgres.sh"
I have altered my pg_hba.conf to bind to all ip addresses and allow password authentication, as below:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 0.0.0.0/0 md5
# IPv6 local connections:
host all all ::1/128 ident
I have turned off the firewall but I am still unable to connect to postgres on port 10001 on the host machine:
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.10001"?
How do I fix this so that port forwarding works?
I have seen https://gielberkers.com/fixing-vagrant-port-forwarding-osx-yosemite/ but haven't tried it as it involves touching files I'm unfamiliar with. Is it the correct approach? It looks like you have to explicitly allow every port you want to forward via Vagrant.
...connections on Unix domain socket "/tmp/.s.PGSQL.10001" means that you are not attempting a TCP/IP connection, so port forwarding cannot happen.
By default, psql use Unix domain sockets on unix-like OSes.
Use the -h option of psql to specify a host, presumably 127.0.0.1 if using IPv4.
Additionally, the PostgreSQL server must listen to the network interface to which the connection will be routed. By default, it listens only to localhost for security reasons.
Setting listen_addresses='*' in postgresql.conf makes it listen on all existing interfaces.

Resources