postgresql-dart icon indicating copy to clipboard operation
postgresql-dart copied to clipboard

Using a single connection for a server will eat up Postgres memory

Open vlidholt opened this issue 5 years ago • 3 comments

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.

vlidholt avatar Aug 14 '19 09:08 vlidholt

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)

isoos avatar Aug 14 '19 15:08 isoos

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.

itsjoeconway avatar Aug 14 '19 17:08 itsjoeconway

@joeconwaystk this sounds likely, thanks for pointing it out!

vlidholt avatar Aug 22 '19 09:08 vlidholt