13#include "catalog/pg_class_d.h"
130 pg_log(
PG_WARNING,
"Relation names for OID %u in database \"%s\" do not match: "
131 "old name \"%s.%s\", new name \"%s.%s\"",
150 pg_fatal(
"Failed to match up old and new tables in database \"%s\"",
219 snprintf(reldesc,
sizeof(reldesc),
"\"%s.%s\"",
230 sizeof(reldesc) -
strlen(reldesc),
231 _(
" which is an index on \"%s.%s\""),
240 sizeof(reldesc) -
strlen(reldesc),
241 _(
" which is an index on OID %u"), rel->
indtable);
252 sizeof(reldesc) -
strlen(reldesc),
253 _(
" which is the TOAST table for \"%s.%s\""),
260 sizeof(reldesc) -
strlen(reldesc),
261 _(
" which is the TOAST table for OID %u"), rel->
toastheap);
265 pg_log(
PG_WARNING,
"No match found in old cluster for new relation with OID %u in database \"%s\": %s",
268 pg_log(
PG_WARNING,
"No match found in new cluster for old relation with OID %u in database \"%s\": %s",
345 "SELECT encoding, datlocprovider, "
346 " datcollate, datctype, datlocale "
347 "FROM pg_catalog.pg_database "
348 "WHERE datname='template0'");
351 "SELECT encoding, datlocprovider, "
352 " datcollate, datctype, daticulocale AS datlocale "
353 "FROM pg_catalog.pg_database "
354 "WHERE datname='template0'");
357 "SELECT encoding, 'c' AS datlocprovider, "
358 " datcollate, datctype, NULL AS datlocale "
359 "FROM pg_catalog.pg_database "
360 "WHERE datname='template0'");
410 "SELECT d.oid, d.datname, d.encoding, d.datcollate, d.datctype, ");
413 "datlocprovider, datlocale, ");
416 "datlocprovider, daticulocale AS datlocale, ");
419 "'c' AS datlocprovider, NULL AS datlocale, ");
421 "pg_catalog.pg_tablespace_location(t.oid) AS spclocation "
422 "FROM pg_catalog.pg_database d "
423 " LEFT OUTER JOIN pg_catalog.pg_tablespace t "
424 " ON d.dattablespace = t.oid "
425 "WHERE d.datallowconn = true "
500 "WITH regular_heap (reloid, indtable, toastheap) AS ( "
501 " SELECT c.oid, 0::oid, 0::oid "
502 " FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n "
503 " ON c.relnamespace = n.oid "
507 " ((n.nspname !~ '^pg_temp_' AND "
508 " n.nspname !~ '^pg_toast_temp_' AND "
509 " n.nspname NOT IN ('pg_catalog', 'information_schema', "
510 " 'binary_upgrade', 'pg_toast') AND "
511 " c.oid >= %u::pg_catalog.oid) OR "
512 " (n.nspname = 'pg_catalog' AND "
513 " relname IN ('pg_largeobject'%s) ))), ",
518 ", 'pg_largeobject_metadata'" :
"");
526 " toast_heap (reloid, indtable, toastheap) AS ( "
527 " SELECT c.reltoastrelid, 0::oid, c.oid "
528 " FROM regular_heap JOIN pg_catalog.pg_class c "
529 " ON regular_heap.reloid = c.oid "
530 " WHERE c.reltoastrelid != 0), ");
539 " all_index (reloid, indtable, toastheap) AS ( "
540 " SELECT indexrelid, indrelid, 0::oid "
541 " FROM pg_catalog.pg_index "
542 " WHERE indisvalid AND indisready "
544 " (SELECT reloid FROM regular_heap "
546 " SELECT reloid FROM toast_heap)) ");
553 "SELECT all_rels.*, n.nspname, c.relname, "
554 " c.relfilenode, c.reltablespace, "
555 " pg_catalog.pg_tablespace_location(t.oid) AS spclocation "
556 "FROM (SELECT * FROM regular_heap "
558 " SELECT * FROM toast_heap "
560 " SELECT * FROM all_index) all_rels "
561 " JOIN pg_catalog.pg_class c "
562 " ON all_rels.reloid = c.oid "
563 " JOIN pg_catalog.pg_namespace n "
564 " ON c.relnamespace = n.oid "
565 " LEFT OUTER JOIN pg_catalog.pg_tablespace t "
566 " ON c.reltablespace = t.oid "
591 char *nspname =
NULL;
606 curr->nsp_alloc =
false;
619 curr->nsp_alloc =
true;
626 curr->tblsp_alloc =
false;
653 curr->tblsp_alloc =
true;
703 return "SELECT slot_name, plugin, two_phase, failover, "
704 "FALSE as caught_up, "
705 "invalidation_reason IS NOT NULL as invalid "
706 "FROM pg_catalog.pg_replication_slots "
707 "WHERE slot_type = 'logical' AND "
708 "database = current_database() AND "
709 "temporary IS FALSE";
729 return "WITH check_caught_up AS ( "
730 " SELECT pg_catalog.binary_upgrade_check_logical_slot_pending_wal(slot_name, "
731 " MAX(confirmed_flush_lsn) OVER ()) as last_pending_wal "
732 " FROM pg_replication_slots "
733 " WHERE slot_type = 'logical' AND "
734 " database = current_database() AND "
735 " temporary IS FALSE AND "
736 " invalidation_reason IS NULL "
737 " ORDER BY confirmed_flush_lsn ASC "
740 "SELECT slot_name, plugin, two_phase, failover, "
741 "CASE WHEN invalidation_reason IS NOT NULL THEN FALSE "
742 "ELSE last_pending_wal IS NULL OR "
743 " confirmed_flush_lsn > last_pending_wal "
745 "invalidation_reason IS NOT NULL as invalid "
746 "FROM pg_catalog.pg_replication_slots, check_caught_up "
747 "WHERE slot_type = 'logical' AND "
748 "database = current_database() AND "
749 "temporary IS FALSE ";
756 return "SELECT slot_name, plugin, two_phase, failover, "
757 "CASE WHEN invalidation_reason IS NOT NULL THEN FALSE "
758 "ELSE (SELECT pg_catalog.binary_upgrade_logical_slot_has_caught_up(slot_name)) "
760 "invalidation_reason IS NOT NULL as invalid "
761 "FROM pg_catalog.pg_replication_slots "
762 "WHERE slot_type = 'logical' AND "
763 "database = current_database() AND "
764 "temporary IS FALSE ";
850 "COUNT(CASE WHEN subretaindeadtuples THEN 1 END) > 0 AS retain_dead_tuples "
851 "FROM pg_catalog.pg_subscription");
854 "'f' AS retain_dead_tuples "
855 "FROM pg_catalog.pg_subscription");
872 for (dbnum = 0; dbnum <
db_arr->ndbs; dbnum++)
906 for (dbnum = 0; dbnum <
db_arr->ndbs; dbnum++)
934 if (slot_arr->
nslots == 0)
943 pg_log(
PG_VERBOSE,
"slot name: \"%s\", output plugin: \"%s\", two_phase: %s",
946 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)
char * pg_strdup(const char *in)
#define pg_malloc_array(type, count)
#define pg_malloc_object(type)
#define pg_malloc0_array(type, count)
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[]