Error while connecting to remote Postgres on centos - postgresql

When I'm trying to connect to Postgres on remote cloud . It is showing :
psql: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
Local system -- Postgres 9.3 (windows)
Remote System is on Azure -- Postgres 9.2(centos)
Command I'm using: psql -h "abc.cloudapp.net" -p 5432
I've set the end-point as 5432 in azure
changed the postgresql.conf to "*" to allow connection
and changed the pg_hba to (host all all ip/24 md5)
Please help me out on this.

Endpoint is OK, and you need to set up the network security group as well.
Try to define not just 5432, but the range of ports (1024-65536 for example).
UPD: I was able to create the CentOs 7.0 + PostgreSQL and connected to that instance:
sudo yum install postgresql-server postgresql-contribs
sudo postgresql-setup initdb
sudo vi /var/lib/pgsql/data/pg_hba.conf
Edit 127.0.0.1/32 to 0.0.0.0/0
sudo systemctl start postgresql
sudo systemctl enable postgresql
sudo vim /var/lib/pgsql/data/postgresql.conf
sudo service postgresql restart
sudo service postgresql restart
sudo -u postgres createuser --superuser azureuser -P
Then i downloaded pgAdmin and connected to that. (see screenshot) (do not pay attention to the test1 database, just change it to postgres).

Related

could not connect to database postgres

createuser: could not connect to database postgres: 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"?
I am trying to install dspace 6.3 on ubuntu server 18.04 but after installing postgresql when I run the command createuser -U postgres -d -A -P dspace I am getting the above error help please
Did you start the server? Try sudo service postgresql restart or sudo systemctl restart postgresql

createuser: could not connect to database postgres: could not connect to server: No such file or directory

I installed postgresql on archlinux using this command:
sudo pacman -S postgresql
And it installed OK. But when I want to create a new user, like this:
sudo -iu postgres
[postgres#amirashabani ~]$ createuser amirashabani
I receive this error:
createuser: could not connect to database postgres: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/run/postgresql/.s.PGSQL.5432"?
How can I fix this?
The problem was that I forgot to start and enable the postgresql service, which was mentioned in the ArchWiki:
Finally, start and enable the postgresql.service.
After doing this:
systemctl start postgresql.service
systemctl enable postgresql.service
Everything worked fine.

Postgresql starting failed

I was connected with remote postgres-9.3 by pgAdmin III. After close pgAdmin i try to connect on another day with the same db.
/etc/init.d/postgresql-9.3 status
dead but pid file exists
service postgresql-9.3 start FAIL
In pgstartup.log file i have:
This account is currently not available
pg_hba.conf:
# "local" is for Unix domain socket connections only
local all all peer
host all all 127.0.0.1/32 trust
host all all 89.70.224.82/32 md5
Operating system on server is CentOS. I don't know unfortunately how postgres was installed on the server because someone else done that.
What i can do with this?
The solution is reset your PostgreSQL logs
[root#user /]#/usr/pgsql-9.3/bin/pg_resetxlog -f /usr/pgsql-9.3/data/
after executing above command display "Transaction log reset"
and then restart PostgreSQL server
[root#user /]# /etc/init.d/postgresql-9.3 restart
Stopping postgresql-9.3 service: [FAILED]
Starting postgresql-9.3 service: [ OK ]
[root#qa /]# /etc/init.d/postgresql-9.3 status
(pid 3003) is running...
after checking your pgadmin
Try to start cluster using native postgres utility.
Assuming you have CentOS 6.6 and postgresql 9.4
sudo -u postgres /usr/pgsql-9.4/bin/pg_ctl -D <YOUR_DATA_DIR> start
You will get some reasonable output.
Then try to start postgres in single user mode
sudo -u postgres /usr/pgsql-9.4/bin/postgres --single -D <YOUR_DATA_DIR> -P -d 1
Beware that resetting xlogs will cause some data lost.
I also recommend to read this article http://blog.endpoint.com/2014/11/when-postgres-will-not-start.html

psql: could not connect to server [ubuntu]

Under the postgres user, I tried the psql command and I'm getting this error:
psql: 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"
But when I run /usr/local/pgsql/bin/psql, it is working.
Is there anything wrong with my configuration?
the above issue seems related to PostgreSQL default port no,
Change the port no in postgresql.conf file and restart the DB server. if u have changed the port while installing.
(OR)
instead of psql type full command like
"psql -p 5432 -h localhost"
You could include the database user too:
psql -U postgres -p 5432 -h localhost
Did you reinstall the postgresql-9.6.3 ?
You need to uninstall postgresql completely
sudo apt-get --purge autoremove postgresql*
sudo apt install postgresql-9.6

Unable to connect to postgres in ubuntu

I am trying to install postgresql on ubuntu.
I followed the steps from http://hocuspokus.net/2008/05/install-postgresql-on-ubuntu-804/.
And on typing the command :
psql template1
I am getting 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 "/var/run/postgresql/.s.PGSQL.5432"?
The problem for me was that I had previously installed version 9.1, and 9.1 was still hogging the default port 5432. I was able to find this with the command:
root#labs:/home/caleb# /etc/init.d/postgresql status
9.1/main (port 5432): down
9.2/main (port 5433): online
So I was able to see that my 9.2 database was running on port 5433. So to connect, I had to explicitly specify port 5433:
psql -p 5433
try the following
psql template0
what resolved this error for me was deleting a file called postmaster.pid in the postgres directory. please see my question/answer using the following link for step by step instructions. my issue was not related to file permissions:
psql: could not connect to server: No such file or directory (Mac OS X)
You can also get in the CLI via this command:
psql -U postgres -p 5432 -h localhost
This should solve the error,
make a symbolic link to the /tmp/.s.PGSQL.5432:
sudo ln -s /tmp/.s.PGSQL.5432 /var/run/postgresql/.s.PGSQL.5432
Thanks to this post