Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432 - postgresql

I install pgadmin4 using the following command sudo install pgadmin4 and then I installed postgresql using sudo install postgresql . In my terminal I ran the command psql -U postgres -h localhost
It shows connection refuse
Then I go to pgadmin4 and created a server and I wanted to connect to the server it shows
pgadmin connection refuse
Then I wrote host all all all md5 in pg_hba.conf file and I wrote listen_addresses = '*' to postgresql.conf file. and I wrote the following command sudo service postgresql restart but again It shows connection refuse message.
I wrote psql and it shows connections on Unix domain socket
Can you please help me in this regard? What I have missed?

Related

Connect to existing instance of Postgresql from WSL 2

I'm running Ubuntu WSL 2 on Windows 10. Before I installed WSL I already had Postgresql installed on my Windows 10. I wanted to connect to the database from WSL but so far it fails.
When running:
psql
I get:
psql: error: could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
When running:
psql -h 127.0.0.1 -p 5432 -U postgres
I get:
psql: error: could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
And WSL clearly doesn't see the database. When running this:
sudo service postgresql start
It returns:
postgresql: unrecognized service
I know that one solution is to install the database in WSL but wanted to try to connect to existing instance first.
You should edit pg_hba.conf
check wsl subnet
execute ipconfig from cmd. Below is example.
Ethernet Adapter vEthernet (WSL)
IPv4 Address . . . . . . . . . . . .: 172.19.230.81
edit pg_hba.conf
pg_hba.conf path is C:\Program Files\PostgreSQL\{postgresqlVersion}\data\pg_hba.conf. if you installed Windows Postgresql default install path.
subnet mask is use value from ipconfig
host all all 172.19.230.0/24 md5
restart postgresql
you can restart postgresql from services.msc. service name is postgresql-x64-{postgresqlVersion}.
access from psql
psql -h 172.19.230.81 -p 5432 -U postgres

Cant access database from pgAdmin

I`m using postgresql database on my web server (ubuntu + nginx) and it works with backend app. I want to connect remotely using pgAdmin
but it always throw this error:
could not connect to server: Connection timed out(0x0000274C/10060)
Is the server running on host "ip" and accepting
TCP/IP connections on port 5432?
I already add to my pg_hba.conf this line:
host all all all password
and also add to postgresql.conf line:
listen_addresses = '*'
netstat -nlt does next result, and it`s enough in tutuorials i found, but still cant access my database
Found a solution, it works as well after this command:
sudo ufw allow 5432/tcp
Open file named pg_hba.conf
sudo vi pg_hba.conf
and add this line to that file
host all all 0.0.0.0/0 md5
It allows access to all databases for all users with an encrypted password
restart your server
sudo /etc/init.d/postgresql restart

Amazon EC2 and PostgreSQL: cannot connect due to time out error

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!

Postgresql connection via terminal - pgadmin

I have a problem connecting (using SSH) to my virtualbox(ubuntu) postgres server.
I set up all nice and correctly.
PostgreSQL settings:
postgresql.conf -> Allowed all incomming connection (*) and set ssl TRUE
pg_hba.conf -> after a lot of changes i came to the point where it seems to work with this settings:
IP4
host all all 0.0.0.0/0 trust
hostssl all all 0.0.0.0/0 trust
host all all 192.168.x.x/32 trust
hostssl all all 192.168.x.x/32 trust
I tried:
Made restart of my postgres server on the virtual machine.
Then i went to my host machine (Snow Leopard), build a ssh connection to the virtualbox (ubuntu) and it's working.
ping my guest machine on port 5432 also works.
Open pgadmin on my host machine (Snow Leopard) -> added server 192.68.56.1 and database pluto, user pippo. The connection worked and i see the DB.
Tried open TERMINAL in Snow Leopard and executed following cmd:
psql -h 192.168.56.1 -U pippo -d pluto
with ERROR:
psql: FATAL: no pg_hba.conf entry for host "192.168.56.1",
user "pippo", database "pluto", SSL off
I also tried to connect through my Java Program ans I got the same error.
What am I doing wrong?
pgAdmin tries to connect with and without SSL by default.
I suspect that you only try to connect without SSL via psql, while the server seems to require SSL for connections. Try:
psql "sslmode=require host=192.168.56.1 dbname=pluto" pippo
More about sslmode in the manual.
Open my query into pgAdmin from command line:
-f The file containing your SQL script to be loaded in the query window
-qc The connection string without password (you can also use ssl connections)
"C:\Program Files\PostgreSQL\9.4\bin\pgAdmin3.exe" -f "C:\slqFiles\FindFunctionByName.sql" -qc "host=localhost port=5432 dbname=myDatabase user=postgres"
The password will be collected from the password file located in the application folder: %APPDATA%\postgresql\pgpass.conf
You need permissions for connection. Try to add to C:\Program Files\PostgreSQL\9.6\data\pg_hba.conf next line:
host all all ::/0 trust

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