pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: wagner.engel@gmail.com
Subject: BUG #16202: Cannot restore database that has materialized view using crosstab (tablefunc)
Date: Fri, 10 Jan 2020 17:38:05 +0000
Message-ID: <16202-b6b345c9d2819409@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      16202
Logged by:          Wagner Engel
Email address:      wagner.engel@gmail.com
PostgreSQL version: 12.1
Operating system:   Debian 10
Description:        

If I build a materizalized view that uses the crosstab() function, a
dump/restore cycle will not restore the database.
A simple test case is:

create.sql:
--------------------------------
CREATE EXTENSION tablefunc;

CREATE TABLE t (
	id INTEGER
);

CREATE VIEW v AS
SELECT * FROM crosstab (
	'SELECT id FROM t as t1',
	'SELECT id FROM t as t2'
) ct (a integer, b integer);

CREATE MATERIALIZED VIEW mv AS
SELECT * FROM v;
--------------------------------

$ createdb -h localhost -U postgres abc
$ psql -h localhost -U postgres abc < create.sql
CREATE EXTENSION
CREATE TABLE
CREATE VIEW
SELECT 0
$ pg_dump --host localhost --username "postgres" --format plain --file
abc.sql abc
$ createdb -h localhost -U postgres abc2
$ psql -h localhost -U postgres abc2 < abc.sql
SET
SET
SET
SET
SET
 set_config 
------------
 
(1 row)

SET
SET
SET
SET
CREATE EXTENSION
COMMENT
CREATE VIEW
ALTER TABLE
SET
SET
CREATE MATERIALIZED VIEW
ALTER TABLE
CREATE TABLE
ALTER TABLE
COPY 0
ERROR:  relation "t" does not exist
LINE 1: SELECT id FROM t as t2
                       ^
QUERY:  SELECT id FROM t as t2



Using format custom and pg_restore also fails:

$ pg_dump --host localhost --username "postgres" --format custom --file
abc.backup abc
$ createdb -h localhost -U postgres abc3
$ pg_restore --host localhost --username "postgres" -d abc3 abc.backup 
pg_restore: while PROCESSING TOC:
pg_restore: from TOC entry 2901; 0 1094129 MATERIALIZED VIEW DATA mv
postgres
pg_restore: error: could not execute query: ERROR:  relation "t" does not
exist
LINE 1: SELECT id FROM t as t2
                       ^
QUERY:  SELECT id FROM t as t2
Command was: REFRESH MATERIALIZED VIEW public.mv;


pg_restore: warning: errors ignored on restore: 1



Extra:
Within the abc.sql dump, the CREATE TABLE command is after both create view
commands. Moving it before makes no difference.



Versions:
$ pg_dump -V
pg_dump (PostgreSQL) 12.1 (Debian 12.1-1.pgdg100+1)
$ pg_restore -V
pg_restore (PostgreSQL) 12.1 (Debian 12.1-1.pgdg100+1)
$ psql -V
psql (PostgreSQL) 12.1 (Debian 12.1-1.pgdg100+1)
$ psql -h localhost -U postgres abc -c "SELECT version();"
                                                     version                
                                     
------------------------------------------------------------------------------------------------------------------
 PostgreSQL 12.1 (Debian 12.1-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled
by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
(1 row)



view thread (3+ messages)  latest in thread

Message-ID: <16202-b6b345c9d2819409@postgresql.org>
Permalink:  ../16202-b6b345c9d2819409@postgresql.org/
Also on:    postgresql.org/message-id/16202-b6b345c9d2819409@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: noreply@postgresql.org, wagner.engel@gmail.com
  Subject: Re: BUG #16202: Cannot restore database that has materialized view using crosstab (tablefunc)
  In-Reply-To: <16202-b6b345c9d2819409@postgresql.org>
  References: <16202-b6b345c9d2819409@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