PostgreSQL Bugs

Collected from the PG bugs email list.

Bug ID16369
PG Version12.2
OSCentOS 8, Red Hat 8, Mac OS X 10.14.6
Opened2020-04-15 20:20:35+00
Reported byCameron Ezell
StatusNew

Body of first available message related to this bug follows.

The following bug has been logged on the website:

Bug reference:      16369
Logged by:          Cameron Ezell
Email address:      (redacted)
PostgreSQL version: 12.2
Operating system:   CentOS 8, Red Hat 8, Mac OS X 10.14.6
Description:        

It seems that there are a few bugs that are throwing segmentation faults and
causing data corruption. These issues keep appearing for our team when using
tables that contain generated columns introduced in PostgreSQL 12. This has
been tested on 12.2 & 12.1 on CentOS 8 as well as 12.1 on MacOS 10.14.6:

select version();
-- PostgreSQL 12.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.3
20140911 (Red Hat 4.8.3-9), 64-bit

CREATE SCHEMA if not exists test;commit;

CREATE TABLE if not exists test.bug_report
(
    id bigint generated by default as identity,
    hostname varchar,
    hostname_short varchar GENERATED ALWAYS AS (split_part(hostname, '.',
1)) STORED,
    device text,
    mount text,
    used_space_bytes bigint,
    used_space_gb numeric GENERATED ALWAYS AS (ROUND(used_space_bytes /
1073741824.0,2)) STORED,
    avail_space_bytes bigint,
    avail_space_gb numeric GENERATED ALWAYS AS (ROUND(avail_space_bytes /
1073741824.0,2)) STORED,
    inserted_dts timestamp with time zone NOT NULL DEFAULT
clock_timestamp(),
    inserted_by text NOT NULL DEFAULT session_user
);commit;

-- No problems on the following insert
INSERT INTO test.bug_report(hostname, device, mount, used_space_bytes,
avail_space_bytes) VALUES ('123456789', 'devtmpfs', '/dev', 0,
6047076131313);
select * from test.bug_report;commit;

-- On CentOS 8, this bug is triggered with a hostname with 10+ characters.
On MacOS 10.14.6, 19+ characters.
INSERT INTO test.bug_report(hostname, device, mount, used_space_bytes,
avail_space_bytes) VALUES ('12345678901234567890', 'devtmpfs', '/dev', 0,
6047076131313);commit;
-- This should immediately crash the postgres service

-- Inserting some strings below that character threshold will insert just
fine, but a select statement on the table will now throw an error
INSERT INTO test.bug_report(hostname, device, mount, used_space_bytes,
avail_space_bytes) VALUES ('abc', 'devtmpfs', '/dev', 0,
6047076131313);commit;
select * from test.bug_report;commit;
--ERROR:  XX000: invalid memory alloc request size 18446744073709551613
--LOCATION:  palloc, mcxt.c:934


-- Once the "hostname_short" column no longer references any other column, I
am unable to reproduce this error
CREATE TABLE if not exists test.bug_report2
(
    id bigint generated by default as identity,
    hostname varchar,
    hostname_short varchar GENERATED ALWAYS AS ('static_string') STORED,
    device text,
    mount text,
    used_space_bytes bigint,
    used_space_gb numeric GENERATED ALWAYS AS (ROUND(used_space_bytes /
1073741824.0,2)) STORED,
    avail_space_bytes bigint,
    avail_space_gb numeric GENERATED ALWAYS AS (ROUND(avail_space_bytes /
1073741824.0,2)) STORED,
    inserted_dts timestamp with time zone NOT NULL DEFAULT
clock_timestamp(),
    inserted_by text NOT NULL DEFAULT session_user
);commit;

INSERT INTO test.bug_report2(hostname, device, mount, used_space_bytes,
avail_space_bytes) VALUES ('12345678901234567890', 'devtmpfs', '/dev', 0,
6047076131313);commit;
select * from test.bug_report2;commit;

INSERT INTO test.bug_report2(hostname, device, mount, used_space_bytes,
avail_space_bytes) VALUES ('abc', 'devtmpfs', '/dev', 0,
6047076131313);commit;
select * from test.bug_report2;commit;

-- simply referencing another column in the generated column will cause a
crash
CREATE TABLE if not exists test.bug_report3
(
    id bigint generated by default as identity,
    hostname varchar,
    hostname_short varchar GENERATED ALWAYS AS (hostname) STORED,
    device text,
    mount text,
    used_space_bytes bigint,
    used_space_gb numeric GENERATED ALWAYS AS (ROUND(used_space_bytes /
1073741824.0,2)) STORED,
    avail_space_bytes bigint,
    avail_space_gb numeric GENERATED ALWAYS AS (ROUND(avail_space_bytes /
1073741824.0,2)) STORED,
    inserted_dts timestamp with time zone NOT NULL DEFAULT
clock_timestamp(),
    inserted_by text NOT NULL DEFAULT session_user
);commit;

-- immediate crash
INSERT INTO test.bug_report3(hostname, device, mount, used_space_bytes,
avail_space_bytes) VALUES ('12345678901234567890', 'devtmpfs', '/dev', 0,
6047076131313);commit;

-- no crash on insert
INSERT INTO test.bug_report3(hostname, device, mount, used_space_bytes,
avail_space_bytes) VALUES ('abc', 'devtmpfs', '/dev', 0,
6047076131313);commit;
-- error thrown on select
select * from test.bug_report3;commit;
--ERROR:  XX000: invalid memory alloc request size 18446744073709551613
--LOCATION:  palloc, mcxt.c:934

Messages

DateAuthorSubject
2020-04-15 20:20:35+00PG Bug reporting formBUG #16369: Segmentation Faults and Data Corruption with Generated Columns
2020-04-15 23:35:57+00David RowleyRe: BUG #16369: Segmentation Faults and Data Corruption with Generated Columns
2020-04-15 23:52:21+00Tom LaneRe: BUG #16369: Segmentation Faults and Data Corruption with Generated Columns
2020-04-16 00:40:24+00David RowleyRe: BUG #16369: Segmentation Faults and Data Corruption with Generated Columns
2020-04-16 05:30:36+00Michael PaquierRe: BUG #16369: Segmentation Faults and Data Corruption with Generated Columns
2020-04-17 09:04:46+00Peter EisentrautRe: BUG #16369: Segmentation Faults and Data Corruption with Generated Columns
2020-04-17 10:01:26+00David RowleyRe: BUG #16369: Segmentation Faults and Data Corruption with Generated Columns
2020-04-17 17:06:23+00Terry SchmittRe: BUG #16369: Segmentation Faults and Data Corruption with Generated Columns
2020-04-18 02:13:17+00David RowleyRe: BUG #16369: Segmentation Faults and Data Corruption with Generated Columns
2020-04-18 09:28:56+00Michael PaquierRe: BUG #16369: Segmentation Faults and Data Corruption with Generated Columns