[Segmentation fault] pg_dump binary-upgrade fail for type without element

From: Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: [Segmentation fault] pg_dump binary-upgrade fail for type without element
Date: 2014-10-16 05:39:35
Message-ID: CAGPqQf04kSdwjyjpd0V54yYX-hToNDFGJawdutHWP7gYNw2g9Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi All,

pg_dump binary-upgrade fail with segmentation fault for type without
element.

Consider the following testcase:

rushabh(at)postgresql$ ./db/bin/psql postgres
psql (9.5devel)
Type "help" for help.

postgres=# drop type typ;
DROP TYPE
postgres=# create type typ as ();
CREATE TYPE
postgres=# \q
rushabh(at)postgresql$ ./db/bin/pg_dump postgres --binary-upgrade
pg_dump: row number 0 is out of range 0..-1
Segmentation fault (core dumped)

Stake trace:

(gdb) bt
#0 0x0000003a2cc375f2 in ____strtoull_l_internal () from /lib64/libc.so.6
#1 0x0000000000417a08 in dumpCompositeType (fout=0x1365200,
tyinfo=0x13b1340) at pg_dump.c:9356
#2 0x00000000004156a2 in dumpType (fout=0x1365200, tyinfo=0x13b1340) at
pg_dump.c:8449
#3 0x0000000000414b08 in dumpDumpableObject (fout=0x1365200,
dobj=0x13b1340) at pg_dump.c:8135
#4 0x00000000004041f8 in main (argc=3, argv=0x7fff838ff6e8) at
pg_dump.c:812

Into dumpCompositeType(), query fetch the elements for the composite type,
but in case there are no elements for the type then it returns zero rows. In
the following code block:

if (binary_upgrade)
{
Oid typrelid = atooid(PQgetvalue(res, 0, i_typrelid));

binary_upgrade_set_type_oids_by_type_oid(fout, q,
tyinfo->dobj.catId.oid);
binary_upgrade_set_pg_class_oids(fout, q, typrelid, false);
}

it fetching the typrelid which require for binary_upgrade. But in case query
is returning zero rows (for the composite type without element) is failing.

Looking further into code I found that rather then fetching typrelid, we can
use the already stored typrelid from TypeInfo structure.

Following commit added code related to binary_upgrade:

commit 28f6cab61ab8958b1a7dfb019724687d92722538
Author: Bruce Momjian <bruce(at)momjian(dot)us>
Date: Wed Jan 6 05:18:18 2010 +0000

binary upgrade:

Preserve relfilenodes for views and composite types --- even though we
don't store data in, them, they do consume relfilenodes.

Bump catalog version.

PFA patch to fix the issue. I think this need to fix in the back branch as
well
because its effecting pg_upgrade. Fix should backport till PG91, as on PG90
it was not allowed to create type without element.

postgres=# select version();

version
-------------------------------------------------------------------------------------------------------------------
PostgreSQL 9.0.18 on x86_64-unknown-linux-gnu, compiled by GCC gcc (GCC)
4.4.7 20120313 (Red Hat 4.4.7-4), 64-bit
(1 row)
postgres=# create type typ as ();
ERROR: syntax error at or near ")"
LINE 1: create type typ as ();
^

Regards,
Rushabh Lathia
www.EnterpriseDB.com

Attachment Content-Type Size
type_without_element.patch text/x-diff 2.0 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Craig Ringer 2014-10-16 05:44:02 Re: CREATE POLICY and RETURNING
Previous Message Amit Kapila 2014-10-16 05:05:21 Re: TODO : Allow parallel cores to be used by vacuumdb [ WIP ]