I'm playing around pgpool2.
I'm connecting to postgresql which is running on port 5432 with command psql -U postgres -p 5432 and it's connecting normally.
When I'm connecting to pgpool2 running on 9999 port with command psql -U postgres -p 9999 - it returns back dialog like:
psql: root#master:/linux/path#
What I'm doing wrong? Is there way to connect to pgpool using psql?
I cannot connect to it from application also.
UPD I've got following error pool_do_auth: maybe protocol version mismatch (current version 3)
Solved : Problem was in pgpool auth on backends. Editing pg_hba.conf fixed problem.
This error message and behavior are because of a problem with pgpool authenticating to postgres, not with you authenticating to pgpool as you might suspect. If you check the postgres logs, it will tell you which line in your postgres pg_hba.conf is being rejected.
However, since (IIRC) pgpool cannot do peer authentication, it is probably this one, which says that all local (unix socket) connections will be authenticated by pretending the system username is the postgres username:
local all all peer
You want to change that to:
local all all trust
At least to make things work. However, you will lose some security this way. However, if all your users (that can access the unix socket) are trusted, this is okayish.
Related
I use postgres 11, I just try to connect with one of my user to psql and pgadmin4
my pg_hba.conf file
# "local" is for Unix domain socket connections only
local all all peer
host sito lcm_admin 127.0.0.1/32 md5
host sito sito_lcm 127.0.0.1/32 md5
My postgres user have a password.
I tried my posgres user, sito_lcm and lcm_admin to connect to pgAdmin4, alway get
Invalid username or password
I know there are good because It's the one I use to connect to posgres db in a java program
for psql i tried
su - postgres
typed my password
authentication fail
tried with one of my db user
psql -U lcm_admin sito
psql: FATAL: Peer authentication failed for user "lcm_admin"
Edit
With Daniel Vérité tips, I can connect to psql but not to pgAdmin4
First time i see this screen, my last connection was a few month ago, don't know if some updated had created this issue
Because of this rule in pg_hba.conf
host sito lcm_admin 127.0.0.1/32 md5
You probably want to invoke psql that way:
psql -U lcm_admin -h 127.0.0.1 sito
Then it will ask for a password instead of failing with "Peer authentication failed".
Note that rules in pg_hba.conf are tested in their order in the file (top to bottom), and it stops at the first one that matches.
About connectiong with pgAdmin4:
As mentioned in https://www.pgadmin.org/docs/pgadmin4/latest/getting_started.html there is an additional step to access pgAdmin4 itself, as an application.
In a server deployment, an email address and password are asked at installation time. If you don't remember the password but you gave a valid email address, the link "Forgotten your password" might work for you.
Otherwise I guess reinstalling pgAdmin4 from scratch might work too.
Personally, I launch pgAdmin4 as a docker container without a persistent volume:
$ docker run -p8080:80 -e PGADMIN_DEFAULT_EMAIL=foo#example.com -e PGADMIN_DEFAULT_PASSWORD=bar dpage/pgadmin4
Then I connect to http://localhost:8080 and the email/password to enter on the first page are those environment variables passed on the command line.
I am having an issue that has been bothering me for some time now. It is with postgres on my mac. I set a password for postgres and I can not remember it for some reason. I have looked up and attempted several different methods for trying to reset the password but none of them are working and I need it fixed as soon as possible.
Here is what my pg_hba.conf file
# TYPE DATABASE USER ADDRESS METHOD
local all all trust
I reset the local all all trust and then restarted my postgres server running
brew services restart postgres
and when i go to try and open postgres on my terminal I get the same password issue:
omars-MacBook-Pro:postgres omarjandali$ psql -U postgres -W -h localhost
Password:
psql: error: could not connect to server: FATAL: password authentication failed for user "postgres"
or
omars-MacBook-Pro:~ omarjandali$ psql -h 127.0.0.1 -U postgres
Password for user postgres:
psql: error: could not connect to server: FATAL: password authentication failed for user "postgres"`
You only configured "local" connections which are using Unix domain sockets. But your psql command line tries to establish a TCP connection (-h ...), which is not configured in your pg_hba.conf.
You need to use host instead of localin pg_hba.conf to allow trusted, non-password connections through TCP.
But that is a really, really bad idea, because that means that as soon as your Mac is visible on the internet, everybody can connect to your Postgres instance and hack it. This isn't a theoretical threat - there have been numerous posts on this site regarding that.
If you want to allow connections without passwords, at least only allow them from "localhost", not from the outside:
# TYPE DATABASE USER ADDRESS METHOD
host all all samehost trust
I'm trying to setup postgres cluster of two nodes (primary and standby). In order to activate automatic failover, I'm using pgpool-II.
I followed the following article: https://www.pgpool.net/docs/41/en/html/example-cluster.html
and the only thing difference I did is installing postgresql version 12 instead of version 11.
Knowing that I'm trying it useing two centos7 images on VMware. I faced the following issues:
When I run systemctl status pgpool.service on both nodes, it returned success.
Also I can access postgresql using the watchdog delegate IP.
But what testing failover, everything goes wrong.
Scenario 1:
I accessed my database using watchdog delegate Ip.
I disconnect the standby server.
Result: My session to postgresql continued to work for less than a minute and then it failed. and I'm unable to connect again, until I reconnect the standby node, and restart the pgpool service again.
Scenario 2:
I accessed my database using watchdog delegate Ip.
I disconnect the primary server.
Result: My session stopped directly. and the standby server is not promoted to be master.
I noticed something (might be related to the above described problem): when I try to run the following command
psql 192.168.220.146 -p 9999 -U postgres -c "show pool_nodes"
it fails to work and returned the following:
psql: error: could not connect to server: 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.9999"
However if I ran: psql 192.168.220.160 -p 5432 -U postgres
it works fine and I can access the postgres shell.
My pool_hba file:
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
host all pgpool 0.0.0.0/0 scram-sha-256
host all postgres 0.0.0.0/0 scram-sha-256
Any help would be appreciated.
I followed the following article: https://www.pgpool.net/docs/41/en/html/example-cluster.html and the only thing difference I did is installing postgresql version 11.
I not ping delegate_IP = '192.168.1.233'. May i help you?
Thanks you.
you are not providing -h argument to psql for specifying the IP address. So effectively psql is trying to connect to UNIX domain socket and considering the IP address in the command as the database name.
Try putting -h before the IP address
psql -h 192.168.220.146 -p 9999 -U postgres -c "show pool_nodes"
I have a PostgreSQL DB sitting on my local machine (Windows) and I would like to import it into my Hortonworks Sandbox using Apache Sqoop. While something like this sounds great, the complicating factor is that my Sandbox is sitting in a Docker container, so statements such as sqoop list-tables --connect jdbc:postgresql://127.0.0.1/ambari --username ambari -P seem to run into authentication errors. I believe the issue comes from trying to connect to the local host from inside the docker container.
I looked at this post on connecting to a MySQL DB from within a container and this one to try to use PostgreSQL instead, but have so far been unsuccessful. I have tried connecting to '127.0.0.1' and '172.17.0.1' (the host's IP) in order to connect to my local host from within Docker. I have also adjusted PostgreSQL's configuration file to listen for connections on all IP addresses. However, I still get the following error messages when I run sqoop list-tables --connect jdbc:postgresql://<ip>:5432/<db_name> --username postgres -P (where <ip> is either 127.0.0.1 or 172.17.0.1, and <db_name> is the name of my database)
For connecting with 127.0.0.1:
ERROR sqoop.Sqoop: Got exception running Sqoop: java.lang.RuntimeException: org.postgresql.util.PSQLException: FATAL: Ident authentication failed for user "postgres"
For connecting with 172.17.0.1:
Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
Any suggestions would be very helpful!
If this is just for local testing and not for production level coding, you can enable all trusted connections to your database by updating the pg_hba.conf file
Locate your pg_hba.conf file inside your postgres data directory
Vim the file and update it with the following lines:
#TYPE DATABASE USER ADDRESS METHOD
local all all trust
host all all 0.0.0.0/0 trust
host all all ::1/128 trust
Restart your postgres service
If you do this, your first use case (using 127.0.0.1) should work
I have Postgres installed in my local machine.
When I execute
psql -U postgres -d buzzsumo
it correctly asks for my password to the user postgres.
However, when I run
psql -U postgres -d buzzsumo -h localhost
it gives me this error message:
psql: FATAL: role "postgres" does not exist
Why is this the case, when in the first example I am connecting to my local server, which is equivalent to passing in localhost?
You don't say but I'm guessing you're running postgres on either on MacOS or Linux.
The first form (with no -h) connects via a "unix socket". The second form, with "-h localhost" connects via TCP/IP to localhost (IP address 127.0.0.1).
Postgres treats these two types of connections differently - or at least, it can do so. If you check the "pgsql/data/pg_hba.conf" file to see what authentication mechanisms are configured for the two types of connections.
Your first example connects via Unix socket, the second one via TCP/IP local loop (localhost).
For the first example, you need the connection type local in pg_hba.conf, for the second lines starting with host are relevant. You probably have defined different authentication methods for these classes of connections.