pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
26+ messages / 6 participants
[nested] [flat]

Commits from this thread:
  2018-08-10 9353d94a9b 4974d7f87e  Handle parallel index builds on mapped relations.
* BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-03 11:45  PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 2 replies; 26+ messages in thread

From: PG Bug reporting form @ 2018-08-03 11:45 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: deathlock13@gmail.com

The following bug has been logged on the website:

Bug reference:      15309
Logged by:          death lock
Email address:      deathlock13@gmail.com
PostgreSQL version: 11beta2
Operating system:   Debian10 64b
Description:        

11beta2 and git REL_11_STABLE, gcc 8.2, pg.conf : autovacuum=off
DB restored from plain-format backup, first 'vacuum full' ends with ERR :
"catalog is missing 1 attribute(s) for relid ..." - seem to point to only
PrimaryKey, sometimes the same PK



^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-03 13:53  Tom Lane <tgl@sss.pgh.pa.us>
  parent: PG Bug reporting form <noreply@postgresql.org>
  1 sibling, 2 replies; 26+ messages in thread

From: Tom Lane @ 2018-08-03 13:53 UTC (permalink / raw)
  To: deathlock13@gmail.com; +Cc: pgsql-bugs@lists.postgresql.org

=?utf-8?q?PG_Bug_reporting_form?= <noreply@postgresql.org> writes:
> 11beta2 and git REL_11_STABLE, gcc 8.2, pg.conf : autovacuum=off
> DB restored from plain-format backup, first 'vacuum full' ends with ERR :
> "catalog is missing 1 attribute(s) for relid ..." - seem to point to only
> PrimaryKey, sometimes the same PK

If you could provide a self-contained example, this would be very
interesting, but there's nothing we can do with just the information
you've provided here.

Perhaps you can strip and/or anonymize your backup dump file down
to a postable example that reproduces this problem?

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-03 16:51  Peter Geoghegan <pg@bowt.ie>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 26+ messages in thread

From: Peter Geoghegan @ 2018-08-03 16:51 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: deathlock13@gmail.com, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

On Fri, Aug 3, 2018 at 6:53 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Perhaps you can strip and/or anonymize your backup dump file down
> to a postable example that reproduces this problem?

It would also be interesting to see the result of this query, which
relies on the v11 amcheck extension (so "CREATE EXTENSION amcheck"
first):

SELECT bt_index_parent_check(index => c.oid, heapallindexed => true),
               c.relname,
               c.relpages
FROM pg_index i
JOIN pg_opclass op ON i.indclass[0] = op.oid
JOIN pg_am am ON op.opcmethod = am.oid
JOIN pg_class c ON i.indexrelid = c.oid
JOIN pg_namespace n ON c.relnamespace = n.oid
WHERE am.amname = 'btree' AND n.nspname = 'pg_catalog'
-- Don't check temp tables, which may be from another session:
AND c.relpersistence != 't'
-- Function may throw an error when this is omitted:
AND c.relkind = 'i' AND i.indisready AND i.indisvalid
ORDER BY c.relpages DESC;

If that doesn't raise an error, you could try the same query, but
remove "AND n.nspname = 'pg_catalog'". That will take considerably
longer, but probably won't be intolerable.

Thanks
-- 
Peter Geoghegan




^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-03 17:11  Andres Freund <andres@anarazel.de>
  parent: Peter Geoghegan <pg@bowt.ie>
  0 siblings, 1 reply; 26+ messages in thread

From: Andres Freund @ 2018-08-03 17:11 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org,Peter Geoghegan <pg@bowt.ie>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: deathlock13@gmail.com,PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>



On August 3, 2018 9:51:01 AM PDT, Peter Geoghegan <pg@bowt.ie> wrote:
>On Fri, Aug 3, 2018 at 6:53 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Perhaps you can strip and/or anonymize your backup dump file down
>> to a postable example that reproduces this problem?
>
>It would also be interesting to see the result of this query, which
>relies on the v11 amcheck extension (so "CREATE EXTENSION amcheck"
>first):

Maybe I'm missing something, but doesn't that error likely point to a bug in the new parallel index creation code, rather than the created indexes?

Andres
-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.




^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-03 17:29  Peter Geoghegan <pg@bowt.ie>
  parent: Andres Freund <andres@anarazel.de>
  0 siblings, 1 reply; 26+ messages in thread

From: Peter Geoghegan @ 2018-08-03 17:29 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>; Tom Lane <tgl@sss.pgh.pa.us>; deathlock13@gmail.com

On Fri, Aug 3, 2018 at 10:11 AM, Andres Freund <andres@anarazel.de> wrote:
> Maybe I'm missing something, but doesn't that error likely point to a bug in the new parallel index creation code, rather than the created indexes?

I've certainly seen error messages like that with cases of
catalog corruption. I recall repairing pg_attribute by hand when this
happened, and then having to reindex the system catalogs.

I don't really know what's wrong here, but I wouldn't be surprised if
amcheck detected a problem. Let's see.

-- 
Peter Geoghegan




^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-03 17:58  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Peter Geoghegan <pg@bowt.ie>
  0 siblings, 1 reply; 26+ messages in thread

From: Tom Lane @ 2018-08-03 17:58 UTC (permalink / raw)
  To: Peter Geoghegan <pg@bowt.ie>; +Cc: Andres Freund <andres@anarazel.de>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>; deathlock13@gmail.com

Peter Geoghegan <pg@bowt.ie> writes:
> On Fri, Aug 3, 2018 at 10:11 AM, Andres Freund <andres@anarazel.de> wrote:
>> Maybe I'm missing something, but doesn't that error likely point to a bug in the new parallel index creation code, rather than the created indexes?

> I've certainly seen error messages like that with cases of
> catalog corruption. I recall repairing pg_attribute by hand when this
> happened, and then having to reindex the system catalogs.

> I don't really know what's wrong here, but I wouldn't be surprised if
> amcheck detected a problem. Let's see.

I think the OP's time would be more usefully spent on creating a
submittable test case.  We will want that whether or not amcheck
complains, because the mere fact of the complaint is not likely to be
enough to find the problem.  (I do agree that this smells like a problem
in parallel index build.)

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-03 18:03  Peter Geoghegan <pg@bowt.ie>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 26+ messages in thread

From: Peter Geoghegan @ 2018-08-03 18:03 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Andres Freund <andres@anarazel.de>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>; deathlock13@gmail.com

