From fab5893663593f0daff7558045f250382d41bcf7 Mon Sep 17 00:00:00 2001 From: Erik Berg Date: Thu, 18 Jul 2024 18:18:14 +0200 Subject: [PATCH] Run Timescale schema during an upgrade In the case that timescale has already been enabled, and we're upgrading from 6.x to 7.x, the auditlog should also get converted. (Which it was not in the 6.x schemas) --- roles/zabbix_server/tasks/initialize-pgsql.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/roles/zabbix_server/tasks/initialize-pgsql.yml b/roles/zabbix_server/tasks/initialize-pgsql.yml index 6aba0b332..f4e59aa8e 100644 --- a/roles/zabbix_server/tasks/initialize-pgsql.yml +++ b/roles/zabbix_server/tasks/initialize-pgsql.yml @@ -105,8 +105,20 @@ query: "SELECT db_extension FROM config WHERE db_extension = 'timescaledb'" register: _config_db_extension + # NOTE: Zabbix 7.0 adds a hypertable for auditlog. + - name: "PostgreSQL | Check for auditlog hypertable" + community.postgresql.postgresql_query: + login_user: "{{ zabbix_server_dbuser }}" + login_password: "{{ zabbix_server_dbpassword }}" + login_host: "{{ zabbix_server_dbhost }}" + port: "{{ zabbix_server_dbport }}" + db: "{{ zabbix_server_dbname }}" + query: "SELECT hypertable_name FROM timescaledb_information.hypertables WHERE hypertable_name = 'auditlog'" + register: _hypertable_auditlog + - name: "PostgreSQL | Create TimescaleDB hypertables" - when: (_config_db_extension.query_result | length == 0) + when: (_config_db_extension.query_result | length == 0) or + (zabbix_server_version is version('7.0', '>=') and _hypertable_auditlog.query_result | length == 0) community.postgresql.postgresql_db: login_user: "{{ zabbix_server_dbuser }}" login_password: "{{ zabbix_server_dbpassword }}"