I'm having big troubles connecting to PostgreSQL, installed in WSL2 Ubuntu, from the Windows 10 host.
Here is what I have done so far.
Set password for postgres user.
Set the following in pg_hpa.conf
local all postgres md5
host all all 0.0.0.0/0 md5
Set the following in postgresql.conf
listen_addresses = '*'
Tested successfully that I can connect with psql -U postgres - so password should be set correctly.
When I try to connect using either pgAdmin or psql from the Windows 10 host, I get the following error.
error: could not connect to server: FATAL: password authentication failed for user "postgres"
Anything else I can change in pg_hpa.conf or other PostgreSQL configurations which might help?
I'm thinking that I could have something to do with that WSL2 has its own IP, even tough that connections from the hosts are made appear coming from localhost. The connection seems to be made, but authentication failed for some reason when it is not made from within Ubuntu.
I later tested with nc -l 5432 and for some reason, port 5432 didn't reach WSL2 on local host, but did on WSL-2 IP. If I use any other free port e.g. 5434 (free both on Windows and WSL-2) it works fine and I can connect to the PostgreSQL service on WSl-2 through localhost on windows.
I didn't change any options since the original posted question - only the port.
Update: It turns out that there indeed was a process from an old install of postgres on Windows which was listening on port 5432. This of cause explains it all. ..:/
As was pointed out by the original poster, ensure that you do not have a Windows service already running and listening on that port. In my case it was a PostgreSQL instance installed as a Windows service. Whatever the underlying networking support, it seems you can have a process/service listening on port 5432 in Windows as well as a separate Linux process listening on port 5432 from WSL2.
It was not enough to stop the Windows PostgreSQL service. Connecting from the Windows pgAdmin4 installation program failed. I also disabled the service from Microsoft Services console.
I needed to also stop and start the WSL2 postgresql. Only then was I successfully able to connect from my Windows pgAdmin4 installation program to the WSL2 postgreSQL
Related
As the title suggest I'm trying to configure a postgresql server to be accessible remotely. I've followed many guides and viewed some of the other answers here however I'm still having trouble.
The details:
os, windows 10
postgresql version on host is 11.6
postgresql version on remote is 11.2 with anaconda install
I have changed the pg_hba.conf and postgresql.conf to allow for connections to the server.
More specifically I've added the line
host all all xxx.xx.x.0/0 trust
I can verify that the host is listening on local address 0.0.0.0:5432 via netstat.
I can ping the ip of the host from the remote, and I have set windows firewalls on the host to allow connection.
Yet I still recieve the following error when trying to access psql from the remote.
psql: could not connect to server: Connection timed out (0x0000274C/10060)
Is the server running on host "xxx.xx.x.144" and accepting
TCP/IP connections on port 5432?```
I had to double check the windows firewall permissions. The connection was enabled but the application was not set to allowed. It turns out a local user can enable connection but I needed the system admin to set the application executable to allowed by the windows fire wall.
I think I followed any possible guide before asking here.
I am trying to remotely connect to a PostgreSQL db installed on a EC2 Linux instance (Ubuntu server 18.04, free tier if it matters).
Here are all the steps I did before hitting a wall and begging for help.
I connected to my instance via SSH
I downloaded and installed postgres following this docs
I created a new used (umberto)
I created a new DB (wondermap)
I created a new OS user with the same name as in step 3 (umberto)
I connected to my new db with my new user from the server and everything woked fine
I edited /etc/postgresql/10/main/pg_hba.conf adding these lines:
host all all 0.0.0.0/0 md5
host all all ::/0 md5
I edited /etc/postgresql/10/main/postgresql.conf changing #listen_addresses = 'localhost' into listen_addresses = '*'
i restarted the postgres server with sudo service postgresql restart
I added a new Inbound rule in the instance security group like so:
TCP port:5432 source:0.0.0.0/0, ::/0
After all, I am trying to connect from my local mahine (either using pgadmin3 or psql) but I still receive a timeout error (host is hidden):
psql -h <PUBLIC-IP-OF-MY-INSTANCE> -U umberto -d wondermap
or even
psql -h <PUBLIC-IP-OF-MY-INSTANCE> -U postgres
psql: could not connect to server: Connection timed out
Is the server running on host "<PUBLIC-IP-OF-MY-INSTANCE>" and accepting
Doing SELECT version(); shows:
PostgreSQL 10.7 (Ubuntu 10.7-0ubuntu0.18.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0, 64-bit
What could be the problem?
Apparently, I stil had to unblock postgres port on server's firewall.
sudo ufw allow 5432/tcp
That did the trick!
Ubuntu 16.04 LTS
I have followed the guides which all say the same thing; to enable remote connection to a postgres server, update the postgresql.conf file, update the pg_hba.conf file and make sure the port (5432) is open and firewall is not blocking.
When I attempt to connect to my server from the remote machine using the following command, I receive no response (for example, 'Connection refused...'). It hangs as if the firewall has DROP policy, but I checked and the host's firewall is ACCEPT all. Here is the command:
psql -h 45.67.82.123 -U postgres -p 5432 -d mydatabase
I have googled extensively and can't find anyone else who's psql request sits with no response from the host server.
Edit: I should mention I have been connecting locally on the host machine. I should also mention that the data directory on the host machine is in a non-default location. I have my cluster on a mounted drive, in case this could affect the remote connection.
Solution:
It is my first AWS instance and I didn't know they have their own firewall rules on the platform. So I was highly confused by the fact all my policies were ACCEPT on my server. Turns out you are behind AWS firewall and you have to go onto the platform to add/change security groups etc. In the past when I've used Digital Ocean droplets or Linodes, the firewall policy on the vps is all I need to change. AWS threw me another curveball there.
I'm trying to connect my local gui for postgres to a virtual server that I have running postgres.
I can
su postgres_user
Then
pgsql
Here pgsql loads.
When I go to my pg_hba.conf I have
host all all x.x.x.x/24 trust
In postgresql.conf
listen_addresses = 'localhost,x.x.x.x'
I have ubuntu 16 and postgres 9.5
I have the issue when I try to connect I get the error:
could not connect to server: Connection refused...Is the server running on host "hostip" and accepting TCP/IP connections on port 5432.
If you are using linode, you must either whitelist your ip or use putty (in windows) to tunnel postgres to connect to it.
putty tunneling is easier, however more annoying to deal with on a day to day basis
Follow the tutorial here.
here
Note, it's the same for PGAdmin as it is for any gui in windows.
New to web development. Trying to connect and register new server for pgAdminIII. (using cloud 9 ide)..
I get this error when viewing in the browser..
_PG::CONNECTION BAD _
could not connect to server: Connection refused Is the server running on
"localhost" (::1) and accepting TCP/IP connections on port 5432?
could not connect to server: Connection
refused Is the server running on host "localhost"
(127.0.0.1) and accepting TCP/IP connections on port 5432
PS. trying to access via new user "ubuntu" SUPERUSER created..
How can I fix this?
PPS. On cloud 9's community forum, an employee says..
"Only ports 8080, 8081 and 8082 are open for workspaces so if you want to access the DB externally you'll need to run it on one of these ports. Make sure you can access it with curl from a local terminal and ensure it's listening on 0.0.0.0 not 127.0.0.1, as the latter only allows local connections."
Lastly, their ide comes with postgres installed, all I needed to do, was set it up..
How do I use the above info while trying to register the new server in order to use the gui?
Let me know if I need to include anything else.
Thanks.
You should enable postgresql service by performing sudo service postgresql start.
After enabling, you can access the console using sudo sudo -u postgres psql and CREATE ROLE ubuntu LOGIN REPLICATION CREATEDB CREATEROLE SUPERUSER; to allow Rails take advantage of your database.
Rails also complains about template read error after creating ubuntu role.
To fix the template error, read up on this.
You should get PostgreSQL server up and running in no time. Happy coding!
Edit:
You should only use localhost for local and system resources (i.e. psql, etc.) while 0.0.0.0 is for everything else like running Rails or Apache server.