Tables created WITH OIDS cannot be dumped/restored properly
От | Derek Nelson |
---|---|
Тема | Tables created WITH OIDS cannot be dumped/restored properly |
Дата | |
Msg-id | e002deb9-dbe2-25c0-3e71-7bd9a756138a@pipelinedb.com обсуждение исходный текст |
Ответы |
Re: Tables created WITH OIDS cannot be dumped/restored properly
|
Список | 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!
Вложения
В списке pgsql-bugs по дате отправления: