Re: pgstat_report_activity() and parallel CREATE INDEX (was: Parallel index creation & pg_stat_activity)

From: Noah Misch <noah(at)leadboat(dot)com>
To: Peter Geoghegan <pg(at)bowt(dot)ie>
Cc: Andres Freund <andres(at)anarazel(dot)de>, Phil Florent <philflorent(at)hotmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pgstat_report_activity() and parallel CREATE INDEX (was: Parallel index creation & pg_stat_activity)
Date: 2020-10-14 02:26:36
Message-ID: 20201014022636.GA1962668@rfd.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Mar 07, 2018 at 05:53:18PM -0800, Peter Geoghegan wrote:
> On Thu, Mar 1, 2018 at 2:47 PM, Peter Geoghegan <pg(at)bowt(dot)ie> wrote:
> > No. Just an oversight. Looks like _bt_parallel_build_main() should
> > call pgstat_report_activity(), just like ParallelQueryMain().
> >
> > I'll come up with a patch soon.
>
> Attached patch has parallel CREATE INDEX propagate debug_query_string
> to workers.

Two test suites segfault under the following configuration:

cat >/tmp/max_parallel.conf <<EOF
log_line_prefix = '%m [%p:%l] %q%a '
log_connections = 'true'
log_disconnections = 'true'
log_statement = 'all'
fsync = off
authentication_timeout = '600s'
wal_sender_timeout = '18000s'
wal_level = minimal
max_wal_senders = 0

# Maximize parallelism. Many suites fail under these settings, due to plan
# changes. That is not a bug, but new crashes do qualify as bugs.

force_parallel_mode = regress
min_parallel_index_scan_size = 0
min_parallel_table_scan_size = 0
parallel_setup_cost = 0
parallel_tuple_cost = 0
EOF
make -C src/test/modules/worker_spi check TEMP_CONFIG=/tmp/max_parallel.conf # [1]
make -C src/test/subscription check PROVE_TESTS=t/010_truncate.pl TEMP_CONFIG=/tmp/max_parallel.conf # [2]

In both, the crash is at the strlen(debug_query_string) from $SUBJECT.
worker_spi is easy to fix by setting debug_query_string, as attached. Since
worker_spi has real query strings, I think that's an independent good. In the
other suite, logical replication apply_handle_truncate() constructs an
ExecuteTruncateGuts() call without use of a query string. Options:

1. Disable parallelism for the index build under ExecuteTruncateGuts().
Nobody will mourn a performance loss from declining parallelism for an
empty index, but I feel like this is fixing in the wrong place.
2. Make _bt_begin_parallel() and begin_parallel_vacuum() recognize the
debug_query_string==NULL case and reproduce it on the worker.
3. Require bgworkers to set debug_query_string before entering code of vacuum,
truncate, etc. Logical replication might synthesize a DDL statement, or it
might just use a constant string.

I tend to prefer (2), but (3) isn't bad. Opinions?

(With debug_query_string fixed, 010_truncate.pl next fails with "cannot take
query snapshot during a parallel operation". I'll report that separately,
probably on the thread for commit 039eb6e.)

