pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedTables created WITH OIDS cannot be dumped/restored properly
6+ messages / 2 participants
[nested] [flat]
* Tables created WITH OIDS cannot be dumped/restored properly
@ 2018-11-01 19:56 Derek Nelson <derek@pipelinedb.com>
0 siblings, 1 reply; 6+ messages in thread
From: Derek Nelson @ 2018-11-01 19:56 UTC (permalink / raw)
To: pgsql-bugs
PG version: 11.0
OS: Ubuntu 16.04 (also verified on Ubuntu 14.04 and 18.04)
Package: Binaries installed via official PostgreSQL apt repository
--
Hello PG community! I'm one of the PipelineDB developers (PostgreSQL
extension) and as we've begun adding support for PG 11 our test
infrastructure identified an issue with dumping/restoring tables created
WITH OIDs. Naturally this also affects pg_upgrade.
If a table is created WITH OIDS, dumped and then restored, the resulting
table will not contain the OID column.
I have attached a short script that reproduces the issue reliably (at
least on the aforementioned operating systems), and I'll briefly outline
the steps I took here:
1) Initialize data directory and run server
2) psql -c "CREATE TABLE test (x integer) WITH OIDS"
3) psql -c "SELECT oid FROM test" -> Ok, column is there
4) pg_dump > dump.sql
5) Stop server
6) Initialize new data directory and run server
7) psql -f dump.sql
8) psql -c "SELECT oid FROM test" -> ERROR: column "oid" does not exist
This behavior appears to have been introduced by this commit:
https://github.com/postgres/postgres/commit/9a95a77d9d5d3003d2d67121f
In pg_backup_archiver.c, there is a comparison being done between two
bool fields to determine whether or not to output "SET default_with_oids
= on" before a table's CREATE TABLE dump output:
https://github.com/postgres/postgres/blob/master/src/bin/pg_dump/pg_backup_archiver.c#L3385
And it appears that the above commit changes the bool type from char to
_Bool (assuming stdbool.h is present) which has led to unexpected
results for this comparison. These two bool fields are not only being
set to true and false--they're being set to true, false, and "not set"
(signified by -1). I believe the -1 assignment does not behave as
expected when bool is _Bool.
Ultimately this prevents pg_backup_archiver.c from outputting "SET
default_with_oids = on" prior to the dumped CREATE TABLE command, and
thus the table is created without OIDs.
--
The simplest fix for the issue is to revert the types of these two bool
fields to char, as prior to this commit bool would have been defined as
char. Perhaps a more involved solution is warranted, but this was the
least intrusive way I saw to restore the behavior from prior to the
introduction of stdbool.h.
I've attached a patch containing this change, and would be happy to
submit it elsewhere if necessary or improve upon it based on any
guidance from the community. Thank you!
Attachments:
default-with-oids.patch (text/x-patch, 917B) download
diff --git a/src/bin/pg_dump/pg_backup_archiver.h b/src/bin/pg_dump/pg_backup_archiver.h
index 26dd044..4b814d3 100644
--- a/src/bin/pg_dump/pg_backup_archiver.h
+++ b/src/bin/pg_dump/pg_backup_archiver.h
@@ -347,7 +347,7 @@ struct _archiveHandle
char *currUser; /* current username, or NULL if unknown */
char *currSchema; /* current schema, or NULL */
char *currTablespace; /* current tablespace, or NULL */
- bool currWithOids; /* current default_with_oids setting */
+ char currWithOids; /* current default_with_oids setting */
void *lo_buf;
size_t lo_buf_used;
@@ -375,7 +375,7 @@ struct _tocEntry
char *tablespace; /* null if not in a tablespace; empty string
* means use database default */
char *owner;
- bool withOids; /* Used only by "TABLE" tags */
+ char withOids; /* Used only by "TABLE" tags */
char *desc;
char *defn;
char *dropStmt;
repro.sh (application/x-shellscript, 649B) download
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Tables created WITH OIDS cannot be dumped/restored properly
@ 2018-11-09 08:26 Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
parent: Derek Nelson <derek@pipelinedb.com>
0 siblings, 1 reply; 6+ messages in thread
From: Peter Eisentraut @ 2018-11-09 08:26 UTC (permalink / raw)
To: Derek Nelson <derek@pipelinedb.com>; pgsql-bugs
On 01/11/2018 20:56, Derek Nelson wrote:
> Hello PG community! I'm one of the PipelineDB developers (PostgreSQL
> extension) and as we've begun adding support for PG 11 our test
> infrastructure identified an issue with dumping/restoring tables created
> WITH OIDs. Naturally this also affects pg_upgrade.
>
> If a table is created WITH OIDS, dumped and then restored, the resulting
> table will not contain the OID column.
Good catch. It's actually only if the affected table is the first table
in the output (or perhaps some other narrow circumstances). We do have
a test case for WITH OIDS tables, but that table ends up not the first
in the output.
I propose to apply the attached patch. It's slightly different from
yours in that I don't think we need to change the type of the withOids
field.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Attachments:
0001-pg_dump-Fix-dumping-of-WITH-OIDS-tables.patch (text/plain, 1.4K) download
From 873a4086f1c2939e714743ec2c706bfdf0744855 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Fri, 9 Nov 2018 09:17:25 +0100
Subject: [PATCH] pg_dump: Fix dumping of WITH OIDS tables
A table with OIDs that was the first in the dump output would not get
dumped with OIDs enabled. Fix that.
The reason was that the currWithOids flag was declared to be bool but
actually also takes a -1 value for "don't know yet". But under
stdbool.h semantics, that is coerced to true, so the required SET
default_with_oids command is not output again. Change the variable
type to char to fix that.
Reported-by: Derek Nelson <derek@pipelinedb.com>
---
src/bin/pg_dump/pg_backup_archiver.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/bin/pg_dump/pg_backup_archiver.h b/src/bin/pg_dump/pg_backup_archiver.h
index 26dd0442e8..05e9de632f 100644
--- a/src/bin/pg_dump/pg_backup_archiver.h
+++ b/src/bin/pg_dump/pg_backup_archiver.h
@@ -347,7 +347,8 @@ struct _archiveHandle
char *currUser; /* current username, or NULL if unknown */
char *currSchema; /* current schema, or NULL */
char *currTablespace; /* current tablespace, or NULL */
- bool currWithOids; /* current default_with_oids setting */
+ char currWithOids; /* current default_with_oids setting: true,
+ * false, or -1 for unknown, forcing a SET */
void *lo_buf;
size_t lo_buf_used;
--
2.19.1
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Tables created WITH OIDS cannot be dumped/restored properly
@ 2018-11-12 20:00 Derek Nelson <derek@pipelinedb.com>
parent: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
0 siblings, 1 reply; 6+ messages in thread
From: Derek Nelson @ 2018-11-12 20:00 UTC (permalink / raw)
To: pgsql-bugs
Thanks for the quick turnaround! I considered only changing the type of
currWithOids but thought it may make sense to change both for uniformity as
well as future proofing against a similar issue being introduced again
moving forward. In any case, this seems like a good, minimal fix--thanks
again!
ᐧ
On Fri, Nov 9, 2018 at 12:26 AM, Peter Eisentraut <
peter.eisentraut@2ndquadrant.com> wrote:
> On 01/11/2018 20:56, Derek Nelson wrote:
> > Hello PG community! I'm one of the PipelineDB developers (PostgreSQL
> > extension) and as we've begun adding support for PG 11 our test
> > infrastructure identified an issue with dumping/restoring tables created
> > WITH OIDs. Naturally this also affects pg_upgrade.
> >
> > If a table is created WITH OIDS, dumped and then restored, the resulting
> > table will not contain the OID column.
>
> Good catch. It's actually only if the affected table is the first table
> in the output (or perhaps some other narrow circumstances). We do have
> a test case for WITH OIDS tables, but that table ends up not the first
> in the output.
>
> I propose to apply the attached patch. It's slightly different from
> yours in that I don't think we need to change the type of the withOids
> field.
>
> --
> Peter Eisentraut http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
>
--
Derek Nelson
CEO & Co-Founder, PipelineDB <http://www.pipelinedb.com;
(650) 564-7097 | LinkedIn <http://www.linkedin.com/in/derekjn;
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Tables created WITH OIDS cannot be dumped/restored properly
@ 2018-11-13 08:54 Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
parent: Derek Nelson <derek@pipelinedb.com>
0 siblings, 1 reply; 6+ messages in thread
From: Peter Eisentraut @ 2018-11-13 08:54 UTC (permalink / raw)
To: Derek Nelson <derek@pipelinedb.com>; pgsql-bugs
On 12/11/2018 21:00, Derek Nelson wrote:
> Thanks for the quick turnaround! I considered only changing the type of
> currWithOids but thought it may make sense to change both for uniformity
> as well as future proofing against a similar issue being introduced
> again moving forward. In any case, this seems like a good, minimal
> fix--thanks again!
Committed to master and PG11.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Tables created WITH OIDS cannot be dumped/restored properly
@ 2018-11-15 03:27 Derek Nelson <derek@pipelinedb.com>
parent: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
0 siblings, 1 reply; 6+ messages in thread
From: Derek Nelson @ 2018-11-15 03:27 UTC (permalink / raw)
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: pgsql-bugs
Thank you so much Peter! Is this backported to the official PG11 releases
or will it become available when 11.x is out?
On Tue, Nov 13, 2018, 12:54 AM Peter Eisentraut <
peter.eisentraut@2ndquadrant.com wrote:
> On 12/11/2018 21:00, Derek Nelson wrote:
> > Thanks for the quick turnaround! I considered only changing the type of
> > currWithOids but thought it may make sense to change both for uniformity
> > as well as future proofing against a similar issue being introduced
> > again moving forward. In any case, this seems like a good, minimal
> > fix--thanks again!
>
> Committed to master and PG11.
>
> --
> Peter Eisentraut http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
>
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Tables created WITH OIDS cannot be dumped/restored properly
@ 2018-11-20 08:33 Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
parent: Derek Nelson <derek@pipelinedb.com>
0 siblings, 0 replies; 6+ messages in thread
From: Peter Eisentraut @ 2018-11-20 08:33 UTC (permalink / raw)
To: Derek Nelson <derek@pipelinedb.com>; +Cc: pgsql-bugs
On 15/11/2018 04:27, Derek Nelson wrote:
> Thank you so much Peter! Is this backported to the official PG11
> releases or will it become available when 11.x is out?
I'm not quite sure what the difference between these two statements is.
The fix will be in PG 11.2 in any case.
By the way, we are currently planning on getting rid of WITH OIDS
support altogether in PG 12.
> On Tue, Nov 13, 2018, 12:54 AM Peter Eisentraut
> <peter.eisentraut@2ndquadrant.com
> <mailto:peter.eisentraut@2ndquadrant.com> wrote:
>
> On 12/11/2018 21:00, Derek Nelson wrote:
> > Thanks for the quick turnaround! I considered only changing the
> type of
> > currWithOids but thought it may make sense to change both for
> uniformity
> > as well as future proofing against a similar issue being introduced
> > again moving forward. In any case, this seems like a good, minimal
> > fix--thanks again!
>
> Committed to master and PG11.
>
> --
> Peter Eisentraut http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
>
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2018-11-20 08:33 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-11-01 19:56 Tables created WITH OIDS cannot be dumped/restored properly Derek Nelson <derek@pipelinedb.com>
2018-11-09 08:26 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2018-11-12 20:00 ` Derek Nelson <derek@pipelinedb.com>
2018-11-13 08:54 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2018-11-15 03:27 ` Derek Nelson <derek@pipelinedb.com>
2018-11-20 08:33 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.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