Postgres login via localhost timeout - postgresql

I've installed Postgres.app and modified the port number to 5466, I've enabled listen_addresses='*'.
I've setup 'trust' in pg_hba.conf.
I can connect through the socket via psql. However, psql -h localhost -p 5466 fails and returns *"server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request."
Port 5466 is mapped to postgresql.
Any help as to why I can connect to the socket, but not to localhost would be appreciated. If i connect on another port an error is returned instantly telling me there is no server there, but when I connect on the correct port the connection hangs and returns the error above.

The problem was a program to monitor internet traffic blocked all ports other than 80: https://github.com/PostgresApp/PostgresApp/issues/169

Related

How can I connect to server when trying to use postgresql?

I get this error message (see below) and do not know what to do about it.
Error message:
"psql: error: connection to server at "localhost" (::1), port 5432 failed: Connection refused (0x0000274D/10061) Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused (0x0000274D/10061) Is the server running on that host and accepting TCP/IP connections? "
I am using Windows 10 (64bit) and have tried the same thing on Kali and Ubuntu and still was not able to use postgresql.
Does anyone have a suggestion what do to? However, please use "language" that I can understand or at least look up simply because I am new to programming (in general). Thank you
P. S. I tried various different things such as using pgAdmin to change ports but cannot solve a problem. I do not know if this is important but I istalled postgresql via Binaries because regular Installer was giving an error message telling me that comspec does not point to cmd.exe even though it actually did...
If you
properly set up your db (installation and initialization using initdb), and if you
have your data directory containing your postgresql.conf and pg_hba.conf among other things, and you
properly started the postgresql service,
then I can assume your problem is in the connection string.
Try to include the superusername and/or db name, your error maybe due to psql connecting to user localhost which does not exist inside your db.
Try to run psql with -U and -d options:
psql -U postgres -d postgres

How to connect to a remote PostgreSQL server using pgAdmin and Unix Domain Socket over SSH tunneling

I want to connect to a remote PostgreSQL server from my Windows machine using pgAdmin.
Can I connect to the server using unix domain socket over SSH tunneling?
The PostgreSQL server and the tunneling SSH server are running on the same machine.
In pgAdmin documentation, the Host name/address field of the Server Dialog is explained as:
Specify the IP address of the server host, or the fully qualified domain name in the Host name/address field. If you provide a unix domain socket, the directory name must begin with a “/”.
so, I specified /var/run/postgresql in that field to use a unix domain socket, but the following error message appears:
Unable to connect to server:
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
This is the server machine's log:
systemd[1]: Started Session 28 of user ***.
sshd[630]: pam_unix(sshd:session): session opened for user *** by (uid=0)
sshd[634]: error: connect_to /var/run/postgresql: unknown host (Name or service not known)
sshd[630]: pam_unix(sshd:session): session closed for user ***
Of course, I can connect to the PostgreSQL server using a unix domain socket on the server machine.
The following psql command works.
$ psql -h /var/run/postgresql -U *** -d ***

Postgres PgAdmin 3: Server doesn't listen - Tried everything

I tried opening ports in IPTables,
Set Listen address to *
Added
host all all 23.81.27.0/24 trust
and even
host all all 0.0.0.0/0 trust
YouGetSignal shows the port is closed, and i can't connect to my DB via PgAdmin.
I get
could not connect to server: Connection timed out (0x0000274C/10060)
Is the server running on host "23.81.27.206" and accepting TCP/IP
connections on port 5432?
Any ideas?
I already tried to reboot Postgresql, IPtables, and the server.
With this error
could not connect to server: Connection timed out (0x0000274C/10060)
Is the server running on host "23.81.27.206" and accepting TCP/IP
connections on port 5432?
no need to modify hba_file. Either listen_address in postgres.conf not set to listen on external iface, or firewall blocks it/ not translating/ othernetwork issues. First case often people modify listen_address in wrong postgres.conf or do not restart server. To make sure it did not happen to you, ssh to server, psql to it and check
show config_file;
show listen_addresses;
If those ok, then still on remotes shell :
psql -h 23.81.27.206
If you get connected, stop looking into postgres config - check network (firewall, PAT,NAT,routes, your client connection ((maybe you not connected to the Internet?..)))
Turns out it was IPTables after all. I did "Service iptables stop" And i can connect. I can't manage to allow my ip/open that port. But i guess this is how i have to do it. i just enable it whenever im done.