[1]
#0 __strlen_sse2_pminub () at ../sysdeps/x86_64/multiarch/strlen-sse2-pminub.S:38
#1 0x0000000000508844 in _bt_begin_parallel (request=1, isconcurrent=<optimized out>, buildstate=0x7ffe353692a0) at nbtsort.c:1536
#2 _bt_spools_heapscan (indexInfo=0x2446768, buildstate=0x7ffe353692a0, index=..., heap=0x7ff995b85948) at nbtsort.c:394
#3 btbuild (heap=0x7ff995b85948, index=0x7ff995b85d78, indexInfo=0x2446768) at nbtsort.c:326
#4 0x0000000000568d0b in index_build (heapRelation=heapRelation(at)entry=0x7ff995b85948, indexRelation=indexRelation(at)entry=0x7ff995b85d78, indexInfo=indexInfo(at)entry=0x2446768, isreindex=isreindex(at)entry=false,
parallel=parallel(at)entry=true) at index.c:2898
#5 0x000000000056a450 in index_create (heapRelation=heapRelation(at)entry=0x7ff995b85948, indexRelationName=indexRelationName(at)entry=0x7ffe35369800 "pg_toast_16388_index", indexRelationId=16393,
indexRelationId(at)entry=0, parentIndexRelid=parentIndexRelid(at)entry=0, parentConstraintId=parentConstraintId(at)entry=0, relFileNode=relFileNode(at)entry=0, indexInfo=indexInfo(at)entry=0x2446768,
indexColNames=0x2445a28, accessMethodObjectId=accessMethodObjectId(at)entry=403, tableSpaceId=tableSpaceId(at)entry=0, collationObjectId=collationObjectId(at)entry=0x7ffe35369780,
classObjectId=classObjectId(at)entry=0x7ffe35369790, coloptions=coloptions(at)entry=0x7ffe35369770, reloptions=reloptions(at)entry=0, flags=flags(at)entry=1, constr_flags=constr_flags(at)entry=0,
allow_system_table_mods=allow_system_table_mods(at)entry=true, is_internal=is_internal(at)entry=true, constraintId=constraintId(at)entry=0x0) at index.c:1217
#6 0x000000000058ad36 in create_toast_table (rel=rel(at)entry=0x7ff995b7db68, toastOid=toastOid(at)entry=0, toastIndexOid=toastIndexOid(at)entry=0, reloptions=reloptions(at)entry=0, lockmode=lockmode(at)entry=8,
check=check(at)entry=false) at toasting.c:310
#7 0x000000000058afe2 in CheckAndCreateToastTable (relOid=relOid(at)entry=16388, reloptions=reloptions(at)entry=0, lockmode=lockmode(at)entry=8, check=check(at)entry=false) at toasting.c:82
#8 0x000000000058b029 in NewRelationCreateToastTable (relOid=relOid(at)entry=16388, reloptions=reloptions(at)entry=0) at toasting.c:71
#9 0x00000000007f3027 in ProcessUtilitySlow (pstate=pstate(at)entry=0x240dc40, pstmt=pstmt(at)entry=0x2409358,
queryString=queryString(at)entry=0x24056a0 "CREATE SCHEMA \"schema4\" CREATE TABLE \"counted\" (\t\ttype text CHECK (type IN ('total', 'delta')), \t\tvalue\tinteger)CREATE UNIQUE INDEX \"counted_unique_total\" ON \"counted\" (type) WHERE type = 'total'", context=context(at)entry=PROCESS_UTILITY_SUBCOMMAND, params=params(at)entry=0x0, queryEnv=queryEnv(at)entry=0x0, qc=qc(at)entry=0x0, dest=0xa91ea0 <donothingDR>)
at utility.c:1191
#10 0x00000000007f14b4 in standard_ProcessUtility (pstmt=0x2409358,
queryString=0x24056a0 "CREATE SCHEMA \"schema4\" CREATE TABLE \"counted\" (\t\ttype text CHECK (type IN ('total', 'delta')), \t\tvalue\tinteger)CREATE UNIQUE INDEX \"counted_unique_total\" ON \"counted\" (type) WHERE type = 'total'", context=PROCESS_UTILITY_SUBCOMMAND, params=0x0, queryEnv=0x0, dest=0xa91ea0 <donothingDR>, qc=0x0) at utility.c:1071
#11 0x0000000000615ba6 in CreateSchemaCommand (stmt=stmt(at)entry=0x2408b40,
queryString=queryString(at)entry=0x24056a0 "CREATE SCHEMA \"schema4\" CREATE TABLE \"counted\" (\t\ttype text CHECK (type IN ('total', 'delta')), \t\tvalue\tinteger)CREATE UNIQUE INDEX \"counted_unique_total\" ON \"counted\" (type) WHERE type = 'total'", stmt_location=0, stmt_len=0) at schemacmds.c:192
#12 0x00000000007f2365 in ProcessUtilitySlow (pstate=pstate(at)entry=0x24090d0, pstmt=pstmt(at)entry=0x2408d98,
queryString=queryString(at)entry=0x24056a0 "CREATE SCHEMA \"schema4\" CREATE TABLE \"counted\" (\t\ttype text CHECK (type IN ('total', 'delta')), \t\tvalue\tinteger)CREATE UNIQUE INDEX \"counted_unique_total\" ON \"counted\" (type) WHERE type = 'total'", context=context(at)entry=PROCESS_UTILITY_QUERY, params=params(at)entry=0x0, queryEnv=queryEnv(at)entry=0x0, qc=qc(at)entry=0x7ffe35369fd0, dest=0xa91de0 <spi_printtupDR>)
at utility.c:1125
#13 0x00000000007f14b4 in standard_ProcessUtility (pstmt=0x2408d98,
queryString=0x24056a0 "CREATE SCHEMA \"schema4\" CREATE TABLE \"counted\" (\t\ttype text CHECK (type IN ('total', 'delta')), \t\tvalue\tinteger)CREATE UNIQUE INDEX \"counted_unique_total\" ON \"counted\" (type) WHERE type = 'total'", context=PROCESS_UTILITY_QUERY, params=0x0, queryEnv=0x0, dest=0xa91de0 <spi_printtupDR>, qc=0x7ffe35369fd0) at utility.c:1071
#14 0x00000000006a1ace in _SPI_execute_plan (plan=plan(at)entry=0x7ffe3536a050, paramLI=paramLI(at)entry=0x0, snapshot=snapshot(at)entry=0x0, crosscheck_snapshot=crosscheck_snapshot(at)entry=0x0,
read_only=read_only(at)entry=false, fire_triggers=fire_triggers(at)entry=true, tcount=tcount(at)entry=0, caller_dest=caller_dest(at)entry=0x0) at spi.c:2443
#15 0x00000000006a2102 in SPI_execute (
src=0x24056a0 "CREATE SCHEMA \"schema4\" CREATE TABLE \"counted\" (\t\ttype text CHECK (type IN ('total', 'delta')), \t\tvalue\tinteger)CREATE UNIQUE INDEX \"counted_unique_total\" ON \"counted\" (type) WHERE type = 'total'", read_only=read_only(at)entry=false, tcount=tcount(at)entry=0) at spi.c:515
#16 0x00007ff98a80592f in initialize_worker_spi (table=0x237d268) at worker_spi.c:150
#17 worker_spi_main (main_arg=<optimized out>) at worker_spi.c:187
#18 0x0000000000753f0f in StartBackgroundWorker () at bgworker.c:820

