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

Поиск
Список
Период
Сортировка
От Rushabh Lathia
Тема Re: [Segmentation fault] pg_dump binary-upgrade fail for type without element
Дата
Msg-id CAGPqQf1F2hfsXuPdmE_AyKtajqiP6X=HktcOVskz9gyL9NM_Gw@mail.gmail.com
обсуждение исходный текст
Ответ на [Segmentation fault] pg_dump binary-upgrade fail for type without element  (Rushabh Lathia <rushabh.lathia@gmail.com>)
Ответы Re: [Segmentation fault] pg_dump binary-upgrade fail for type without element
Список pgsql-hackers
PFA patch patch for the master branch.

On Thu, Oct 16, 2014 at 11:09 AM, Rushabh Lathia <rushabh.lathia@gmail.com> wrote:
Hi All,

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

Consider the following testcase:

rushabh@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@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@momjian.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



--
Rushabh Lathia
Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Craig Ringer
Дата:
Сообщение: Re: CREATE POLICY and RETURNING
Следующее
От: Etsuro Fujita
Дата:
Сообщение: Re: Improve automatic analyze messages for inheritance trees