@cryptotaxi247 / netdata-1 / commits / 48f3bb0d1

user configurable sqlite PRAGMAs (#12917)

* user configurable sqlite PRAGMAs * added cache size

Costa Tsaousis committed May 16, 2022 at 14:06 UTC 48f3bb0d170c7e1e91cb1149ad8e8c814dcca514
3 files changed +59 -44
database/sqlite/sqlite_functions.c
+28 -2
@@ -5,8 +5,6 @@
5 #define DB_METADATA_VERSION "1"
6
7 const char *database_config[] = {
8 - "PRAGMA auto_vacuum=incremental; PRAGMA synchronous=1 ; PRAGMA journal_mode=WAL; PRAGMA temp_store=MEMORY;",
9 - "PRAGMA journal_size_limit=16777216;",
8 "CREATE TABLE IF NOT EXISTS host(host_id blob PRIMARY KEY, hostname text, "
9 "registry_hostname text, update_every int, os text, timezone text, tags text);",
10 "CREATE TABLE IF NOT EXISTS chart(chart_id blob PRIMARY KEY, host_id blob, type text, id text, name text, "
@@ -395,6 +393,34 @@ int sql_init_database(db_check_action_type_t rebuild, int memory)
393
394 info("SQLite database %s initialization", sqlite_database);
395
396 + char buf[1024 + 1] = "";
397 + const char *list[2] = { buf, NULL };
398 +
399 + // PRAGMA schema.auto_vacuum = 0 | NONE | 1 | FULL | 2 | INCREMENTAL;
400 + snprintfz(buf, 1024, "PRAGMA auto_vacuum=%s;", config_get(CONFIG_SECTION_SQLITE, "auto vacuum", "INCREMENTAL"));
401 + if(init_database_batch(rebuild, 0, list)) return 1;
402 +
403 + // PRAGMA schema.synchronous = 0 | OFF | 1 | NORMAL | 2 | FULL | 3 | EXTRA;
404 + snprintfz(buf, 1024, "PRAGMA synchronous=%s;", config_get(CONFIG_SECTION_SQLITE, "synchronous", "NORMAL"));
405 + if(init_database_batch(rebuild, 0, list)) return 1;
406 +
407 + // PRAGMA schema.journal_mode = DELETE | TRUNCATE | PERSIST | MEMORY | WAL | OFF
408 + snprintfz(buf, 1024, "PRAGMA journal_mode=%s;", config_get(CONFIG_SECTION_SQLITE, "journal mode", "WAL"));
409 + if(init_database_batch(rebuild, 0, list)) return 1;
410 +
411 + // PRAGMA temp_store = 0 | DEFAULT | 1 | FILE | 2 | MEMORY;
412 + snprintfz(buf, 1024, "PRAGMA temp_store=%s;", config_get(CONFIG_SECTION_SQLITE, "temp store", "MEMORY"));
413 + if(init_database_batch(rebuild, 0, list)) return 1;
414 +
415 + // PRAGMA schema.journal_size_limit = N ;
416 + snprintfz(buf, 1024, "PRAGMA journal_size_limit=%lld;", config_get_number(CONFIG_SECTION_SQLITE, "journal size limit", 16777216));
417 + if(init_database_batch(rebuild, 0, list)) return 1;
418 +
419 + // PRAGMA schema.cache_size = pages;
420 + // PRAGMA schema.cache_size = -kibibytes;
421 + snprintfz(buf, 1024, "PRAGMA cache_size=%lld;", config_get_number(CONFIG_SECTION_SQLITE, "cache size", -2000));
422 + if(init_database_batch(rebuild, 0, list)) return 1;
423 +
424 if (init_database_batch(rebuild, 0, &database_config[0]))
425 return 1;
426
libnetdata/config/appconfig.c
+30 -42
@@ -805,50 +805,38 @@ void appconfig_generate(struct config *root, BUFFER *wb, int only_changed)
805 struct section *co;
806 struct config_option *cv;
807
808 - for(i = 0; i < 3 ;i++) {
809 - switch(i) {
810 - case 0:
811 - buffer_strcat(wb,
812 - "# netdata configuration\n"
813 - "#\n"
814 - "# You can download the latest version of this file, using:\n"
815 - "#\n"
816 - "# wget -O /etc/netdata/netdata.conf http://localhost:19999/netdata.conf\n"
817 - "# or\n"
818 - "# curl -o /etc/netdata/netdata.conf http://localhost:19999/netdata.conf\n"
819 - "#\n"
820 - "# You can uncomment and change any of the options below.\n"
821 - "# The value shown in the commented settings, is the default value.\n"
822 - "#\n"
823 - "\n# global netdata configuration\n");
824 - break;
825 -
826 - case 1:
827 - buffer_strcat(wb, "\n\n# per plugin configuration\n");
828 - break;
829 -
830 - case 2:
831 - buffer_strcat(wb, "\n\n# per chart configuration\n");
832 - break;
833 - }
834 -
808 + buffer_strcat(wb,
809 + "# netdata configuration\n"
810 + "#\n"
811 + "# You can download the latest version of this file, using:\n"
812 + "#\n"
813 + "# wget -O /etc/netdata/netdata.conf http://localhost:19999/netdata.conf\n"
814 + "# or\n"
815 + "# curl -o /etc/netdata/netdata.conf http://localhost:19999/netdata.conf\n"
816 + "#\n"
817 + "# You can uncomment and change any of the options below.\n"
818 + "# The value shown in the commented settings, is the default value.\n"
819 + "#\n"
820 + "\n# global netdata configuration\n");
821 +
822 + for(i = 0; i <= 13 ;i++) {
823 appconfig_wrlock(root);
824 for(co = root->first_section; co ; co = co->next) {
837 - if(!strcmp(co->name, CONFIG_SECTION_GLOBAL)
838 - || !strcmp(co->name, CONFIG_SECTION_WEB)
839 - || !strcmp(co->name, CONFIG_SECTION_STATSD)
840 - || !strcmp(co->name, CONFIG_SECTION_PLUGINS)
841 - || !strcmp(co->name, CONFIG_SECTION_CLOUD)
842 - || !strcmp(co->name, CONFIG_SECTION_REGISTRY)
843 - || !strcmp(co->name, CONFIG_SECTION_HEALTH)
844 - || !strcmp(co->name, CONFIG_SECTION_STREAM)
845 - || !strcmp(co->name, CONFIG_SECTION_HOST_LABEL)
846 - || !strcmp(co->name, CONFIG_SECTION_ML)
847 - || !strcmp(co->name, CONFIG_SECTION_GLOBAL_STATISTICS)
848 - )
849 - pri = 0;
850 - else if(!strncmp(co->name, "plugin:", 7)) pri = 1;
851 - else pri = 2;
825 + if(!strcmp(co->name, CONFIG_SECTION_GLOBAL)) pri = 0;
826 + else if(!strcmp(co->name, CONFIG_SECTION_HOST_LABEL)) pri = 1;
827 + else if(!strcmp(co->name, CONFIG_SECTION_SQLITE)) pri = 2;
828 + else if(!strcmp(co->name, CONFIG_SECTION_CLOUD)) pri = 3;
829 + else if(!strcmp(co->name, CONFIG_SECTION_ML)) pri = 4;
830 + else if(!strcmp(co->name, CONFIG_SECTION_HEALTH)) pri = 5;
831 + else if(!strcmp(co->name, CONFIG_SECTION_STREAM)) pri = 6;
832 + else if(!strcmp(co->name, CONFIG_SECTION_WEB)) pri = 7;
833 + // by default, new sections will get pri = 8 (set at the end, below)
834 + else if(!strcmp(co->name, CONFIG_SECTION_REGISTRY)) pri = 9;
835 + else if(!strcmp(co->name, CONFIG_SECTION_GLOBAL_STATISTICS)) pri = 10;
836 + else if(!strcmp(co->name, CONFIG_SECTION_STATSD)) pri = 11;
837 + else if(!strcmp(co->name, CONFIG_SECTION_PLUGINS)) pri = 12;
838 + else if(!strncmp(co->name, "plugin:", 7)) pri = 13; // << change the loop too if you change this
839 + else pri = 8; // this is used for any new (currently unknown) sections
840
841 if(i == pri) {
842 int loaded = 0;
libnetdata/config/appconfig.h
+1
@@ -83,6 +83,7 @@
83 #define CONFIG_FILENAME "netdata.conf"
84
85 #define CONFIG_SECTION_GLOBAL "global"
86 +#define CONFIG_SECTION_SQLITE "sqlite"
87 #define CONFIG_SECTION_WEB "web"
88 #define CONFIG_SECTION_STATSD "statsd"
89 #define CONFIG_SECTION_PLUGINS "plugins"