lncapital / torq

55 stars 6 forks source link

Postgresql: sorry, too many clients already #1

Closed HolgerHatGarKeineNode closed 1 year ago

HolgerHatGarKeineNode commented 1 year ago

Torq: v0.22.1 | Commit: 41c72e5

I've been getting the following 500 error message since the last version I ran with Docker.

Is there perhaps a process that is creating too many connections to the database and then not closing those connections?

Trying on my own right now to figure out what is going wrong.

I have only one LND instance connected. And Torq always ran 100% without problems.

Object { description: "pq: remaining connection slots are reserved for non-replication superuser connections", code: "", attributes: null }

FATAL:  remaining connection slots are reserved for non-replication superuser connections
FATAL:  sorry, too many clients already
HolgerHatGarKeineNode commented 1 year ago

I have set the max_connections with TS_TUNE_MAX_CONNS higher. If there are problems with this limit again, then there will be a problem with unclosed connections.

HolgerHatGarKeineNode commented 1 year ago

Ok, after about an hour of keeping Torq open in the web browser, 100 connections are open and apparently not closed properly. Default limit is 100 connections, so at this point the database would not react anymore.

Now the question arises why these connections remain open?

In order for me to continue using Torq, I now need to restart the containers at this point.

postgres=# SELECT pid, usename, state
FROM pg_stat_activity;
pid  | usename  |             state
------+----------+-------------------------------
27 |          |
30 | postgres |
29 | postgres |
31 | postgres | idle
32 | postgres | idle
70 | torq     | idle in transaction (aborted)
34 | torq     | idle
37 | torq     | idle in transaction (aborted)
38 | torq     | idle in transaction (aborted)
109 | torq     | idle in transaction (aborted)
68 | torq     | idle in transaction (aborted)
128 | torq     | idle in transaction (aborted)
147 | torq     | idle in transaction (aborted)
166 | torq     | idle in transaction (aborted)
185 | torq     | idle in transaction (aborted)
299 | torq     | idle in transaction (aborted)
230 | torq     | idle in transaction (aborted)
236 | torq     | idle in transaction (aborted)
272 | torq     | idle in transaction (aborted)
285 | postgres | active
288 | torq     | idle in transaction (aborted)
339 | torq     | idle in transaction (aborted)
358 | torq     | idle in transaction (aborted)
377 | torq     | idle in transaction (aborted)
396 | torq     | idle in transaction (aborted)
415 | torq     | idle in transaction (aborted)
435 | torq     | idle in transaction (aborted)
454 | torq     | idle in transaction (aborted)
473 | torq     | idle in transaction (aborted)
494 | torq     | idle in transaction (aborted)
513 | torq     | idle in transaction (aborted)
532 | torq     | idle in transaction (aborted)
551 | torq     | idle in transaction (aborted)
591 | torq     | idle in transaction (aborted)
569 | torq     | idle in transaction (aborted)
610 | torq     | idle in transaction (aborted)
630 | torq     | idle in transaction (aborted)
649 | torq     | idle in transaction (aborted)
668 | torq     | idle in transaction (aborted)
718 | torq     | idle in transaction (aborted)
690 | torq     | idle in transaction (aborted)
751 | torq     | idle in transaction (aborted)
706 | torq     | idle in transaction (aborted)
770 | torq     | idle in transaction (aborted)
789 | torq     | idle in transaction (aborted)
808 | torq     | idle in transaction (aborted)
827 | torq     | idle in transaction (aborted)
846 | torq     | idle in transaction (aborted)
913 | torq     | idle in transaction (aborted)
879 | torq     | idle in transaction (aborted)
932 | torq     | idle in transaction (aborted)
885 | torq     | idle in transaction (aborted)
951 | torq     | idle in transaction (aborted)
970 | torq     | idle in transaction (aborted)
989 | torq     | idle in transaction (aborted)
1008 | torq     | idle in transaction (aborted)
1027 | torq     | idle in transaction (aborted)
1046 | torq     | idle in transaction (aborted)
1065 | torq     | idle in transaction (aborted)
1087 | torq     | idle in transaction (aborted)
1106 | torq     | idle in transaction (aborted)
1125 | torq     | idle in transaction (aborted)
1144 | torq     | idle in transaction (aborted)
1163 | torq     | idle in transaction (aborted)
1183 | torq     | idle in transaction (aborted)
1202 | torq     | idle in transaction (aborted)
1221 | torq     | idle in transaction (aborted)
1240 | torq     | idle in transaction (aborted)
1259 | torq     | idle in transaction (aborted)
1272 | torq     | idle in transaction (aborted)
1300 | torq     | idle in transaction (aborted)
1319 | torq     | idle in transaction (aborted)
1338 | torq     | idle in transaction (aborted)
1357 | torq     | idle in transaction (aborted)
1376 | torq     | idle in transaction (aborted)
1395 | torq     | idle in transaction (aborted)
1414 | torq     | idle in transaction (aborted)
1433 | torq     | idle in transaction (aborted)
1452 | torq     | idle in transaction (aborted)
1474 | torq     | idle in transaction (aborted)
1491 | torq     | idle in transaction (aborted)
1512 | torq     | idle in transaction (aborted)
1530 | torq     | idle in transaction (aborted)
1550 | torq     | idle in transaction (aborted)
1569 | torq     | idle in transaction (aborted)
1588 | torq     | idle in transaction (aborted)
1607 | torq     | idle in transaction (aborted)
1626 | torq     | idle in transaction (aborted)
1645 | torq     | idle in transaction (aborted)
1667 | torq     | idle in transaction (aborted)
1686 | torq     | idle in transaction (aborted)
1705 | torq     | idle in transaction (aborted)
1724 | torq     | idle in transaction (aborted)
1788 | torq     | idle in transaction (aborted)
1807 | torq     | idle in transaction (aborted)
1758 | torq     | idle in transaction (aborted)
1826 | torq     | idle
1755 | torq     | idle in transaction (aborted)
25 |          |
24 |          |
26 |          |
(101 rows)
2Fast2BCn commented 1 year ago

