Enable primary keys, best logic

Approach to keep partitions when upgrading to 6.0:
Stop zabbix server.
*** prepare tables:
 
RENAME TABLE history TO history_old;
RENAME TABLE history_uint TO history_uint_old;
RENAME TABLE history_str TO history_str_old;
RENAME TABLE history_log TO history_log_old;
RENAME TABLE history_text TO history_text_old;
 
CREATE TABLE history LIKE history_old;
CREATE TABLE history_uint LIKE history_uint_old;
CREATE TABLE history_str LIKE history_str_old;
CREATE TABLE history_log LIKE history_log_old;
CREATE TABLE history_text LIKE history_text_old;
 
*** manage indexes on empty tables:
DROP INDEX `history_1` ON history;
ALTER TABLE history ADD PRIMARY KEY (`itemid`,`clock`,`ns`);
 
DROP INDEX `history_uint_1` ON history_uint;
ALTER TABLE history_uint ADD PRIMARY KEY (`itemid`,`clock`,`ns`);
 
DROP INDEX `history_str_1` ON history_str;
ALTER TABLE history_str ADD PRIMARY KEY (`itemid`,`clock`,`ns`);
 
DROP INDEX `history_log_1` ON history_log;
ALTER TABLE history_log ADD PRIMARY KEY (`itemid`,`clock`,`ns`);
 
DROP INDEX `history_text_1` ON history_text;
ALTER TABLE history_text ADD PRIMARY KEY (`itemid`,`clock`,`ns`);
 
Stop zabbix server.
 
*** DATA migration here ***
 
** drop not needed tables:
DROP TABLE history_old;
DROP TABLE history_uint_old;
DROP TABLE history_str_old;
DROP TABLE history_log_old;
DROP TABLE history_text_old;

No comments: