Docker PostgreSQL: cannot connect to the server on Windows 7 - windows

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.

Related

how do I connect to postgresql with psql from powershell?

I have installed PostgreSQL 13 on Windows 10 using the EDB installer and it seems to work fine. I can connect easily with psql in the included SQL Shell application. However, I can not connect from powershell:
~> psql -U postgres -h localhost
psql: error: could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
Any permutation of psql command line switches yields the same result. I checked pg_hba.conf and it looks sane - all local connections are allowed. All the search results for the error code above on the internet assume the server is not running but it is running just fine (see SQL Shell above). Within that shell, all the postgres tables are visible, etc. What do I need to do to connect psql to the server on localhost from powershell?
Default installed pg_hba.conf:
# "local" is for Unix domain socket connections only
local all all scram-sha-256
# IPv4 local connections:
host all all 127.0.0.1/32 scram-sha-256
# IPv6 local connections:
host all all ::1/128 scram-sha-256
The IPv4 line above should cover me in powershell? Yes? tcp connections are allowed in postgresql.conf:
listen_addresses = '*' # what IP address(es) to listen on;
Long time linux PostgreSQL user, first time in powershell on Windows, though...
This morning I found the problem - the EDB installer had setup the postgres service to run on port 5433. After a couple of decades or running it on 5432 I didn't even notice that the number was different in postgresql.conf. It was late...
Something else must be running on 5432. Will check later on.

Trying to connect Postgresql remotely(windows OS)

New to PostgreSQL and running PostgreSQL on windows
I have a PostgreSQL running locally on a remote machine and also a PostgreSQL on my laptop(win 10)(same LAN), trying to connect to the remote PostgreSQL from my laptop but getting the error
no pg_hba.conf entry for host "xxx.xxx.x.xxx", user "postgres", database "postgres", SSL off
I can telnet the remote machine with port 5432
telnet xxx.xxx.x.xxx 5432 is OK ,for testing purpose ,I have given all for the connection and also my PostgreSQL installation/configuration is default on my laptop and on the remote machine . Not sure how to dig the issue here, is there any issue of running services locally without specific ip is a problem?
when I run select(host(inet_server_add r())) my o/p is just ::1
My pg_hba file is as below ,
#IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all all md5
#IPv6 local connections:
host all all ::1/128 md5
#Allow replication connections from localhost, by a user with the
replication privilege.
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5

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?

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.

Could not connect to Postgresql on Mac OS X after Installation

So I installed Postgresql onto my Mac and whenever I run anything like psql or createdb cool_database_name I get the following error.
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.5432"?
So I follow along the different solutions. I reinstall postgresql to no avail. I go to postgresql.conf` and change it to
#port = 5432 # (change requires restart)
#max_connections = 20 # (change requires restart)
# Note: Increasing max_connections costs ~400 bytes of shared memory per
# connection slot, plus lock space (see max_locks_per_transaction).
#superuser_reserved_connections = 3 # (change requires restart)
#unix_socket_directory = '/var/pgsql_socket' # (change requires restart)
#unix_socket_group = '' # (change requires restart)
#unix_socket_permissions = 0777 # begin with 0 to use octal notation
yet still nothing. I run commands such as
ls -lA /var/run/postgresql
Which tell me the file or directory does not exist.
I also check into the pg_hba.conf file but everything looks ok
# "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 jason trust
#host replication jason 127.0.0.1/32 trust
#host replication jason ::1/128 trust
When I run psql -h localhost I get
psql: could not connect to server: Connection refused
Is the server running on host "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?
could not connect to server: Connection refused
Is the server running on host "localhost" (fe80::1) and accepting
TCP/IP connections on port 5432?
I'm at a lost as to how to fix this. Any help would be appreciated.
The problem is that Mac OS ships PostgreSQL
$ `which psql` --version
psql (PostgreSQL) 9.1.4
contains support for command-line editing
You need change PATH like this:
export PATH="path_to_bin_folder_of_your_new_postgres_install:$PATH"
e.g., for Postgres.app:
export PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
This might be useful: http://blog.ringerc.id.au/2012/09/postgresql-packaging-on-mac-os-x-is-mess.html

Resources