Getting Error running psql Command for PostgreSQL - windows

I have installed the Postgres on my windows 10 PC and I set the environment variable also after when I run psql command it shows following 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 5433?
I have checked the port no service is running on 5433 and also tried changing it but getting the same error.I also tried installing Postgres outside Program File (thought maybe it's permission related issue) but still problem persist.I installed Postgres 13

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.

#2002 - Connection refused — The server is not responding (or the local server's socket is not correctly configured)

My phpmyadmin showing this error, I am working on Ubuntu OS:
2002 - Connection refused — The server is not responding (or the local server's socket is not correctly configured)
mysqli_real_connect(): (HY000/2002): Connection refused
Connection for controluser as defined in your configuration failed
mysqli_real_connect(): (HY000/2002): Connection refused
This problem is occurred on Ubuntu, I tried all previous stack overflow answers, but it doesn't work for me.
I faced that similar problem using lamp , check if you may have more than two mysql path like in
Find all the other mysql installed in your system
`whereis mysql`
`mysql: /opt/lampp/bin/mysql /opt/lampp/bin/mysql.server /usr/share/man/man1/mysql.1.gz`
Now if in you're system two mysql if overlapping then remove others and keep only one mysql installed by lamp
sudo rm -rf /etc/mysql
Here is the link i found for apache2 i did the same with mysql and it's working
http://xmodulo.com/how-to-uninstall-and-remove-apache2-on-ubuntu-debian.html
Finally stop all the mysql existing service running
sudo service mysql stop
sudo /etc/init.d/apache2 stop
sudo /opt/lampp/lampp start

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?

can't connect to postgres on windows10

I am setting up project on my windows PC and I have a problem with postgres.
Project is set on docker.
when I run docker-compose up I receive error
: *** Failed to connect to database dev; trying to create database
/usr/local/bundle/gems/sequel-4.48.0/lib/sequel/adapters/postgres.rb:224:in `initialize': PG::ConnectionBad: could not connect to server: Connection refused (Sequel::DatabaseConnectionError)
Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?
I don't know what to do. I have already installed microsoft easy-fix for TCP-IP, shut down windows firewall, changed all connection in pg_hba.conf to trust. Nothing helps. I don't have any antivirus software installed.
nmap report:
Nmap scan report for localhost (127.0.0.1)
Host is up (0.0027s latency).
Other addresses for localhost (not scanned): ::1
Not shown: 995 closed ports
PORT STATE SERVICE
135/tcp open msrpc
445/tcp open microsoft-ds
2068/tcp open avocentkvm
2179/tcp open vmrdp
5432/tcp open postgresql
edit:
I run psql -h localhost and received
psql: CATASTROPHIC: role "Kamil" does not exist
Kamil is my PC name.
edit2:
is it possible that docker doesn't have access to postgres on localhost?
problem solved
I had to set environment var to DB_HOST=docker.for.win.localhost

Postgresql refusing connection to server

I have been trying to connect to my postgresql 9.3 server but I keep getting this error.
Server doesn't listen
The server doesn't accept connections: the connection library reports
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and accepting TCP/IP
connections on port 5433? 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?
I have tried connecting through pgadmin3 and the command line.
psql.exe -h localhost -U postgres
This command also gives the same error.
I am on a windows machine. I have tried creating a separate server also with the same result.
I have no idea whats happening. Please help.
Thanks
As the error clearly tells or asks actually, Is the server running on host "localhost"?
So the chances are, the Postgres server is not running on your machine.
You can start the service(the layman way) by going to services and starting the service.
Here is how you do it:
Open Run Window by Winkey + R
Type services.msc
Search Postgres service based on the version installed.
Click stop, start or restart the service option.
Start the server with postgres -D ['data folder']
As in docs:
http://www.postgresql.org/docs/9.1/static/server-start.html
So in my Windows postgres installation from the bin folder:
postgres.exe -D ..\data
where data is in the postgresql installation folder
I had the same issue like Venkatesh had. But in my case I had installed pgadmin in version 9. But also installed version 12 at the same time.
When I now uninstalled version 9, the port was already set in the config of version 12 and not given free.
So my solution was to change the port of version 12 in the postgresql.conf file. Or even simplier, change the port in the server creation from 5432 to 5433. Now you are able to create a server again.
I got this same error. This happened when I uninstall and re-install postgress, for some reason after second-time installation, pgadmin tries to connect to the server on port 5433 whereas the server is running on 5432.
Rightclick server properties and change the port to 5432 and try to connect again. It should work now.
Your server running on port 5432 but in the properties, the port is set to 5433.
You must go to pgAdmin, click on database version, ex: PostgresSQL 10 and edit properties.
A new window appears and you need to change the port to 5432 [this is default port].
Hope this helps.

Resources