On Fri, Aug 3, 2018 at 10:58 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> I think the OP's time would be more usefully spent on creating a
> submittable test case.  We will want that whether or not amcheck
> complains, because the mere fact of the complaint is not likely to be
> enough to find the problem.  (I do agree that this smells like a problem
> in parallel index build.)

A test case would be ideal, but it's unlikely to take very long to run
amcheck. If verification is limited to the system catalogs, then it
will probably take just a few seconds.

-- 
Peter Geoghegan




^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-06 17:43  Peter Geoghegan <pg@bowt.ie>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 26+ messages in thread

From: Peter Geoghegan @ 2018-08-06 17:43 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: deathlock13@gmail.com, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

On Fri, Aug 3, 2018 at 6:53 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> =?utf-8?q?PG_Bug_reporting_form?= <noreply@postgresql.org> writes:
>> 11beta2 and git REL_11_STABLE, gcc 8.2, pg.conf : autovacuum=off
>> DB restored from plain-format backup, first 'vacuum full' ends with ERR :
>> "catalog is missing 1 attribute(s) for relid ..." - seem to point to only
>> PrimaryKey, sometimes the same PK
>
> If you could provide a self-contained example, this would be very
> interesting, but there's nothing we can do with just the information
> you've provided here.

I got an off-list testcase from the OP, who writes:

"""
I've attached my 'SHOW ALL' and a backup of example db from PG wiki,
just kept renaming schema/tables until got a large enough number of
indexes - seem to be key to reproducing error(s).

2018-08-06 11:31:44 CEST|TEST|postgres|[local]| ERROR:  duplicate key
value violates unique constraint "pg_class_relname_nsp_index"
2018-08-06 11:31:44 CEST|TEST|postgres|[local]| DETAIL:  Key (relname,
relnamespace)=(pg_class_tblspc_relfilenode_index, 11) already exists.
2018-08-06 11:31:44 CEST|TEST|postgres|[local]| STATEMENT:  vacuum
full analyze ;

or 2018-08-06 11:20:13 CEST|PUMA|postgres|[local]| DETAIL:  Key
(relname, relnamespace)=(idx_last_name, 16498) already exists.

Got this after runing your query with amcheck  before 'VACUUM FULL'
2018-08-06 11:51:10 CEST|||| PANIC:  could not open critical system index 2676
2018-08-06 11:51:10 CEST|TEST|postgres|[local]| ERROR:  could not open
critical system index 2676
2018-08-06 11:51:10 CEST|TEST|postgres|[local]| CONTEXT:  parallel worker
2018-08-06 11:51:10 CEST|TEST|postgres|[local]| STATEMENT:  vacuum full;
2018-08-06 11:51:10 CEST|||| LOG:  background worker "parallel worker"
(PID 16618) was terminated by signal 6: Aborted
2018-08-06 11:51:10 CEST|||| LOG:  terminating any other active server processes

2018-08-06 12:11:24 CEST|||| ERROR:  could not open relation with OID 2696
2018-08-06 12:11:24 CEST|TEST|postgres|[local]| ERROR:  could not open
relation with OID 2696
2018-08-06 12:11:24 CEST|TEST|postgres|[local]| CONTEXT:  parallel worker
2018-08-06 12:11:24 CEST|TEST|postgres|[local]| STATEMENT:  vacuum full;
2018-08-06 12:11:24 CEST|||| LOG:  background worker "parallel worker"
(PID 16930) exited with exit code 1
"""

I can reproduce this with the backup provided. This seems to boil down
to the following:

1. Create a database with tens of thousands of relations, each of
which contain no data.

2. Run an unqualified VACUUM FULL.

This is what I see after the restore:

pg@foodb[22648]=# vacuum FULL ;
ERROR:  duplicate key value violates unique constraint
"pg_class_relname_nsp_index"
DETAIL:  Key (relname, relnamespace)=(customer_pkey, 16445) already exists.
pg@foodb[22648]=# :amcheck
ERROR:  heap tuple (358,1) from table "pg_attribute" lacks matching
index tuple within index "pg_attribute_relid_attnam_index"

I'll work to isolate and diagnose the problem today. It likely has
something to do with corrupting the state needed by a catalog parallel
index build in the context of the VACUUM FULL. pg_attribute grows to
several tens of megabytes here, which is enough to get a parallel
index build.

-- 
Peter Geoghegan




^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-06 20:31  Peter Geoghegan <pg@bowt.ie>
  parent: Peter Geoghegan <pg@bowt.ie>
  0 siblings, 1 reply; 26+ messages in thread

From: Peter Geoghegan @ 2018-08-06 20:31 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: deathlock13@gmail.com, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

On Mon, Aug 6, 2018 at 10:43 AM, Peter Geoghegan <pg@bowt.ie> wrote:
> I'll work to isolate and diagnose the problem today. It likely has
> something to do with corrupting the state needed by a catalog parallel
> index build in the context of the VACUUM FULL. pg_attribute grows to
> several tens of megabytes here, which is enough to get a parallel
> index build.

This repro can be further simplified, by just doing a VACUUM FULL on
pg_attribute alone. There is no index corruption prior to that point.
After that point, there is -- both pg_attribute_relid_attnam_index and
pg_attribute_relid_attnum_index seem to become corrupt. All other
symptoms probably stem from this initial corruption, so I'm focusing
on it.

What I see if I look at the corrupt pg_attribute_relid_attnum_index
structure is that the index does actually have an entry for a heap
tuple that amcheck complains about lacking an entry for -- at least,
it has a key match. The problem that amcheck noticed was that the heap
item pointer was not as it should be (i.e. the index tuple points to
the wrong heap tuple). I also noticed that nearby index tuples had
duplicate entries, the first pointing to approximately the same place
in the heap that the corrupt-to-amcheck tuple points to, and the
second pointing to approximately the same place in the heap that
amcheck expected to find it at (amcheck was complaining about an
adjacent entry, so it's only approximately the same place in the
heap).

I suspect that the problem is that parallel workers have a different
idea about which relfilenode they need to scan, or something along
those lines. Maybe cluster_rel() needs to be taught about parallel
CREATE INDEX. I must have missed some detail within cluster.c prior to
parallel CREATE INDEX going in.

-- 
Peter Geoghegan




^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-06 20:37  Peter Geoghegan <pg@bowt.ie>
  parent: Peter Geoghegan <pg@bowt.ie>
  0 siblings, 1 reply; 26+ messages in thread

