Connections remain active even after terminating the session in Postgres Yesterday, I added the pldbgapi extension in my Postgres DB to debug a function. I was using PgAdmin for debugging the same. But today, when I tried invoking a simple query, it was taking a lot of time to execute. I tried to find out the active sessions using the below query:
select * from pg_stat_activity where datname = 'dbname';

In the results, 6 sessions were there, out of which 4 were active. On checking the query that these active sessions were executing, I found that all the 4 sessions were executing the same query and these queries were invoked yesterday when debugging the function.
So every time I debug a function, a new session was created and all the created sessions didn't get closed and remained in the active state.
I tried to close the session using pg_terminate_backend and pg_cancel_backend but nothing works and all 4 sessions remain in the active state.
I didn't know how this happened and why I am not able to close these connections.
If you had permission to kill them with pg_cancel_backend, but doing so did not work, then they must be in a state where they are not responding to interrupts.  That is probably a bug, either in PostgreSQL itself, or in your code, or in pldbgapi.  What does wait_event_type and wait_event say?  Can you attach to them with gdb and get backtraces?