I am currently managing a 3-node PostgreSQL asynchronous streaming replication cluster setup, which includes one master node and two standby nodes, all sitting behind a pgpool load balancer. During high write transactions (approximately 90% write and 10% read), I'm encountering issues that cause my application to get stuck and generate errors.
Issue:
- Scenario 1: When I direct both read and write traffic solely to the primary node, everything functions correctly, and the application runs smoothly.
- Scenario 2: When I distribute the load across the standby nodes (writes to the primary, reads to the standbys), I start seeing a failure rate of about 3% to 5%, causing the application logs to get stuck with the following error:
java.lang.RuntimeException: org.postgresql.util.PSQLException: The connection attempt failed.
Caused by: org.postgresql.util.PSQLException: The connection attempt failed
20230402 184393.543 Master-slave integrity test hit SQL problem: Database NOT ok! org.postgresql.util.PSQLException I/O error occurred while sending to the backend.
WARNING: Failed to check connection: java.net.ConnectException: Connection refused(Connection refused)
Despite these issues, the CPU, RAM, and load average metrics on all database nodes appear normal.However, the load balancer logs consistently show the following error in both scenarios (primary-only and primary+standby):
SQLUtilsMDS/SAS pid 6354333: ERROR: unable to read data from frontend.
Question:
What could be causing these connection issues when distributing the read load across the standby nodes? Could this be an application-side issue, or is there something I need to tweak in my pgpool configuration or PostgreSQL settings to handle the high write transaction load better?
Any insights or suggestions would be greatly appreciated.