Browse Source

postgres: drop use of 'WITH OIDS'

PostgreSQL since version 12 no longer supports 'WITH OIDS':
Previously, a normally-invisible oid column could be specified during
table creation using WITH OIDS; that ability has been removed. Columns
can still be explicitly declared as type oid. Operations on tables that
have columns created using WITH OIDS will need adjustment.
The system catalogs that previously had hidden oid columns now have
ordinary oid columns. Hence, SELECT * will now output those columns,
whereas previously they would be displayed only if selected explicitly.

Drop 'WITH OIDS' as it was stated even on tables for plugins which
didn't make any use of the then exposed 'oid' column.
In the case of datacache and datastore the 'oid' column is used,
so replace the 'WITH OIDS' statement with an explicit 'oid' column
having 'OID' type and a corresponding sequence.

No measures are taken to still work with PostgreSQL before version 12.
Users should update PostgreSQL to version 12 or newer.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle 3 years ago
parent
commit
daa0f22b63

+ 1 - 1
configure.ac

@@ -1335,7 +1335,7 @@ CPPFLAGS=$SAVE_CPPFLAGS
 
 # test for postgres:
 postgres=false
-AX_LIB_POSTGRESQL([9.5],
+AX_LIB_POSTGRESQL([12.0],
   [CPPFLAGS="$CPPFLAGS $POSTGRESQL_CPPFLAGS"
    AC_CHECK_HEADERS([libpq-fe.h],
    postgres=true)

+ 7 - 2
src/datacache/plugin_datacache_postgres.c

@@ -67,14 +67,19 @@ static int
 init_connection (struct Plugin *plugin)
 {
   struct GNUNET_PQ_ExecuteStatement es[] = {
+    GNUNET_PQ_make_try_execute ("CREATE TEMPORARY SEQUENCE IF NOT EXISTS gn011dc_oid_seq"),
     GNUNET_PQ_make_execute ("CREATE TEMPORARY TABLE IF NOT EXISTS gn011dc ("
+                            "  oid OID NOT NULL DEFAULT nextval('gn011dc_oid_seq'),"
                             "  type INTEGER NOT NULL,"
                             "  prox INTEGER NOT NULL,"
                             "  discard_time BIGINT NOT NULL,"
                             "  key BYTEA NOT NULL,"
                             "  value BYTEA NOT NULL,"
-                            "  path BYTEA DEFAULT NULL)"
-                            "WITH OIDS"),
+                            "  path BYTEA DEFAULT NULL)"),
+    GNUNET_PQ_make_try_execute (
+      "ALTER SEQUENCE gnu011dc_oid_seq OWNED BY gn011dc.oid"),
+    GNUNET_PQ_make_try_execute (
+      "CREATE INDEX IF NOT EXISTS idx_oid ON gn011dc (oid)"),
     GNUNET_PQ_make_try_execute (
       "CREATE INDEX IF NOT EXISTS idx_key ON gn011dc (key)"),
     GNUNET_PQ_make_try_execute (

+ 10 - 4
src/datastore/plugin_datastore_postgres.c

@@ -72,8 +72,10 @@ init_connection (struct Plugin *plugin)
      * we only test equality on it and can cast it to/from uint32_t. For repl, prio, and anonLevel
      * we do math or inequality tests, so we can't handle the entire range of uint32_t.
      * This will also cause problems for expiration times after 294247-01-10-04:00:54 UTC.
-     * PostgreSQL also recommends against using WITH OIDS.
-     */GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS gn090 ("
+     */
+    GNUNET_PQ_make_try_execute (
+      "CREATE SEQUENCE IF NOT EXISTS gn090_oid_seq"),
+    GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS gn090 ("
                             "  repl INTEGER NOT NULL DEFAULT 0,"
                             "  type INTEGER NOT NULL DEFAULT 0,"
                             "  prio INTEGER NOT NULL DEFAULT 0,"
@@ -82,8 +84,12 @@ init_connection (struct Plugin *plugin)
                             "  rvalue BIGINT NOT NULL DEFAULT 0,"
                             "  hash BYTEA NOT NULL DEFAULT '',"
                             "  vhash BYTEA NOT NULL DEFAULT '',"
-                            "  value BYTEA NOT NULL DEFAULT '')"
-                            "WITH OIDS"),
+                            "  value BYTEA NOT NULL DEFAULT '',"
+                            "  oid OID NOT NULL DEFAULT nextval('gn090_oid_seq'))"),
+    GNUNET_PQ_make_try_execute (
+      "ALTER SEQUENCE gn090_oid_seq OWNED BY gn090.oid"),
+    GNUNET_PQ_make_try_execute (
+      "CREATE INDEX IF NOT EXISTS oid_hash ON gn090 (oid)"),
     GNUNET_PQ_make_try_execute (
       "CREATE INDEX IF NOT EXISTS idx_hash ON gn090 (hash)"),
     GNUNET_PQ_make_try_execute (

+ 2 - 4
src/namecache/plugin_namecache_postgres.c

@@ -64,15 +64,13 @@ database_setup (struct Plugin *plugin)
                             " query BYTEA NOT NULL DEFAULT '',"
                             " block BYTEA NOT NULL DEFAULT '',"
                             " expiration_time BIGINT NOT NULL DEFAULT 0"
-                            ")"
-                            "WITH OIDS");
+                            ")");
   struct GNUNET_PQ_ExecuteStatement es_default =
     GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS ns096blocks ("
                             " query BYTEA NOT NULL DEFAULT '',"
                             " block BYTEA NOT NULL DEFAULT '',"
                             " expiration_time BIGINT NOT NULL DEFAULT 0"
-                            ")"
-                            "WITH OIDS");
+                            ")");
   const struct GNUNET_PQ_ExecuteStatement *cr;
 
   if (GNUNET_YES ==

+ 2 - 4
src/namestore/plugin_namestore_postgres.c

@@ -73,8 +73,7 @@ database_setup (struct Plugin *plugin)
       " record_data BYTEA NOT NULL DEFAULT '',"
       " label TEXT NOT NULL DEFAULT '',"
       " CONSTRAINT zl UNIQUE (zone_private_key,label)"
-      ")"
-      "WITH OIDS");
+      ")");
   struct GNUNET_PQ_ExecuteStatement es_default =
     GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS ns098records ("
                             " seq BIGSERIAL PRIMARY KEY,"
@@ -85,8 +84,7 @@ database_setup (struct Plugin *plugin)
                             " record_data BYTEA NOT NULL DEFAULT '',"
                             " label TEXT NOT NULL DEFAULT '',"
                             " CONSTRAINT zl UNIQUE (zone_private_key,label)"
-                            ")"
-                            "WITH OIDS");
+                            ")");
   const struct GNUNET_PQ_ExecuteStatement *cr;
   struct GNUNET_PQ_ExecuteStatement sc = GNUNET_PQ_EXECUTE_STATEMENT_END;