[2]
#0 __strlen_sse2_pminub () at ../sysdeps/x86_64/multiarch/strlen-sse2-pminub.S:38
#1 0x0000000000508844 in _bt_begin_parallel (request=1, isconcurrent=<optimized out>, buildstate=0x7ffdc868f310) at nbtsort.c:1536
#2 _bt_spools_heapscan (indexInfo=0x1c5bb48, buildstate=0x7ffdc868f310, index=..., heap=0x7f7f33bad800) at nbtsort.c:394
#3 btbuild (heap=0x7f7f33bad800, index=0x7f7f33badd98, indexInfo=0x1c5bb48) at nbtsort.c:326
#4 0x0000000000568d0b in index_build (heapRelation=heapRelation(at)entry=0x7f7f33bad800, indexRelation=indexRelation(at)entry=0x7f7f33badd98, indexInfo=indexInfo(at)entry=0x1c5bb48, isreindex=isreindex(at)entry=true,
parallel=parallel(at)entry=true) at index.c:2898
#5 0x000000000056baea in reindex_index (indexId=indexId(at)entry=16387, skip_constraint_checks=<optimized out>, persistence=persistence(at)entry=112 'p', options=options(at)entry=0) at index.c:3541
#6 0x000000000056c060 in reindex_relation (relid=<optimized out>, flags=flags(at)entry=1, options=options(at)entry=0) at index.c:3764
#7 0x000000000062e5a7 in ExecuteTruncateGuts (explicit_rels=explicit_rels(at)entry=0x1c5ae60, relids=<optimized out>, relids_logged=relids_logged(at)entry=0x1c5bd50, behavior=behavior(at)entry=DROP_RESTRICT,
restart_seqs=<optimized out>) at tablecmds.c:1890
#8 0x000000000078c099 in apply_handle_truncate (s=0x7ffdc868f7b0) at worker.c:1879
#9 apply_dispatch (s=s(at)entry=0x7ffdc868f890) at worker.c:1930
#10 0x000000000078cfbb in LogicalRepApplyLoop (last_received=23166784) at worker.c:2155
#11 ApplyWorkerMain (main_arg=<optimized out>) at worker.c:3101
#12 0x0000000000753f0f in StartBackgroundWorker () at bgworker.c:820
#13 0x000000000076162d in do_start_bgworker (rw=0x1bdbb50) at postmaster.c:5890
#14 maybe_start_bgworkers () at postmaster.c:6115
#15 0x00000000007621ae in sigusr1_handler (postgres_signal_arg=<optimized out>) at postmaster.c:5276
#16 <signal handler called>
#17 0x00007f7f31f1d983 in __select_nocancel () at ../sysdeps/unix/syscall-template.S:81
#18 0x00000000004881cf in ServerLoop () at postmaster.c:1706
#19 0x0000000000763885 in PostmasterMain (argc=argc(at)entry=4, argv=argv(at)entry=0x1bb3030) at postmaster.c:1415
#20 0x000000000048a56d in main (argc=4, argv=0x1bb3030) at main.c:209

Attachment Content-Type Size
worker_spi-debug_query_string-v0.patch text/plain 2.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2020-10-14 02:53:55 Re: Assertion failure with LEFT JOINs among >500 relations
Previous Message Thomas Munro 2020-10-14 01:48:18 Re: Two fsync related performance issues?