title: How to set up permissions on foreign table using postgres_fdw?
body: <p>The source data is in a <em>keys</em> table in the <em>public</em> schema of  database <em>keys</em>  (reference pg docs:  <a href="https://www.postgresql.org/docs/current/postgres-fdw.html" rel="nofollow noreferrer">https://www.postgresql.org/docs/current/postgres-fdw.html</a>) :</p>
  <pre><code>create table keys (
      id varchar not null,
      keyname varchar not null,
      created timestamp default current_timestamp not null,
      modified timestamp default current_timestamp not null
  );
  </code></pre>
  <p>The referencing user/schema/database is <em>vids</em>/<em>public</em>/<em>vids</em> .</p>
  <ol>
  <li>Set up the server connection</li>
  </ol>
  <pre><code>CREATE SERVER keys
          FOREIGN DATA WRAPPER postgres_fdw
          OPTIONS (host '1.2.3.4', port '5432', dbname 'keys');
  </code></pre>
  <ol start="2">
  <li>Create the user mapping</li>
  </ol>
  <pre><code>CREATE USER MAPPING FOR vids
          SERVER keys
          OPTIONS (user 'keys', password 'keys');
  </code></pre>
  <ol start="3">
  <li>Create the table mapping</li>
  </ol>
  <pre><code>create foreign table keys (
      id varchar not null,
      keyname varchar not null,
      created timestamp default current_timestamp not null,
      modified timestamp default current_timestamp not null
  ) server keys options (schema_name 'public', table_name 'keys');
  </code></pre>
  <ol start="4">
  <li>Try to access the foreign table when connected as <em>vids</em> in the <em>vids</em> db:</li>
  </ol>
  <pre><code>vids=&gt; select * from keys;
  ERROR:  permission denied for foreign table keys
  </code></pre>
  <p>I do not understand given that the user <em>keys</em> is the owner of the <em>keys</em> table in the foreign database. What should be done here?</p>