Hello,
I am having a similar issue when using operator 2.2.0 on minikube after following the instructions here: Install on Minikube - Percona Operator for PostgreSQL. When I try to access the database using a service or when connecting to the pod directly, I can get a connection.
$ PGPASSWORD='my-password' psql -h pg-cluster1-ha -U developer
psql (15.4 (Ubuntu 15.4-1.pgdg22.04+1), server 15.2 - Percona Distribution)
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)
(works)
$ PGPASSWORD='my-password' psql -h 10.244.0.30 -U developer
psql (15.4 (Ubuntu 15.4-1.pgdg22.04+1), server 15.2 - Percona Distribution)
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)
(works)
in both cases, SSL connection is made… no issues at all. However, when I try this:
$ PGPASSWORD='my-password' psql -h pg-cluster1-pgbouncer -U developer
psql: error: connection to server at "pg-cluster1-pgbouncer" (10.107.250.90), port 5432 failed: FATAL: server login has been failing, try again later (server_login_retry)
connection to server at "pg-cluster1-pgbouncer" (10.107.250.90), port 5432 failed: FATAL: SSL required
(it either freezes, no reply at all or the above error.)
The pgbouncer log shows:
2023-09-04 11:38:36.898 UTC [7] LOG C-0x557b55d76b60: developer/(nouser)@10.244.0.40:57928 closing because: server login has been failing, try again later (server_login_retry) (age=0s)
2023-09-04 11:38:36.898 UTC [7] WARNING C-0x557b55d76b60: developer/(nouser)@10.244.0.40:57928 pooler error: server login has been failing, try again later (server_login_retry)
2023-09-04 11:38:36.898 UTC [7] LOG C-0x557b55d76b60: (nodb)/(nouser)@10.244.0.40:57936 closing because: SSL required (age=0s)
2023-09-04 11:38:36.898 UTC [7] WARNING C-0x557b55d76b60: (nodb)/(nouser)@10.244.0.40:57936 pooler error: SSL required
but clearly psql is trying SSL.
If I try to connect using the pgbouncer pod IP directly I get:
$ PGPASSWORD='my-password' psql -h 10.244.0.32 -U developer
psql: error: connection to server at "10.244.0.32", port 5432 failed: FATAL: server login has been failing, try again later (server_login_retry)
connection to server at "10.244.0.32", port 5432 failed: FATAL: SSL required
The pgbouncer log shows:
2023-09-04 11:46:02.376 UTC [7] LOG C-0x557b55d76900: developer/(nouser)@10.244.0.40:49098 closing because: server login has been failing, try again later (server_login_retry) (age=0s)
2023-09-04 11:46:02.376 UTC [7] WARNING C-0x557b55d76900: developer/(nouser)@10.244.0.40:49098 pooler error: server login has been failing, try again later (server_login_retry)
2023-09-04 11:46:02.376 UTC [7] LOG C-0x557b55d76900: (nodb)/(nouser)@10.244.0.40:49106 closing because: SSL required (age=0s)
2023-09-04 11:46:02.376 UTC [7] WARNING C-0x557b55d76900: (nodb)/(nouser)@10.244.0.40:49106 pooler error: SSL required
It seems strange that in both cases it is showing (nodb)/(nouser).
Is that normal?
pg_hba.conf includes theses entries:
# Do not edit this file manually!
# It will be overwritten by Patroni!
local all "postgres" peer
hostssl replication "_crunchyrepl" all cert
hostssl "postgres" "_crunchyrepl" all cert
host all "_crunchyrepl" all reject
host all "monitor" "127.0.0.0/8" scram-sha-256
host all "monitor" "::1/128" scram-sha-256
host all "monitor" all reject
hostssl all "_crunchypgbouncer" all scram-sha-256
host all "_crunchypgbouncer" all reject
hostssl all all all md5
host all "developer" "127.0.0.0/8" peer
host all all "0.0.0.0/0" md5
but there is another pg_hba.conf here: /opt/crunchy/conf/postgres/pg_hba.conf . Perhaps this is a template?
There is no editor on the postgres instance. Does this mean that the only way to configure pg_hba.conf? Perhaps I should be configuring it from within psql using SQL?
I have tried to add the setting: tlsOnly to cr.yaml but according to the docs, this setting no longer exists in version 2.2.0 according to this page: Custom Resource options - Percona Operator for PostgreSQL
Including it produces this error:
Error from server (BadRequest): error when creating "percona-postgresql-cluster.yaml": PerconaPGCluster in version "v2" cannot be handled as a PerconaPGCluster: strict decoding error: unknown field "spec.tlsOnly"
I have also tried to look at the pgbouncer config as suggested above but strangely there is nothing in the /etc/pgbouncer/pgbouncer.ini as suggested above but there are pgbouncer ini files here:
- /usr/share/doc/pgbouncer/pgbouncer.ini (owned by root so I CANNOT edit but looks like a template)
- /opt/crunchy/conf/pgbouncer.ini (owned by daemon, so must be the one)
- /etc/pgbouncer/pgbouncer.ini (EMPTY)
- /etc/pgbouncer/…2023_09_02_23_45_54.1327105812/pgbouncer.ini (EMPTY)
The only one I can edit contains:
[databases]
* = host=PG_SERVICE port=PG_PORT auth_user=pgbouncer
[pgbouncer]
listen_port = 6432
listen_addr = *
auth_type = md5
auth_file = /pgconf/users.txt
auth_query = SELECT username, password from pgbouncer.get_auth($1)
pidfile = /tmp/pgbouncer.pid
logfile = /dev/stdout
admin_users = pgbouncer
stats_users = pgbouncer
default_pool_size = DEFAULT_POOL_SIZE
max_client_conn = MAX_CLIENT_CONN
max_db_connections = MAX_DB_CONNECTIONS
min_pool_size = MIN_POOL_SIZE
pool_mode = POOL_MODE
reserve_pool_size = RESERVE_POOL_SIZE
reserve_pool_timeout = RESERVE_POOL_TIMEOUT
query_timeout = QUERY_TIMEOUT
ignore_startup_parameters = IGNORE_STARTUP_PARAMETERS
So… why can I connect directly using SSL but NOT using pgbouncer? There is no specific requirement to connect via SSL… it’s optional so is pgbouncer trying to connect o the database without?
Apologies for so many related questions… but I have been trying to get things working for quite some time. Please assist.