Enable interface to release sqlite memory (#19952)
* Enable release memory via sqlite3_release_memory(bytes) * Enable sqlite3_release_memory
Stelios Fragkakis committed
Mar 24, 2025 at 19:19 UTC
ad39ad335d2b13a4ff7e1d960a73e5f232cd7b50
3 files changed
+14
src/database/sqlite/sqlite_functions.c
+12
@@ -410,8 +410,20 @@ int sqlite_library_init(void)
410
411
SPINLOCK sqlite_spinlock = SPINLOCK_INITIALIZER;
412
413
+int sqlite_release_memory(int bytes)
414
+{
415
+ return sqlite3_release_memory(bytes);
416
+}
417
+
418
void sqlite_library_shutdown(void)
419
{
420
+#ifdef NETDATA_INTERNAL_CHECKS
421
+ int bytes;
422
+ do {
423
+ bytes = sqlite_release_memory(1024 * 1024);
424
+ netdata_log_info("SQLITE: Released %d bytes of memory", bytes);
425
+ } while (bytes);
426
+#endif
427
spinlock_lock(&sqlite_spinlock);
428
(void) sqlite3_shutdown();
429
spinlock_unlock(&sqlite_spinlock);
src/database/sqlite/sqlite_functions.h
+1
@@ -118,4 +118,5 @@ void sqlite_library_shutdown(void);
118
void sql_close_database(sqlite3 *database, const char *database_name);
119
void sqlite_close_databases(void);
120
uint64_t get_total_database_space(void);
121
+int sqlite_release_memory(int bytes);
122
#endif //NETDATA_SQLITE_FUNCTIONS_H
src/database/sqlite/vendored/sqlite3.c
+1
@@ -30,6 +30,7 @@
30
#endif
31
#define SQLITE_UDL_CAPABLE_PARSER 1
32
#define SQLITE_ENABLE_UPDATE_DELETE_LIMIT 1
33
+#define SQLITE_ENABLE_MEMORY_MANAGEMENT 1
34
#define SQLITE_OMIT_LOAD_EXTENSION 1
35
#define SQLITE_ENABLE_DBSTAT_VTAB 1
36
#define SQLITE_ENABLE_DBPAGE_VTAB 1