go-sqlite3 icon indicating copy to clipboard operation
go-sqlite3 copied to clipboard

Running pragma optimize on all connections

Open YairHalberstadt opened this issue 4 years ago • 1 comments

https://www.sqlite.org/lang_analyze.html recommends running

PRAGMA analysis_limit=400;
PRAGMA optimize;

on each DB Connection just before it closes.

However as https://github.com/mattn/go-sqlite3/issues/255 points out, there is no way to do access all connections at the moment.

It's important that this be run on every connection, since each connection stores data about which tables need to be analyzed base on queries it ran.

I wonder if we could expose some API to do this?

Thanks!

YairHalberstadt avatar Nov 11 '21 09:11 YairHalberstadt

Perhaps we could add a CloseHook, analogous to the existing ConnectHook. That would be very flexible and would allow you to perform any such pre-close actions, log, etc. whenever an individual connection in the pool is closed.

rittneje avatar Feb 20 '22 06:02 rittneje