pqxx: broken_connection on trying to connect to posgres db - postgresql

I have this problem trying to connect to the local postrgres databases. Until now i succeeded to connect to the same databases using jdbc or working directly in PGAdmin, this error happens when i try to connect using pqxx library or from shell:
pqxx code:
#include <pqxx/connection.hxx>
int main(){
pqxx::connection conn("user=postgres port=5432 dbname=pqxx-test password=postgres");
return 0;
}
or from shell, as user postgres:
psql pqxx-test
both the cases raise this error:
could not connect to server: No such file or directory Is the server
running locally and accepting connections on Unix domain socket
"/var/run/postgresql/.s.PGSQL.5432"
Searching for the solution i think i understood i have to edit pq_hba.conf and postgresql.conf files in order to connect in these ways, but in pg_hba.conf is already set:
local all all md5
and in postgresql.conf
listen_addresses='*'
And by the way, i'm not even able to edit these files because of a problem with the viminfo, but maybe this is another problem..
Can anyone help me?
edit:
using PostgreSQL 9.6.2
on Ubuntu 14.04
edit:
as postgres user, if i ask for the postgre version using:
psql -V
the result is 9.6.2
but looking at the file system hierarchy, all conf file are inside this folder
/opt/PostreSQL/9.4/data/
can that be the problem?

You seem to have a mix of client-side postgresql 9.6 configured for the ubuntu FS layout and a postgresql server 9.4 presumably downloaded from EntrepriseDB (and installed under /opt/PostgreSQL) using its own layout.
Assuming that the postgresql is running, the simplest solution is to add host=localhost to your connection string, so that it will use a TCP connection instead of the Unix domain socket /var/run/postgresql/.s.PGSQL.5432 that does not exist because of the mismatch.

Related

Can't connect to postgres via PSQL or php, only pgAdmin4

I have PostgreSQL 12 installed and using Windows 10. My goal is to connect to postgre via php, because it didn't work I tried with plsql but it didn't work either, i always get (with both plsql and php using PDO):
FATAL: password authentication failed for user "postgres"
Connection via plsql in cmd
However, when trying via pgAdmin4, I can connect and access my databases. I first use my root password then sometime my postgres user one, so I'm sure my password works.
Here is my pg_hba.conf file:
pg_hba.conf file
I have a set password for postgres which was set vua pgAdmin4.
I don't understand why it would work one way and not the other, can anyone help me?
So after trying several things, I found that plsql and php error was due to the wrong port being adressed.
By default 5432 is used, but for some reason my configuration was using 5433.
You can find this information in pgAdmin4 by opening PostgreSQL 12 properties, and then checking in connection tab.
To change the used port in plsql I used:
psql -U postgres -p 5433
Change 5433 by your configured port if you have same issue, you also need to specify the port if using php's PDO.

Multiple installations of Postgres on Ubuntu

This is the first time I am setting up multiple Postgres postgres servers on Ubuntu 12.04LTS. (I know multiple versions is a bad idea, but need to sanity check new installation before I migrate and kill the old instance)
Original Postgres V9.1 is installed using bundled apt-get install. (Port : 5432)
New Postgres V10 is installed via EnterpriseDB package. (Port : 5433)
I am able to use standard utilities for the V9.1 like psql, pg_dump, etc. However, I am not able to access psql of V10. Instead I am getting this error message (note the incorrect port):
/opt/PostgreSQL/10/bin$ ./psqlpsql.bin: 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"?
I would like to be able to manage both ideally by using psql.
I usually use Python to connect to databases and I am able to create an SQLAlchemy connection to new instance at port 5433. I can query pg_catalog and information_schema as well.
Thanks in advance!
The default port of postgres is 5432.
So If you want to access psql of V10, use the below commands:
export PATH=/opt/PostgreSQL/10/bin:$PATH
psql -p 5433

GPDB-psql: could not connect to server: No such file or directory

We have the small array of Greenplum database.In that, We have a master node. when I am trying to use PSQL utility
Getting this error :
[gpadmin#master gpseg-1]$ psql
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"?
We tried
on searching for postmaster.pid files.We have removed it.But still, the error remains.
You need to export your PGPORT and source Postgres.sh_path(inside your GPDB).
After that you will be able to do psql and connect to the database.

Problems trying to configure Ecrire with postgresql

I've been trying to configure Ecrire with my postgresql database, but I keep running into this error whenever I input psql -d postgres.
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"?
I just don't know how to fix this. Please help!
Is the database running?
ps auxwf | grep postgres
It's also possible that the socket file is in another directory, or the database is listening on another port. Can you post the values "unix_socket_directories" and "port" from your postgresql.conf file?

How to connect to postgres with two terminals?

I have a terminal I can connect to postgres
psql testdb
but when I open a new tab or a new terminal and tried to connect to psql an error is returned
This error returns
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5433"?
I tried creating another user and using another port
createuser testing_multiple
psql -p 5433
the same error occurs.
Your issue is probably that you're working within virtualenv. It isn't a chroot, but it sets a bunch of environment variables to fake the local environment, quite likely including the PATH and other settings.
Most likely the unix socket is at a different location to that compiled into the psql binary you're using. I'd say your PostgreSQL server socket is probably actually at /tmp/.s.PGSQL.5433, in which case export PGHOST=/tmp/ will work. Since you can connect from within the virtualenv terminal you can check though - within psql, run SHOW unix_socket_directories;. The location shown there is what you can give in PGHOST to connect to that PostgreSQL server.
The reason that export PGHOST=localhost works is that you are forcing psql (and other clients that use libpq) to connect over TCP/IP, instead of the default unix socket connection.