zabbix-pgsql-partitioning icon indicating copy to clipboard operation
zabbix-pgsql-partitioning copied to clipboard

Events partitioning error with keys

Open alexmirtoff opened this issue 7 years ago • 8 comments

If i am turning on partitionig of the events table, i am seeing an error in postgres logs:

2017-11-28 11:23:27 MSK zabbix zabbix ERROR:  insert or update on table "problem" violates foreign key constraint "c_problem_2"
2017-11-28 11:23:27 MSK zabbix zabbix DETAIL:  Key (r_eventid)=(67189991) is not present in table "events".
2017-11-28 11:23:27 MSK zabbix zabbix STATEMENT:  update problem set r_eventid=67189991,r_clock=1511857405,r_ns=231733137,userid=0 where eventid=67184930;

Help me, please.

alexmirtoff avatar Nov 28 '17 08:11 alexmirtoff

Please, which version of Zabbix and PostgreSQL?

cavaliercoder avatar Nov 28 '17 09:11 cavaliercoder

Sorry.

Zabbix 3.4.4 PostgreSQL 9.6.3

alexmirtoff avatar Nov 28 '17 09:11 alexmirtoff

.. any ideas?

alexmirtoff avatar Dec 04 '17 07:12 alexmirtoff

I apologise I'm a little time constrained to take a deeper look in the short term. I suspect the database schema has changed in Zabbix 3.4, meaning my scripts are no longer appropriate (they were written for 3.2).

cavaliercoder avatar Dec 05 '17 03:12 cavaliercoder

The issue is relating to 2 x constraints on the Problems Table when you try to partition the events table.

Namely, c_problem_1 and c_problem_2.

_1 references the eventid that generated the problem _2 references the eventid that recovered the problem

I come from a mysql backend. Could you point me in the right direction in manipulating the constraints to point to the event table partitioning? event_recovery_1_fk_trigger Function from your 3.2 fix seems to address this? partially...?

darrynv avatar Feb 26 '18 05:02 darrynv

This morning, I applied the partitioning bootstrap to our 3.2.11 instance (not upgraded from previous versions) and get the same errors, e.g.: query failed: [0] PGRES_FATAL_ERROR:ERROR: insert or update on table "problem" violates foreign key constraint "c_problem_2" query failed: [0] PGRES_FATAL_ERROR:ERROR: insert or update on table "alerts" violates foreign key constraint "c_alerts_2" query failed: [0] PGRES_FATAL_ERROR:ERROR: insert or update on table "event_recovery" violates foreign key constraint "c_event_recovery_2"

Because there is a 'fix' script for when you upgrade to 3.2 from an earlier release, which also mentions these keys, I ran that as well, hoping to get rid of the errors, but unfortunately, it didn't.

So, right now, after running the bootstrap script and running the select statement to partition a few tables (trends, trends_uint, history, history_uint, history_text, history_str and history_log), I have a Zabbix 3.2 server that no longer shows what the current state is, what is a problem, what is no longer a problem and doesn't send any email because of this. It appears I have to rollback to unpartitioned tables to solve the problem.

ghost avatar Apr 12 '18 11:04 ghost

This script hasn't had a meaningful update since Zabbix 3.2.7 (Aug 2017). It's possible the schema has changed since this time.

cavaliercoder avatar Apr 12 '18 22:04 cavaliercoder

@cavaliercoder so there is no solution for me? I think that the problem I'm facing is also relevant for Zabbix 3.4 and it would be nice if you, or someone else, could find a solution for this.

ghost avatar Apr 13 '18 07:04 ghost