title: trigger function to refresh remote materialized view on UPDATE
body: <p>I have the following trigger and trigger function setup in order to refresh a MATERIALIZED VIEW on a remote server every time a local table A gets updated. The MV in turn is created from a foreign table of the local table A. After the trigger runs, the materialized view is updated, however, it is only updated to the state BEFORE the UPDATE happened. I'm not sure why this is the case. Either the trigger function runs before the UPDATE is commited, but that should be what the 'AFTER' part of the trigger is for, right? Or the MV refresh is to fast(?), but adding pg_sleep doesn't change the result. </p>
  
  <pre><code>CREATE OR REPLACE FUNCTION public.refresh_remote_mv()
  RETURNS TRIGGER AS
  $func$
  BEGIN
  PERFORM dblink_connect('remote_server');
  PERFORM dblink_exec(
  $$
   REFRESH MATERIALIZED VIEW m_config;
  $$);
  PERFORM dblink_disconnect();
  RETURN NULL;
  END
  $func$ LANGUAGE plpsql;
  </code></pre>
  
  <p>Trigger:</p>
  
  <pre><code>CREATE TRIGGER tr_remote_refresh
  AFTER UPDATE ON m_config
  EXECUTE PROCEDURE refresh_remote_mv()
  </code></pre>