Yesod/Persistent not closing DB connections

69 Views Asked by At

I have a web app that uses Yesod and Persistent. I'm using the default scaffolded Foundation.hs and Application.hs. I've written a function which processes a local JSON file, and then inserts a row into several tables for each item in the JSON file. So it is going to be performing 1000+ inserts in all.

Running the function in GHCI, it successfully saves some rows, and then errors with:

libpq: failed (FATAL: sorry, too many clients already)

Using the postgres query:

select * from pg_stat_activity where datname = 'mydb-name'

I can see that there are 100 idle connections that have been created by my app and not closed. I then need to kill these connections to be able to do anything.

Shouldn't persistent be closing these connections as the INSERT queries complete? What do I need to do differently?

0

There are 0 best solutions below