BUG #17789: process_pgfdw_appname() fails for autovacuum workers - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #17789: process_pgfdw_appname() fails for autovacuum workers
Date
Msg-id 17789-8b31c5a4672b74d9@postgresql.org
Whole thread Raw
Responses Re: BUG #17789: process_pgfdw_appname() fails for autovacuum workers  (Kyotaro Horiguchi <horikyota.ntt@gmail.com>)
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      17789
Logged by:          Alexander Lakhin
Email address:      exclusion@gmail.com
PostgreSQL version: 15.2
Operating system:   Ubuntu 22.04
Description:

When executing the following queries:
CREATE EXTENSION postgres_fdw;
DO $d$
        BEGIN
            EXECUTE $$CREATE SERVER loopback FOREIGN DATA WRAPPER
postgres_fdw
                OPTIONS (dbname '$$||current_database()||$$',
                         port '$$||current_setting('port')||$$'
                )$$;
        END;
    $d$;
CREATE USER MAPPING FOR CURRENT_USER SERVER loopback;
ALTER SERVER loopback OPTIONS (application_name 'postgres_fdw %d/%u');
CREATE TABLE t1 (a int);
INSERT INTO t1 SELECT * FROM generate_series(1, 66) i;
CREATE FOREIGN TABLE ft1 (b int) INHERITS (t1)
      SERVER LOOPBACK OPTIONS (table_name 'anytable');
\c -
SELECT pg_sleep(60)

with the autovacuum enabled:
autovacuum = on
autovacuum_naptime = 1
autovacuum_vacuum_threshold = 1

I get an assertion failure:
Core was generated by `postgres: autovacuum worker regression
                        '.
Program terminated with signal SIGABRT, Aborted.

warning: Section `.reg-xstate/2522086' in core file too small.
#0  __pthread_kill_implementation (no_tid=0, signo=6,
threadid=140402663786304) at ./nptl/pthread_kill.c:44
44      ./nptl/pthread_kill.c: No such file or directory.
(gdb) bt
#0  __pthread_kill_implementation (no_tid=0, signo=6,
threadid=140402663786304) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=140402663786304) at
./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=140402663786304, signo=signo@entry=6) at
./nptl/pthread_kill.c:89
#3  0x00007fb20a30e476 in __GI_raise (sig=sig@entry=6) at
../sysdeps/posix/raise.c:26
#4  0x00007fb20a2f47f3 in __GI_abort () at ./stdlib/abort.c:79
#5  0x0000564b2ecc55c8 in ExceptionalCondition
(conditionName=conditionName@entry=0x7fb1feb3f81e "MyProcPort != NULL", 
    errorType=errorType@entry=0x7fb1feb3e700 "FailedAssertion",
fileName=fileName@entry=0x7fb1feb3f75a "option.c", 
    lineNumber=lineNumber@entry=464) at assert.c:69
#6  0x00007fb1feb31b30 in process_pgfdw_appname (appname=<optimized out>) at
option.c:464
#7  0x00007fb1feb2ae40 in connect_pg_server
(server=server@entry=0x564b30b0c220, user=user@entry=0x564b30b0c0b0)
    at connection.c:416
#8  0x00007fb1feb2b2be in make_new_connection
(entry=entry@entry=0x564b30b203d0, user=user@entry=0x564b30b0c0b0)
    at connection.c:344
#9  0x00007fb1feb2b799 in GetConnection (user=0x564b30b0c0b0,
will_prep_stmt=will_prep_stmt@entry=false, 
    state=state@entry=0x0) at connection.c:204
#10 0x00007fb1feb34a44 in postgresAnalyzeForeignTable
(relation=0x7fb1feb4fa30, func=<optimized out>, 
    totalpages=0x7fff7f91b4a8) at postgres_fdw.c:4951
#11 0x0000564b2e916252 in acquire_inherited_sample_rows
(onerel=onerel@entry=0x7fb1feb4b940, elevel=elevel@entry=13, 
    rows=rows@entry=0x564b30b27750, targrows=targrows@entry=30000,
totalrows=totalrows@entry=0x7fff7f91b5b0, 
    totaldeadrows=totaldeadrows@entry=0x7fff7f91b5b8) at analyze.c:1470
#12 0x0000564b2e91983f in do_analyze_rel
(onerel=onerel@entry=0x7fb1feb4b940, params=params@entry=0x564b30aaaaa4, 
    va_cols=va_cols@entry=0x0, acquirefunc=0x564b2e91854e
<acquire_sample_rows>, relpages=1, inh=inh@entry=true, 
    in_outer_xact=false, elevel=13) at analyze.c:534
#13 0x0000564b2e91a167 in analyze_rel (relid=<optimized out>,
relation=0x564b30b07250, 
    params=params@entry=0x564b30aaaaa4, va_cols=0x0,
in_outer_xact=<optimized out>, bstrategy=<optimized out>)
    at analyze.c:269
#14 0x0000564b2e9a8ec7 in vacuum (relations=0x564b30b092b8,
params=params@entry=0x564b30aaaaa4, 
    bstrategy=<optimized out>, bstrategy@entry=0x564b30b034a8,
isTopLevel=isTopLevel@entry=true) at vacuum.c:492
#15 0x0000564b2eace110 in autovacuum_do_vac_analyze
(tab=tab@entry=0x564b30aaaaa0, 
    bstrategy=bstrategy@entry=0x564b30b034a8) at autovacuum.c:3149
#16 0x0000564b2ead028a in do_autovacuum () at autovacuum.c:2472
#17 0x0000564b2ead07ce in AutoVacWorkerMain (argc=argc@entry=0,
argv=argv@entry=0x0) at autovacuum.c:1715
#18 0x0000564b2ead08ac in StartAutoVacWorker () at autovacuum.c:1493
#19 0x0000564b2ead8300 in StartAutovacuumWorker () at postmaster.c:5541
#20 0x0000564b2ead932f in sigusr1_handler (postgres_signal_arg=<optimized
out>) at postmaster.c:5246
#21 <signal handler called>
#22 0x00007fb20a3e774d in __GI___select (nfds=nfds@entry=8,
readfds=readfds@entry=0x7fff7f91c960, 
    writefds=writefds@entry=0x0, exceptfds=exceptfds@entry=0x0,
timeout=timeout@entry=0x7fff7f91c8d0)
    at ../sysdeps/unix/sysv/linux/select.c:69
#23 0x0000564b2ead999d in ServerLoop () at postmaster.c:1770
#24 0x0000564b2eadad45 in PostmasterMain (argc=argc@entry=3,
argv=argv@entry=0x564b30a29620) at postmaster.c:1478
#25 0x0000564b2ea1f2b0 in main (argc=3, argv=0x564b30a29620) at main.c:202

(A build without asserts crashes with a segmentation fault for me.)
Observed on REL_15_STABLE..master since the process_pgfdw_appname()
introduction (6e0cb3de).
Maybe the assert should be replaced by checks for MyProcPort in cases
'd','u' for compatibility with autovacuum workers.


pgsql-bugs by date:

Previous
From: David Rowley
Date:
Subject: Re: BUG #17777: An assert failed in nodeWindowAgg.c
Next
From: Fujii Masao
Date:
Subject: array_agg(DISTINCT) caused a segmentation fault