13#include "catalog/pg_class_d.h"
131 pg_log(
PG_WARNING,
"Relation names for OID %u in database \"%s\" do not match: "
132 "old name \"%s.%s\", new name \"%s.%s\"",
151 pg_fatal(
"Failed to match up old and new tables in database \"%s\"",
220 snprintf(reldesc,
sizeof(reldesc),
"\"%s.%s\"",
231 sizeof(reldesc) -
strlen(reldesc),
232 _(
" which is an index on \"%s.%s\""),
241 sizeof(reldesc) -
strlen(reldesc),
242 _(
" which is an index on OID %u"), rel->
indtable);
253 sizeof(reldesc) -
strlen(reldesc),
254 _(
" which is the TOAST table for \"%s.%s\""),
261 sizeof(reldesc) -
strlen(reldesc),
262 _(
" which is the TOAST table for OID %u"), rel->
toastheap);
266 pg_log(
PG_WARNING,
"No match found in old cluster for new relation with OID %u in database \"%s\": %s",
269 pg_log(
PG_WARNING,
"No match found in new cluster for old relation with OID %u in database \"%s\": %s",
346 "SELECT encoding, datlocprovider, "
347 " datcollate, datctype, datlocale "
348 "FROM pg_catalog.pg_database "
349 "WHERE datname='template0'");
352 "SELECT encoding, datlocprovider, "
353 " datcollate, datctype, daticulocale AS datlocale "
354 "FROM pg_catalog.pg_database "
355 "WHERE datname='template0'");
358 "SELECT encoding, 'c' AS datlocprovider, "
359 " datcollate, datctype, NULL AS datlocale "
360 "FROM pg_catalog.pg_database "
361 "WHERE datname='template0'");
411 "SELECT d.oid, d.datname, d.encoding, d.datcollate, d.datctype, ");
414 "datlocprovider, datlocale, ");
417 "datlocprovider, daticulocale AS datlocale, ");
420 "'c' AS datlocprovider, NULL AS datlocale, ");
422 "pg_catalog.pg_tablespace_location(t.oid) AS spclocation "
423 "FROM pg_catalog.pg_database d "
424 " LEFT OUTER JOIN pg_catalog.pg_tablespace t "
425 " ON d.dattablespace = t.oid "
426 "WHERE d.datallowconn = true "
501 "WITH regular_heap (reloid, indtable, toastheap) AS ( "
502 " SELECT c.oid, 0::oid, 0::oid "
503 " FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n "
504 " ON c.relnamespace = n.oid "
508 " ((n.nspname !~ '^pg_temp_' AND "
509 " n.nspname !~ '^pg_toast_temp_' AND "
510 " n.nspname NOT IN ('pg_catalog', 'information_schema', "
511 " 'binary_upgrade', 'pg_toast') AND "
512 " c.oid >= %u::pg_catalog.oid) OR "
513 " (n.nspname = 'pg_catalog' AND "
514 " relname IN ('pg_largeobject'%s) ))), ",
519 ", 'pg_largeobject_metadata'" :
"");
527 " toast_heap (reloid, indtable, toastheap) AS ( "
528 " SELECT c.reltoastrelid, 0::oid, c.oid "
529 " FROM regular_heap JOIN pg_catalog.pg_class c "
530 " ON regular_heap.reloid = c.oid "
531 " WHERE c.reltoastrelid != 0), ");
540 " all_index (reloid, indtable, toastheap) AS ( "
541 " SELECT indexrelid, indrelid, 0::oid "
542 " FROM pg_catalog.pg_index "
543 " WHERE indisvalid AND indisready "
545 " (SELECT reloid FROM regular_heap "
547 " SELECT reloid FROM toast_heap)) ");
554 "SELECT all_rels.*, n.nspname, c.relname, "
555 " c.relfilenode, c.reltablespace, "
556 " pg_catalog.pg_tablespace_location(t.oid) AS spclocation "
557 "FROM (SELECT * FROM regular_heap "
559 " SELECT * FROM toast_heap "
561 " SELECT * FROM all_index) all_rels "
562 " JOIN pg_catalog.pg_class c "
563 " ON all_rels.reloid = c.oid "
564 " JOIN pg_catalog.pg_namespace n "
565 " ON c.relnamespace = n.oid "
566 " LEFT OUTER JOIN pg_catalog.pg_tablespace t "
567 " ON c.reltablespace = t.oid "
592 char *nspname =
NULL;
607 curr->nsp_alloc =
false;
620 curr->nsp_alloc =
true;
627 curr->tblsp_alloc =
false;
654 curr->tblsp_alloc =
true;
704 return "SELECT slot_name, plugin, two_phase, failover, "
705 "FALSE as caught_up, "
706 "invalidation_reason IS NOT NULL as invalid "
707 "FROM pg_catalog.pg_replication_slots "
708 "WHERE slot_type = 'logical' AND "
709 "database = current_database() AND "
710 "temporary IS FALSE";
730 return "WITH check_caught_up AS ( "
731 " SELECT pg_catalog.binary_upgrade_check_logical_slot_pending_wal(slot_name, "
732 " MAX(confirmed_flush_lsn) OVER ()) as last_pending_wal "
733 " FROM pg_replication_slots "
734 " WHERE slot_type = 'logical' AND "
735 " database = current_database() AND "
736 " temporary IS FALSE AND "
737 " invalidation_reason IS NULL "
738 " ORDER BY confirmed_flush_lsn ASC "
741 "SELECT slot_name, plugin, two_phase, failover, "
742 "CASE WHEN invalidation_reason IS NOT NULL THEN FALSE "
743 "ELSE last_pending_wal IS NULL OR "
744 " confirmed_flush_lsn > last_pending_wal "
746 "invalidation_reason IS NOT NULL as invalid "
747 "FROM pg_catalog.pg_replication_slots, check_caught_up "
748 "WHERE slot_type = 'logical' AND "
749 "database = current_database() AND "
750 "temporary IS FALSE ";
757 return "SELECT slot_name, plugin, two_phase, failover, "
758 "CASE WHEN invalidation_reason IS NOT NULL THEN FALSE "
759 "ELSE (SELECT pg_catalog.binary_upgrade_logical_slot_has_caught_up(slot_name)) "
761 "invalidation_reason IS NOT NULL as invalid "
762 "FROM pg_catalog.pg_replication_slots "
763 "WHERE slot_type = 'logical' AND "
764 "database = current_database() AND "
765 "temporary IS FALSE ";
851 "COUNT(CASE WHEN subretaindeadtuples THEN 1 END) > 0 AS retain_dead_tuples "
852 "FROM pg_catalog.pg_subscription");
855 "'f' AS retain_dead_tuples "
856 "FROM pg_catalog.pg_subscription");
873 for (dbnum = 0; dbnum <
db_arr->ndbs; dbnum++)
907 for (dbnum = 0; dbnum <
db_arr->ndbs; dbnum++)
935 if (slot_arr->
nslots == 0)
944 pg_log(
PG_VERBOSE,
"slot name: \"%s\", output plugin: \"%s\", two_phase: %s",
947 slot_info->two_phase ?
"true" :
"false");
void cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel)
void PQfinish(PGconn *conn)
int PQfnumber(const PGresult *res, const char *field_name)
void * pg_malloc(size_t size)
char * pg_strdup(const char *in)
void * pg_malloc0(size_t size)
static void print_slot_infos(LogicalSlotInfoArr *slot_arr)
static void process_rel_infos(DbInfo *dbinfo, PGresult *res, void *arg)
static void get_template0_info(ClusterInfo *cluster)
FileNameMap * gen_db_file_maps(DbInfo *old_db, DbInfo *new_db, int *nmaps, const char *old_pgdata, const char *new_pgdata)
static void report_unmatched_relation(const RelInfo *rel, const DbInfo *db, bool is_new_db)
static void get_db_infos(ClusterInfo *cluster)
static void free_rel_infos(RelInfoArr *rel_arr)
static void print_rel_infos(RelInfoArr *rel_arr)
static void create_rel_filename_map(const char *old_data, const char *new_data, const DbInfo *old_db, const DbInfo *new_db, const RelInfo *old_rel, const RelInfo *new_rel, FileNameMap *map)
static void free_db_and_rel_infos(DbInfoArr *db_arr)
static char * get_rel_infos_query(void)
static void process_old_cluster_logical_slot_infos(DbInfo *dbinfo, PGresult *res, void *arg)
static const char * get_old_cluster_logical_slot_infos_query(ClusterInfo *cluster)
static void print_db_infos(DbInfoArr *db_arr)
void get_subscription_info(ClusterInfo *cluster)
int count_old_cluster_logical_slots(void)
void get_db_rel_and_slot_infos(ClusterInfo *cluster)
void pfree(void *pointer)
static struct LogicalRepInfos dbinfos
UpgradeTask * upgrade_task_create(void)
PGconn * connectToServer(ClusterInfo *cluster, const char *db_name)
void upgrade_task_run(const UpgradeTask *task, const ClusterInfo *cluster)
void void pg_log(eLogType type, const char *fmt,...) pg_attribute_printf(2
PGresult * executeQueryOrDie(PGconn *conn, const char *fmt,...) pg_attribute_printf(2
void upgrade_task_free(UpgradeTask *task)
#define GET_MAJOR_VERSION(v)
void upgrade_task_add_step(UpgradeTask *task, const char *query, UpgradeTaskProcessCB process_cb, bool free_result, void *arg)
#define is_absolute_path(filename)
void initPQExpBuffer(PQExpBuffer str)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
char * psprintf(const char *fmt,...)
const char * tablespace_suffix
LogicalSlotInfoArr slot_arr
char db_tablespace[MAXPGPATH]
const char * new_tablespace
const char * old_tablespace_suffix
const char * old_tablespace
RelFileNumber relfilenumber
const char * new_tablespace_suffix
ClusterInfo * running_cluster
transferMode transfer_mode
#define FirstNormalObjectId
static const pg_conv_map maps[]