From: | PG Bug reporting form <noreply(at)postgresql(dot)org> |
---|---|
To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
Cc: | cameron(dot)ezell(at)clearcapital(dot)com |
Subject: | BUG #16369: Segmentation Faults and Data Corruption with Generated Columns |
Date: | 2020-04-15 20:20:35 |
Message-ID: | 16369-5845a6f1bef59884@postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
The following bug has been logged on the website:
Bug reference: 16369
Logged by: Cameron Ezell
Email address: cameron(dot)ezell(at)clearcapital(dot)com
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
From | Date | Subject | |
---|---|---|---|
Next Message | David G. Johnston | 2020-04-15 20:21:25 | Re: BUG #16368: Incorrect function inlining in the presence of a window function |
Previous Message | Elvis Pranskevichus | 2020-04-15 20:08:28 | Re: BUG #16368: Incorrect function inlining in the presence of a window function |