As you can see, this should look for any idle
connections older than 2 weeks and terminate them. Since this application is run daily, I believe this will help to keep the pool as clear as possible. Of course, if there's a better way - one that does not require the implementation of some new 3rd-party solution (at least, at this time) - I'm all ears, but, for the time being, I believe this will "solve" my problem.
ADDITIONAL REFERENCE / POSSIBLE ALTERNATE SOLUTION
As I was looking around a bit more, I also came across this answer on StackOverflow:
How to close idle connections in PostgreSQL automatically?
The linked answer refers to using the idle_in_transaction_session_timeout
setting introduced in PostgreSQL 9.6. As stated in fresko's answer, I should be able to set this with a single SQL command sent to the server either as a superuser for the time beingentirety of the server:
ALTER SYSTEM SET idle_in_transaction_session_timeout = '5min';
or for individual user connections on a per-session basis (if needed)
SET SESSION idle_in_transaction_session_timeout = '5min';
I checked this setting on my server and it appears to be disabled (0
), so I may look into configuring this setting as well. I'll be referring to the v12 documentation page for Client Connection Defaults in case anyone wants to "follow along".