File tree Expand file tree Collapse file tree 4 files changed +30
-0
lines changed Expand file tree Collapse file tree 4 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -375,6 +375,16 @@ for easy modification.
375
375
*Default *: None
376
376
377
377
378
+ ``constants.DATABASE_VACUUM_ON_SHUTDOWN ``
379
+
380
+ Vacuum SQLite database on shutdown - when enabled, the database will be vacuumed on shutdown
381
+ to reduce its size on disk.
382
+
383
+ *Type *: ``boolean ``
384
+
385
+ *Default *: False
386
+
387
+
378
388
Example usage:
379
389
380
390
.. code-block :: python
Original file line number Diff line number Diff line change @@ -47,6 +47,9 @@ class Constants:
47
47
# Use a string like '5 per minute' or None to disable (default), for details see
48
48
# http://limits.readthedocs.io/en/stable/string-notation.html
49
49
ERROR_LOG_RATE_LIMIT = None
50
+ # Vacuum SQLite database on shutdown - when enabled, the database will be vacuumed on shutdown
51
+ # to reduce its size on disk
52
+ DATABASE_VACUUM_ON_SHUTDOWN = False
50
53
51
54
52
55
constants = Constants () # pylint: disable=invalid-name
Original file line number Diff line number Diff line change @@ -152,3 +152,9 @@ def expire_events(self):
152
152
with self ._connect () as connection :
153
153
cursor = connection .cursor ()
154
154
cursor .execute (query_delete )
155
+
156
+ # ----------------------------------------------------------------------
157
+ def vacuum (self ):
158
+ with self ._connect () as connection :
159
+ cursor = connection .cursor ()
160
+ cursor .execute ("VACUUM;" )
Original file line number Diff line number Diff line change @@ -97,6 +97,7 @@ def run(self):
97
97
self ._log_general_error (exc )
98
98
# check for empty queue and report if not
99
99
self ._warn_about_non_empty_queue_on_shutdown ()
100
+ self ._vaccum_database ()
100
101
101
102
# ----------------------------------------------------------------------
102
103
def force_flush_queued_events (self ):
@@ -357,3 +358,13 @@ def _warn_about_non_empty_queue_on_shutdown(self):
357
358
f'Non-empty queue while shutting down ({ queue_size } events pending). '
358
359
'This indicates a previous error.' ,
359
360
extra = dict (queue_size = queue_size ))
361
+
362
+ # ----------------------------------------------------------------------
363
+ def _vaccum_database (self ):
364
+ if not constants .DATABASE_VACUUM_ON_SHUTDOWN :
365
+ return
366
+
367
+ try :
368
+ self ._database .vacuum ()
369
+ except DatabaseLockedError :
370
+ self ._safe_log ('debug' , 'Database is locked, ignore vacuuming database' )
You can’t perform that action at this time.
0 commit comments