Monday, 29 October 2012

Zabbix on Oracle - few notes

We migrated Zabbix from MySQL to Oracle.
At the same time we moved to partitioning, here excellent article how to do it on MySQL. On Oracle we partitioned the same tables, created the same indexes, but go with interval partitioning (it is nice to not have to create new partitions manually or program it) based upon weeks (the partitioning key is of NUMBER type and we need an equal interval value for every period, so month is out due to variable number of days).

Almost no problems with upgrade to 2.0.2. We had to change the database however due to national character set - must be UTF-8, while we had previously fixed UTF16 - zabbix on Oracle is based mainly upon NVARCHAR2 type, and upgrade sets some columns to width bigger than 2000.
It is worth to enable CURSOR_SHARING to FORCE (actually I would say this is inevitable).
At the same time I would not recommend to use any automatic memory management (even ASMM). May be this is only our case, but frequently we run into ORA-4031 problems, which eventually ended with instance hangover or crash. As soon as I disabled any automatic memory management completely, the problems gone.

In addition to partition maintenance here there is an action for job, which will drop the HISTORY% tables' old partitions:
 begin
  for cmd in (
    with 
    conf as (select 9+1 part_num_left from dual)
    select 'alter table '||p.table_name||' drop partition '||p.partition_name||' update global indexes'  ddl1 
    from 
      user_tab_partitions p, 
      (select tp.table_name, count(*) l_pnum 
        from user_tab_partitions tp 
        where tp.table_name like 'HISTORY%' 
        group by tp.table_name 
        having count(*)>(select part_num_left from conf)) t
    where 1=1
      and p.table_name=t.table_name 
      and p.table_name like 'HISTORY%' 
      and p.partition_name<>'DONT_DELETE' 
      and p.partition_position between 2 and (t.l_pnum-(select part_num_left from conf)) 
    order by p.table_name, p.partition_position)
  loop
    execute immediate cmd.ddl1;
  end loop;
end;

The partitions labeled DONT_DELETE are partitions on the first position of relevant tables. The label is due to the fact one can not drop the first partition from a table partitioned by interval. It is comfortable to create those partitions before the time we want to store in table in order to keep it empty. The code above drops partitions leaving last n ones (here 9 + DONT_DELETE). The line with condition on DONT_DELETE partition name is actually redundant as the code starts dropping from second partition.

7 comments:

Anonymous said...

Hi, can you publish some details about oracle partitioning of zabbix tables ?
Unfortunately, I'm not very familiar with partitioning at all :-(

rems said...

Why not. But tell me what do You mean by details?

Unknown said...

I installed zabbix 2.4.3 and zabbix-2.4.4rc1-51402 on Oracle Linux 7
odbc is OK, I can connect to Oracle via slplus and isql
But zabbix server does not start due to zabbix-to-oracle connection problem
Details: https://www.zabbix.com/forum/showthread.php?p=160390#post160390

Help me please

rems said...

I may point out only few things You may try:
1. if MYDB is not Your database SID (You have it specified as a SERVICE_NAME) then use SID instead
2. look for some ORA- error message (it should be somewhere) - this should tell more about the problem nature - it may be even something simple
Without ORA- message it is really hard to tell exactly what is going on.

Unknown said...

Hi, would you please kindly post your method of migrating zabbix from mysql to oracle?
Thanks

rems said...

I am not sure if I recall correctly. One of the ways and quite simple is to dump with mysqldump to inserts - as the database structure is quite simple, there is no problem to run it afterwards on an Oracle database may be after small adjustments.
Of course this is not the fastest way. I am not sure if we kept then the history - it is possible we moved only the configuration parts.

Another way is to dump to some fixed format (e.g. CSV) and then use the sqlldr tool to load it to an Oracle database.

rems said...

@Pantera Ali
I 've looked at the link Your provided. I 'm pretty sure we have Zabbix compiled against the native drivers (as it was pointed out in the response of the provided thread) - so I would suggest to stick to such approach.