BUG #16369: Segmentation Faults and Data Corruption with Generated Columns - Mailing list pgsql-bugs
From | PG Bug reporting form |
---|---|
Subject | BUG #16369: Segmentation Faults and Data Corruption with Generated Columns |
Date | |
Msg-id | 16369-5845a6f1bef59884@postgresql.org Whole thread Raw |
Responses |
Re: BUG #16369: Segmentation Faults and Data Corruption withGenerated Columns
|
List | pgsql-bugs |
The following bug has been logged on the website: Bug reference: 16369 Logged by: Cameron Ezell Email address: cameron.ezell@clearcapital.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
pgsql-bugs by date: