PostgreSQL Bugs

Collected from the PG bugs email list.

Bug ID15437
PG Version10.5
OSDebian 9
Opened2018-10-18 11:57:41+00
Reported byDmitry Shalashov
StatusNew

Body of first available message related to this bug follows.

The following bug has been logged on the website:

Bug reference:      15437
Logged by:          Dmitry Shalashov
Email address:      (redacted)
PostgreSQL version: 10.5
Operating system:   Debian 9
Description:        

I tried to use declarative partitioning and, to avoid creating partitions by
hand, to make them in ON BEFORE STATEMENT trigger. Trigger executes
successfully (proved that with RAISE NOTICE), but server crashes.

Error in the log could look like that:

[24329207.147193] postgres[23599]: segfault at 15948 ip 00005652ff2e586e sp
00007fffd9ee5a50 error 4 in postgres[5652ff17d000+6de000]
2018-10-18 14:52:13 MSK [4312]: [17-1] user=,db= LOG:  server process (PID
4636) was terminated by signal 11: Segmentation fault
2018-10-18 14:52:13 MSK [4312]: [18-1] user=,db= DETAIL:  Failed process was
running: INSERT INTO test (value) VALUES (1);
2018-10-18 14:52:13 MSK [4312]: [19-1] user=,db= LOG:  terminating any other
active server processes

Test case follows:

CREATE TABLE test (id serial NOT NULL, value integer NOT NULL, ctime
timestamp NOT NULL DEFAULT now()) PARTITION BY RANGE (ctime);

CREATE OR REPLACE FUNCTION week_table_suffix_from_ts(ts timestamp with time
zone) RETURNS text
    LANGUAGE plpgsql
    AS $$
DECLARE
    table_suffix text := replace(substring((date_trunc('week', ts))::text
from 1 for 10),'-','');
BEGIN
    RETURN table_suffix;
END;
$$;

CREATE OR REPLACE FUNCTION test_trigger_func() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
DECLARE
    table_prefix    text    := 'test_';
    table_suffix    text    := week_table_suffix_from_ts(now());
    table_name      text    := 'creatives_' || table_suffix;
    table_exists    boolean;
BEGIN
    EXECUTE format(
        'SELECT EXISTS (SELECT 1 FROM pg_tables WHERE schemaname = $1 AND
tablename = $2)'
    ) INTO table_exists USING 'public', table_name;

    IF NOT table_exists THEN
        EXECUTE format(
            'CREATE TABLE IF NOT EXISTS %I PARTITION OF test FOR VALUES FROM
(%L) TO (%L)'::text,
            table_name,
            date_trunc('week', now()),
            date_trunc('week', now() + interval '1 week')
        );
    END IF;

    RETURN NULL;
END;
$$;

CREATE TRIGGER test_trigger BEFORE INSERT ON test FOR EACH STATEMENT EXECUTE
PROCEDURE test_trigger_func();

INSERT INTO test (value) VALUES (1);

Messages

DateAuthorSubject
2018-10-18 11:57:41+00=?utf-8?q?PG_Bug_reporting_form?=BUG #15437: Segfault during insert into declarative partitioned table with a trigger creating partition
2018-10-19 02:40:34+00Amit LangoteRe: BUG #15437: Segfault during insert into declarative partitioned table with a trigger creating partition
2018-10-19 02:52:51+00Tom LaneRe: BUG #15437: Segfault during insert into declarative partitioned table with a trigger creating partition
2018-10-19 03:45:33+00Amit LangoteRe: BUG #15437: Segfault during insert into declarative partitioned table with a trigger creating partition
2018-10-19 09:38:09+00Dmitry ShalashovRe: BUG #15437: Segfault during insert into declarative partitioned table with a trigger creating partition
2018-10-19 09:43:24+00Dmitry ShalashovRe: BUG #15437: Segfault during insert into declarative partitioned table with a trigger creating partition
2018-10-23 03:36:14+00Amit LangoteRe: BUG #15437: Segfault during insert into declarative partitioned table with a trigger creating partition
2018-10-29 02:44:59+00Michael PaquierRe: BUG #15437: Segfault during insert into declarative partitioned table with a trigger creating partition
2018-10-29 03:31:17+00Michael PaquierRe: BUG #15437: Segfault during insert into declarative partitioned table with a trigger creating partition
2018-10-29 05:15:06+00Amit LangoteRe: BUG #15437: Segfault during insert into declarative partitioned table with a trigger creating partition
2018-10-29 05:28:53+00Amit LangoteRe: BUG #15437: Segfault during insert into declarative partitioned table with a trigger creating partition
2018-10-29 06:57:14+00Michael PaquierRe: BUG #15437: Segfault during insert into declarative partitioned table with a trigger creating partition
2018-10-29 07:32:03+00Amit LangoteRe: BUG #15437: Segfault during insert into declarative partitioned table with a trigger creating partition
2018-10-30 04:11:19+00Michael PaquierRe: BUG #15437: Segfault during insert into declarative partitioned table with a trigger creating partition
2018-11-01 23:58:04+00Michael PaquierRe: BUG #15437: Segfault during insert into declarative partitioned table with a trigger creating partition
2018-11-02 01:54:41+00Amit LangoteRe: BUG #15437: Segfault during insert into declarative partitioned table with a trigger creating partition
2018-11-02 02:30:53+00Michael PaquierRe: BUG #15437: Segfault during insert into declarative partitioned table with a trigger creating partition
2018-11-02 02:45:29+00Amit LangoteRe: BUG #15437: Segfault during insert into declarative partitioned table with a trigger creating partition
2018-11-05 02:09:21+00Michael PaquierRe: BUG #15437: Segfault during insert into declarative partitioned table with a trigger creating partition
2018-11-05 04:31:25+00Amit LangoteRe: BUG #15437: Segfault during insert into declarative partitioned table with a trigger creating partition
2018-11-05 19:23:05+00Alvaro HerreraRe: BUG #15437: Segfault during insert into declarative partitioned table with a trigger creating partition
2018-11-06 00:14:07+00Michael PaquierRe: BUG #15437: Segfault during insert into declarative partitioned table with a trigger creating partition