postgresql-dart
postgresql-dart copied to clipboard
Using a single connection for a server will eat up Postgres memory
I initially used a single database connection to make all my (very small) queries. This will cause the database memory to slowly decrease until the database crashes.
I solved it by creating a new connection for each session in my server, but this seem to be a serious issue where the connection seem to cause the database to allocate memory which isn't returned until the connection is closed.
Interesting observation. I've implemented a connection pool that would re-connect after a certain amount of use, but I thought that issue is some memory buildup on the Dart side, and not on the Postgresql side (never checked it though). Do you have a scenario where you can replicate this reliably? (e.g. running a Postgresql in docker and then doing the queries as a loop)
Is it due to statement reuse for queries being on by default? The statement is stored in the database server for each query string, per connection. You can disable reuse with a boolean flag to your execution method if you are generating dynamic queries often.
@joeconwaystk this sounds likely, thanks for pointing it out!