LCOV - code coverage report
Current view: top level - src/backend/utils/adt - pg_upgrade_support.c (source / functions) Hit Total Coverage
Test: PostgreSQL 14devel Lines: 44 78 56.4 %
Date: 2020-12-05 17:06:23 Functions: 8 10 80.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  *  pg_upgrade_support.c
       3             :  *
       4             :  *  server-side functions to set backend global variables
       5             :  *  to control oid and relfilenode assignment, and do other special
       6             :  *  hacks needed for pg_upgrade.
       7             :  *
       8             :  *  Copyright (c) 2010-2020, PostgreSQL Global Development Group
       9             :  *  src/backend/utils/adt/pg_upgrade_support.c
      10             :  */
      11             : 
      12             : #include "postgres.h"
      13             : 
      14             : #include "catalog/binary_upgrade.h"
      15             : #include "catalog/heap.h"
      16             : #include "catalog/index.h"
      17             : #include "catalog/namespace.h"
      18             : #include "catalog/pg_type.h"
      19             : #include "commands/extension.h"
      20             : #include "miscadmin.h"
      21             : #include "utils/array.h"
      22             : #include "utils/builtins.h"
      23             : 
      24             : 
      25             : #define CHECK_IS_BINARY_UPGRADE                                 \
      26             : do {                                                            \
      27             :     if (!IsBinaryUpgrade)                                       \
      28             :         ereport(ERROR,                                          \
      29             :                 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),    \
      30             :                  errmsg("function can only be called when server is in binary upgrade mode"))); \
      31             : } while (0)
      32             : 
      33             : Datum
      34        1328 : binary_upgrade_set_next_pg_type_oid(PG_FUNCTION_ARGS)
      35             : {
      36        1328 :     Oid         typoid = PG_GETARG_OID(0);
      37             : 
      38        1328 :     CHECK_IS_BINARY_UPGRADE;
      39        1328 :     binary_upgrade_next_pg_type_oid = typoid;
      40             : 
      41        1328 :     PG_RETURN_VOID();
      42             : }
      43             : 
      44             : Datum
      45        1326 : binary_upgrade_set_next_array_pg_type_oid(PG_FUNCTION_ARGS)
      46             : {
      47        1326 :     Oid         typoid = PG_GETARG_OID(0);
      48             : 
      49        1326 :     CHECK_IS_BINARY_UPGRADE;
      50        1326 :     binary_upgrade_next_array_pg_type_oid = typoid;
      51             : 
      52        1326 :     PG_RETURN_VOID();
      53             : }
      54             : 
      55             : Datum
      56        1330 : binary_upgrade_set_next_heap_pg_class_oid(PG_FUNCTION_ARGS)
      57             : {
      58        1330 :     Oid         reloid = PG_GETARG_OID(0);
      59             : 
      60        1330 :     CHECK_IS_BINARY_UPGRADE;
      61        1330 :     binary_upgrade_next_heap_pg_class_oid = reloid;
      62             : 
      63        1330 :     PG_RETURN_VOID();
      64             : }
      65             : 
      66             : Datum
      67         868 : binary_upgrade_set_next_index_pg_class_oid(PG_FUNCTION_ARGS)
      68             : {
      69         868 :     Oid         reloid = PG_GETARG_OID(0);
      70             : 
      71         868 :     CHECK_IS_BINARY_UPGRADE;
      72         868 :     binary_upgrade_next_index_pg_class_oid = reloid;
      73             : 
      74         868 :     PG_RETURN_VOID();
      75             : }
      76             : 
      77             : Datum
      78         444 : binary_upgrade_set_next_toast_pg_class_oid(PG_FUNCTION_ARGS)
      79             : {
      80         444 :     Oid         reloid = PG_GETARG_OID(0);
      81             : 
      82         444 :     CHECK_IS_BINARY_UPGRADE;
      83         444 :     binary_upgrade_next_toast_pg_class_oid = reloid;
      84             : 
      85         444 :     PG_RETURN_VOID();
      86             : }
      87             : 
      88             : Datum
      89          82 : binary_upgrade_set_next_pg_enum_oid(PG_FUNCTION_ARGS)
      90             : {
      91          82 :     Oid         enumoid = PG_GETARG_OID(0);
      92             : 
      93          82 :     CHECK_IS_BINARY_UPGRADE;
      94          82 :     binary_upgrade_next_pg_enum_oid = enumoid;
      95             : 
      96          82 :     PG_RETURN_VOID();
      97             : }
      98             : 
      99             : Datum
     100           2 : binary_upgrade_set_next_pg_authid_oid(PG_FUNCTION_ARGS)
     101             : {
     102           2 :     Oid         authoid = PG_GETARG_OID(0);
     103             : 
     104           2 :     CHECK_IS_BINARY_UPGRADE;
     105           2 :     binary_upgrade_next_pg_authid_oid = authoid;
     106           2 :     PG_RETURN_VOID();
     107             : }
     108             : 
     109             : Datum
     110           0 : binary_upgrade_create_empty_extension(PG_FUNCTION_ARGS)
     111             : {
     112             :     text       *extName;
     113             :     text       *schemaName;
     114             :     bool        relocatable;
     115             :     text       *extVersion;
     116             :     Datum       extConfig;
     117             :     Datum       extCondition;
     118             :     List       *requiredExtensions;
     119             : 
     120           0 :     CHECK_IS_BINARY_UPGRADE;
     121             : 
     122             :     /* We must check these things before dereferencing the arguments */
     123           0 :     if (PG_ARGISNULL(0) ||
     124           0 :         PG_ARGISNULL(1) ||
     125           0 :         PG_ARGISNULL(2) ||
     126           0 :         PG_ARGISNULL(3))
     127           0 :         elog(ERROR, "null argument to binary_upgrade_create_empty_extension is not allowed");
     128             : 
     129           0 :     extName = PG_GETARG_TEXT_PP(0);
     130           0 :     schemaName = PG_GETARG_TEXT_PP(1);
     131           0 :     relocatable = PG_GETARG_BOOL(2);
     132           0 :     extVersion = PG_GETARG_TEXT_PP(3);
     133             : 
     134           0 :     if (PG_ARGISNULL(4))
     135           0 :         extConfig = PointerGetDatum(NULL);
     136             :     else
     137           0 :         extConfig = PG_GETARG_DATUM(4);
     138             : 
     139           0 :     if (PG_ARGISNULL(5))
     140           0 :         extCondition = PointerGetDatum(NULL);
     141             :     else
     142           0 :         extCondition = PG_GETARG_DATUM(5);
     143             : 
     144           0 :     requiredExtensions = NIL;
     145           0 :     if (!PG_ARGISNULL(6))
     146             :     {
     147           0 :         ArrayType  *textArray = PG_GETARG_ARRAYTYPE_P(6);
     148             :         Datum      *textDatums;
     149             :         int         ndatums;
     150             :         int         i;
     151             : 
     152           0 :         deconstruct_array(textArray,
     153             :                           TEXTOID, -1, false, TYPALIGN_INT,
     154             :                           &textDatums, NULL, &ndatums);
     155           0 :         for (i = 0; i < ndatums; i++)
     156             :         {
     157           0 :             char       *extName = TextDatumGetCString(textDatums[i]);
     158           0 :             Oid         extOid = get_extension_oid(extName, false);
     159             : 
     160           0 :             requiredExtensions = lappend_oid(requiredExtensions, extOid);
     161             :         }
     162             :     }
     163             : 
     164           0 :     InsertExtensionTuple(text_to_cstring(extName),
     165             :                          GetUserId(),
     166           0 :                          get_namespace_oid(text_to_cstring(schemaName), false),
     167             :                          relocatable,
     168           0 :                          text_to_cstring(extVersion),
     169             :                          extConfig,
     170             :                          extCondition,
     171             :                          requiredExtensions);
     172             : 
     173           0 :     PG_RETURN_VOID();
     174             : }
     175             : 
     176             : Datum
     177           0 : binary_upgrade_set_record_init_privs(PG_FUNCTION_ARGS)
     178             : {
     179           0 :     bool        record_init_privs = PG_GETARG_BOOL(0);
     180             : 
     181           0 :     CHECK_IS_BINARY_UPGRADE;
     182           0 :     binary_upgrade_record_init_privs = record_init_privs;
     183             : 
     184           0 :     PG_RETURN_VOID();
     185             : }
     186             : 
     187             : Datum
     188           6 : binary_upgrade_set_missing_value(PG_FUNCTION_ARGS)
     189             : {
     190           6 :     Oid         table_id = PG_GETARG_OID(0);
     191           6 :     text       *attname = PG_GETARG_TEXT_P(1);
     192           6 :     text       *value = PG_GETARG_TEXT_P(2);
     193           6 :     char       *cattname = text_to_cstring(attname);
     194           6 :     char       *cvalue = text_to_cstring(value);
     195             : 
     196           6 :     CHECK_IS_BINARY_UPGRADE;
     197           6 :     SetAttrMissing(table_id, cattname, cvalue);
     198             : 
     199           6 :     PG_RETURN_VOID();
     200             : }

Generated by: LCOV version 1.13