Ad Widget

Collapse

Zabbix Postgresql 9.? autopartitioning

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alledm
    Member
    • May 2012
    • 84

    #91
    I am using the statement:
    IF NOT EXISTS
    Do not throw an error if a relation with the same name already exists. A notice is issued in this case. Note that there is no guarantee that the existing relation is anything like the one that would have been created.
    Which is new in postgres 9.1. What version are you using?

    I don't know why this condition happens given that I am using the command above, but it can easily be trapped by an exception block
    Code:
    EXCEPTION
    WHEN undefined_table THEN
        BEGIN
        startdate := EXTRACT(epoch FROM date_trunc(selector, TO_TIMESTAMP(NEW.clock)));
        enddate := EXTRACT(epoch FROM date_trunc(selector, TO_TIMESTAMP(NEW.clock) + _interval ));
     
        create_table_part:= 'CREATE TABLE IF NOT EXISTS '|| prefix || quote_ident(tablename) || ' (CHECK ((clock >= ' || quote_literal(startdate) || ' AND clock < ' || quote_literal(enddate) || '))) INHERITS ('|| TG_TABLE_NAME || ')';
        create_index_part:= 'CREATE INDEX '|| quote_ident(tablename) || '_1 on ' || prefix || quote_ident(tablename) || '(itemid,clock)';
     
        EXECUTE create_table_part;
        EXECUTE create_index_part;
    EXCEPTION
    WHEN duplicate_table THEN
      -- There it goes the infamous race condition.
    END;
    
    --insert it again
    EXECUTE 'INSERT INTO ' || prefix || quote_ident(tablename) || ' SELECT ($1).*' USING NEW;
    RETURN NULL;
     
    END;
    Please test it as I do not have a working environment and add it to my solution if this solves your problem

    Comment

    • alledm
      Member
      • May 2012
      • 84

      #92
      Actually,

      it seems to be related to the fact that Postgres sucks at this

      Please see:
      Hi, I've recently seen a few errors on our continuous integration system during a test using a badly written partitioning …


      I still think the exception might put a patch to this but please test it and let me know

      Comment

      • lhfarias
        Junior Member
        • Jul 2016
        • 3

        #93
        Hi everybody
        Does anyone do partitioning with non-itemid-tables in zabbix, for example events and alerts??
        Is data purge the only option for those tables?

        Comment

        • syepes
          Junior Member
          • Jun 2016
          • 8

          #94
          lhfarias, did you find any info additional info on this subject?

          Originally posted by lhfarias
          Hi everybody
          Does anyone do partitioning with non-itemid-tables in zabbix, for example events and alerts??
          Is data purge the only option for those tables?

          Comment

          Working...