Re: odd behavior in materialized view

Lists: pgsql-hackers
From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: odd behavior in materialized view
Date: 2013-03-04 21:45:56
Message-ID: CAHGQGwHuee=mM419pmDz9_3F0rgJoiFmifv7Mt11GS3MnL94YQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

When I accessed the materialized view in the standby server,
I got the following ERROR message. Looks odd to me. Is this a bug?

ERROR: materialized view "hogeview" has not been populated
HINT: Use the REFRESH MATERIALIZED VIEW command.

The procedure to reproduce this error message is:

In the master server:
CREATE TABLE hoge (i int);
INSERT INTO hoge VALUES (generate_series(1,100));
CREATE MATERIALIZED VIEW hogeview AS SELECT * FROM hoge;
DELETE FROM hoge;
REFRESH MATERIALIZED VIEW hogeview;
SELECT count(*) FROM hogeview;

In the standby server
SELECT count(*) FROM hogeview;

SELECT count(*) goes well in the master, and expectedly returns 0.
OTOH, in the standby, it emits the error message.

Regards,

--
Fujii Masao


From: Kevin Grittner <kgrittn(at)ymail(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: odd behavior in materialized view
Date: 2013-03-04 22:36:23
Message-ID: 1362436583.60921.YahooMailNeo@web162902.mail.bf1.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:

> When I accessed the materialized view in the standby server,

> I got the following ERROR message. Looks odd to me. Is this a bug?
>
>    ERROR:  materialized view "hogeview" has not been populated
>    HINT:  Use the REFRESH MATERIALIZED VIEW command.
>
> The procedure to reproduce this error message is:
>
> In the master server:
>    CREATE TABLE hoge (i int);
>    INSERT INTO hoge VALUES (generate_series(1,100));
>    CREATE MATERIALIZED VIEW hogeview AS SELECT * FROM hoge;
>    DELETE FROM hoge;
>    REFRESH MATERIALIZED VIEW hogeview;
>    SELECT count(*) FROM hogeview;
>
> In the standby server
>    SELECT count(*) FROM hogeview;
>
> SELECT count(*) goes well in the master, and expectedly returns 0.
> OTOH, in the standby, it emits the error message.

Will investigate.

Thanks for testing!

--
Kevin Grittner
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Kevin Grittner <kgrittn(at)ymail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: odd behavior in materialized view
Date: 2013-03-05 13:12:46
Message-ID: CAHGQGwHsdtuD6vZNvE382R6eLxyhokCJ8_V1O6RcCeF5-=ge3A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Mar 5, 2013 at 7:36 AM, Kevin Grittner <kgrittn(at)ymail(dot)com> wrote:
> Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>
>> When I accessed the materialized view in the standby server,
>
>> I got the following ERROR message. Looks odd to me. Is this a bug?
>>
>> ERROR: materialized view "hogeview" has not been populated
>> HINT: Use the REFRESH MATERIALIZED VIEW command.
>>
>> The procedure to reproduce this error message is:
>>
>> In the master server:
>> CREATE TABLE hoge (i int);
>> INSERT INTO hoge VALUES (generate_series(1,100));
>> CREATE MATERIALIZED VIEW hogeview AS SELECT * FROM hoge;
>> DELETE FROM hoge;
>> REFRESH MATERIALIZED VIEW hogeview;
>> SELECT count(*) FROM hogeview;
>>
>> In the standby server
>> SELECT count(*) FROM hogeview;
>>
>> SELECT count(*) goes well in the master, and expectedly returns 0.
>> OTOH, in the standby, it emits the error message.
>
> Will investigate.

Thanks!

And I found another problem. When I ran the following SQLs in the master,
PANIC error occurred in the standby.

CREATE TABLE hoge (i int);
INSERT INTO hoge VALUES (generate_series(1,100));
CREATE MATERIALIZED VIEW hogeview AS SELECT * FROM hoge;
VACUUM ANALYZE;

The PANIC error messages that I got in the standby are

WARNING: page 0 of relation base/12297/16387 is uninitialized
CONTEXT: xlog redo visible: rel 1663/12297/16387; blk 0
PANIC: WAL contains references to invalid pages
CONTEXT: xlog redo visible: rel 1663/12297/16387; blk 0

base/12297/16387 is the file of the materialized view 'hogeview'.

Regards,

--
Fujii Masao


From: Kevin Grittner <kgrittn(at)ymail(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: odd behavior in materialized view
Date: 2013-03-05 14:06:01
Message-ID: 1362492361.40718.YahooMailNeo@web162904.mail.bf1.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:

> And I found another problem. When I ran the following SQLs in the
> master, PANIC error occurred in the standby.
>
>     CREATE TABLE hoge (i int);
>     INSERT INTO hoge VALUES (generate_series(1,100));
>     CREATE MATERIALIZED VIEW hogeview AS SELECT * FROM hoge;
>     VACUUM ANALYZE;
>
> The PANIC error messages that I got in the standby are
>
>     WARNING:  page 0 of relation base/12297/16387 is uninitialized
>     CONTEXT:  xlog redo visible: rel 1663/12297/16387; blk 0
>     PANIC:  WAL contains references to invalid pages
>     CONTEXT:  xlog redo visible: rel 1663/12297/16387; blk 0
>
> base/12297/16387 is the file of the materialized view 'hogeview'.

Yeah, that looks like it will be fixed by the fix for the first
problem.  The write of a first page without any rows to indicate
that it is a scannable empty relation must be WAL-logged.  I should
have something later today.

Thanks for spotting this.

--
Kevin Grittner
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Kevin Grittner <kgrittn(at)ymail(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: odd behavior in materialized view
Date: 2013-03-06 23:21:32
Message-ID: 1362612092.94072.YahooMailNeo@web162903.mail.bf1.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
> On Tue, Mar 5, 2013 at 7:36 AM, Kevin Grittner <kgrittn(at)ymail(dot)com> wrote:
>> Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>>
>>> When I accessed the materialized view in the standby server,
>>
>>> I got the following ERROR message. Looks odd to me. Is this a bug?
>>>
>>>     ERROR:  materialized view "hogeview" has not been populated
>>>     HINT:  Use the REFRESH MATERIALIZED VIEW command.
>>>
>>> The procedure to reproduce this error message is:
>>>
>>> In the master server:
>>>     CREATE TABLE hoge (i int);
>>>     INSERT INTO hoge VALUES (generate_series(1,100));
>>>     CREATE MATERIALIZED VIEW hogeview AS SELECT * FROM hoge;
>>>     DELETE FROM hoge;
>>>     REFRESH MATERIALIZED VIEW hogeview;
>>>     SELECT count(*) FROM hogeview;
>>>
>>> In the standby server
>>>     SELECT count(*) FROM hogeview;
>>>
>>> SELECT count(*) goes well in the master, and expectedly returns 0.
>>> OTOH, in the standby, it emits the error message.
>>
>> Will investigate.
>
> Thanks!
>
> And I found another problem. When I ran the following SQLs in the master,
> PANIC error occurred in the standby.
>
>     CREATE TABLE hoge (i int);
>     INSERT INTO hoge VALUES (generate_series(1,100));
>     CREATE MATERIALIZED VIEW hogeview AS SELECT * FROM hoge;
>     VACUUM ANALYZE;
>
> The PANIC error messages that I got in the standby are
>
>     WARNING:  page 0 of relation base/12297/16387 is uninitialized
>     CONTEXT:  xlog redo visible: rel 1663/12297/16387; blk 0
>     PANIC:  WAL contains references to invalid pages
>     CONTEXT:  xlog redo visible: rel 1663/12297/16387; blk 0
>
> base/12297/16387 is the file of the materialized view 'hogeview'.

I was able to replicate both bugs, and they both appear to be fixed
by the attached, which I have just pushed.

--
Kevin Grittner
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Attachment Content-Type Size
matview-WAL-log-extension.patch text/x-patch 1.1 KB

From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Kevin Grittner <kgrittn(at)ymail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: odd behavior in materialized view
Date: 2013-03-07 16:18:45
Message-ID: CAHGQGwESOme9HUmUq_jTYi8j++qP2HoZxyqXR=37zuU8tHEOkw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Mar 7, 2013 at 8:21 AM, Kevin Grittner <kgrittn(at)ymail(dot)com> wrote:
> Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>> On Tue, Mar 5, 2013 at 7:36 AM, Kevin Grittner <kgrittn(at)ymail(dot)com> wrote:
>>> Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>>>
>>>> When I accessed the materialized view in the standby server,
>>>
>>>> I got the following ERROR message. Looks odd to me. Is this a bug?
>>>>
>>>> ERROR: materialized view "hogeview" has not been populated
>>>> HINT: Use the REFRESH MATERIALIZED VIEW command.
>>>>
>>>> The procedure to reproduce this error message is:
>>>>
>>>> In the master server:
>>>> CREATE TABLE hoge (i int);
>>>> INSERT INTO hoge VALUES (generate_series(1,100));
>>>> CREATE MATERIALIZED VIEW hogeview AS SELECT * FROM hoge;
>>>> DELETE FROM hoge;
>>>> REFRESH MATERIALIZED VIEW hogeview;
>>>> SELECT count(*) FROM hogeview;
>>>>
>>>> In the standby server
>>>> SELECT count(*) FROM hogeview;
>>>>
>>>> SELECT count(*) goes well in the master, and expectedly returns 0.
>>>> OTOH, in the standby, it emits the error message.
>>>
>>> Will investigate.
>>
>> Thanks!
>>
>> And I found another problem. When I ran the following SQLs in the master,
>> PANIC error occurred in the standby.
>>
>> CREATE TABLE hoge (i int);
>> INSERT INTO hoge VALUES (generate_series(1,100));
>> CREATE MATERIALIZED VIEW hogeview AS SELECT * FROM hoge;
>> VACUUM ANALYZE;
>>
>> The PANIC error messages that I got in the standby are
>>
>> WARNING: page 0 of relation base/12297/16387 is uninitialized
>> CONTEXT: xlog redo visible: rel 1663/12297/16387; blk 0
>> PANIC: WAL contains references to invalid pages
>> CONTEXT: xlog redo visible: rel 1663/12297/16387; blk 0
>>
>> base/12297/16387 is the file of the materialized view 'hogeview'.
>
> I was able to replicate both bugs, and they both appear to be fixed
> by the attached, which I have just pushed.

Thanks! I confirmed that the problem that I reported has disappeared in HEAD.

Unfortunately I found another odd behavior. When I accessed the MV
after VACUUM ANALYZE, I got the following error.

ERROR: materialized view "hogeview" has not been populated
HINT: Use the REFRESH MATERIALIZED VIEW command.
STATEMENT: select * from hogeview where i < 10;

The test case to reproduce that is:

create table hoge (i int);
insert into hoge values (generate_series(1,100000));
create materialized view hogeview as select * from hoge where i % 2 = 0;
create index hogeviewidx on hogeview (i);
delete from hoge;
refresh materialized view hogeview;
select * from hogeview where i < 10;
vacuum analyze;
select * from hogeview where i < 10;

The last SELECT command caused the above error.

Regards,

--
Fujii Masao


From: Kevin Grittner <kgrittn(at)ymail(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: odd behavior in materialized view
Date: 2013-03-07 16:52:39
Message-ID: 1362675159.53476.YahooMailNeo@web162906.mail.bf1.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:

> Thanks! I confirmed that the problem that I reported has
> disappeared in HEAD.
>
> Unfortunately I found another odd behavior. When I accessed the
> MV after VACUUM ANALYZE, I got the following error.
>
>     ERROR:  materialized view "hogeview" has not been populated
>     HINT:  Use the REFRESH MATERIALIZED VIEW command.
>     STATEMENT:  select * from hogeview where i < 10;
>
> The test case to reproduce that is:
>
> create table hoge (i int);
> insert into hoge values (generate_series(1,100000));
> create materialized view hogeview as select * from hoge where i % 2 = 0;
> create index hogeviewidx on hogeview (i);
> delete from hoge;
> refresh materialized view hogeview;
> select * from hogeview where i < 10;
> vacuum analyze;
> select * from hogeview where i < 10;
>
> The last SELECT command caused the above error.

Thanks.  Will fix.

--
Kevin Grittner
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Kevin Grittner <kgrittn(at)ymail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: odd behavior in materialized view
Date: 2013-03-07 17:28:51
Message-ID: CAHGQGwHQuio9H3jhMGn01NujWor+PgLh9=3Z3K-qoqgKQGrU_Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Mar 8, 2013 at 1:52 AM, Kevin Grittner <kgrittn(at)ymail(dot)com> wrote:
> Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>
>> Thanks! I confirmed that the problem that I reported has
>> disappeared in HEAD.
>>
>> Unfortunately I found another odd behavior. When I accessed the
>> MV after VACUUM ANALYZE, I got the following error.
>>
>> ERROR: materialized view "hogeview" has not been populated
>> HINT: Use the REFRESH MATERIALIZED VIEW command.
>> STATEMENT: select * from hogeview where i < 10;
>>
>> The test case to reproduce that is:
>>
>> create table hoge (i int);
>> insert into hoge values (generate_series(1,100000));
>> create materialized view hogeview as select * from hoge where i % 2 = 0;
>> create index hogeviewidx on hogeview (i);
>> delete from hoge;
>> refresh materialized view hogeview;
>> select * from hogeview where i < 10;
>> vacuum analyze;
>> select * from hogeview where i < 10;
>>
>> The last SELECT command caused the above error.
>
> Thanks. Will fix.

Thanks!

I found one typo in the document of MV. Please see the attached patch.

Regards,

--
Fujii Masao

Attachment Content-Type Size
typo.patch application/octet-stream 520 bytes

From: Kevin Grittner <kgrittn(at)ymail(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: odd behavior in materialized view
Date: 2013-03-07 17:42:48
Message-ID: 1362678168.94839.YahooMailNeo@web162903.mail.bf1.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:

> I found one typo in the document of MV. Please see the attached
> patch.

Pushed.  Thanks!

--
Kevin Grittner
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Kevin Grittner <kgrittn(at)ymail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: odd behavior in materialized view
Date: 2013-03-10 07:37:44
Message-ID: CAHGQGwH+4vtyq==L6HRuPxTggfqrnLf0mWj75BfisOske28gMA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Mar 8, 2013 at 2:42 AM, Kevin Grittner <kgrittn(at)ymail(dot)com> wrote:
> Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>
>> I found one typo in the document of MV. Please see the attached
>> patch.
>
> Pushed. Thanks!

Thanks!

I found that pg_dump always fails against 9.2 or before server because
of the MV patch.

$ pg_dump
pg_dump: [archiver (db)] query failed: pg_dump: [archiver (db)] query was:

Attached patch fixes this problem.

Regards,

--
Fujii Masao

Attachment Content-Type Size
pg_dump_bugfix_matview.patch application/octet-stream 2.9 KB

From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Kevin Grittner <kgrittn(at)ymail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: odd behavior in materialized view
Date: 2013-03-25 17:28:53
Message-ID: CAHGQGwF7ChAY1zWLXGyKiYmXp-Pwk_FA5U1Cg_0pXQnyUXMpcQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Mar 8, 2013 at 1:52 AM, Kevin Grittner <kgrittn(at)ymail(dot)com> wrote:
> Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>
>> Thanks! I confirmed that the problem that I reported has
>> disappeared in HEAD.
>>
>> Unfortunately I found another odd behavior. When I accessed the
>> MV after VACUUM ANALYZE, I got the following error.
>>
>> ERROR: materialized view "hogeview" has not been populated
>> HINT: Use the REFRESH MATERIALIZED VIEW command.
>> STATEMENT: select * from hogeview where i < 10;
>>
>> The test case to reproduce that is:
>>
>> create table hoge (i int);
>> insert into hoge values (generate_series(1,100000));
>> create materialized view hogeview as select * from hoge where i % 2 = 0;
>> create index hogeviewidx on hogeview (i);
>> delete from hoge;
>> refresh materialized view hogeview;
>> select * from hogeview where i < 10;
>> vacuum analyze;
>> select * from hogeview where i < 10;
>>
>> The last SELECT command caused the above error.
>
> Thanks. Will fix.

Ping? ISTM this problem has not been fixed in HEAD yet.

Regards,

--
Fujii Masao


From: Kevin Grittner <kgrittn(at)ymail(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: odd behavior in materialized view
Date: 2013-03-26 15:26:04
Message-ID: 1364311564.21763.YahooMailNeo@web162901.mail.bf1.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:

> Ping? ISTM this problem has not been fixed in HEAD yet.

It's next on my list.  The other reports seemed more serious and
more likely to be contentious in terms of the best fix.

--
Kevin Grittner
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company