RDS PostgreSQL - too may connections for database "db_name" - postgresql

I'm getting too many connections for database error. But there's only 6 active connections to the entire Postgres RDS Server.
Npgsql.PostgresException (0x80004005): 53300: too many connections for
database "db_name"
Max Connections: 300
Active Connections: 6
SELECT * FROM pg_stat_activity where datname = 'dbname'; is getting empty

Related

PgBouncer - Server DNS lookup failed

I am trying to test PgBouncer connection with pgbench on a PostgreSQL server. But I'm getting error as closing because: server DNS lookup failed and at pgbench getting this message:
pgbench -c 10 -t 10 -C -f C:\Users\Administrator\Downloads\query.sql -U postgres -p 6432 -n tags
Password:
pgbench: error: connection to server at "localhost" (::1), port 6432 failed: FATAL: client_login_timeout (server down)
This is observed in PgBouncer log:
LOG C-01715ff0: tags/postgres#[::1]:52768 login attempt: db=tags user=postgres tls=no
WARNING DNS lookup failed: localhost: result=11001
LOG S-0174d218: tags/postgres#(bad-af):0 closing because: server DNS lookup failed (age=0s)
I'm running PostgreSQL-14.5 on Windows Server 2019
PgBouncer Config:
[databases]
postgres = host=localhost port=5435
tags = dbname=postgres host=localhost port=5435 user=postgres password=Admin#!23 auth_user=postgres
[pgbouncer]
logfile = C:\Program Files (x86)\PgBouncer\log\pgbouncer.log
pidfile = C:\Program Files (x86)\PgBouncer\log\pgbouncer.pid
listen_addr = *
listen_port = 6432
auth_type = md5
auth_file = C:\Program Files (x86)\PgBouncer\etc\userlist.txt
admin_users = postgres
stats_users = postgres
pool_mode = session
max_client_conn = 100
default_pool_size = 20
I tried solutions suggested in this post, like, setting
listen_addresses = '*' in postgresql.conf
but could not get the issue resolved. I also searched over the internet for the solution & did not find any.
Am I missing anything or please suggest a solution to this issue. Thanks in advance.
I can connect to Postgres DB after setting [databases] configuration in pgbouncer.ini like this : tags = host=127.0.0.1 port=5435 auth_user=postgres dbname=postgres.
Turns out the issue was with localhost not added in pg_hba.conf.

fatal error : ssl closed pg_hba.conf site, database tool can connect to postgre but in code throw exception

