Search code examples
databasemariadbpartitioningzabbix

Mariadb Parititioning


There is table named history in Zabbix database, I have created partitions on this table.

And the partition type is range and column type is UNIX_TYPESTAMP.

After the date is changed zabbix service does not insert data to the related partition.

What is the problem?

And how do I display all partitions? Could you please help how do I write data to the related partitions?

Sample of Partition creation statement;

                        .
                        .
                        .
 ALTER TABLE zabbix.history_test PARTITION BY RANGE(clock)(PARTITION     
 p28082021  VALUES LESS THAN(UNIX_TIMESTAMP("2021-08-28 00:00:00"    
  ))ENGINE=InnoDB);

Server version: 10.1.31-MariaDB MariaDB Server

 EXPLAIN PARTITIONS SELECT * FROM zabbix.history;
 +------+-------------+---------+------------+------+---------------+------ 


 | id   | select_type | table   | partitions | type | possible_keys | key  | 
 key_len | ref  | rows     | Extra |


   |    1 | SIMPLE      | history | p28082021  | ALL  | NULL          | NULL 
   | NULL    | NULL | 18956757 |       |





     SELECT DISTINCT PARTITION_EXPRESSION  FROM 
     INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME='history' AND 
      TABLE_SCHEMA='zabbix';
      +----------------------+
      | PARTITION_EXPRESSION |
      +----------------------+
      | clock                |
      +----------------------+


         MariaDB [(none)]> SELECT PARTITION_ORDINAL_POSITION, TABLE_ROWS, PARTITION_METHOD
            FROM information_schema.PARTITIONS
             WHERE TABLE_SCHEMA = 'zabbix' AND TABLE_NAME = 'history';
        +----------------------------+------------+------------------+
        | PARTITION_ORDINAL_POSITION | TABLE_ROWS | PARTITION_METHOD |
        +----------------------------+------------+------------------+
        |                          1 |   18851132 | RANGE            |
        +----------------------------+------------+------------------+



         SELECT FROM_UNIXTIME(MAX(clock)) FROM zabbix.history;
         +---------------------------+
         | FROM_UNIXTIME(MAX(clock)) |
         +---------------------------+
         | 2018-04-07 23:06:06       |
         +---------------------------+


         SELECT FROM_UNIXTIME(MIN(clock)) FROM zabbix.history;
         +---------------------------+
         | FROM_UNIXTIME(MIN(clock)) |
         +---------------------------+
         | 2018-04-06 01:06:23       |
         +---------------------------+

Solution

  • This document help me to create partition on clock column. There are stored procedures, that create partitions,you can check it.

    https://www.zabbix.org/wiki/Docs/howto/mysql_partition