pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedpg_dump and pg_restore on inherited tables problem
3+ messages / 3 participants
[nested] [flat]
* pg_dump and pg_restore on inherited tables problem
@ 2017-09-04 09:00 Piotr S <stegiszn@gmail.com>
2017-09-04 15:24 ` Re: pg_dump and pg_restore on inherited tables problem Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 3+ messages in thread
From: Piotr S @ 2017-09-04 09:00 UTC (permalink / raw)
To: pgsql-bugs
Hello, i think there is a problem with some specify situation when source
database was set different default value between main and inherited table.
This test was created on:
OS: Windows 10 Pro
Machine:
- Intel(R) Core(TM) i5-2500K CPU @ 3.30 GHz 3.30 GHz
- RAM 8GB
- x64 architecture
Database: PostgreSQL 9.6.5, compiled by Visual C++ build 1800, 64-bit
What to do is in the todo.txt
Best regards,
Piotr
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
todo.txt (text/plain, 1.5K) download
--STEP 1
createdb.exe -E UTF8 -O postgres -h localhost -p 5440 -U postgres "55555"
--STEP 2
CREATE TABLE test(
id int8,
inh_level int8,
description varchar(100)
) without oids;
CREATE TABLE test_otw(PRIMARY KEY (id)) inherits (test);
ALTER TABLE test ADD PRIMARY KEY(id, inh_level);
ALTER TABLE only test ALTER COLUMN inh_level SET DEFAULT 0;
ALTER TABLE only test_otw ALTER COLUMN inh_level SET DEFAULT NULL;
INSERT INTO test(id, description) VALUES (1, 'some test row');
INSERT INTO test_otw(id, description) VALUES (1, 'some test row');
--STEP 3
pg_dump.exe --host localhost --port 5440 --username "postgres" --format custom --blobs --inserts --column-inserts --verbose --file "reload.backup" "55"
--STEP 4
dropdb.exe -h localhost -p 5440 -U postgres "66"
--STEP 5
createdb.exe -E UTF8 -O postgres -h localhost -p 5440 -U postgres "66"
--STEP 6
pg_restore.exe -h localhost -p 5440 -U postgres -d "66" -v "reload.backup"
--STEP 7
--RESULTS AFTER RESTORE
/*
55=# select * from only test;
id | inh_level | description
----+-----------+---------------
1 | 0 | some test row
55=# select * from only test_otw;
id | inh_level | description
----+-----------+---------------
1 | | some test row
66=# select * from only test;
id | inh_level | description
----+-----------+---------------
1 | 0 | some test row
66=# select * from only test_otw;
id | inh_level | description
----+-----------+-------------
*/
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: pg_dump and pg_restore on inherited tables problem
2017-09-04 09:00 pg_dump and pg_restore on inherited tables problem Piotr S <stegiszn@gmail.com>
@ 2017-09-04 15:24 ` Tom Lane <tgl@sss.pgh.pa.us>
2017-09-04 23:06 ` Re: pg_dump and pg_restore on inherited tables problem Michael Paquier <michael.paquier@gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Tom Lane @ 2017-09-04 15:24 UTC (permalink / raw)
To: Piotr S <stegiszn@gmail.com>; +Cc: pgsql-bugs
Piotr S <stegiszn@gmail.com> writes:
> Hello, i think there is a problem with some specify situation when source
> database was set different default value between main and inherited table.
The problem here is that your child table doesn't have a not-null
constraint on the inh_level column, while the parent does. That's
a logically inconsistent situation, and it's not really pg_dump's
fault that it fails to reproduce it exactly.
We've fixed that problem in v10: now, the child table inherits the
not-null constraint when you do the ALTER ADD PRIMARY KEY. So your setup
script fails to insert the inconsistent data:
d1=# INSERT INTO test_otw(id, description) VALUES (1, 'some test row');
ERROR: null value in column "inh_level" violates not-null constraint
DETAIL: Failing row contains (1, null, some test row).
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: pg_dump and pg_restore on inherited tables problem
2017-09-04 09:00 pg_dump and pg_restore on inherited tables problem Piotr S <stegiszn@gmail.com>
2017-09-04 15:24 ` Re: pg_dump and pg_restore on inherited tables problem Tom Lane <tgl@sss.pgh.pa.us>
@ 2017-09-04 23:06 ` Michael Paquier <michael.paquier@gmail.com>
0 siblings, 0 replies; 3+ messages in thread
From: Michael Paquier @ 2017-09-04 23:06 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Piotr S <stegiszn@gmail.com>; pgsql-bugs
On Tue, Sep 5, 2017 at 12:24 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> We've fixed that problem in v10: now, the child table inherits the
> not-null constraint when you do the ALTER ADD PRIMARY KEY.
Here is the result commit, with a reference to the thread:
commit: c30f1770a93db1492755934048656ea809c1f569
author: Tom Lane <tgl@sss.pgh.pa.us>
date: Fri, 4 Aug 2017 11:45:18 -0400
Apply ALTER ... SET NOT NULL recursively in ALTER ... ADD PRIMARY KEY.
If you do ALTER COLUMN SET NOT NULL against an inheritance parent table,
it will recurse to mark all the child columns as NOT NULL as well. This
is necessary for consistency: if the column is labeled NOT NULL then
reading it should never produce nulls.
However, that didn't happen in the case where ALTER ... ADD PRIMARY KEY
marks a target column NOT NULL that wasn't before. That was questionable
from the beginning, and now Tushar Ahuja points out that it can lead to
dump/restore failures in some cases. So let's make that case recurse too.
Although this is meant to fix a bug, it's enough of a behavioral change
that I'm pretty hesitant to back-patch, especially in view of the lack
of similar field complaints. It doesn't seem to be too late to put it
into v10 though.
Michael Paquier, editorialized on slightly by me
Discussion: https://postgr.es/m/b8794d6a-38f0-9d7c-ad4b-e85adf860fc9@enterprisedb.com
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2017-09-04 23:06 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-09-04 09:00 pg_dump and pg_restore on inherited tables problem Piotr S <stegiszn@gmail.com>
2017-09-04 15:24 ` Tom Lane <tgl@sss.pgh.pa.us>
2017-09-04 23:06 ` Michael Paquier <michael.paquier@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox