简体   繁体   中英

Async foreign tables, foreign data wrapper

i am working on foreign data wrappers in postgres, using multicorn and using triggers to insert data in foreign tables, however i do not want the postgres to wait for response after trigger, just trigger inserts it and then forgets. how can that be possible.

Actually i am using it for a foreign table

CREATE FOREIGN TABLE media_es (
    id BIGINT,
    title TEXT,
    description TEXT,
    tags TEXT,
    query TEXT,
    score NUMERIC
  )
  SERVER multicorn_es
  OPTIONS (
      host 'elasticsearch',  
      port '9200',
      index 'test',
      type 'media',
      rowid_column 'id',
      query_column 'query',
      score_column 'score'
  );


CREATE TRIGGER es_insert_media
      AFTER INSERT
          ON media
      FOR EACH ROW
          EXECUTE PROCEDURE index_media();

CREATE OR REPLACE FUNCTION index_media()
      RETURNS trigger
      AS $def$
          BEGIN
          INSERT INTO media_es
                (
                  id,
                  title,
                  description,
                  tags
              )
          VALUES
              (
                  NEW.id,
                  NEW.title,
                  NEW.description,
                  NEW.tags
              )
          ;
          RETURN NEW;  
      END;
  $def$ LANGUAGE plpgsql;

postgres dblink extension allows async calls to remote server via dblink-send-query command.

not sure how it will work within trigger in terms of establishing multiple connections. caution should be taken here for resource leakage

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM