title: How to shut down idle connections to Postgres DB in Amazon RDS
body: <p>We have a Postgres database set up in the RDS. I wrote some APIs to handle data ingestion to the db using Spring Boot. Recently I discovered that lots of connections kept their sessions alive after calling the APIs. Some of the sessions date back to 3 months ago. </p>
  
  <p>I wonder if there is a way to automatically close these connections after it's been inactive for a while. From <a href="https://stackoverflow.com/questions/12391174/how-to-close-idle-connections-in-postgresql-automatically">How to close idle connections in PostgreSQL automatically?</a>, looks like I can set up a cron job to look for dead connections with a SQL query and terminate them with <code>pg_trminate_backend</code>. Is this the best option? Is there something that can be done in the web application layer? Or maybe some RDS parameters? Need some advice on this.</p>