Hello,

Is Torq actually working as expected? It's not panicking or in a boot loop? There are no errors in the logs from the Torq container? We also fixed a problem with the install script today.

HolgerHatGarKeineNode commented 1 year ago

Ah thank you for the hint to look in the logs as well. Is there possibly a migration missing in my database?

violates foreign key constraint

There seems to be an ID that should be used that is not present.

{"level":"error","error":"store payments: db exec: pq: insert or update on table \"_hyper_7_39_chunk\" violates foreign key constraint \"39_114_fk_payment_destination_node_id\"","time":"2023-05-23T19:19:48Z","message":"Failed to store payments, will retry in 10 seconds"}
{"level":"error","error":"store payment for nodeId: 1: store payments: db exec: pq: insert or update on table \"_hyper_7_39_chunk\" violates foreign key constraint \"39_114_fk_payment_destination_node_id\"","time":"2023-05-23T19:19:48Z","message":"LndServicePaymentsService failed to process for nodeId: 1"}
{"level":"info","time":"2023-05-23T19:19:48Z","message":"LndServicePaymentsService terminated for nodeId: 1"}
{"level":"info","time":"2023-05-23T19:20:48Z","message":"LndServicePaymentsService boot attempt for nodeId: 1."}
{"level":"info","time":"2023-05-23T19:20:48Z","message":"LndServicePaymentsService service booted for nodeId: 1"}
{"level":"error","error":"store payments: db exec: pq: insert or update on table \"_hyper_7_39_chunk\" violates foreign key constraint \"39_114_fk_payment_destination_node_id\"","time":"2023-05-23T19:20:49Z","message":"Failed to store payments, will retry in 10 seconds"}
2Fast2BCn commented 1 year ago

Thank you for this. I will look into this problem. We will have to create a new release to fix this.