Connection to Postgres in Windows powershell - postgresql

When I try to connect to postgres in windows powersehll I get the error:
error: connection to server at "localhost" (::1), port 5432 failed:
FATAL: password authentication failed for user "user"
But I can connect correctly through wsl (Windows Subsystem for Linux).
BTW I use the following command
$ psql -U user
and postgres is installed in container with Docker.
What can be wrong?

Related

psql: ERROR: no pg_hba.conf entry for host "x.x.x.x", user "cp", database "abcd", SSL off PGBOUNCER Issue

I am trying to connect to database using pgbouncer. Our db is POSTGRESQL which run on the managed service given by AZURE. Now after configuring Pgbouncer.ini file on Ubuntu 18.04 LTS I am facing the following issue: Whenever I try connecting using localhost :
psql -U user -h localhost -p 6432 abcd
It'll give the output as
psql: ERROR: no pg_hba.conf entry for host "x,x,x,xx", user "username", database "dbname", SSL off
I am quite intrigued I haven't given such config they why still pgbouncer is looking for pg_hba.conf file.

How to copy PostgreSQL database to server from local computer

I am trying to copy PostgreSQL database from my computer to Ubuntu 20.04 server. Also, a python script with a database is running on the server using docker-compose. I enter this command on my computer:
pg_dump -C -h localhost -U steamtrader_pguser steamtrader | psql -h *server IP* -U steamtrader_pguser steamtrader
but I get errors:
psql: error: FATAL: password authentication failed for user "steamtrader_pguser"
pg_dump: error: could not write to output file: Broken pipe
The PostgreSQL account on the server and on my computer have the same username, password and database name. But when I enter the password, I get an error that it is incorrect. I also get errors on the server side:
FATAL: password authentication failed for user "steamtrader_pguser"
DETAIL: Password does not match for user "steamtrader_pguser"
Connection matched pg_hba.conf line 94: "host all all 0.0.0.0/0 md5"
I enter the command on my computer while the database script is running on the server. If I stop the script but leave the server running, I get the following error when I issue the command:
Password: psql: error: could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "18.188.219.232" and accepting
TCP/IP connections on port 5432?
I'm new to this topic, so I would really appreciate your help!

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

How to run postgresql from Command line and know available Databases in Windows

I am very new to postgreSQL and struggling to create a connection in my Eclipese.
Here is what I have done till now:
Installed DBeaver plugin for eclipse from marketplace.
Installed PostgreSQL version 10 from https://www.postgresql.org/download/windows/
Now I attempt to create a connection in Eclipse but I get an error "FATAL: password authentication failed for user "testuser"
I checked through a similar thread (
Getting authentication failed error with postgresql from command line
) but could not resolve the issue.
Could you please help.
To connect the PostgreSQL via Command line you have to install a PostgreSQL provided tool called "psql" if not installed already.
Then use the below command to connect to PostgreSQL database.
psql -h localhost -p 5432 -U postgres
Explanation:
localhost: is the hostname of machine where PostgreSQL is installed.
5432 : is the default PostgreSQL port
postgres : is the username of to connect to DB
Solution for your issue:
FATAL: password authentication failed for user "testuser"
As error message specified, either user not exists on database or the password that you supplied to connect is incorrect. Re-verify your user and password, and try again.
All the best.

PSQL: SSL error: unknown protocol

all. I have a new Ubuntu 17.04 server setup. I can access it through ssh successfully. Also, I have a postgresql database installed. It is already configured to accept remote connections through the following configurations:
pg_hba.conf
host all all 0.0.0.0/0 md5
postgresql.conf
listen_addresses = '*'
But when I try to access the database from my computer, I get the following error:
psql -h [SERVER_IP] -d db_production -U dbuser
psql: SSL error: unknown protocol
expected authentication request from server, but received S
I also have a docker container running inside the server. If I access it through /bin/bash and also try to connect with the server db, I get this error:
psql -h [SERVER_IP] -d db_production -U dbuser
psql: could not connect to server: Connection refused
Is the server running on host "[SERVER_IP]" and accepting
TCP/IP connections on port 5432?
The port 5432 is opened and the firewall is disabled. Does anybody have gone through that?
First, do you use the local server host when you're connected into the docker? The server IP, in that case, should be localhost or 127.0.0.1.
Try to use the complete DB URL:
psql postgres://dbuser:dbPass#SERVER_IP:5432/dbname?sslmode=prefer