How to connect remote postgresql database from kong application? - postgresql

I have a kong services which is in failed status with below error message from journalctl
/usr/local/share/lua/5.1/kong/cmd/migrations.lua:213: [PostgreSQL error] failed to retrieve PostgreSQL server_version_num: FATAL: password authentication failed for user "konguser"
postgres information from Kong.conf as below
cat /etc/kong/kong.conf|grep -i pg
pg_host = xxxx.yyyyy.ap-south-1.rds.amazonaws.com
pg_port = 5432 # Port of the Postgres server.
pg_user = konguser # Postgres user.
pg_password = "zzzzzzz" # Postgres user's password.
pg_database = kong_db # The database name to connect to.
Troubleshooted the same by trying to connect the same manually using psql as below and it worked
[root#ip-10-0-2-30 system]# psql -U konguser -p 5432 -h xxxx.yyyyy.ap-south-1.rds.amazonaws.com -d kong_db
Password for user konguser:
psql (10.15, server 10.9)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.
kong_db=>
Not sure what is causing the failure.Could you please help to troubleshoot

Looks like your rds instance is using ssl.
Default kong configuration is without ssl.
https://docs.konghq.com/gateway-oss/2.4.x/configuration/#postgres-settings
Two solution, remove ssl from rds, or activate it on kong side with
pg_ssl=on

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.

Aurora serverless Postgresql fails to connect via TLS/SSL

I am trying to connect to a serverless Aurora serverless PostGRESQL RDS instance with SSL, but in vain.
My RDS lies on a private subnet group (2 private subnets) and I am trying to connect from an EC2 instance lying in public subnet.
What works:
psql -h "mydb.cluster-cyjoviss5z9y.eu-central-1.rds.amazonaws.com" -p 5432 -d "dbname=mydb user=postgres password=NVMXeyQRXIzW50xx"
psql (9.2.24, server 10.7)
WARNING: psql version 9.2, server version 10.0.
Some psql features might not work.
SSL connection (cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256)
Type "help" for help.
mydb=
However, this doesn't work:
psql -h "mydb.cluster-cyjoviss5z9y.eu-central-1.rds.amazonaws.com" -p 5432 -d "dbname=mydb user=postgres password=NVMXeyQRXIzW50xx sslmode=verify-ca"
Error:
psql: root certificate file "/home/ec2-user/.postgresql/root.crt" does not exist
OR
psql: SSL error: certificate verify failed
The same above command with sudo works, but when I verify the connection it still says:
mydb=> select ssl_is_used();
ssl_is_used
-------------
f
(1 row)
So I downloaded the root certificate from here, as suggested in this page. It even mentions that AWS Serverless instances don't require the root certificate to be downloaded.
I converted the PEM file into CRT using this. I tried giving the root.crt file with 777 and 600 permissions, both didn't help.
Any hints on what can possibly go wrong here?
Apparently AWS still doesn't support SSL connections for Postgres Aurora databases yet!

Why psql ask to enter password when trying to connect using pgbouncer

I've install pgbouncer-1.7.2 on the same Linux server as PostgreSQL-9.6 database.
When I try to connect to my local database using pgbouncer, database ask to enter password. For example:
psql -p 6432 -U postgres -d mydb10 -h localhost
**Password for user postgres:**
Login is OK after I enter the password.
The same direct request run without password:
psql -p 5432 -U postgres -d mydb10 -h localhost
psql (9.6.5)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.
mydb10=# \q
Pgbouncer settings (not all of them):
[databases]
* = host=127.0.0.1 port=5432 auth_user=postgres pool_size=20
[pgbouncer]
listen_addr = *
listen_port = 6432
auth_type = md5
auth_file = /etc/pgbouncer/userlist.txt
;; auth_query = SELECT usename, passwd FROM pg_shadow WHERE usename=$1
PostgreSQL settings (not all of them):
port = 5432
All METHOD in pg_hba.conf are set to 'trust'.
If I set auth_type = trust, connection via pgbouncer do not require password.
What is interesting is that the same configuration when pgbouncer installed on separate server, has no such problem.
Pleas, let me know if you have any idea how to fix this.
Seems that auth_type = trust is a way to go if you want connection without password check (as you have configured trust in pg_hba.conf)
Regarding
What is interesting is that the same configuration when pgbouncer installed on separate server, has no such problem.
Maybe /etc/pgbouncer/userlist.txt on that different server differs?
PS also note that from version 1.7 onward, pgbouncer supports auth_type = hba that you might find suitable.
PPS your problem with access through different pgbouncer instances might be because of different .pgpass files, which is used by psql

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

Connection refused while creating connection pool for postgresql vendor in glassfish server admin console

I am trying to create a connection pool to a PostgreSQL database in Glassfish server.
What I have done the steps as:
I copied the jar of postgresql jdbc jar in full path
C:\Program Files\glassfish-3.1.1\glassfish\domains\domain1\lib\ext
I have specified full path to the jar in the glassfish server admin console:
Pool Name: post-gre-sql_CommonPush_postgresPool
Resource Type: javax.sql.XADataSource
Datasource Classname: org.postgresql.ds.PGSimpleDataSource
In case of additional properties I have specified as:
driverClass:org.postgresql.Driver
URL: jdbc:postgresql://10.137.243.1:5432/CommonPush
portNumber: 5432
databaseName: CommonPush
serverName: 10.137.243.1(My system's IP)
user: postgres
password:
When I ping the above settings I get the error as:
An error has occurred
Ping Connection Pool for post-gre-sql_CommonPush_postgresPool is
Failed. Ping failed Exception - Connection could not be allocated
because: Connection refused. Check that the hostname and port are
correct and that the postmaster is accepting TCP/IP connections.
Please check the server.log for more details.
Ping failed Exception - Connection could not be allocated because:
Connection refused. Check that the hostname and port are correct and
that the postmaster is accepting TCP/IP connections. Please check the
server.log for more details.
I am not able to figure out this problem, can anyone help?
You should use the Resource Type javax.sql.DataSource. I'm not sure if this is causing the error, you may also try to change the hostname to localhost.
Can you access the PostgreSQL DB via pgAdmin or psql commands?
Cause could be that the user may not be having enough privileges on the db objects.
Grant the required privileges to the user, like:
###GRANT USAGE ON service_schema TO admin
sudo -u postgres psql -p 5432 -d service_db -c "GRANT USAGE ON SCHEMA "service_schema" TO "admin";"
###GRANT PREVILEGES ON TABLES OF service_schema TO admin
sudo -u postgres psql -p 5432 -d service_db -c "GRANT ALL ON TABLES IN SCHEMA "service_schema" TO "admin";"
###GRANT PREVILEGES ON SEQUENCES OF service_schema TO admin
sudo -u postgres psql -p 5432 -d service_db -c "GRANT ALL ON SEQUENCES IN SCHEMA "service_schema" TO "admin";"
###GRANT PREVILEGES ON FUNCTIONS OF service_schema TO admin
sudo -u postgres psql -p 5432 -d service_db -c "GRANT ALL ON FUNCTIONS IN SCHEMA "service_schema" TO "admin";"