crecto
crecto copied to clipboard
maximum prepared statements issue
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.
Interesting I didn't know about this, I'll have to research it further.
Do you have any ideas?
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 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 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)