BUG #14325: backup restore inherited constraint

Started by Nonameover 9 years ago3 messagesbugs
Jump to latest
#1Noname
vbv256@yandex.ru

The following bug has been logged on the website:

Bug reference: 14325
Logged by: Boris Vuks
Email address: vbv256@yandex.ru
PostgreSQL version: 9.5.4
Operating system: Slackware64. Build from source.
Description:

Incorrect dumping inherited table constraint.

If child table has field with removed inherit constraint.
In dump file this constraint not removed and data not restored correctly.
Problem also exist in PostgreSQL 9.1. Before this version appropriate
construction not used by me.

-- --- to reproduce problem ----------
bash$ psql template1
template1=# create database test;
template1=# \c test

test=# create table test_parent(
field1 int,
field2 int not null
);

test=# create table test(
)inherits(test_parent);

test=# alter table test alter COLUMN field2 drop not null;

test=# insert into test(field1, field2)
values(1,1),
(1,null);

test=# \d test
Table "public.test"
Column | Type | Modifiers
--------+---------+-----------
field1 | integer |
field2 | integer |
Inherits: test_parent

-- ..... COMMENT: modifiers of field2 is empty.......
test=# \q

bash$ pg_dump -C test > test.sql
bash$ psql template1
template1=# drop database test;
template1=# \q

bash$ psql template1 < test.sql
......
ERROR: null value in column "field2" violates not-null constraint
DETAIL: Failing row contains (1, null).
CONTEXT: COPY test, line 2: "1 \N"
COPY 0
.......

bash$ psql test
test=# \d test
Table "public.test"
Column | Type | Modifiers
--------+---------+-----------
field1 | integer |
field2 | integer | not null
Inherits: test_parent

-- ..... COMMENT: modifiers of field2 is not empty .......

\q

-- ----------end ----------------
in result table test has field2 with constraint NOT NULL :(

Sorry for my bad english.

PS: System Detail:
# uname -a
Linux v 4.7.0 #1 SMP Mon Aug 1 03:59:35 EEST 2016 x86_64 Intel(R) Core(TM)2
Quad CPU Q8300 @ 2.50GHz GenuineIntel GNU/Linux

PostgreSQL configure line:
./configure \
--prefix=/usr \
--libdir=/usr/lib64 \
--with-perl \
--with-python \
--with-openssl \
--with-libxml \
--with-libxslt

PS1: Currently I solve this problem use modify dump with 'sed' by adding
ALTER for remove constraint from field in this case for table 'test'.

PS2: I'am undestand logical incorrection this construction.
If parent requre field value, then child should not remove this constraint.

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#2Michael Paquier
michael@paquier.xyz
In reply to: Noname (#1)
Re: BUG #14325: backup restore inherited constraint

On Fri, Sep 16, 2016 at 3:27 PM, <vbv256@yandex.ru> wrote:

If child table has field with removed inherit constraint.
In dump file this constraint not removed and data not restored correctly.
Problem also exist in PostgreSQL 9.1. Before this version appropriate
construction not used by me.

-- --- to reproduce problem ----------
bash$ psql template1
template1=# create database test;
template1=# \c test

[... test ...]

What we ought to do here is forbid DROP NOT NULL on the table test.
See here for example:
/messages/by-id/21633.1448383428@sss.pgh.pa.us
So this is a known limiration, and there have been some discussions
about removing this limitation in the backend, like here:
/messages/by-id/CAKOSWNkN6HSyatuys8xZxzRCR-KL1OkHS5-b9qd9bf1Rad3PLA@mail.gmail.com
But there is no concrete patch lately. I don't think it would be
*that* complicated to get a rebased and polished version of what has
been proposed. It just needs care and time.

Sorry for my bad english.

I think that's fine! And I am no native speaker either.
--
Michael

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#3Nikolay Samokhvalov
samokhvalov@gmail.com
In reply to: Michael Paquier (#2)
Re: BUG #14325: backup restore inherited constraint

On Tue, Sep 20, 2016 at 1:14 AM, Michael Paquier <michael.paquier@gmail.com>
wrote:

On Fri, Sep 16, 2016 at 3:27 PM, <vbv256@yandex.ru> wrote:

If child table has field with removed inherit constraint.
In dump file this constraint not removed and data not restored correctly.
Problem also exist in PostgreSQL 9.1. Before this version appropriate
construction not used by me.

-- --- to reproduce problem ----------
bash$ psql template1
template1=# create database test;
template1=# \c test

[... test ...]

What we ought to do here is forbid DROP NOT NULL on the table test.

+1 for this approach. Just encountered with the same behavior.