I use flink cdc 2.0.0 to connect to postgresql in vmware.
I can connect to mysql in VM and do the SELECT in my code. But I can't do the same to postgres. And it throw an exception 'FATAL: no pg_hba.conf entry for host "192.168.42.1", user "postgres", database "mydb", SSL off error'
Caused by: org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host "192.168.42.1", user "postgres", database "mydb", SSL off error
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:525)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:146)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:197)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:217)
at org.postgresql.Driver.makeConnection(Driver.java:458)
at org.postgresql.Driver.connect(Driver.java:260)
at io.debezium.jdbc.JdbcConnection.lambda$patternBasedFactory$1(JdbcConnection.java:231)
at io.debezium.jdbc.JdbcConnection.connection(JdbcConnection.java:872)
at io.debezium.jdbc.JdbcConnection.connection(JdbcConnection.java:867)
at io.debezium.connector.postgresql.TypeRegistry.<init>(TypeRegistry.java:122)
... 8 more
Suppressed: org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host "192.168.42.1", user "postgres", database "mydb", SSL off error
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:525)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:146)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:206)
... 16 more
I have modified the settings in pg_hba.conf and postgresql.conf:
host all all all trust # at the bottom of the file
listen_addresses = '*'
And it's weird that there's no problem using the database tool DBeaver, this can create and select...
Here's my code:
DebeziumSourceFunction<String> source = PostgreSQLSource.<String>builder()
.hostname("192.168.42.130")
.port(5432)
.username("postgres")
.password("123456")
.database("mydb")
.schemaList("public")
.tableList("big_data_public.public.user")
.deserializer(new StringDebeziumDeserializationSchema())
.build();
The ip '192.168.42.130' is the ip of my VM.
The ip '192.168.42.1' is the ip of VMware Network Adapter VMnet8.(I don't understand why the code throw an exception with this IP)

Postgres giving fatal error while running my application through JBOSS

I am running my application through JBoss with postgresql database but giving me max connection error but through PGAdmin I am able to connect database
17:14:44,917 ERROR [STDERR] [WARNING]
com.mchange.v2.resourcepool.BasicResourceP ool$AcquireTask#52900718 --
Acquisition Attempt Failed!!! Clearing pending acqui res. While trying
to acquire a needed new resource, we failed to succeed more th an the
maximum number of allowed acquisition attempts (2). Last acquisition
atte mpt exception: org.postgresql.util.PSQLException: FATAL:
remaining connection sl ots are reserved for non-replication superuser
connections
at org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(Conn
Try to open file:
/etc/postgres/postgresql.conf
And increase number off connections like:
max_connections = 100

heroku postgresql could not connect to server: Connection timed out

I'm trying to connect to postgres database in heroku using heroku pg:psql postgresql-rigid-33416 --app murmuring-ocean-62645, however I got this message
--> Connecting to postgresql-rigid-33416
psql: could not connect to server: Connection timed out (0x0000274C/10060)
Is the server running on host "ec2-50-17-225-140.compute-1.amazonaws.com" (50.17.225.140) and accepting
TCP/IP connections on port 5432?
I have tried to turn off my firewall but the problem persists. Any idea how to solve this?
EDIT:
heroku version
heroku/7.16.0 win32-x64 node-v10.10.0
heroku pg:info
=== DATABASE_URL
Plan: Hobby-dev
Status: Available
Connections: 0/20
PG Version: 10.5
Created: 2018-10-09 14:03 UTC
Data Size: 7.6 MB
Tables: 0
Rows: 0/10000 (In compliance)
Fork/Follow: Unsupported
Rollback: Unsupported
Continuous Protection: Off
Add-on: postgresql-rigid-33416
In case someone else has this issue. I had same problem. I had to lower my network security by changing my Firewall Level on my local compter to 'Low' and it works.

pgpool HA + repmgr for Postgresql 9.6

I'm trying to conifure pgpool in my postgresql environment (2 postgresql servers + 1 pgpool) to do HA while repmgr is responsible for the replication.
I'm getting the next messages in the log :
017-12-03 19:27:07: pid 19033: DEBUG: pool_flush_it: flush size: 0
2017-12-03 19:27:07: pid 19033: DEBUG: pool_read: read 103 bytes from backend 1
2017-12-03 19:27:07: pid 19033: ERROR: failed to authenticate
2017-12-03 19:27:07: pid 19033: DETAIL: password authentication failed for user "nobody"
2017-12-03 19:27:07: pid 19033: DEBUG: find_primary_node: no primary node found
2017-12-03 19:27:08: pid 19033: LOG: find_primary_node: checking backend no 0
2017-12-03 19:27:08: pid 19033: DEBUG: SSL is requested but SSL support is not available
2017-12-03 19:34:27: pid 22132: ERROR: unable to read data from DB node 1
2017-12-03 19:34:27: pid 22132: DETAIL: EOF encountered with backend
2017-12-03 19:28:27: pid 19033: DEBUG: find_primary_node: no primary node found
The pool_hba.conf :
TYPE DATABASE USER CIDR-ADDRESS METHOD
local all all trust
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
In postgresql pg_hba.conf I enabled connection from pgpool server :
####pgpool####
host all all 172.22.13.170/32 trust
1.What can be the problem ?
2.If the repmgr is responsible for the replication should I set the parameter backend_flag to 'DISALLOW_TO_FAILOVER'?
Thanks.
I'm just getting up to speed on repmgr and pgpool, but I think there are multiple issues here:
1) Your pgpool.conf has some default settings for alive checking, and the user for that is 'nobody', so to get that to work you need to create a pgsql user with that name so that pgpool can query all hosts to find the current master.
2) pgpool executes scripts to change which is the master etc, and that script would normally just run repmgr commands to promote a new primary at failover, so I don't think DISALLOW_TO_FAILOVER is needed.
If repmgr would failover, then the 1 part of you question would make pgpool find which the new master is anyway, but in that case i would have repmgr configure to not failover automatically (since they could fight on who should do what.