LCOV - code coverage report
Current view: top level - src/backend/utils/adt - pg_upgrade_support.c (source / functions) Hit Total Coverage
Test: PostgreSQL 13devel Lines: 49 83 59.0 %
Date: 2019-08-24 07:07:03 Functions: 9 11 81.8 %
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-2019, 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        1324 : binary_upgrade_set_next_pg_type_oid(PG_FUNCTION_ARGS)
      34             : {
      35        1324 :     Oid         typoid = PG_GETARG_OID(0);
      36             : 
      37        1324 :     CHECK_IS_BINARY_UPGRADE;
      38        1324 :     binary_upgrade_next_pg_type_oid = typoid;
      39             : 
      40        1324 :     PG_RETURN_VOID();
      41             : }
      42             : 
      43             : Datum
      44        1246 : binary_upgrade_set_next_array_pg_type_oid(PG_FUNCTION_ARGS)
      45             : {
      46        1246 :     Oid         typoid = PG_GETARG_OID(0);
      47             : 
      48        1246 :     CHECK_IS_BINARY_UPGRADE;
      49        1246 :     binary_upgrade_next_array_pg_type_oid = typoid;
      50             : 
      51        1246 :     PG_RETURN_VOID();
      52             : }
      53             : 
      54             : Datum
      55         418 : binary_upgrade_set_next_toast_pg_type_oid(PG_FUNCTION_ARGS)
      56             : {
      57         418 :     Oid         typoid = PG_GETARG_OID(0);
      58             : 
      59         418 :     CHECK_IS_BINARY_UPGRADE;
      60         418 :     binary_upgrade_next_toast_pg_type_oid = typoid;
      61             : 
      62         418 :     PG_RETURN_VOID();
      63             : }
      64             : 
      65             : Datum
      66        1250 : binary_upgrade_set_next_heap_pg_class_oid(PG_FUNCTION_ARGS)
      67             : {
      68        1250 :     Oid         reloid = PG_GETARG_OID(0);
      69             : 
      70        1250 :     CHECK_IS_BINARY_UPGRADE;
      71        1250 :     binary_upgrade_next_heap_pg_class_oid = reloid;
      72             : 
      73        1250 :     PG_RETURN_VOID();
      74             : }
      75             : 
      76             : Datum
      77         826 : binary_upgrade_set_next_index_pg_class_oid(PG_FUNCTION_ARGS)
      78             : {
      79         826 :     Oid         reloid = PG_GETARG_OID(0);
      80             : 
      81         826 :     CHECK_IS_BINARY_UPGRADE;
      82         826 :     binary_upgrade_next_index_pg_class_oid = reloid;
      83             : 
      84         826 :     PG_RETURN_VOID();
      85             : }
      86             : 
      87             : Datum
      88         418 : binary_upgrade_set_next_toast_pg_class_oid(PG_FUNCTION_ARGS)
      89             : {
      90         418 :     Oid         reloid = PG_GETARG_OID(0);
      91             : 
      92         418 :     CHECK_IS_BINARY_UPGRADE;
      93         418 :     binary_upgrade_next_toast_pg_class_oid = reloid;
      94             : 
      95         418 :     PG_RETURN_VOID();
      96             : }
      97             : 
      98             : Datum
      99          82 : binary_upgrade_set_next_pg_enum_oid(PG_FUNCTION_ARGS)
     100             : {
     101          82 :     Oid         enumoid = PG_GETARG_OID(0);
     102             : 
     103          82 :     CHECK_IS_BINARY_UPGRADE;
     104          82 :     binary_upgrade_next_pg_enum_oid = enumoid;
     105             : 
     106          82 :     PG_RETURN_VOID();
     107             : }
     108             : 
     109             : Datum
     110           2 : binary_upgrade_set_next_pg_authid_oid(PG_FUNCTION_ARGS)
     111             : {
     112           2 :     Oid         authoid = PG_GETARG_OID(0);
     113             : 
     114           2 :     CHECK_IS_BINARY_UPGRADE;
     115           2 :     binary_upgrade_next_pg_authid_oid = authoid;
     116           2 :     PG_RETURN_VOID();
     117             : }
     118             : 
     119             : Datum
     120           0 : binary_upgrade_create_empty_extension(PG_FUNCTION_ARGS)
     121             : {
     122             :     text       *extName;
     123             :     text       *schemaName;
     124             :     bool        relocatable;
     125             :     text       *extVersion;
     126             :     Datum       extConfig;
     127             :     Datum       extCondition;
     128             :     List       *requiredExtensions;
     129             : 
     130           0 :     CHECK_IS_BINARY_UPGRADE;
     131             : 
     132             :     /* We must check these things before dereferencing the arguments */
     133           0 :     if (PG_ARGISNULL(0) ||
     134           0 :         PG_ARGISNULL(1) ||
     135           0 :         PG_ARGISNULL(2) ||
     136           0 :         PG_ARGISNULL(3))
     137           0 :         elog(ERROR, "null argument to binary_upgrade_create_empty_extension is not allowed");
     138             : 
     139           0 :     extName = PG_GETARG_TEXT_PP(0);
     140           0 :     schemaName = PG_GETARG_TEXT_PP(1);
     141           0 :     relocatable = PG_GETARG_BOOL(2);
     142           0 :     extVersion = PG_GETARG_TEXT_PP(3);
     143             : 
     144           0 :     if (PG_ARGISNULL(4))
     145           0 :         extConfig = PointerGetDatum(NULL);
     146             :     else
     147           0 :         extConfig = PG_GETARG_DATUM(4);
     148             : 
     149           0 :     if (PG_ARGISNULL(5))
     150           0 :         extCondition = PointerGetDatum(NULL);
     151             :     else
     152           0 :         extCondition = PG_GETARG_DATUM(5);
     153             : 
     154           0 :     requiredExtensions = NIL;
     155           0 :     if (!PG_ARGISNULL(6))
     156             :     {
     157           0 :         ArrayType  *textArray = PG_GETARG_ARRAYTYPE_P(6);
     158             :         Datum      *textDatums;
     159             :         int         ndatums;
     160             :         int         i;
     161             : 
     162           0 :         deconstruct_array(textArray,
     163             :                           TEXTOID, -1, false, 'i',
     164             :                           &textDatums, NULL, &ndatums);
     165           0 :         for (i = 0; i < ndatums; i++)
     166             :         {
     167           0 :             char       *extName = TextDatumGetCString(textDatums[i]);
     168           0 :             Oid         extOid = get_extension_oid(extName, false);
     169             : 
     170           0 :             requiredExtensions = lappend_oid(requiredExtensions, extOid);
     171             :         }
     172             :     }
     173             : 
     174           0 :     InsertExtensionTuple(text_to_cstring(extName),
     175             :                          GetUserId(),
     176           0 :                          get_namespace_oid(text_to_cstring(schemaName), false),
     177             :                          relocatable,
     178           0 :                          text_to_cstring(extVersion),
     179             :                          extConfig,
     180             :                          extCondition,
     181             :                          requiredExtensions);
     182             : 
     183           0 :     PG_RETURN_VOID();
     184             : }
     185             : 
     186             : Datum
     187           0 : binary_upgrade_set_record_init_privs(PG_FUNCTION_ARGS)
     188             : {
     189           0 :     bool        record_init_privs = PG_GETARG_BOOL(0);
     190             : 
     191           0 :     CHECK_IS_BINARY_UPGRADE;
     192           0 :     binary_upgrade_record_init_privs = record_init_privs;
     193             : 
     194           0 :     PG_RETURN_VOID();
     195             : }
     196             : 
     197             : Datum
     198           4 : binary_upgrade_set_missing_value(PG_FUNCTION_ARGS)
     199             : {
     200           4 :     Oid         table_id = PG_GETARG_OID(0);
     201           4 :     text       *attname = PG_GETARG_TEXT_P(1);
     202           4 :     text       *value = PG_GETARG_TEXT_P(2);
     203           4 :     char       *cattname = text_to_cstring(attname);
     204           4 :     char       *cvalue = text_to_cstring(value);
     205             : 
     206           4 :     CHECK_IS_BINARY_UPGRADE;
     207           4 :     SetAttrMissing(table_id, cattname, cvalue);
     208             : 
     209           4 :     PG_RETURN_VOID();
     210             : }

Generated by: LCOV version 1.13