PostgreSQL 12 authentication error - could not connect to the server - postgresql

I have a postgresql 12.2 database on a Red Hat linux 8.4 OS, this database is part of a pgpool cluster.
When I run the following command to check the cluster status:
psql -h <dbnode hostname> -p 9999 -U postgres -c 'show pool_nodes'
it gives the below error after I enter the password:
I am sure that the password is correct, what might be the issue here?
I checked pg_hba.conf file and I have this entry already:
host all all <DB_IP_ADDRESS> md5
I tried other methods as well like "trust", but still no luck.
Can someone help me on this please?

Related

PostgreSQL: Can't log into Postgres - sudo broken?

Hey so after I ran into somes issues I decided to uninstall Postgres and re-install it (re install a newer version btw).
I'm trying to access postgres to create a new db for my Rails app so I run su postgresor su _postgres then I am asked a password but nothing that I enter works.
So I tried sudo -u postgres psql and got
sudo: unknown user: postgres
sudo: unable to initialize policy plugin
I tried also to disable SIP (see: here)
but it didn't work either. same results.
I don't know what to do. Any idea ? I am using Mac OS High Sierra 10.13.6.
Thanks to #gordon Davidson and #wildplasser 's help, I found the solution:
sudo -u myusername psql postgres
I had this same challenge when trying to access a PostgreSQL database.
When I run the command below:
sudo -u postgres psql
I get the error below:
sudo: unknown user: postgres
sudo: unable to initialize policy plugin
The issue was that I did not have the PostgreSQL database server installed on the server. The server only had a MySQL database server set up on it.
That's all.
I hope this helps
From your EC2 node issue the following command to test if database is reachable.
/opt/gitlab/embedded/bin/psql -U YourExistingUsername -d template1 -h AWS-RDS-POSTGRES-ENDPOINT

Phoenix and Postgres install - not talking

My OS is Fedora 26
I have installed Postgresql and Phoenix.
Postgres has a superuser "postgres" with password "postgres". This is confirmed by running \du in psql.
When I run $ mix ecto.create, I get
** (Mix) The database for Hello.Repo couldn't be created: FATAL 28000 (invalid_authorization_specification): Ident authentication failed for user "postgres"
I suspect it may be a permissions issue. To log into psql requires
$ sudo -u postgres psql postgres
Whereas Phoenix when attempting to use postgres may not have sudo privilages.
$ psql --version
psql (PostgreSQL) 9.6.8
Any thoughts appreciated.
By default the authentication for the postgres database user connecting to the DB locally is to verify that the operating system user is also postgres. This is what the error message refers to as Ident authentication and is why connection after doing sudo -u postgres works.
To connect as the postgres user using another means of authentication you need to edit the pg_hba.conf file. (HBA stands for host based authentication).
The line that allows this will look like this:
local all postgres peer
Add a line that looks like this (without removing the other line!):
local all postgres md5
And you should be able to connect using the password for postgres as well.
If I remember correctly you will need to restart the DB for this to take effect.

Is Postgres Ignoring the "trust" in pg_hba.conf File?

I have the following lines in my pg_hba.conf file:
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
host all all localhost trust
and I've restarted Postgres. When I connect at the command line everything works as expected:
$ psql -U me -W
Password for user me: # I can type any password and it will work
psql (9.5.7)
Type "help" for help.
me=#
However, when I connect through a software library (the Node library pg, through the library knex) I get an error:
password authentication failed for user "me"
I'm not specifically looking for a fix, I'm just trying to understand how this is even possible. If I just told Postgres to trust anyone, how can I still be getting errors about authentication failing? Was there something wrong with my pg_hba.conf entries, or does Postgres just choose to ignore them under certain circumstances, or ....
EDIT
In case it helps the database connection URL my program is using to connect is:postgres://localhost:5432/mydb.
When you did psql -U me -h localhost, psql failed to connect because it doesn't know what database to connect to.
Solution is psql -U me -h localhost -d database_name
Hope this helps.

How to connect pgAdmin III (Windows) to postgresql (Linux in virtual box)

I have a postgresql demon on my virtual Linux box, and just installed pgAdmin III on the Windows machine. Now I'd like to configure the first connection.
What I did so far:
I edited /etc/postgresql/9.1/main/pg_hba.conf and added a line to make the demon accept connections from my Windows machine:
host all all 192.168.123.45/32 md5
I set a shell passphrase for the system user postgres (sudo passwd postgres)
Edit: this seems to be irrelevant
I copied /usr/share/postgresql/9.1/pg_service.conf.sample to /etc/postgresql-common/pg_service.conf and uncommented the sample service, giving me
[postgres]
dbname=postgres
user=postgres
Edit: this seems to be irrelevant
I put a line into /etc/environment to point to the pgservice.conf file:
PGSERVICEFILE=/etc/postgresql-common/pg_service.conf
(which works; when I duplicated the PuTTY session, it had this variable)
I restarted the database server after each change:
sudo /etc/init.d/postgresql restart
Finally, I restartet the Linux box,
The server seems to have restarted successfully:
[ ok ] Restarting PostgreSQL 9.1 database server: main.
However, when I try to connect to the service, pgAdmin III gives me an error message:
Error connecting to the server: definition of service "postgres" not found.
dmesg | grep postgres gives me a single line:
[ 18.054965] postgres (2242): /proc/2242/oom_adj is deprecated, please use /proc/2242/oom_score_adj instead.
I have no clue whether postgresql uses my pq_service.conf at all, or whatever else is the problem; any help is appreciated ...
Edit:
My original question, "How can I know whether postgresql uses my pg_service.conf file?", seems to be answered - it simply doesn't. I still can't connect; but now the question doesn't match the error messages anymore.
I removed the "Service" entry from my "New Server Registration" data. Now I get another error - something like "password authentication for user >>postgres<< failed". I'm quite sure the password is correct - I just set it ... and I tested it by commenting out my ssh key from the authorized_keys file.
I'd happily connect with my ssh key, but this seems to be difficult as well. With PuTTY, my key is taken from Pageant, and I'm logged in without any problem; pgAdmin talks about "SSH tunnelling", but I normally don't need tunnels for this local machine ...
I tried to create a tunnel anyway.
PuTTY session:
Source port is 5432
destination is my-vbox.host.name:5432
In pgAdmin, "SSH Tunnel":
Username postgres
using Identity file
Tunnel host localhost → error:
"SSH error: Could not connect to socket with error code 10051"
Tunnel host localhost:5432 → error:
"SSH error: Unable to resolve host: localhost:5432"
Tunnel host 127.0.0.1:5432 → error:
"SSH error: Unable to resolve host: 127.0.0.1:5432"
How the heck is this supposed to be configured?!
I finally managed to connect as db user tobias (I never had problems to connect locally, with psql).
# sudo -u postgres psql postgres
psql (9.1.9)
Type "help" for help.
postgres=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
postgres | Superuser, Create role, Create DB, Replication | {}
tobias | Superuser | {}
postgres=# ALTER USER tobias WITH PASSWORD 's3cr3t';
ALTER ROLE
After doing this, I could connect as tobias, using the password just set.
The "Maintenance DB" happens to be template1; I didn't try to change this.
For further reference - I activated log_connections in /etc/postgresql/9.1/main/postgresql.conf and watched the log:
sudo tail -f /var/log/postgresql/postgresql-9.1-main.log

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