pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: lalbin@scharp.org
To: pgsql-bugs@postgresql.org
Subject: BUG #14147: Restore of MatView of Foreign Data Table fails
Date: Wed, 18 May 2016 16:07:57 +0000
Message-ID: <20160518160757.16249.48982@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

The following bug has been logged on the website:

Bug reference:      14147
Logged by:          Lloyd Albin
Email address:      lalbin@scharp.org
PostgreSQL version: 9.5.3
Operating system:   SUSE Linux (64-bit)
Description:        

I have found that restoration of Materialized Views of Foreign Data Tables
where user postgres does not have a user mapping will fail. It seems that it
is trying to execute the Foreign Data Table in some way instead of reading
the Foreign Table Definition.

The only workaround that I have found is to create a user mapping for user
postgres for every foreign data connection. 

Example:

CREATE DATABASE db_a
  WITH ENCODING = 'UTF8'
    TEMPLATE = template1;

CREATE ROLE joe LOGIN PASSWORD 'xxx';

SET ROLE joe;
	
CREATE TABLE public.test (
  id SERIAL,
  v TEXT,
  PRIMARY KEY(id)
) 
WITH (oids = false);

SET ROLE postgres;
	
CREATE DATABASE db_b
  WITH ENCODING = 'UTF8'
    TEMPLATE = template1;	

CREATE EXTENSION postgres_fdw;

GRANT USAGE
  ON FOREIGN DATA WRAPPER postgres_fdw TO joe;

CREATE SERVER db_a
  FOREIGN DATA WRAPPER postgres_fdw
  OPTIONS (
    host 'localhost',
    port '5432',
    dbname 'db_a');

CREATE USER MAPPING FOR joe
  SERVER db_a
  OPTIONS (
    user 'joe',
    password 'xxx');

CREATE FOREIGN TABLE public."test" (
  id INTEGER NOT NULL,
  v TEXT
) 
SERVER db_a
OPTIONS (
  schema_name 'public',
  table_name 'test');

CREATE MATERIALIZED VIEW public.mv_test AS SELECT * FROM public.test;
  
CREATE DATABASE db_c
  WITH ENCODING = 'UTF8'
    TEMPLATE = template1;

pg_dump -h localhost -U postgres -Fc db_b > db_b.pgdump

pg_restore -h localhost -U postgres -d db_c db_b.pgdump	

pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 183; 1259 16430
MATERIALIZED VI
EW mv_test joe
pg_restore: [archiver (db)] could not execute query: ERROR:  user mapping
not fo
und for "postgres"
    Command was: CREATE MATERIALIZED VIEW mv_test AS
 SELECT test.id,
    test.v
   FROM test
  WITH NO DATA;



pg_restore: [archiver (db)] could not execute query: ERROR:  relation
"mv_test"
does not exist
    Command was: ALTER TABLE mv_test OWNER TO joe;


pg_restore: [archiver (db)] Error from TOC entry 2104; 0 16430 MATERIALIZED
VIEW
 DATA mv_test joe
pg_restore: [archiver (db)] could not execute query: ERROR:  relation
"mv_test"
does not exist
    Command was: REFRESH MATERIALIZED VIEW mv_test;



WARNING: errors ignored on restore: 3



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs


view thread (3+ messages)  latest in thread

Message-ID: <20160518160757.16249.48982@wrigleys.postgresql.org>
Permalink:  ../20160518160757.16249.48982@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20160518160757.16249.48982@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: lalbin@scharp.org
  Subject: Re: BUG #14147: Restore of MatView of Foreign Data Table fails
  In-Reply-To: <20160518160757.16249.48982@wrigleys.postgresql.org>
  References: <20160518160757.16249.48982@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox