[ZBX-20706] Zabbix SQL Query causing 100% Usage with MariaDB Makes Zabbix Unusable Created: 2022 Mar 03  Updated: 2023 Jun 28  Resolved: 2022 Jul 13

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Problem report Priority: Trivial
Reporter: Travis Johnson Assignee: Zabbix Development Team
Resolution: Duplicate Votes: 0
Labels: performance, usability
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Three RHEL 8.5 nodes with 2 CPUs, 4 GB RAM. Web front end with MariaDB on one node, Zabbix Server on 2 other nodes in HA configuration


Attachments: File server.cnf     File table_size.csv     File trigger_query.csv     PNG File zabbix_server_logs.png     PNG File zabbix_server_timeout.png     Text File zabbix_sql_query.txt    
Issue Links:
Causes
causes ZBX-22960 LTS MariaDB 10.6.1->10.6.14+ CE/EE ca... Confirmed
Duplicate
duplicates ZBX-20936 Zabbix 6 Upgrade Fails on Server Proc... Closed

 Description   

Steps to reproduce:

  1. Upgrade to Zabbix 6.0.1
  2. Login into Zabbix front end
  3. Observe very slow load times on zabbix dashboard and zabbix server timeout 
  4. run top command and saw MariaDB process taking 100% of 1 CPU of a 2 CPU system
  5. Review zabbix server logs
  6. Identify query
  7. run tests while connected to zabbix database to verify log query times

Result:
See zabbix_server_timeout screenshot...

See zabbix_server_logs screenshot...

See attached zabbix_sql_query.txt...

Expected:
No Zabbix server timeouts and normal load times



 Comments   
Comment by Edgar Akhmetshin [ 2022 Mar 04 ]

Hello Travis,

Please provide additional information:

  1. MariaDB exact version used and table sizes (replace <zabbix db name> with actual name):
    select version();
    
    SELECT
      TABLE_NAME AS `Table`,
      ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)`
    FROM
      information_schema.TABLES
    WHERE
      TABLE_SCHEMA = "<zabbix db name>"
    ORDER BY
      (DATA_LENGTH + INDEX_LENGTH)
    DESC;
    
  2. output from the following query:
    ANALYZE select distinct d.triggerid_down,d.triggerid_up from trigger_depends d,triggers t,hosts h,items i,functions f where t.triggerid=d.triggerid_down and t.flags<>2 and h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=d.triggerid_down and h.status in (0,1);
    

Also MariaDB configuration file would be helpful.

Regards,
Edgar

Comment by Travis Johnson [ 2022 Mar 04 ]

Hi Edgar,

Here is the output from the commands you provided:

select version();
10.6.7-MariaDB

see  table_size.csv for table size information

see trigger_query.csvfor the second query command you requested

see server.cnffor MariaDB configuration

 

Additionally, our zabbix cluster is brand new and we haven't added many devices yet.

Please let me know if you need anything else!

Comment by Edgar Akhmetshin [ 2022 Mar 07 ]

Do you have any additional database configuration files (in include directories for example)?

Comment by Fernando Collado Permuy [ 2022 Mar 07 ]

Just my two cents here, we're seeing the same behavior with MariaDB 10.6, Rocky Linux 8, and Zabbix 6.0.

Using  a very simple test environment, a small vagrant machine with MariaDB 10.6 from the official MariaDB Repo (no tunning at all in my.cnf) and a clean Zabbix 6 install (no other hosts added only the default Zabbix server host), and we get a lot of slow queries with the same select:

977:20220307:113729.416 slow query: 51.571350 sec, "select distinct d.triggerid_down,d.triggerid_up from trigger_depends d,triggers t,hosts h,items i,functions f where t.triggerid=d.triggerid_down and t.flags<>2 and h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=d.triggerid_down and h.status in (0,1)"
977:20220307:113922.890 slow query: 52.474598 sec, "select distinct d.triggerid_down,d.triggerid_up from trigger_depends d,triggers t,hosts h,items i,functions f where t.triggerid=d.triggerid_down and t.flags<>2 and h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=d.triggerid_down and h.status in (0,1)"
977:20220307:114118.002 slow query: 53.586517 sec, "select distinct d.triggerid_down,d.triggerid_up from trigger_depends d,triggers t,hosts h,items i,functions f where t.triggerid=d.triggerid_down and t.flags<>2 and h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=d.triggerid_down and h.status in (0,1)"
977:20220307:114313.576 slow query: 54.160693 sec, "select distinct d.triggerid_down,d.triggerid_up from trigger_depends d,triggers t,hosts h,items i,functions f where t.triggerid=d.triggerid_down and t.flags<>2 and h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=d.triggerid_down and h.status in (0,1)"
977:20220307:114506.700 slow query: 51.791388 sec, "select distinct d.triggerid_down,d.triggerid_up from trigger_depends d,triggers t,hosts h,items i,functions f where t.triggerid=d.triggerid_down and t.flags<>2 and h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=d.triggerid_down and h.status in (0,1)"

Rolling back to MariaDB 10.5 seems to solve the problem.

Comment by Vladislavs Sokurenko [ 2022 May 02 ]

Currently looks like query analyser in MariaDB is misbehaving and not planning query correctly because there shouldn't be many trigger_depends but it looks like it just attempts to read all triggers, functions, hosts and items regardless of this fact, best solution would be to read all trigger dependencies without also finding related triggers, hosts, items and functions, alternative could be to add inner join to give more hints for MariaDB query analyser that it should only find related information for trigger_depends table.

Comment by Vladislavs Sokurenko [ 2022 May 11 ]

Related issue:
ZBX-20936

Comment by Vladislavs Sokurenko [ 2022 Jul 13 ]

Thank you for your report, closing as a duplicate of ZBX-20936

Generated at Tue Jun 24 06:48:26 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.