using Trigger update another database's table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • littlemaster
    New Member
    • Apr 2010
    • 25

    using Trigger update another database's table

    I have two data base A, & B. If a table updated or inserted or deleted means then that data have to update in table which is in data base B.

    I tried with dblink module, it is not workig fully. One table only getting updated... If u know the the solution let me know it...
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    So you need data replication. If you need it for more than one tabele you can use some tools like Slony-I.

    Comment

    • littlemaster
      New Member
      • Apr 2010
      • 25

      #3
      I was not aware of slony. I am working in 'linux' environment. Can u give better explanation?

      Comment

      • rski
        Recognized Expert Contributor
        • Dec 2006
        • 700

        #4
        Slony-I is a tool that allows data replication between databases.
        More you can find here http://slony.info.

        Comment

        • littlemaster
          New Member
          • Apr 2010
          • 25

          #5
          slony is not working in my system.

          my trigger procedure code is,


          create or replace function insert_data() returns trigger as '
          DECLARE
          cid integer;
          cmpname text;
          sdate timestamp;
          fdate timestamp;
          phone integer;
          status text;
          query text;
          BEGIN
          IF(TG_OP = ''INSERT'') THEN
          cid:= NEW.id;
          cmpname:=NEW.na me;
          sdate:= NEW.start_date;
          fdate:= NEW.from_date;
          phone:= NEW.phoneno;
          status:= NEW.flag;
          query:=''insert into company(id,name ,start_date,fro m_date,phoneno, flag) values(''||cid| |'',''||quote_l iteral(cmpname) ||'',''||quote_ literal(sdate)| |'',''||quote_l iteral(fdate)|| '',''||phone||' ',''||quote_lit eral(status)||' ')'';
          perform dblink_exec(''d bname=savithri port=5432 host=192.168.1. 200 user=savithri password=savith ri'',query);
          RAISE EXCEPTION ''%'' ,query;
          END IF;
          RETURN NEW;
          END;
          ' LANGUAGE 'plpgsql';

          trigger is,
          create trigger t1 after insert on company for each row execute procedure insert_data();

          I run the dblink.sql file in both data bases. Data is not adding in source data base but data adding in destination database. can u give the solution for this???

          Comment

          Working...