MatteoGioioso / serverless-pg

A package for managing PostgreSQL connections at SERVERLESS scale
MIT License
321 stars 16 forks source link

Possibility to only terminate connections from the "serverless" services/clients. #76

Closed santriseus closed 2 years ago

santriseus commented 2 years ago

Hi, It is not an issue but more like a question/feature suggestion. After a quick look at library I understand that it terminates any backend connection according to strategy, regardless if it was created by the serverless-pg library or not. Do I understand it right? In this case it can terminate connections from the different clients in long-running containers or servers. For sure, in ideal world every client should have resilience and recover, but there could be some issues with it. Is it technically possible to introduce something like 'client name' in pg client and forward it to tables we use for monitoring processes, and then introduce optional filtering by this client id when trying to kill a process?

MatteoGioioso commented 2 years ago

Yes, that's correct. I have never thought about this use case, but it seems a very useful addition indeed.

PostgreSQL has the application_name option in the connection string, and I think pg_stat_activity has it as a column: https://www.postgresql.org/docs/current/monitoring-stats.html#MONITORING-PG-STAT-ACTIVITY-VIEW

I will try to see how this could be implemented.

One question that I have in mind:

MatteoGioioso commented 2 years ago

I have added this functionality in the new major version (2)