Unable to connect to PostgreSQL server: could not connect to server: Permission denied - linux

Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: Permission denied Is the server running on host "10.0.1.201" and accepting TCP/IP connections on port 5432?
This is the error i am getting when trying to connect to remote database from linux based server
Though i am able to connect to it from localhost
Can anyone help me in this

One possible scenario/solution that worked for me (for the very same problem) is here:
service httpd stop
service postgresql stop
setsebool -P httpd_can_network_connect 1
service httpd start
service postgresql start
Here we're basically allowing HTTPD to connect to PostgreSQL over network by setting SELinux bool equals to 1 (true).

Check the listen_addresses setting in postgresql.conf. If it is set to localhost, then only loopback connections will be accepted, and remote connections will get a "connection refused" error. Set listen_addresses to "*" to enable listening on all interfaces.

In PostgreSQL you have to configure client authentication in pg_hba.conf on the remote server.
Read more about pg_hba.conf # http://developer.postgresql.org/pgdocs/postgres/auth-pg-hba-conf.html , otherwise you'll never connect to that server :).
Hope it will help,
Stefan

Related

Logs to troubleshoot SSH tunneling errors

I am trying to troubleshoot connection errors when using SSH tunneling to connect to a rhel 8 EC2 server. Does anyone know of a log location on RHEL 8 that may contain more information when the connection is refused?
For reference I am using the following command (which works on all my other servers)
ssh -i -L 8745:IPOfServer:8443 ec2-user#IPOfServer
I get the error "open failed: connect failded: Connection refused
I can connect on 8080 but 8443 is refused even though the port is open and the application and firewalld are configured to listen on 8443 and 8080.
Thanks!!

Docker Postgresql can't connect remotely

I can connect my docker postgresql in my local server windows via ip or localhost. When I try to connect it remotely from my personal windows I have timeout error. Thinking about 5432 port is blocked or not listening.
I have changed pg_hba.conf & postgresql.conf files for remote connection and also checked for firewall but it was disabled.
Answer is I should have checked my server's firewall conf also, just dockerVM is not enough :)

As I can, configure the firewall of ubuntu server for the server to accept connections of the terminals through PostgreSQL port 5432

Configuration: Server: Ubuntu server 16.04 LTS using webmin
Terminal: Windows 7 Using PgAmin III
I was unable to establish the connection between my terminal and my server through pgAdmin III on port 5432.
On my server I added:
in file postgresql.conf I edited
in #Connection Settings
listen_addresses = '*'
in file pg_hba.conf I added
in #IPv4 local connections
host all all 172.x.x.x/32 md5 //this is IP Terminal (Hidden x)
I checked the port, this is 5432 default and user is postgres
When I try to establish the connection on PgAdmin III:
Host: //My Server IP (Ping console successful)
Port: 5432
username: postgres
password: //My password
Show me the following message:
Server doesn't listen
The server doesn't accept connections: the connection library reports
could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "Mi SERVER IP Hidden" and accepting TCP/IP connections on port 5432?
If you encounter this message, please check if the server you're trying to contact is actually running PostgreSQL on the given port. Test if you have network connectivity from your client to the server host using ping or equivalent tools. Is your network / VPN / SSH tunnel / firewall configured correctly?
For security reasons, PostgreSQL does not listen on all available IP addresses on the server machine initially. In order to access the server over the network, you need to enable listening on the address first.
For PostgreSQL servers starting with version 8.0, this is controlled using the "listen_addresses" parameter in the postgresql.conf file. Here, you can enter a list of IP addresses the server should listen on, or simply use '*' to listen on all available IP addresses. For earlier servers (Version 7.3 or 7.4), you'll need to set the "tcpip_socket" parameter to 'true'.
You can use the postgresql.conf editor that is built into pgAdmin III to edit the postgresql.conf configuration file. After changing this file, you need to restart the server process to make the setting effective.
If you double-checked your configuration but still get this error message, it's still unlikely that you encounter a fatal PostgreSQL misbehaviour. You probably have some low level network connectivity problems (e.g. firewall configuration). Please check this thoroughly before reporting a bug to the PostgreSQL community.

Error remote access MongoDB on Ubuntu server

I have an Ubuntu 14.04 Linux server with MongoDB 3.2.4 running at Digital Ocean as a droplet (one-click Apps).
Pinging the server works (droplet is distroyed after posting this):
ping 198.199.125.101
I created database test and user:
db.createUser({"user": "test", "pwd": "test", "roles": ["dbOwner"]})
In mongod.conf I changed bindIp: 0.0.0.0 and restarted mongoDB
I disabled the firewall and reboot the server. Just for test, just to prove iptables is not the issue (don't do this on a regular server):
sudo ufw disable
The problem is I can't get remote access to the mongo Database
mongo 198.199.125.101:27021/test -u "test" -p "test"
Error message (connection refused):
MongoDB shell version: 3.2.0
connecting to: 198.199.125.101:27021/test
2016-05-11T22:05:35.876+0200 W NETWORK [thread1] Failed to connect to 198.199.125.101:27021, reason: errno:61 Connection refused
2016-05-11T22:05:35.879+0200 E QUERY [thread1] Error: couldn't connect to server 198.199.125.101:27021, connection attempt failed :
connect#src/mongo/shell/mongo.js:226:14
#(connect):1:6
exception: connect failed
First run netstat on the mongo machine to verify that the port 27021 is open. netstat -anp should do it.
Then do "telnet 127.0.0.1 27021" to make sure it is open.
Once you are sure the port is open, then use telnet 198.199.125.101 27021 to verify you can connect to the mongo machine on port 27021. If you can, then it has something to do with your app. If not then something is blocking the connection. Some firewall or something. Are you on aws?
As per netstat, can you try mongo 198.199.125.101:27017/test -u "test" -p "test"

Failed to reach erlang port mapper (server ports open and connecting via Telnet)

I am trying to add a new server to an existing cluster. I am using community version 2.1.1 on both ubuntu servers on windows azure. I tried to add new server via web interface and via command line. But i am getting following error.
***"Failed to reach erlang port mapper. Timeout connecting to "xx.xx.xx.xx" on port "4369". This could be due to an incorrect host/port combination or a firewall in place between the servers.']***
Port 4369 is open on both servers and iam able to connect to 4369 port on other server using telnet
Got the same error when used the following command.
/opt/couchbase/bin/couchbase-cli server-add --cluster=xx.xx.xx.xx:8091 -u user -p password --server-add=yy.yy.yy.yy:8091 --server-add-username=Administrator --server-add-password=password
ERROR: unable to server-add yy.yy.yy.yy:8091 (400) Bad Request
[u'Prepare join failed. Failed to reach erlang port mapper. Timeout connecting to "xx.xx.xx.xx" on port "4369". This could be due to an incorrect host/port combination or a firewall in place between the servers.']
root#xx.xx.xx.xx:/home/azureuser/project# telnet yy.yy.yy.yy 4369
Trying yy.yy.yy.yy...
Connected to yy.yy.yy.yy.
Escape character is '^]'.
^]q
telnet> q
Connection closed.
What will be the issue? Please help me sort this out.
There are a number of ports required to be open between cluster nodes (in addition to 4369) - I'd suggest ensuring all of the ports listed in the Couchbase Installation Guide - Network ports are open and accessible.

Resources