LCOV - code coverage report
Current view: top level - src/backend/utils/adt - pg_upgrade_support.c (source / functions) Hit Total Coverage
Test: PostgreSQL 15beta1 Lines: 69 108 63.9 %
Date: 2022-05-18 03:10:05 Functions: 13 16 81.2 %
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-2022, 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/namespace.h"
      17             : #include "catalog/pg_type.h"
      18             : #include "commands/extension.h"
      19             : #include "miscadmin.h"
      20             : #include "utils/array.h"
      21             : #include "utils/builtins.h"
      22             : 
      23             : 
      24             : #define CHECK_IS_BINARY_UPGRADE                                 \
      25             : do {                                                            \
      26             :     if (!IsBinaryUpgrade)                                       \
      27             :         ereport(ERROR,                                          \
      28             :                 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),    \
      29             :                  errmsg("function can only be called when server is in binary upgrade mode"))); \
      30             : } while (0)
      31             : 
      32             : Datum
      33           0 : binary_upgrade_set_next_pg_tablespace_oid(PG_FUNCTION_ARGS)
      34             : {
      35           0 :     Oid         tbspoid = PG_GETARG_OID(0);
      36             : 
      37           0 :     CHECK_IS_BINARY_UPGRADE;
      38           0 :     binary_upgrade_next_pg_tablespace_oid = tbspoid;
      39             : 
      40           0 :     PG_RETURN_VOID();
      41             : }
      42             : 
      43             : Datum
      44        1424 : binary_upgrade_set_next_pg_type_oid(PG_FUNCTION_ARGS)
      45             : {
      46        1424 :     Oid         typoid = PG_GETARG_OID(0);
      47             : 
      48        1424 :     CHECK_IS_BINARY_UPGRADE;
      49        1424 :     binary_upgrade_next_pg_type_oid = typoid;
      50             : 
      51        1424 :     PG_RETURN_VOID();
      52             : }
      53             : 
      54             : Datum
      55        1422 : binary_upgrade_set_next_array_pg_type_oid(PG_FUNCTION_ARGS)
      56             : {
      57        1422 :     Oid         typoid = PG_GETARG_OID(0);
      58             : 
      59        1422 :     CHECK_IS_BINARY_UPGRADE;
      60        1422 :     binary_upgrade_next_array_pg_type_oid = typoid;
      61             : 
      62        1422 :     PG_RETURN_VOID();
      63             : }
      64             : 
      65             : Datum
      66           8 : binary_upgrade_set_next_multirange_pg_type_oid(PG_FUNCTION_ARGS)
      67             : {
      68           8 :     Oid         typoid = PG_GETARG_OID(0);
      69             : 
      70           8 :     CHECK_IS_BINARY_UPGRADE;
      71           8 :     binary_upgrade_next_mrng_pg_type_oid = typoid;
      72             : 
      73           8 :     PG_RETURN_VOID();
      74             : }
      75             : 
      76             : Datum
      77           8 : binary_upgrade_set_next_multirange_array_pg_type_oid(PG_FUNCTION_ARGS)
      78             : {
      79           8 :     Oid         typoid = PG_GETARG_OID(0);
      80             : 
      81           8 :     CHECK_IS_BINARY_UPGRADE;
      82           8 :     binary_upgrade_next_mrng_array_pg_type_oid = typoid;
      83             : 
      84           8 :     PG_RETURN_VOID();
      85             : }
      86             : 
      87             : Datum
      88        1418 : binary_upgrade_set_next_heap_pg_class_oid(PG_FUNCTION_ARGS)
      89             : {
      90        1418 :     Oid         reloid = PG_GETARG_OID(0);
      91             : 
      92        1418 :     CHECK_IS_BINARY_UPGRADE;
      93        1418 :     binary_upgrade_next_heap_pg_class_oid = reloid;
      94             : 
      95        1418 :     PG_RETURN_VOID();
      96             : }
      97             : 
      98             : Datum
      99        1138 : binary_upgrade_set_next_heap_relfilenode(PG_FUNCTION_ARGS)
     100             : {
     101        1138 :     Oid         nodeoid = PG_GETARG_OID(0);
     102             : 
     103        1138 :     CHECK_IS_BINARY_UPGRADE;
     104        1138 :     binary_upgrade_next_heap_pg_class_relfilenode = nodeoid;
     105             : 
     106        1138 :     PG_RETURN_VOID();
     107             : }
     108             : 
     109             : Datum
     110         948 : binary_upgrade_set_next_index_pg_class_oid(PG_FUNCTION_ARGS)
     111             : {
     112         948 :     Oid         reloid = PG_GETARG_OID(0);
     113             : 
     114         948 :     CHECK_IS_BINARY_UPGRADE;
     115         948 :     binary_upgrade_next_index_pg_class_oid = reloid;
     116             : 
     117         948 :     PG_RETURN_VOID();
     118             : }
     119             : 
     120             : Datum
     121         948 : binary_upgrade_set_next_index_relfilenode(PG_FUNCTION_ARGS)
     122             : {
     123         948 :     Oid         nodeoid = PG_GETARG_OID(0);
     124             : 
     125         948 :     CHECK_IS_BINARY_UPGRADE;
     126         948 :     binary_upgrade_next_index_pg_class_relfilenode = nodeoid;
     127             : 
     128         948 :     PG_RETURN_VOID();
     129             : }
     130             : 
     131             : Datum
     132         492 : binary_upgrade_set_next_toast_pg_class_oid(PG_FUNCTION_ARGS)
     133             : {
     134         492 :     Oid         reloid = PG_GETARG_OID(0);
     135             : 
     136         492 :     CHECK_IS_BINARY_UPGRADE;
     137         492 :     binary_upgrade_next_toast_pg_class_oid = reloid;
     138             : 
     139         492 :     PG_RETURN_VOID();
     140             : }
     141             : 
     142             : Datum
     143         492 : binary_upgrade_set_next_toast_relfilenode(PG_FUNCTION_ARGS)
     144             : {
     145         492 :     Oid         nodeoid = PG_GETARG_OID(0);
     146             : 
     147         492 :     CHECK_IS_BINARY_UPGRADE;
     148         492 :     binary_upgrade_next_toast_pg_class_relfilenode = nodeoid;
     149             : 
     150         492 :     PG_RETURN_VOID();
     151             : }
     152             : 
     153             : Datum
     154          88 : binary_upgrade_set_next_pg_enum_oid(PG_FUNCTION_ARGS)
     155             : {
     156          88 :     Oid         enumoid = PG_GETARG_OID(0);
     157             : 
     158          88 :     CHECK_IS_BINARY_UPGRADE;
     159          88 :     binary_upgrade_next_pg_enum_oid = enumoid;
     160             : 
     161          88 :     PG_RETURN_VOID();
     162             : }
     163             : 
     164             : Datum
     165           2 : binary_upgrade_set_next_pg_authid_oid(PG_FUNCTION_ARGS)
     166             : {
     167           2 :     Oid         authoid = PG_GETARG_OID(0);
     168             : 
     169           2 :     CHECK_IS_BINARY_UPGRADE;
     170           2 :     binary_upgrade_next_pg_authid_oid = authoid;
     171           2 :     PG_RETURN_VOID();
     172             : }
     173             : 
     174             : Datum
     175           0 : binary_upgrade_create_empty_extension(PG_FUNCTION_ARGS)
     176             : {
     177             :     text       *extName;
     178             :     text       *schemaName;
     179             :     bool        relocatable;
     180             :     text       *extVersion;
     181             :     Datum       extConfig;
     182             :     Datum       extCondition;
     183             :     List       *requiredExtensions;
     184             : 
     185           0 :     CHECK_IS_BINARY_UPGRADE;
     186             : 
     187             :     /* We must check these things before dereferencing the arguments */
     188           0 :     if (PG_ARGISNULL(0) ||
     189           0 :         PG_ARGISNULL(1) ||
     190           0 :         PG_ARGISNULL(2) ||
     191           0 :         PG_ARGISNULL(3))
     192           0 :         elog(ERROR, "null argument to binary_upgrade_create_empty_extension is not allowed");
     193             : 
     194           0 :     extName = PG_GETARG_TEXT_PP(0);
     195           0 :     schemaName = PG_GETARG_TEXT_PP(1);
     196           0 :     relocatable = PG_GETARG_BOOL(2);
     197           0 :     extVersion = PG_GETARG_TEXT_PP(3);
     198             : 
     199           0 :     if (PG_ARGISNULL(4))
     200           0 :         extConfig = PointerGetDatum(NULL);
     201             :     else
     202           0 :         extConfig = PG_GETARG_DATUM(4);
     203             : 
     204           0 :     if (PG_ARGISNULL(5))
     205           0 :         extCondition = PointerGetDatum(NULL);
     206             :     else
     207           0 :         extCondition = PG_GETARG_DATUM(5);
     208             : 
     209           0 :     requiredExtensions = NIL;
     210           0 :     if (!PG_ARGISNULL(6))
     211             :     {
     212           0 :         ArrayType  *textArray = PG_GETARG_ARRAYTYPE_P(6);
     213             :         Datum      *textDatums;
     214             :         int         ndatums;
     215             :         int         i;
     216             : 
     217           0 :         deconstruct_array(textArray,
     218             :                           TEXTOID, -1, false, TYPALIGN_INT,
     219             :                           &textDatums, NULL, &ndatums);
     220           0 :         for (i = 0; i < ndatums; i++)
     221             :         {
     222           0 :             char       *extName = TextDatumGetCString(textDatums[i]);
     223           0 :             Oid         extOid = get_extension_oid(extName, false);
     224             : 
     225           0 :             requiredExtensions = lappend_oid(requiredExtensions, extOid);
     226             :         }
     227             :     }
     228             : 
     229           0 :     InsertExtensionTuple(text_to_cstring(extName),
     230             :                          GetUserId(),
     231           0 :                          get_namespace_oid(text_to_cstring(schemaName), false),
     232             :                          relocatable,
     233           0 :                          text_to_cstring(extVersion),
     234             :                          extConfig,
     235             :                          extCondition,
     236             :                          requiredExtensions);
     237             : 
     238           0 :     PG_RETURN_VOID();
     239             : }
     240             : 
     241             : Datum
     242           0 : binary_upgrade_set_record_init_privs(PG_FUNCTION_ARGS)
     243             : {
     244           0 :     bool        record_init_privs = PG_GETARG_BOOL(0);
     245             : 
     246           0 :     CHECK_IS_BINARY_UPGRADE;
     247           0 :     binary_upgrade_record_init_privs = record_init_privs;
     248             : 
     249           0 :     PG_RETURN_VOID();
     250             : }
     251             : 
     252             : Datum
     253           6 : binary_upgrade_set_missing_value(PG_FUNCTION_ARGS)
     254             : {
     255           6 :     Oid         table_id = PG_GETARG_OID(0);
     256           6 :     text       *attname = PG_GETARG_TEXT_P(1);
     257           6 :     text       *value = PG_GETARG_TEXT_P(2);
     258           6 :     char       *cattname = text_to_cstring(attname);
     259           6 :     char       *cvalue = text_to_cstring(value);
     260             : 
     261           6 :     CHECK_IS_BINARY_UPGRADE;
     262           6 :     SetAttrMissing(table_id, cattname, cvalue);
     263             : 
     264           6 :     PG_RETURN_VOID();
     265             : }

Generated by: LCOV version 1.14