Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gIJcz-0007uR-5b for pgsql-bugs@arkaria.postgresql.org; Thu, 01 Nov 2018 20:31:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gIJcx-0000Sw-4I for pgsql-bugs@arkaria.postgresql.org; Thu, 01 Nov 2018 20:31:39 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gIJ4k-00026N-Li for pgsql-bugs@lists.postgresql.org; Thu, 01 Nov 2018 19:56:18 +0000 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gIJ4h-00074o-4a for pgsql-bugs@postgresql.org; Thu, 01 Nov 2018 19:56:17 +0000 Received: by mail-pf1-x431.google.com with SMTP id i62-v6so1994113pfi.0 for ; Thu, 01 Nov 2018 12:56:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pipelinedb-com.20150623.gappssmtp.com; s=20150623; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=5xl2jFhoX4/SEqnjfZejCXkOfwOOJlFW4WeiyBTaxXI=; b=tBkjn5uBwD6/XlWnSvaAXppSQSlzUVNKOb4bCdUw5mHBYB73kfTW2IxzwlfF9lrcpy Osg8UUyDbh9HS6zKN7ifrqX7DMfR5U3sixKUI7Tn9Zb6YjNf8i3luQIVf0EOsTcl271l 8TcBjdSCtxuxzZdM8L4bBfgxAM7sqTuPCdhHa9HLS9otqn651Q0nhjsn4UwgM08807KF 7ynM9f5plEZBakkQbdFIqjAWiAlL0q32VrmjK27uwGZj6vrFxoiWeDbwX7yG9/jFuzsN vxlYNHChAsx64hdN9lQNmxdqhGbKwpOAN7spnTbUSwJGSjtPovjq61lc+IdyPJEBA+4I JwLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=5xl2jFhoX4/SEqnjfZejCXkOfwOOJlFW4WeiyBTaxXI=; b=ByCPLltGgSNZJP/2pbyy0QFulIqphLfiSMNyAj8xDePB4e5VIeHTLRGjEX4xASzp4k HPzJZAZsdcPBALRUUQ3wdKZaIvb8DdtaQ2mZyqikWc9tZKZRzI1elFGkEMDdFYmDQEBk 9BzzHR3Z8HoqB8SCU/+/Igj422bZtpOgKOQwTjYPrSbSWNCCtrhfo/YOibTzWk60tDk+ wYiQ280soCrUOV8Ht2gi3yFXL5MUNGAItp9wRAadZ1KGN3MIJPNgU4RCXDwC0WtxJAcX l6tB7QjzCCb5IItfvU2yERTj8Gwh3fg3s7A/7a7fZdXGebMdDzufsfki4k2GP+6qUo+9 TqpQ== X-Gm-Message-State: AGRZ1gLiV4nNPHRlcM8PMOgNY5qJEWjFliviLr9NzE7BP1FIQE307U7e 44USWnDWdmpIQyQ9fuT4ObfioY87GeA= X-Google-Smtp-Source: AJdET5fP3BIysogsPfn/9qURZH5pPa9n8PWOR9Y0pEPVlUmNNGXIeYOd/eUHDWhFsVudSaJ/eftgSQ== X-Received: by 2002:a62:2fc1:: with SMTP id v184-v6mr9003058pfv.115.1541102173074; Thu, 01 Nov 2018 12:56:13 -0700 (PDT) Received: from ?IPv6:2605:e000:1521:64:80c8:94ac:1563:922f? ([2605:e000:1521:64:80c8:94ac:1563:922f]) by smtp.gmail.com with ESMTPSA id v20-v6sm51984987pfj.107.2018.11.01.12.56.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Nov 2018 12:56:11 -0700 (PDT) To: pgsql-bugs@postgresql.org From: Derek Nelson Subject: Tables created WITH OIDS cannot be dumped/restored properly Message-ID: Date: Thu, 1 Nov 2018 12:56:10 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------3BDB904971D90C24F602EB09" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------3BDB904971D90C24F602EB09 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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! --------------3BDB904971D90C24F602EB09 Content-Type: text/x-patch; name="default-with-oids.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="default-with-oids.patch" 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; --------------3BDB904971D90C24F602EB09 Content-Type: application/x-shellscript; name="repro.sh" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="repro.sh" ZGF0YWRpcj0iZGVmYXVsdF93aXRoX29pZHNfdGVzdCIKCnJtIC1yZiAkZGF0YWRpciAmJiBp bml0ZGIgLUQgJGRhdGFkaXIKcGdfY3RsIC1EICRkYXRhZGlyIHN0YXJ0IC13Cgpwc3FsIC1k IHBvc3RncmVzIC1jICJDUkVBVEUgVEFCTEUgdGVzdCAoeCBpbnRlZ2VyKSBXSVRIIE9JRFMi CnBzcWwgLWQgcG9zdGdyZXMgLWMgIklOU0VSVCBJTlRPIHRlc3QgKHgpIFZBTFVFUyAoMCki CnBzcWwgLWQgcG9zdGdyZXMgLWMgIlNFTEVDVCBvaWQsIHggRlJPTSB0ZXN0IgojICAgb2lk ICB8IHggCiMgLS0tLS0tLSstLS0KIyAgMTYzODcgfCAwCiMgKDEgcm93KQoKcGdfZHVtcCAt ZCBwb3N0Z3JlcyA+IGRlZmF1bHRfd2l0aF9vaWRzX3Rlc3Quc3FsCnBnX2N0bCAtRCAkZGF0 YWRpciBzdG9wCgpybSAtcmYgJGRhdGFkaXIgJiYgaW5pdGRiIC1EICRkYXRhZGlyCnBnX2N0 bCAtRCAkZGF0YWRpciBzdGFydCAtdwoKcHNxbCAtZCBwb3N0Z3JlcyAtZiBkZWZhdWx0X3dp dGhfb2lkc190ZXN0LnNxbApwc3FsIC1kIHBvc3RncmVzIC1jICJTRUxFQ1Qgb2lkLCB4IEZS T00gdGVzdCIKIyBFUlJPUjogIGNvbHVtbiAib2lkIiBkb2VzIG5vdCBleGlzdAojIExJTkUg MTogU0VMRUNUIG9pZCwgeCBGUk9NIHRlc3QKCnBnX2N0bCAtRCAkZGF0YWRpciBzdG9wIC13 Cg== --------------3BDB904971D90C24F602EB09--