From: Peter Geoghegan @ 2018-08-06 20:37 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: deathlock13@gmail.com, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

On Mon, Aug 6, 2018 at 1:31 PM, Peter Geoghegan <pg@bowt.ie> wrote:
> I suspect that the problem is that parallel workers have a different
> idea about which relfilenode they need to scan, or something along
> those lines. Maybe cluster_rel() needs to be taught about parallel
> CREATE INDEX. I must have missed some detail within cluster.c prior to
> parallel CREATE INDEX going in.

To be clear, I mean that the leader process's worker state has the
right relfilenode (the leader process always participates as a
worker), but all worker processes have the stale relfilenode.

-- 
Peter Geoghegan




^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-06 21:21  Peter Geoghegan <pg@bowt.ie>
  parent: Peter Geoghegan <pg@bowt.ie>
  0 siblings, 2 replies; 26+ messages in thread

From: Peter Geoghegan @ 2018-08-06 21:21 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: deathlock13@gmail.com, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

On Mon, Aug 6, 2018 at 1:37 PM, Peter Geoghegan <pg@bowt.ie> wrote:
> To be clear, I mean that the leader process's worker state has the
> right relfilenode (the leader process always participates as a
> worker), but all worker processes have the stale relfilenode.

Sure enough, that's what the bug is - a few debugging calls to
RelationMapFilenodeToOid() within nbtsort.c proves it. Several
approaches to fixing the bug occur to me:

* Ban parallel CREATE INDEX for all catalogs. This was how things were
up until several weeks before the original patch was committed.

* Ban parallel CREATE INDEX for mapped catalogs only.

* Find a way to propagate the state necessary to have parallel workers
agree with the leader on the correct relfilenode.

We could probably propagate backend-local state like
active_local_updates without too much difficulty, which looks like it
would fix the problem. Note that we did something very similar with
reindex-pending-indexes lists in commit 29d58fd3. That commit
similarly involved propagating more backend-local state so that
parallel index builds (or at least REINDEX) on catalogs could be
enabled/work reliably. Maybe we should continue down the road of
making parallel builds work on catalogs, on general principle.

Thoughts?

-- 
Peter Geoghegan




^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-06 21:29  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Peter Geoghegan <pg@bowt.ie>
  1 sibling, 1 reply; 26+ messages in thread

From: Tom Lane @ 2018-08-06 21:29 UTC (permalink / raw)
  To: Peter Geoghegan <pg@bowt.ie>; +Cc: deathlock13@gmail.com, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

Peter Geoghegan <pg@bowt.ie> writes:
> Sure enough, that's what the bug is - a few debugging calls to
> RelationMapFilenodeToOid() within nbtsort.c proves it. Several
> approaches to fixing the bug occur to me:

> * Ban parallel CREATE INDEX for all catalogs. This was how things were
> up until several weeks before the original patch was committed.

> * Ban parallel CREATE INDEX for mapped catalogs only.

> * Find a way to propagate the state necessary to have parallel workers
> agree with the leader on the correct relfilenode.

> We could probably propagate backend-local state like
> active_local_updates without too much difficulty, which looks like it
> would fix the problem. Note that we did something very similar with
> reindex-pending-indexes lists in commit 29d58fd3. That commit
> similarly involved propagating more backend-local state so that
> parallel index builds (or at least REINDEX) on catalogs could be
> enabled/work reliably. Maybe we should continue down the road of
> making parallel builds work on catalogs, on general principle.

Hm.  Post-beta3, I think I'd vote for a conservative fix in v11,
which seems to be "ban for mapped catalogs".  Feel free to make
it work in HEAD, though.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-06 22:06  Peter Geoghegan <pg@bowt.ie>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 26+ messages in thread

From: Peter Geoghegan @ 2018-08-06 22:06 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: deathlock13@gmail.com, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>; Robert Haas <robertmhaas@gmail.com>

On Mon, Aug 6, 2018 at 2:29 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Hm.  Post-beta3, I think I'd vote for a conservative fix in v11,
> which seems to be "ban for mapped catalogs".  Feel free to make
> it work in HEAD, though.

Makes sense. I'm not sure if it's worth pursuing parallel mapped
catalog index builds much further, though. I doubt that ordinary users
care about whether or not this is supported, so this is a matter of
principle. I don't feel strongly on whether or not I should make
mapped builds work on HEAD, so I defer to you, and anyone else that
might have an interest. Does it matter, do you think?

It might be worth teaching heap_beginscan_parallel() to
cross-check each worker's heap relation's rd_smgr.smgr_node to a version
of the same field from the leader, stored in shared memory (in the
ParallelHeapScanDesc). That way, any future recurrence of a similar
bug will be far easier to detect. A "can't happen" error along these
lines seems like it would be worthwhile.

-- 
Peter Geoghegan




^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-06 22:10  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: Peter Geoghegan <pg@bowt.ie>
  1 sibling, 2 replies; 26+ messages in thread

From: Alvaro Herrera @ 2018-08-06 22:10 UTC (permalink / raw)
  To: Peter Geoghegan <pg@bowt.ie>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; deathlock13@gmail.com, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

On 2018-Aug-06, Peter Geoghegan wrote:

> On Mon, Aug 6, 2018 at 1:37 PM, Peter Geoghegan <pg@bowt.ie> wrote:
> > To be clear, I mean that the leader process's worker state has the
> > right relfilenode (the leader process always participates as a
> > worker), but all worker processes have the stale relfilenode.
> 
> Sure enough, that's what the bug is - a few debugging calls to
> RelationMapFilenodeToOid() within nbtsort.c proves it.

Uh, that's weird, isn't it?  I mean, why is the relfilenode changing
underneath?  Why isn't it blocked by the CREATE INDEX?  Or is CREATE
INDEX inflicting that upon itself?

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services




^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-06 22:14  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  1 sibling, 0 replies; 26+ messages in thread

From: Tom Lane @ 2018-08-06 22:14 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Peter Geoghegan <pg@bowt.ie>; deathlock13@gmail.com, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

Alvaro Herrera <alvherre@2ndquadrant.com> writes:
> On 2018-Aug-06, Peter Geoghegan wrote:
>> Sure enough, that's what the bug is - a few debugging calls to
>> RelationMapFilenodeToOid() within nbtsort.c proves it.

> Uh, that's weird, isn't it?  I mean, why is the relfilenode changing
> underneath?

Because we're building a brand new index in a new file.

> Why isn't it blocked by the CREATE INDEX?  Or is CREATE
> INDEX inflicting that upon itself?

The problem is (or so I assume) failure to propagate process-local
state of relmapper.c into the worker processes.  So the leader knows
that we've assigned a new relfilenode to some mapped index, but the
workers don't.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-06 22:16  Peter Geoghegan <pg@bowt.ie>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  1 sibling, 0 replies; 26+ messages in thread

From: Peter Geoghegan @ 2018-08-06 22:16 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; deathlock13@gmail.com, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

On Mon, Aug 6, 2018 at 3:10 PM, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:
> Uh, that's weird, isn't it?  I mean, why is the relfilenode changing
> underneath?  Why isn't it blocked by the CREATE INDEX?  Or is CREATE
> INDEX inflicting that upon itself?

CREATE INDEX/nbtsort.c does not take any special interest in
relfilenode, or anything like that.

As Tom said, this is a failure to propagate the process-local state of
relmapper.c into the worker processes. Or a failure to account for the
fact that that doesn't happen, perhaps.

-- 
Peter Geoghegan




^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-06 22:18  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Peter Geoghegan <pg@bowt.ie>
  0 siblings, 1 reply; 26+ messages in thread

From: Tom Lane @ 2018-08-06 22:18 UTC (permalink / raw)
  To: Peter Geoghegan <pg@bowt.ie>; +Cc: deathlock13@gmail.com, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>; Robert Haas <robertmhaas@gmail.com>

Peter Geoghegan <pg@bowt.ie> writes:
> On Mon, Aug 6, 2018 at 2:29 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Hm.  Post-beta3, I think I'd vote for a conservative fix in v11,
>> which seems to be "ban for mapped catalogs".  Feel free to make
>> it work in HEAD, though.

> Makes sense. I'm not sure if it's worth pursuing parallel mapped
> catalog index builds much further, though. I doubt that ordinary users
> care about whether or not this is supported, so this is a matter of
> principle. I don't feel strongly on whether or not I should make
> mapped builds work on HEAD, so I defer to you, and anyone else that
> might have an interest. Does it matter, do you think?

Apparently there are people out there with catalogs big enough
to justify parallel reindex.  I don't mind if the first version of
the feature doesn't handle that, but probably we should make it work
eventually.

> It might be worth teaching heap_beginscan_parallel() to
> cross-check each worker's heap relation's rd_smgr.smgr_node to a version
> of the same field from the leader, stored in shared memory (in the
> ParallelHeapScanDesc). That way, any future recurrence of a similar
> bug will be far easier to detect. A "can't happen" error along these
> lines seems like it would be worthwhile.

Well, maybe, but why is that field particularly vulnerable?  I'd think you
should crosscheck the index's relfilenode too, at least, if you're going
to worry about that.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-06 22:21  Peter Geoghegan <pg@bowt.ie>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 26+ messages in thread

From: Peter Geoghegan @ 2018-08-06 22:21 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: deathlock13@gmail.com, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>; Robert Haas <robertmhaas@gmail.com>

On Mon, Aug 6, 2018 at 3:18 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Apparently there are people out there with catalogs big enough
> to justify parallel reindex.  I don't mind if the first version of
> the feature doesn't handle that, but probably we should make it work
> eventually.

Okay. I'll pursue this in HEAD.

> Well, maybe, but why is that field particularly vulnerable?  I'd think you
> should crosscheck the index's relfilenode too, at least, if you're going
> to worry about that.

I agree.

I'd like to hear more opinions on the general idea. I'm particularly
interested in what Robert thinks.

-- 
Peter Geoghegan




^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-07 02:32  Peter Geoghegan <pg@bowt.ie>
  parent: Peter Geoghegan <pg@bowt.ie>
  0 siblings, 1 reply; 26+ messages in thread

From: Peter Geoghegan @ 2018-08-07 02:32 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: deathlock13@gmail.com, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>; Robert Haas <robertmhaas@gmail.com>

On Mon, Aug 6, 2018 at 3:21 PM, Peter Geoghegan <pg@bowt.ie> wrote:
> On Mon, Aug 6, 2018 at 3:18 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Apparently there are people out there with catalogs big enough
>> to justify parallel reindex.  I don't mind if the first version of
>> the feature doesn't handle that, but probably we should make it work
>> eventually.
>
> Okay. I'll pursue this in HEAD.

I wrote this in a little over an hour, and it works fine. I'll post it
shortly, once I polish it up some more. I'll also post an alternative
"no mapped relation parallel builds" fix for v11, which will be
trivial.

>> Well, maybe, but why is that field particularly vulnerable?  I'd think you
>> should crosscheck the index's relfilenode too, at least, if you're going
>> to worry about that.
>
> I agree.
>
> I'd like to hear more opinions on the general idea. I'm particularly
> interested in what Robert thinks.

On second thought, the crosscheck of the index's relfilenode seems
like independent work. I won't be working on it as part of the fix for
this bug.

The question of index relfilenode becoming stale or inconsistent
doesn't come up with parallel CREATE INDEX, since currently the
workers never write to the new index relfilenode. If we were going to
do a similar crosscheck for parallel index scan, the new code would be
need to be spread across places like btbeginscan(), and
RelationGetIndexScan(). It's not something that can just be done in
passing.

-- 
Peter Geoghegan




^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-08 01:06  Peter Geoghegan <pg@bowt.ie>
  parent: Peter Geoghegan <pg@bowt.ie>
  0 siblings, 2 replies; 26+ messages in thread

From: Peter Geoghegan @ 2018-08-08 01:06 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: deathlock13@gmail.com, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>; Robert Haas <robertmhaas@gmail.com>

On Mon, Aug 6, 2018 at 7:32 PM, Peter Geoghegan <pg@bowt.ie> wrote:
> I wrote this in a little over an hour, and it works fine. I'll post it
> shortly, once I polish it up some more. I'll also post an alternative
> "no mapped relation parallel builds" fix for v11, which will be
> trivial.

Attached are two patches that each fix the issue -- a conservative
patch for v11, as well as a patch that actually propagates relmapper.c
state, for the master branch. It would be good to get a +1 on both
before pushing.

I'll pursue the parallel heap scan relfilenode cross-check thing
separately. Would still like to hear something from Robert on that
before proceeding.

