crecto icon indicating copy to clipboard operation
crecto copied to clipboard

maximum prepared statements issue

Open metacortex opened this issue 7 years ago • 4 comments

In crystal-db, prepared statements are only closed when the connection is closed.

When it reach the max value, it raises exception

Error: Can't create more than max_prepared_stmt_count statements (current value: 16382)

https://github.com/crystal-lang/crystal-db/issues/60 It is recommended that close the connection and open the new one.

Do you have idea to solve this issue?

Currently I exposed Repo::Config and close/open new connection manually in the loop which inserts millions of rows.

metacortex avatar Sep 28 '17 09:09 metacortex

Interesting I didn't know about this, I'll have to research it further.

Do you have any ideas?

fridgerator avatar Sep 28 '17 12:09 fridgerator

I am just creating the new connection every 10k bulk inserts. https://github.com/metacortex/crecto/tree/reset_connection

Manually calling Repo.reset_connection in the end of every loop. It's little bit ugly but works well for my case.

metacortex avatar Sep 28 '17 15:09 metacortex

@metacortex there have been a few commits to crystal-db since 0.4.2 related to this, is the problem fixed if you use crystal-db master?

fridgerator avatar Oct 07 '17 02:10 fridgerator

@fridgerator No. It just releases the existing connection to prevent leaking. crystal-db raises exception, and handling it should be done outside of crystal-db.

Crecto would handle the exception (re-open connection when this kind of exception caught), or let users handle it. (need to expose access method to db connection instance)

metacortex avatar Oct 08 '17 18:10 metacortex