agroal / pgagroal

High-performance connection pool for PostgreSQL
https://agroal.github.io/pgagroal/
BSD 3-Clause "New" or "Revised" License
684 stars 61 forks source link

Connection status misreported in `pgagroal-cli` output #473

Closed fluca1978 closed 2 months ago

fluca1978 commented 2 months ago

Running version 40acff635d16e00eac08bf5307efdabc03ee13cd I noticed, as reported in #471 that the command pgagroal-cli status details was reporting connections are in Replica status. Example:

% psql -h rachel -U luca -c "select pg_sleep_for( '200 seconds' );" testdb

# and in another terminal

% pgagroal-cli status details
-> TRACE cli.c:691 <status details>
-> DEBUG management.c:1852 pgagroal-cli version 20000
Status:              Running
Active connections:  1
Total connections:   6
Max connections:     15
---------------------
Server:              rachel
Host:                127.0.0.1
Port:                5432
State:               Primary
---------------------
Database:            pgbench
Username:            pgbench
Active connections:  0
Max connections:     12
Initial connections: 5
Min connections:     5
---------------------
Database:            testdb
Username:            luca
Active connections:  1
Max connections:     2
Initial connections: 1
Min connections:     1
---------------------
Connection    1:     Primary         2024-09-26 14:17:26        15     pgbench pgbench 
Connection    2:     Primary         2024-09-26 14:17:26        16     pgbench pgbench 
Connection    3:     Primary         2024-09-26 14:17:26        17     pgbench pgbench 
Connection    4:     Primary         2024-09-26 14:17:26        18     pgbench pgbench 
Connection    5:     Primary         2024-09-26 14:17:26        19     pgbench pgbench 
Connection    6:     Replica         2024-09-26 14:17:45 248540 20     luca testdb psql
Connection    7:     Not init                                            
Connection    8:     Not init                                            
Connection    9:     Not init                                            
Connection   10:     Not init                                            
Connection   11:     Not init                                            
Connection   12:     Not init                                            
Connection   13:     Not init                                            
Connection   14:     Not init                                            
Connection   15:     Not init                                      

Note how the Connection 4 is reported as in Replica instead of In Use.

The problem is that the pgagroal-cli output is decoding the status of a connection as the status of a server, and the contant values match. In other words, pgagroal_server_state_as_string is used also for connections.