-- 
Peter Geoghegan

Attachments: download all (2 files, .tar.gz)

REL_11_STABLE.patch (application/octet-stream, 2.5K) download From 25fa716a81eac0c922c224c225eb4f8fd687a9e4 Mon Sep 17 00:00:00 2001 From: Peter Geoghegan <pg@bowt.ie> Date: Tue, 7 Aug 2018 15:48:48 -0700 Subject: [PATCH 2/3] Handle parallel index builds on mapped relations. Commit 9da0cc35284, which introduced parallel CREATE INDEX, failed to propagate relmapper.c backend local cache state to parallel worker processes. This could result in parallel index builds against mapped catalog relations where the leader process (participating as a worker) scans the new, pristine relfilenode, while worker processes scan the obsolescent relfilenode. When this happened, the final index structure was typically not consistent with the owning table's structure. The final index structure could contain entries formed from both heap relfilenodes. Only rebuilds on mapped catalog relations that occur as part of a VACUUM FULL or CLUSTER could become corrupt in practice, since their mapped relation relfilenode swap is what allows the inconsistency to arise. On master, fix the problem by propagating the required relmapper.c backend state as part of standard parallel initialization (Cf. commit 29d58fd3). On v11, simply disallow builds against mapped catalog relations by treating it as a parallel safety issue. Reported-By: "death lock" Bug: #15309 Discussion: https://postgr.es/m/153329671686.1405.18298309097348420351@wrigleys.postgresql.org Backpatch: 11-, where parallel CREATE INDEX was introduced. --- src/backend/optimizer/plan/planner.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index fd06da98b9..9157442e7b 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -6091,11 +6091,13 @@ plan_create_index_workers(Oid tableOid, Oid indexOid) /* * Determine if it's safe to proceed. * - * Currently, parallel workers can't access the leader's temporary tables. - * Furthermore, any index predicate or index expressions must be parallel - * safe. + * Currently, parallel workers can't access the leader's temporary tables, + * or the leader's relmapper.c state, which is needed for builds on mapped + * relations. Furthermore, any index predicate or index expressions must + * be parallel safe. */ if (heap->rd_rel->relpersistence == RELPERSISTENCE_TEMP || + RelationIsMapped(heap) || !is_parallel_safe(root, (Node *) RelationGetIndexExpressions(index)) || !is_parallel_safe(root, (Node *) RelationGetIndexPredicate(index))) { -- 2.17.1
master.patch (application/octet-stream, 11.7K) download From 6e07d11deba1c17c1a279d943e16837275982042 Mon Sep 17 00:00:00 2001 From: Peter Geoghegan <pg@bowt.ie> Date: Tue, 7 Aug 2018 18:00:00 -0700 Subject: [PATCH 3/3] Handle parallel index builds on mapped relations. Commit 9da0cc35284, which introduced parallel CREATE INDEX, failed to propagate relmapper.c backend local cache state to parallel worker processes. This could result in parallel index builds against mapped catalog relations where the leader process (participating as a worker) scans the new, pristine relfilenode, while worker processes scan the obsolescent relfilenode. When this happened, the final index structure was typically not consistent with the owning table's structure. The final index structure could contain entries formed from both heap relfilenodes. Only rebuilds on mapped catalog relations that occur as part of a VACUUM FULL or CLUSTER could become corrupt in practice, since their mapped relation relfilenode swap is what allows the inconsistency to arise. On master, fix the problem by propagating the required relmapper.c backend state as part of standard parallel initialization (Cf. commit 29d58fd3). On v11, simply disallow builds against mapped catalog relations by treating it as a parallel safety issue. Reported-By: "death lock" Bug: #15309 Discussion: https://postgr.es/m/153329671686.1405.18298309097348420351@wrigleys.postgresql.org Backpatch: 11-, where parallel CREATE INDEX was introduced. --- src/backend/access/transam/README.parallel | 4 ++ src/backend/access/transam/parallel.c | 19 ++++- src/backend/access/transam/xact.c | 4 +- src/backend/utils/cache/relmapper.c | 82 ++++++++++++++++++++-- src/include/utils/relmapper.h | 6 +- 5 files changed, 105 insertions(+), 10 deletions(-) diff --git a/src/backend/access/transam/README.parallel b/src/backend/access/transam/README.parallel index f09a580634..85e5840feb 100644 --- a/src/backend/access/transam/README.parallel +++ b/src/backend/access/transam/README.parallel @@ -125,6 +125,10 @@ worker. This includes: - State related to pending REINDEX operations, which prevents access to an index that is currently being rebuilt. + - Active relmapper.c mapping state. This is needed to allow consistent + answers when fetching the current relfilenode for relation oids of + mapped relations. + To prevent unprincipled deadlocks when running in parallel mode, this code also arranges for the leader and all workers to participate in group locking. See src/backend/storage/lmgr/README for more details. diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c index 30ddf94c95..c168118467 100644 --- a/src/backend/access/transam/parallel.c +++ b/src/backend/access/transam/parallel.c @@ -37,6 +37,7 @@ #include "utils/guc.h" #include "utils/inval.h" #include "utils/memutils.h" +#include "utils/relmapper.h" #include "utils/snapmgr.h" #include "utils/typcache.h" @@ -69,6 +70,7 @@ #define PARALLEL_KEY_ENTRYPOINT UINT64CONST(0xFFFFFFFFFFFF0009) #define PARALLEL_KEY_SESSION_DSM UINT64CONST(0xFFFFFFFFFFFF000A) #define PARALLEL_KEY_REINDEX_STATE UINT64CONST(0xFFFFFFFFFFFF000B) +#define PARALLEL_KEY_RELMAPPER_STATE UINT64CONST(0xFFFFFFFFFFFF000C) /* Fixed-size parallel state. */ typedef struct FixedParallelState @@ -205,6 +207,7 @@ InitializeParallelDSM(ParallelContext *pcxt) Size asnaplen = 0; Size tstatelen = 0; Size reindexlen = 0; + Size relmapperlen = 0; Size segsize = 0; int i; FixedParallelState *fps; @@ -256,8 +259,10 @@ InitializeParallelDSM(ParallelContext *pcxt) shm_toc_estimate_chunk(&pcxt->estimator, sizeof(dsm_handle)); reindexlen = EstimateReindexStateSpace(); shm_toc_estimate_chunk(&pcxt->estimator, reindexlen); + relmapperlen = EstimateRelationMapSpace(); + shm_toc_estimate_chunk(&pcxt->estimator, relmapperlen); /* If you add more chunks here, you probably need to add keys. */ - shm_toc_estimate_keys(&pcxt->estimator, 8); + shm_toc_estimate_keys(&pcxt->estimator, 9); /* Estimate space need for error queues. */ StaticAssertStmt(BUFFERALIGN(PARALLEL_ERROR_QUEUE_SIZE) == @@ -327,6 +332,7 @@ InitializeParallelDSM(ParallelContext *pcxt) char *asnapspace; char *tstatespace; char *reindexspace; + char *relmapperspace; char *error_queue_space; char *session_dsm_handle_space; char *entrypointstate; @@ -373,6 +379,12 @@ InitializeParallelDSM(ParallelContext *pcxt) SerializeReindexState(reindexlen, reindexspace); shm_toc_insert(pcxt->toc, PARALLEL_KEY_REINDEX_STATE, reindexspace); + /* Serialize relmapper state. */ + relmapperspace = shm_toc_allocate(pcxt->toc, relmapperlen); + SerializeRelationMap(relmapperlen, relmapperspace); + shm_toc_insert(pcxt->toc, PARALLEL_KEY_RELMAPPER_STATE, + relmapperspace); + /* Allocate space for worker information. */ pcxt->worker = palloc0(sizeof(ParallelWorkerInfo) * pcxt->nworkers); @@ -1205,6 +1217,7 @@ ParallelWorkerMain(Datum main_arg) char *asnapspace; char *tstatespace; char *reindexspace; + char *relmapperspace; StringInfoData msgbuf; char *session_dsm_handle_space; @@ -1380,6 +1393,10 @@ ParallelWorkerMain(Datum main_arg) reindexspace = shm_toc_lookup(toc, PARALLEL_KEY_REINDEX_STATE, false); RestoreReindexState(reindexspace); + /* Restore relmapper state. */ + relmapperspace = shm_toc_lookup(toc, PARALLEL_KEY_RELMAPPER_STATE, false); + RestoreRelationMap(relmapperspace); + /* * We've initialized all of our state now; nothing should change * hereafter. diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 9aa63c8792..cd8270d5fb 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -2018,7 +2018,7 @@ CommitTransaction(void) HOLD_INTERRUPTS(); /* Commit updates to the relation map --- do this as late as possible */ - AtEOXact_RelationMap(true); + AtEOXact_RelationMap(true, is_parallel_worker); /* * set the current transaction state information appropriately during @@ -2539,7 +2539,7 @@ AbortTransaction(void) AtAbort_Portals(); AtEOXact_LargeObject(false); AtAbort_Notify(); - AtEOXact_RelationMap(false); + AtEOXact_RelationMap(false, is_parallel_worker); AtAbort_Twophase(); /* diff --git a/src/backend/utils/cache/relmapper.c b/src/backend/utils/cache/relmapper.c index c7f0e6f6d4..b242659fe1 100644 --- a/src/backend/utils/cache/relmapper.c +++ b/src/backend/utils/cache/relmapper.c @@ -91,6 +91,16 @@ typedef struct RelMapFile int32 pad; /* to make the struct size be 512 exactly */ } RelMapFile; +/* + * State for serializing local and shared relmappings for parallel workers + * (active states only). See notes on active_* and pending_* updates state. + */ +typedef struct SerializedActiveRelMaps +{ + RelMapFile active_shared_updates; + RelMapFile active_local_updates; +} SerializedActiveRelMaps; + /* * The currently known contents of the shared map file and our database's * local map file are stored here. These can be reloaded from disk @@ -111,6 +121,9 @@ static RelMapFile local_map; * they will become active at the next CommandCounterIncrement. This setup * lets map updates act similarly to updates of pg_class rows, ie, they * become visible only at the next CommandCounterIncrement boundary. + * + * Active shared and active local updates are serialized by the parallel + * infrastructure, and deserialized within parallel workers. */ static RelMapFile active_shared_updates; static RelMapFile active_local_updates; @@ -263,13 +276,16 @@ RelationMapUpdateMap(Oid relationId, Oid fileNode, bool shared, else { /* - * We don't currently support map changes within subtransactions. This - * could be done with more bookkeeping infrastructure, but it doesn't - * presently seem worth it. + * We don't currently support map changes within subtransactions, or + * when in parallel mode. This could be done with more bookkeeping + * infrastructure, but it doesn't presently seem worth it. */ if (GetCurrentTransactionNestLevel() > 1) elog(ERROR, "cannot change relation mapping within subtransaction"); + if (IsInParallelMode()) + elog(ERROR, "cannot change relation mapping in parallel mode"); + if (immediate) { /* Make it active, but only locally */ @@ -452,11 +468,14 @@ AtCCI_RelationMap(void) * * During abort, we just have to throw away any pending map changes. * Normal post-abort cleanup will take care of fixing relcache entries. + * Parallel worker commit/abort is handled by resetting active mappings + * that may have been received from the leader process. (There should be + * no pending updates in parallel workers.) */ void -AtEOXact_RelationMap(bool isCommit) +AtEOXact_RelationMap(bool isCommit, bool isParallelWorker) { - if (isCommit) + if (isCommit && !isParallelWorker) { /* * We should not get here with any "pending" updates. (We could @@ -482,7 +501,10 @@ AtEOXact_RelationMap(bool isCommit) } else { - /* Abort --- drop all local and pending updates */ + /* Abort or parallel worker --- drop all local and pending updates */ + Assert(!isParallelWorker || pending_shared_updates.num_mappings == 0); + Assert(!isParallelWorker || pending_local_updates.num_mappings == 0); + active_shared_updates.num_mappings = 0; active_local_updates.num_mappings = 0; pending_shared_updates.num_mappings = 0; @@ -614,6 +636,54 @@ RelationMapInitializePhase3(void) load_relmap_file(false); } +/* + * EstimateRelationMapSpace + * + * Estimate space needed to pass active shared and local relmaps to parallel + * workers. + */ +Size +EstimateRelationMapSpace(void) +{ + return sizeof(SerializedActiveRelMaps); +} + +/* + * SerializeRelationMap + * + * Serialize active shared and local relmap state for parallel workers. + */ +void +SerializeRelationMap(Size maxSize, char *startAddress) +{ + SerializedActiveRelMaps *relmaps; + + relmaps = (SerializedActiveRelMaps *) startAddress; + relmaps->active_shared_updates = active_shared_updates; + relmaps->active_local_updates = active_local_updates; +} + +/* + * RestoreRelationMap + * + * Restore active shared and local relmap state within a parallel worker. + */ +void +RestoreRelationMap(char *startAddress) +{ + SerializedActiveRelMaps *relmaps; + + if (active_shared_updates.num_mappings != 0 || + active_local_updates.num_mappings != 0 || + pending_shared_updates.num_mappings != 0 || + pending_local_updates.num_mappings != 0) + elog(ERROR, "parallel worker has existing mappings"); + + relmaps = (SerializedActiveRelMaps *) startAddress; + active_shared_updates = relmaps->active_shared_updates; + active_local_updates = relmaps->active_local_updates; +} + /* * load_relmap_file -- load data from the shared or local map file * diff --git a/src/include/utils/relmapper.h b/src/include/utils/relmapper.h index f69b1006bf..fb51943498 100644 --- a/src/include/utils/relmapper.h +++ b/src/include/utils/relmapper.h @@ -48,7 +48,7 @@ extern void RelationMapInvalidate(bool shared); extern void RelationMapInvalidateAll(void); extern void AtCCI_RelationMap(void); -extern void AtEOXact_RelationMap(bool isCommit); +extern void AtEOXact_RelationMap(bool isCommit, bool isParallelWorker); extern void AtPrepare_RelationMap(void); extern void CheckPointRelationMap(void); @@ -59,6 +59,10 @@ extern void RelationMapInitialize(void); extern void RelationMapInitializePhase2(void); extern void RelationMapInitializePhase3(void); +extern Size EstimateRelationMapSpace(void); +extern void SerializeRelationMap(Size maxSize, char *startAddress); +extern void RestoreRelationMap(char *startAddress); + extern void relmap_redo(XLogReaderState *record); extern void relmap_desc(StringInfo buf, XLogReaderState *record); extern const char *relmap_identify(uint8 info); -- 2.17.1
^ permalink raw reply [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-09 16:33  Peter Geoghegan <pg@bowt.ie>
  parent: Peter Geoghegan <pg@bowt.ie>
  1 sibling, 0 replies; 26+ messages in thread

From: Peter Geoghegan @ 2018-08-09 16:33 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: deathlock13@gmail.com, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>; Robert Haas <robertmhaas@gmail.com>

On Tue, Aug 7, 2018 at 6:06 PM, Peter Geoghegan <pg@bowt.ie> wrote:
> On Mon, Aug 6, 2018 at 7:32 PM, Peter Geoghegan <pg@bowt.ie> wrote:
>> I wrote this in a little over an hour, and it works fine. I'll post it
>> shortly, once I polish it up some more. I'll also post an alternative
>> "no mapped relation parallel builds" fix for v11, which will be
>> trivial.
>
> Attached are two patches that each fix the issue -- a conservative
> patch for v11, as well as a patch that actually propagates relmapper.c
> state, for the master branch. It would be good to get a +1 on both
> before pushing.

I'm planning to push these two in about 24 - 30 hours, since I have
buy-in from Tom on the high level approach. If anyone wants to review
the patches in detail, now would be a good time. There isn't much to
them.


-- 
Peter Geoghegan




^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-09 17:34  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Peter Geoghegan <pg@bowt.ie>
  1 sibling, 1 reply; 26+ messages in thread

From: Tom Lane @ 2018-08-09 17:34 UTC (permalink / raw)
  To: Peter Geoghegan <pg@bowt.ie>; +Cc: deathlock13@gmail.com, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>; Robert Haas <robertmhaas@gmail.com>

Peter Geoghegan <pg@bowt.ie> writes:
> Attached are two patches that each fix the issue -- a conservative
> patch for v11, as well as a patch that actually propagates relmapper.c
> state, for the master branch. It would be good to get a +1 on both
> before pushing.

I took a quick look at these.  The v11 patch seems OK as far as it goes,
but I wonder if you shouldn't also include the RelationMapUpdateMap
hunk from the master patch, ie adding rejection of map changes in parallel
mode.

I don't have any objection to the master patch, but it'd be good to get
a +1 from someone who's spent more time with the parallelism
infrastructure than I have.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-09 17:58  Peter Geoghegan <pg@bowt.ie>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 26+ messages in thread

From: Peter Geoghegan @ 2018-08-09 17:58 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: deathlock13@gmail.com, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>; Robert Haas <robertmhaas@gmail.com>

On Thu, Aug 9, 2018 at 10:34 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> I took a quick look at these.  The v11 patch seems OK as far as it goes,
> but I wonder if you shouldn't also include the RelationMapUpdateMap
> hunk from the master patch, ie adding rejection of map changes in parallel
> mode.

Good idea. I'll do that.

> I don't have any objection to the master patch, but it'd be good to get
> a +1 from someone who's spent more time with the parallelism
> infrastructure than I have.

That would be my preference too, but commit 29d58fd3 is very analogous
to the proposed master branch fix, so I feel that it's reasonable to
proceed without final approval from someone like Robert or Amit. I'll
leave pushing until late in the day tomorrow, pacific time.

-- 
Peter Geoghegan




^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-10 13:45  Amit Kapila <amit.kapila16@gmail.com>
  parent: Peter Geoghegan <pg@bowt.ie>
  0 siblings, 1 reply; 26+ messages in thread

From: Amit Kapila @ 2018-08-10 13:45 UTC (permalink / raw)
  To: Peter Geoghegan <pg@bowt.ie>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; deathlock13@gmail.com, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>; Robert Haas <robertmhaas@gmail.com>

On Thu, Aug 9, 2018 at 11:28 PM, Peter Geoghegan <pg@bowt.ie> wrote:
> On Thu, Aug 9, 2018 at 10:34 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> I took a quick look at these.  The v11 patch seems OK as far as it goes,
>> but I wonder if you shouldn't also include the RelationMapUpdateMap
>> hunk from the master patch, ie adding rejection of map changes in parallel
>> mode.
>
> Good idea. I'll do that.
>
>> I don't have any objection to the master patch, but it'd be good to get
>> a +1 from someone who's spent more time with the parallelism
>> infrastructure than I have.
>
> That would be my preference too, but commit 29d58fd3 is very analogous
> to the proposed master branch fix, so I feel that it's reasonable to
> proceed without final approval from someone like Robert or Amit.
>

I haven't studied the complete problem, but the way you are
propagating the information to parallel workers looks correct to me.
Few minor comments:

1.
+void
+RestoreRelationMap(char *startAddress)
+{
+ SerializedActiveRelMaps   *relmaps;
+
+ if (active_shared_updates.num_mappings != 0 ||
+ active_local_updates.num_mappings != 0 ||
+ pending_shared_updates.num_mappings != 0 ||
+ pending_local_updates.num_mappings != 0)
+ elog(ERROR, "parallel worker has existing mappings");
..

Shouldn't above be Assert?

2.
+void
+SerializeRelationMap(Size maxSize, char *startAddress)
+{
+ SerializedActiveRelMaps   *relmaps;
+
+ relmaps = (SerializedActiveRelMaps *) startAddress;
+ relmaps->active_shared_updates = active_shared_updates;
+ relmaps->active_local_updates = active_local_updates;
..
}

Some of the other serialize functions use maxSize for Asserts.  See
SerializeComboCIDState.  I think we can do without that as well, but
it makes code consistent.


-- 
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com




^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-10 16:36  Peter Geoghegan <pg@bowt.ie>
  parent: Amit Kapila <amit.kapila16@gmail.com>
  0 siblings, 0 replies; 26+ messages in thread

From: Peter Geoghegan @ 2018-08-10 16:36 UTC (permalink / raw)
  To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; deathlock13@gmail.com, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>; Robert Haas <robertmhaas@gmail.com>

On Fri, Aug 10, 2018 at 6:45 AM, Amit Kapila <amit.kapila16@gmail.com> wrote:
> I haven't studied the complete problem, but the way you are
> propagating the information to parallel workers looks correct to me.
> Few minor comments:
>
> 1.
> +void
> +RestoreRelationMap(char *startAddress)
> +{
> + SerializedActiveRelMaps   *relmaps;
> +
> + if (active_shared_updates.num_mappings != 0 ||
> + active_local_updates.num_mappings != 0 ||
> + pending_shared_updates.num_mappings != 0 ||
> + pending_local_updates.num_mappings != 0)
> + elog(ERROR, "parallel worker has existing mappings");
> ..
>
> Shouldn't above be Assert?

This was based on AtPrepare_RelationMap().

> 2.
> +void
> +SerializeRelationMap(Size maxSize, char *startAddress)
> +{
> + SerializedActiveRelMaps   *relmaps;
> +
> + relmaps = (SerializedActiveRelMaps *) startAddress;
> + relmaps->active_shared_updates = active_shared_updates;
> + relmaps->active_local_updates = active_local_updates;
> ..
> }
>
> Some of the other serialize functions use maxSize for Asserts.  See
> SerializeComboCIDState.  I think we can do without that as well, but
> it makes code consistent.

I'll put an assert in there.

Thanks
-- 
Peter Geoghegan




^ permalink  raw  reply  [nested|flat] 26+ messages in thread

* Re: BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0
@ 2018-08-10 20:15  Peter Geoghegan <pg@bowt.ie>
  parent: PG Bug reporting form <noreply@postgresql.org>
  1 sibling, 0 replies; 26+ messages in thread

From: Peter Geoghegan @ 2018-08-10 20:15 UTC (permalink / raw)
  To: deathlock13@gmail.com, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

On Fri, Aug 3, 2018 at 4:45 AM, PG Bug reporting form
<noreply@postgresql.org> wrote:
> 11beta2 and git REL_11_STABLE, gcc 8.2, pg.conf : autovacuum=off
> DB restored from plain-format backup, first 'vacuum full' ends with ERR :
> "catalog is missing 1 attribute(s) for relid ..." - seem to point to only
> PrimaryKey, sometimes the same PK

A fix for this bug has been pushed.

Thanks for the report!
-- 
Peter Geoghegan




^ permalink  raw  reply  [nested|flat] 26+ messages in thread


end of thread, other threads:[~2018-08-10 20:15 UTC | newest]

Thread overview: 26+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-08-03 11:45 BUG #15309: ERROR: catalog is missing 1 attribute(s) for relid 760676 when max_parallel_maintenance_workers > 0 PG Bug reporting form <noreply@postgresql.org>
2018-08-03 13:53 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-08-03 16:51   ` Peter Geoghegan <pg@bowt.ie>
2018-08-03 17:11     ` Andres Freund <andres@anarazel.de>
2018-08-03 17:29       ` Peter Geoghegan <pg@bowt.ie>
2018-08-03 17:58         ` Tom Lane <tgl@sss.pgh.pa.us>
2018-08-03 18:03           ` Peter Geoghegan <pg@bowt.ie>
2018-08-06 17:43   ` Peter Geoghegan <pg@bowt.ie>
2018-08-06 20:31     ` Peter Geoghegan <pg@bowt.ie>
2018-08-06 20:37       ` Peter Geoghegan <pg@bowt.ie>
2018-08-06 21:21         ` Peter Geoghegan <pg@bowt.ie>
2018-08-06 21:29           ` Tom Lane <tgl@sss.pgh.pa.us>
2018-08-06 22:06             ` Peter Geoghegan <pg@bowt.ie>
2018-08-06 22:18               ` Tom Lane <tgl@sss.pgh.pa.us>
2018-08-06 22:21                 ` Peter Geoghegan <pg@bowt.ie>
2018-08-07 02:32                   ` Peter Geoghegan <pg@bowt.ie>
2018-08-08 01:06                     ` Peter Geoghegan <pg@bowt.ie>
2018-08-09 16:33                       ` Peter Geoghegan <pg@bowt.ie>
2018-08-09 17:34                       ` Tom Lane <tgl@sss.pgh.pa.us>
2018-08-09 17:58                         ` Peter Geoghegan <pg@bowt.ie>
2018-08-10 13:45                           ` Amit Kapila <amit.kapila16@gmail.com>
2018-08-10 16:36                             ` Peter Geoghegan <pg@bowt.ie>
2018-08-06 22:10           ` Alvaro Herrera <alvherre@2ndquadrant.com>
2018-08-06 22:14             ` Tom Lane <tgl@sss.pgh.pa.us>
2018-08-06 22:16             ` Peter Geoghegan <pg@bowt.ie>
2018-08-10 20:15 ` Peter Geoghegan <pg@bowt.ie>

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