diff options
author | Andres Freund <andres@anarazel.de> | 2018-11-20 15:36:57 -0800 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2018-11-20 16:00:17 -0800 |
commit | 578b229718e8f15fa779e20f086c4b6bb3776106 (patch) | |
tree | 701869752158d27daa080d292befeb2e52f19037 /src/bin/pg_dump/pg_backup_archiver.c | |
parent | 0999ac479292c12a7c373e612b15e1ff47077990 (diff) | |
download | postgresql-578b229718e8f15fa779e20f086c4b6bb3776106.tar.gz |
Remove WITH OIDS support, change oid catalog column visibility.
Previously tables declared WITH OIDS, including a significant fraction
of the catalog tables, stored the oid column not as a normal column,
but as part of the tuple header.
This special column was not shown by default, which was somewhat odd,
as it's often (consider e.g. pg_class.oid) one of the more important
parts of a row. Neither pg_dump nor COPY included the contents of the
oid column by default.
The fact that the oid column was not an ordinary column necessitated a
significant amount of special case code to support oid columns. That
already was painful for the existing, but upcoming work aiming to make
table storage pluggable, would have required expanding and duplicating
that "specialness" significantly.
WITH OIDS has been deprecated since 2005 (commit ff02d0a05280e0).
Remove it.
Removing includes:
- CREATE TABLE and ALTER TABLE syntax for declaring the table to be
WITH OIDS has been removed (WITH (oids[ = true]) will error out)
- pg_dump does not support dumping tables declared WITH OIDS and will
issue a warning when dumping one (and ignore the oid column).
- restoring an pg_dump archive with pg_restore will warn when
restoring a table with oid contents (and ignore the oid column)
- COPY will refuse to load binary dump that includes oids.
- pg_upgrade will error out when encountering tables declared WITH
OIDS, they have to be altered to remove the oid column first.
- Functionality to access the oid of the last inserted row (like
plpgsql's RESULT_OID, spi's SPI_lastoid, ...) has been removed.
The syntax for declaring a table WITHOUT OIDS (or WITH (oids = false)
for CREATE TABLE) is still supported. While that requires a bit of
support code, it seems unnecessary to break applications / dumps that
do not use oids, and are explicit about not using them.
The biggest user of WITH OID columns was postgres' catalog. This
commit changes all 'magic' oid columns to be columns that are normally
declared and stored. To reduce unnecessary query breakage all the
newly added columns are still named 'oid', even if a table's column
naming scheme would indicate 'reloid' or such. This obviously
requires adapting a lot code, mostly replacing oid access via
HeapTupleGetOid() with access to the underlying Form_pg_*->oid column.
The bootstrap process now assigns oids for all oid columns in
genbki.pl that do not have an explicit value (starting at the largest
oid previously used), only oids assigned later by oids will be above
FirstBootstrapObjectId. As the oid column now is a normal column the
special bootstrap syntax for oids has been removed.
Oids are not automatically assigned during insertion anymore, all
backend code explicitly assigns oids with GetNewOidWithIndex(). For
the rare case that insertions into the catalog via SQL are called for
the new pg_nextoid() function can be used (which only works on catalog
tables).
The fact that oid columns on system tables are now normal columns
means that they will be included in the set of columns expanded
by * (i.e. SELECT * FROM pg_class will now include the table's oid,
previously it did not). It'd not technically be hard to hide oid
column by default, but that'd mean confusing behavior would either
have to be carried forward forever, or it'd cause breakage down the
line.
While it's not unlikely that further adjustments are needed, the
scope/invasiveness of the patch makes it worthwhile to get merge this
now. It's painful to maintain externally, too complicated to commit
after the code code freeze, and a dependency of a number of other
patches.
Catversion bump, for obvious reasons.
Author: Andres Freund, with contributions by John Naylor
Discussion: https://postgr.es/m/20180930034810.ywp2c7awz7opzcfr@alap3.anarazel.de
Diffstat (limited to 'src/bin/pg_dump/pg_backup_archiver.c')
-rw-r--r-- | src/bin/pg_dump/pg_backup_archiver.c | 72 |
1 files changed, 5 insertions, 67 deletions
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index defa8a41b7..58bd3805f4 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -80,7 +80,6 @@ static void _printTocEntry(ArchiveHandle *AH, TocEntry *te, bool isData); static char *replace_line_endings(const char *str); static void _doSetFixedOutputState(ArchiveHandle *AH); static void _doSetSessionAuth(ArchiveHandle *AH, const char *user); -static void _doSetWithOids(ArchiveHandle *AH, const bool withOids); static void _reconnectToDB(ArchiveHandle *AH, const char *dbname); static void _becomeUser(ArchiveHandle *AH, const char *user); static void _becomeOwner(ArchiveHandle *AH, TocEntry *te); @@ -1072,7 +1071,7 @@ ArchiveEntry(Archive *AHX, const char *tag, const char *namespace, const char *tablespace, - const char *owner, bool withOids, + const char *owner, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, @@ -1101,7 +1100,6 @@ ArchiveEntry(Archive *AHX, newToc->namespace = namespace ? pg_strdup(namespace) : NULL; newToc->tablespace = tablespace ? pg_strdup(tablespace) : NULL; newToc->owner = pg_strdup(owner); - newToc->withOids = withOids; newToc->desc = pg_strdup(desc); newToc->defn = pg_strdup(defn); newToc->dropStmt = pg_strdup(dropStmt); @@ -2369,7 +2367,6 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt, AH->currUser = NULL; /* unknown */ AH->currSchema = NULL; /* ditto */ AH->currTablespace = NULL; /* ditto */ - AH->currWithOids = -1; /* force SET */ AH->toc = (TocEntry *) pg_malloc0(sizeof(TocEntry)); @@ -2597,7 +2594,7 @@ WriteToc(ArchiveHandle *AH) WriteStr(AH, te->namespace); WriteStr(AH, te->tablespace); WriteStr(AH, te->owner); - WriteStr(AH, te->withOids ? "true" : "false"); + WriteStr(AH, "false"); /* Dump list of dependencies */ for (i = 0; i < te->nDeps; i++) @@ -2699,15 +2696,9 @@ ReadToc(ArchiveHandle *AH) te->tablespace = ReadStr(AH); te->owner = ReadStr(AH); - if (AH->version >= K_VERS_1_9) - { - if (strcmp(ReadStr(AH), "true") == 0) - te->withOids = true; - else - te->withOids = false; - } - else - te->withOids = true; + if (AH->version < K_VERS_1_9 || strcmp(ReadStr(AH), "true") == 0) + write_msg(modulename, + "WARNING: restoring tables WITH OIDS is not supported anymore"); /* Read TOC entry dependencies */ if (AH->version >= K_VERS_1_5) @@ -3254,38 +3245,6 @@ _doSetSessionAuth(ArchiveHandle *AH, const char *user) /* - * Issue a SET default_with_oids command. Caller is responsible - * for updating state if appropriate. - */ -static void -_doSetWithOids(ArchiveHandle *AH, const bool withOids) -{ - PQExpBuffer cmd = createPQExpBuffer(); - - appendPQExpBuffer(cmd, "SET default_with_oids = %s;", withOids ? - "true" : "false"); - - if (RestoringToDB(AH)) - { - PGresult *res; - - res = PQexec(AH->connection, cmd->data); - - if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) - warn_or_exit_horribly(AH, modulename, - "could not set default_with_oids: %s", - PQerrorMessage(AH->connection)); - - PQclear(res); - } - else - ahprintf(AH, "%s\n\n", cmd->data); - - destroyPQExpBuffer(cmd); -} - - -/* * Issue the commands to connect to the specified database. * * If we're currently restoring right into a database, this will @@ -3329,7 +3288,6 @@ _reconnectToDB(ArchiveHandle *AH, const char *dbname) if (AH->currTablespace) free(AH->currTablespace); AH->currTablespace = NULL; - AH->currWithOids = -1; /* re-establish fixed state */ _doSetFixedOutputState(AH); @@ -3377,20 +3335,6 @@ _becomeOwner(ArchiveHandle *AH, TocEntry *te) /* - * Set the proper default_with_oids value for the table. - */ -static void -_setWithOids(ArchiveHandle *AH, TocEntry *te) -{ - if (AH->currWithOids != te->withOids) - { - _doSetWithOids(AH, te->withOids); - AH->currWithOids = te->withOids; - } -} - - -/* * Issue the commands to select the specified schema as the current schema * in the target database. */ @@ -3604,10 +3548,6 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, bool isData) _selectOutputSchema(AH, te->namespace); _selectTablespace(AH, te->tablespace); - /* Set up OID mode too */ - if (strcmp(te->desc, "TABLE") == 0) - _setWithOids(AH, te); - /* Emit header comment for item */ if (!AH->noTocComments) { @@ -4081,7 +4021,6 @@ restore_toc_entries_prefork(ArchiveHandle *AH, TocEntry *pending_list) if (AH->currTablespace) free(AH->currTablespace); AH->currTablespace = NULL; - AH->currWithOids = -1; } /* @@ -4877,7 +4816,6 @@ CloneArchive(ArchiveHandle *AH) clone->currUser = NULL; clone->currSchema = NULL; clone->currTablespace = NULL; - clone->currWithOids = -1; /* savedPassword must be local in case we change it while connecting */ if (clone->savedPassword) |