How do I get a Postgres server to createdb and shut down?

I have an instance of a Postgres server running that I've started with the command:
pg_ctl -D /usr/local/var/postgres/data -l /usr/local/var/postgres/data/server.log start
Running the command createdb test prompts me for my password twice, then I get this error:
createdb: could not connect to database template1: FATAL: password authentication failed for user "joey"
Also, when I try to stop the server using
pg_ctl -D /usr/local/var/postgres/data stop -m smart
I get this error message:
pg_ctl: PID file "/usr/local/var/postgres/data/postmaster.pid" does not exist
Is server running?
Is there something I'm missing or forgot to initialize/install? I used these instructions to install.
I checked this answer and this answer and neither of the two fixed my problem.
From the log file you added in your comment, it looks as if either there is another postgresql instance running on the machine (or possibly something else which is using the same port as postgresql wants to use):
LOG: could not bind IPv6 socket: Address already in use
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
LOG: could not bind IPv4 socket: Address already in use
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
LOG: could not bind IPv6 socket: Address already in use
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
WARNING: could not create listen socket for "localhost"
FATAL: could not create any TCP/IP sockets
This is stopping the database from starting up to begin with.
To see what process that could be, you can use lsof:
$ sudo lsof | grep -i listen
...
postmaste 19732 postgres 3u IPv6 1194355 0t0 TCP localhost:postgres (LISTEN)
postmaste 19732 postgres 4u IPv4 1194356 0t0 TCP localhost:postgres (LISTEN)
...
In the above sample, from a Linux host, you can see that a process called postmaster (it is truncated in the printout) listens on localhost:postgres, meaning the localhost address port 5432 (lsof is translating the port 5432 into 'postgres' via the file /etc/services which contains a mapping between well known port numbers and corresponding services).
The fact that createdb is prompting for your password implies that it is connecting to a database somewhere, although I could not spot it the ps printout you sent.
The other part of your question was why createdb could not connect to your database (or whatever database is running on your machine). If it is a freshly created database cluster then it will not have any users defined other than the default 'postgres' user. You must issue commands with this user:
createdb -U postgres test
Without the -U option it will try to connect using your current login user, which won't exist in the database.
It might also be that you will need to authenticate as the postgres user. The file pg_hba.conf in the postgresql data directory controls what kind of authentication will be needed.
In general the postgresql documentation is excellent; I suggest you read through the section Server Setup and Operation to check that you have a valid configuration.

pgAdmin and PostgreSQL: can't connect to server

I just installed PostgreSQL on Snow Leopard and can't connect to the database server via pgAdmin 3.
I'm on my local machine, however I keep getting this error:
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 5423?
I'm a bit of a noob when it comes to Postgres, so I'm not really sure what the problem is.
I can, however, log in through the command line, via psql -U postgres, and start and stop the server successfully.
Any help would be much appreciated.
The error message pointed out that you tried to connect to server on port 5423. However, postgres server listens on 5432 by default.
From your above comment (SHOW port; gives me "5432"), I think you need to change the port to 5432!
UPDATE: Tuan Dang spotted it. I'll leave this answer in place in case it helps someone else for whom the issue isn't quite the same.
Since you can connect via the command line, run:
SHOW port;
from psql. You'll probably see that the port is not 5432. You need to connect to the port PostgreSQL is actually running on from your application.
It's also possible that it just isn't listening on TCP/IP. Run:
SHOW listen_addresses;
to see what it's listening for.
The reason you can connect via the command line is likely to be because the command line psql you're using is connecting over a unix socket (since you didn't specify a host) and your app is connecting via tcp/ip.