PostgreSQL Source Code  git master
info.c File Reference
#include "postgres_fe.h"
#include "access/transam.h"
#include "catalog/pg_class_d.h"
#include "pg_upgrade.h"
Include dependency graph for info.c:

Go to the source code of this file.

Functions

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 report_unmatched_relation (const RelInfo *rel, const DbInfo *db, bool is_new_db)
 
static void free_db_and_rel_infos (DbInfoArr *db_arr)
 
static void get_db_infos (ClusterInfo *cluster)
 
static void get_rel_infos (ClusterInfo *cluster, DbInfo *dbinfo)
 
static void free_rel_infos (RelInfoArr *rel_arr)
 
static void print_db_infos (DbInfoArr *dbinfo)
 
static void print_rel_infos (RelInfoArr *rel_arr)
 
FileNameMapgen_db_file_maps (DbInfo *old_db, DbInfo *new_db, int *nmaps, const char *old_pgdata, const char *new_pgdata)
 
void get_db_and_rel_infos (ClusterInfo *cluster)
 

Function Documentation

◆ create_rel_filename_map()

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

Definition at line 159 of file info.c.

163 {
164  /* In case old/new tablespaces don't match, do them separately. */
165  if (strlen(old_rel->tablespace) == 0)
166  {
167  /*
168  * relation belongs to the default tablespace, hence relfiles should
169  * exist in the data directories.
170  */
171  map->old_tablespace = old_data;
172  map->old_tablespace_suffix = "/base";
173  }
174  else
175  {
176  /* relation belongs to a tablespace, so use the tablespace location */
177  map->old_tablespace = old_rel->tablespace;
179  }
180 
181  /* Do the same for new tablespaces */
182  if (strlen(new_rel->tablespace) == 0)
183  {
184  map->new_tablespace = new_data;
185  map->new_tablespace_suffix = "/base";
186  }
187  else
188  {
189  map->new_tablespace = new_rel->tablespace;
191  }
192 
193  /* DB oid and relfilenodes are preserved between old and new cluster */
194  map->db_oid = old_db->db_oid;
195  map->relfilenode = old_rel->relfilenode;
196 
197  /* used only for logging and error reporting, old/new are identical */
198  map->nspname = old_rel->nspname;
199  map->relname = old_rel->relname;
200 }
ClusterInfo new_cluster
Definition: pg_upgrade.c:63
ClusterInfo old_cluster
Definition: pg_upgrade.c:62
const char * tablespace_suffix
Definition: pg_upgrade.h:268
Oid db_oid
Definition: pg_upgrade.h:173
Oid relfilenode
Definition: pg_upgrade.h:162
const char * new_tablespace
Definition: pg_upgrade.h:158
const char * old_tablespace_suffix
Definition: pg_upgrade.h:159
const char * old_tablespace
Definition: pg_upgrade.h:157
char * relname
Definition: pg_upgrade.h:165
char * nspname
Definition: pg_upgrade.h:164
const char * new_tablespace_suffix
Definition: pg_upgrade.h:160
char * nspname
Definition: pg_upgrade.h:135
char * tablespace
Definition: pg_upgrade.h:141
Oid relfilenode
Definition: pg_upgrade.h:138
char * relname
Definition: pg_upgrade.h:136

References FileNameMap::db_oid, DbInfo::db_oid, new_cluster, FileNameMap::new_tablespace, FileNameMap::new_tablespace_suffix, RelInfo::nspname, FileNameMap::nspname, old_cluster, FileNameMap::old_tablespace, FileNameMap::old_tablespace_suffix, RelInfo::relfilenode, FileNameMap::relfilenode, RelInfo::relname, FileNameMap::relname, RelInfo::tablespace, and ClusterInfo::tablespace_suffix.

Referenced by gen_db_file_maps().

◆ free_db_and_rel_infos()

static void free_db_and_rel_infos ( DbInfoArr db_arr)
static

Definition at line 565 of file info.c.

566 {
567  int dbnum;
568 
569  for (dbnum = 0; dbnum < db_arr->ndbs; dbnum++)
570  {
571  free_rel_infos(&db_arr->dbs[dbnum].rel_arr);
572  pg_free(db_arr->dbs[dbnum].db_name);
573  }
574  pg_free(db_arr->dbs);
575  db_arr->dbs = NULL;
576  db_arr->ndbs = 0;
577 }
void pg_free(void *ptr)
Definition: fe_memutils.c:105
static void free_rel_infos(RelInfoArr *rel_arr)
Definition: info.c:581
DbInfo * dbs
Definition: pg_upgrade.h:187
char * db_name
Definition: pg_upgrade.h:174
RelInfoArr rel_arr
Definition: pg_upgrade.h:182

References DbInfo::db_name, DbInfoArr::dbs, free_rel_infos(), DbInfoArr::ndbs, pg_free(), and DbInfo::rel_arr.

Referenced by get_db_and_rel_infos().

◆ free_rel_infos()

static void free_rel_infos ( RelInfoArr rel_arr)
static

Definition at line 581 of file info.c.

582 {
583  int relnum;
584 
585  for (relnum = 0; relnum < rel_arr->nrels; relnum++)
586  {
587  if (rel_arr->rels[relnum].nsp_alloc)
588  pg_free(rel_arr->rels[relnum].nspname);
589  pg_free(rel_arr->rels[relnum].relname);
590  if (rel_arr->rels[relnum].tblsp_alloc)
591  pg_free(rel_arr->rels[relnum].tablespace);
592  }
593  pg_free(rel_arr->rels);
594  rel_arr->nrels = 0;
595 }
RelInfo * rels
Definition: pg_upgrade.h:148
bool tblsp_alloc
Definition: pg_upgrade.h:143
bool nsp_alloc
Definition: pg_upgrade.h:142

References RelInfoArr::nrels, RelInfo::nsp_alloc, RelInfo::nspname, pg_free(), RelInfo::relname, RelInfoArr::rels, RelInfo::tablespace, and RelInfo::tblsp_alloc.

Referenced by free_db_and_rel_infos().

◆ gen_db_file_maps()

FileNameMap* gen_db_file_maps ( DbInfo old_db,
DbInfo new_db,
int *  nmaps,
const char *  old_pgdata,
const char *  new_pgdata 
)

Definition at line 39 of file info.c.

42 {
44  int old_relnum,
45  new_relnum;
46  int num_maps = 0;
47  bool all_matched = true;
48 
49  /* There will certainly not be more mappings than there are old rels */
50  maps = (FileNameMap *) pg_malloc(sizeof(FileNameMap) *
51  old_db->rel_arr.nrels);
52 
53  /*
54  * Each of the RelInfo arrays should be sorted by OID. Scan through them
55  * and match them up. If we fail to match everything, we'll abort, but
56  * first print as much info as we can about mismatches.
57  */
58  old_relnum = new_relnum = 0;
59  while (old_relnum < old_db->rel_arr.nrels ||
60  new_relnum < new_db->rel_arr.nrels)
61  {
62  RelInfo *old_rel = (old_relnum < old_db->rel_arr.nrels) ?
63  &old_db->rel_arr.rels[old_relnum] : NULL;
64  RelInfo *new_rel = (new_relnum < new_db->rel_arr.nrels) ?
65  &new_db->rel_arr.rels[new_relnum] : NULL;
66 
67  /* handle running off one array before the other */
68  if (!new_rel)
69  {
70  /*
71  * old_rel is unmatched. This should never happen, because we
72  * force new rels to have TOAST tables if the old one did.
73  */
74  report_unmatched_relation(old_rel, old_db, false);
75  all_matched = false;
76  old_relnum++;
77  continue;
78  }
79  if (!old_rel)
80  {
81  /*
82  * new_rel is unmatched. This shouldn't really happen either, but
83  * if it's a TOAST table, we can ignore it and continue
84  * processing, assuming that the new server made a TOAST table
85  * that wasn't needed.
86  */
87  if (strcmp(new_rel->nspname, "pg_toast") != 0)
88  {
89  report_unmatched_relation(new_rel, new_db, true);
90  all_matched = false;
91  }
92  new_relnum++;
93  continue;
94  }
95 
96  /* check for mismatched OID */
97  if (old_rel->reloid < new_rel->reloid)
98  {
99  /* old_rel is unmatched, see comment above */
100  report_unmatched_relation(old_rel, old_db, false);
101  all_matched = false;
102  old_relnum++;
103  continue;
104  }
105  else if (old_rel->reloid > new_rel->reloid)
106  {
107  /* new_rel is unmatched, see comment above */
108  if (strcmp(new_rel->nspname, "pg_toast") != 0)
109  {
110  report_unmatched_relation(new_rel, new_db, true);
111  all_matched = false;
112  }
113  new_relnum++;
114  continue;
115  }
116 
117  /*
118  * Verify that rels of same OID have same name. The namespace name
119  * should always match, but the relname might not match for TOAST
120  * tables (and, therefore, their indexes).
121  */
122  if (strcmp(old_rel->nspname, new_rel->nspname) != 0 ||
123  strcmp(old_rel->relname, new_rel->relname) != 0)
124  {
125  pg_log(PG_WARNING, "Relation names for OID %u in database \"%s\" do not match: "
126  "old name \"%s.%s\", new name \"%s.%s\"\n",
127  old_rel->reloid, old_db->db_name,
128  old_rel->nspname, old_rel->relname,
129  new_rel->nspname, new_rel->relname);
130  all_matched = false;
131  old_relnum++;
132  new_relnum++;
133  continue;
134  }
135 
136  /* OK, create a mapping entry */
137  create_rel_filename_map(old_pgdata, new_pgdata, old_db, new_db,
138  old_rel, new_rel, maps + num_maps);
139  num_maps++;
140  old_relnum++;
141  new_relnum++;
142  }
143 
144  if (!all_matched)
145  pg_fatal("Failed to match up old and new tables in database \"%s\"\n",
146  old_db->db_name);
147 
148  *nmaps = num_maps;
149  return maps;
150 }
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static void report_unmatched_relation(const RelInfo *rel, const DbInfo *db, bool is_new_db)
Definition: info.c:208
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)
Definition: info.c:159
#define pg_fatal(...)
void void pg_log(eLogType type, const char *fmt,...) pg_attribute_printf(2
@ PG_WARNING
Definition: pg_upgrade.h:240
Oid reloid
Definition: pg_upgrade.h:137
static const pg_conv_map maps[]

References create_rel_filename_map(), DbInfo::db_name, maps, RelInfoArr::nrels, RelInfo::nspname, pg_fatal, pg_log(), pg_malloc(), PG_WARNING, DbInfo::rel_arr, RelInfo::relname, RelInfo::reloid, RelInfoArr::rels, and report_unmatched_relation().

Referenced by transfer_all_new_dbs().

◆ get_db_and_rel_infos()

void get_db_and_rel_infos ( ClusterInfo cluster)

Definition at line 274 of file info.c.

275 {
276  int dbnum;
277 
278  if (cluster->dbarr.dbs != NULL)
280 
282 
283  for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
284  get_rel_infos(cluster, &cluster->dbarr.dbs[dbnum]);
285 
286  if (cluster == &old_cluster)
287  pg_log(PG_VERBOSE, "\nsource databases:\n");
288  else
289  pg_log(PG_VERBOSE, "\ntarget databases:\n");
290 
291  if (log_opts.verbose)
292  print_db_infos(&cluster->dbarr);
293 }
void cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel)
Definition: cluster.c:108
static void print_db_infos(DbInfoArr *dbinfo)
Definition: info.c:599
static void get_db_infos(ClusterInfo *cluster)
Definition: info.c:303
static void free_db_and_rel_infos(DbInfoArr *db_arr)
Definition: info.c:565
static void get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
Definition: info.c:384
LogOpts log_opts
Definition: util.c:17
@ PG_VERBOSE
Definition: pg_upgrade.h:237
bool verbose
Definition: pg_upgrade.h:278

References cluster(), free_db_and_rel_infos(), get_db_infos(), get_rel_infos(), log_opts, old_cluster, pg_log(), PG_VERBOSE, print_db_infos(), and LogOpts::verbose.

Referenced by check_and_dump_old_cluster(), check_new_cluster(), and create_new_objects().

◆ get_db_infos()

static void get_db_infos ( ClusterInfo cluster)
static

Definition at line 303 of file info.c.

304 {
305  PGconn *conn = connectToServer(cluster, "template1");
306  PGresult *res;
307  int ntups;
308  int tupnum;
309  DbInfo *dbinfos;
310  int i_datname,
311  i_oid,
312  i_encoding,
313  i_datcollate,
314  i_datctype,
315  i_datlocprovider,
316  i_daticulocale,
317  i_spclocation;
318  char query[QUERY_ALLOC];
319 
320  snprintf(query, sizeof(query),
321  "SELECT d.oid, d.datname, d.encoding, d.datcollate, d.datctype, ");
323  snprintf(query + strlen(query), sizeof(query) - strlen(query),
324  "'c' AS datlocprovider, NULL AS daticulocale, ");
325  else
326  snprintf(query + strlen(query), sizeof(query) - strlen(query),
327  "datlocprovider, daticulocale, ");
328  snprintf(query + strlen(query), sizeof(query) - strlen(query),
329  "pg_catalog.pg_tablespace_location(t.oid) AS spclocation "
330  "FROM pg_catalog.pg_database d "
331  " LEFT OUTER JOIN pg_catalog.pg_tablespace t "
332  " ON d.dattablespace = t.oid "
333  "WHERE d.datallowconn = true "
334  "ORDER BY 1");
335 
336  res = executeQueryOrDie(conn, "%s", query);
337 
338  i_oid = PQfnumber(res, "oid");
339  i_datname = PQfnumber(res, "datname");
340  i_encoding = PQfnumber(res, "encoding");
341  i_datcollate = PQfnumber(res, "datcollate");
342  i_datctype = PQfnumber(res, "datctype");
343  i_datlocprovider = PQfnumber(res, "datlocprovider");
344  i_daticulocale = PQfnumber(res, "daticulocale");
345  i_spclocation = PQfnumber(res, "spclocation");
346 
347  ntups = PQntuples(res);
348  dbinfos = (DbInfo *) pg_malloc(sizeof(DbInfo) * ntups);
349 
350  for (tupnum = 0; tupnum < ntups; tupnum++)
351  {
352  dbinfos[tupnum].db_oid = atooid(PQgetvalue(res, tupnum, i_oid));
353  dbinfos[tupnum].db_name = pg_strdup(PQgetvalue(res, tupnum, i_datname));
354  dbinfos[tupnum].db_encoding = atoi(PQgetvalue(res, tupnum, i_encoding));
355  dbinfos[tupnum].db_collate = pg_strdup(PQgetvalue(res, tupnum, i_datcollate));
356  dbinfos[tupnum].db_ctype = pg_strdup(PQgetvalue(res, tupnum, i_datctype));
357  dbinfos[tupnum].db_collprovider = PQgetvalue(res, tupnum, i_datlocprovider)[0];
358  if (PQgetisnull(res, tupnum, i_daticulocale))
359  dbinfos[tupnum].db_iculocale = NULL;
360  else
361  dbinfos[tupnum].db_iculocale = pg_strdup(PQgetvalue(res, tupnum, i_daticulocale));
362  snprintf(dbinfos[tupnum].db_tablespace, sizeof(dbinfos[tupnum].db_tablespace), "%s",
363  PQgetvalue(res, tupnum, i_spclocation));
364  }
365  PQclear(res);
366 
367  PQfinish(conn);
368 
369  cluster->dbarr.dbs = dbinfos;
370  cluster->dbarr.ndbs = ntups;
371 }
void PQfinish(PGconn *conn)
Definition: fe-connect.c:4261
void PQclear(PGresult *res)
Definition: fe-exec.c:718
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3340
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3735
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3448
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3760
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define QUERY_ALLOC
Definition: pg_upgrade.h:22
PGconn * connectToServer(ClusterInfo *cluster, const char *db_name)
Definition: server.c:28
#define GET_MAJOR_VERSION(v)
Definition: pg_upgrade.h:26
PGresult * executeQueryOrDie(PGconn *conn, const char *fmt,...) pg_attribute_printf(2
#define snprintf
Definition: port.h:225
#define atooid(x)
Definition: postgres_ext.h:42
PGconn * conn
Definition: streamutil.c:54
uint32 major_version
Definition: pg_upgrade.h:265
char * db_iculocale
Definition: pg_upgrade.h:180
char db_collprovider
Definition: pg_upgrade.h:179
char * db_collate
Definition: pg_upgrade.h:177
int db_encoding
Definition: pg_upgrade.h:181
char * db_ctype
Definition: pg_upgrade.h:178

References atooid, cluster(), conn, connectToServer(), DbInfo::db_collate, DbInfo::db_collprovider, DbInfo::db_ctype, DbInfo::db_encoding, DbInfo::db_iculocale, DbInfo::db_name, DbInfo::db_oid, executeQueryOrDie(), GET_MAJOR_VERSION, ClusterInfo::major_version, old_cluster, pg_malloc(), pg_strdup(), PQclear(), PQfinish(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), QUERY_ALLOC, res, and snprintf.

Referenced by get_db_and_rel_infos().

◆ get_rel_infos()

static void get_rel_infos ( ClusterInfo cluster,
DbInfo dbinfo 
)
static

Definition at line 384 of file info.c.

385 {
387  dbinfo->db_name);
388  PGresult *res;
389  RelInfo *relinfos;
390  int ntups;
391  int relnum;
392  int num_rels = 0;
393  char *nspname = NULL;
394  char *relname = NULL;
395  char *tablespace = NULL;
396  int i_spclocation,
397  i_nspname,
398  i_relname,
399  i_reloid,
400  i_indtable,
401  i_toastheap,
402  i_relfilenode,
403  i_reltablespace;
404  char query[QUERY_ALLOC];
405  char *last_namespace = NULL,
406  *last_tablespace = NULL;
407 
408  query[0] = '\0'; /* initialize query string to empty */
409 
410  /*
411  * Create a CTE that collects OIDs of regular user tables, including
412  * matviews and sequences, but excluding toast tables and indexes. We
413  * assume that relations with OIDs >= FirstNormalObjectId belong to the
414  * user. (That's probably redundant with the namespace-name exclusions,
415  * but let's be safe.)
416  *
417  * pg_largeobject contains user data that does not appear in pg_dump
418  * output, so we have to copy that system table. It's easiest to do that
419  * by treating it as a user table.
420  */
421  snprintf(query + strlen(query), sizeof(query) - strlen(query),
422  "WITH regular_heap (reloid, indtable, toastheap) AS ( "
423  " SELECT c.oid, 0::oid, 0::oid "
424  " FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n "
425  " ON c.relnamespace = n.oid "
426  " WHERE relkind IN (" CppAsString2(RELKIND_RELATION) ", "
427  CppAsString2(RELKIND_MATVIEW) ") AND "
428  /* exclude possible orphaned temp tables */
429  " ((n.nspname !~ '^pg_temp_' AND "
430  " n.nspname !~ '^pg_toast_temp_' AND "
431  " n.nspname NOT IN ('pg_catalog', 'information_schema', "
432  " 'binary_upgrade', 'pg_toast') AND "
433  " c.oid >= %u::pg_catalog.oid) OR "
434  " (n.nspname = 'pg_catalog' AND "
435  " relname IN ('pg_largeobject') ))), ",
437 
438  /*
439  * Add a CTE that collects OIDs of toast tables belonging to the tables
440  * selected by the regular_heap CTE. (We have to do this separately
441  * because the namespace-name rules above don't work for toast tables.)
442  */
443  snprintf(query + strlen(query), sizeof(query) - strlen(query),
444  " toast_heap (reloid, indtable, toastheap) AS ( "
445  " SELECT c.reltoastrelid, 0::oid, c.oid "
446  " FROM regular_heap JOIN pg_catalog.pg_class c "
447  " ON regular_heap.reloid = c.oid "
448  " WHERE c.reltoastrelid != 0), ");
449 
450  /*
451  * Add a CTE that collects OIDs of all valid indexes on the previously
452  * selected tables. We can ignore invalid indexes since pg_dump does.
453  * Testing indisready is necessary in 9.2, and harmless in earlier/later
454  * versions.
455  */
456  snprintf(query + strlen(query), sizeof(query) - strlen(query),
457  " all_index (reloid, indtable, toastheap) AS ( "
458  " SELECT indexrelid, indrelid, 0::oid "
459  " FROM pg_catalog.pg_index "
460  " WHERE indisvalid AND indisready "
461  " AND indrelid IN "
462  " (SELECT reloid FROM regular_heap "
463  " UNION ALL "
464  " SELECT reloid FROM toast_heap)) ");
465 
466  /*
467  * And now we can write the query that retrieves the data we want for each
468  * heap and index relation. Make sure result is sorted by OID.
469  */
470  snprintf(query + strlen(query), sizeof(query) - strlen(query),
471  "SELECT all_rels.*, n.nspname, c.relname, "
472  " c.relfilenode, c.reltablespace, "
473  " pg_catalog.pg_tablespace_location(t.oid) AS spclocation "
474  "FROM (SELECT * FROM regular_heap "
475  " UNION ALL "
476  " SELECT * FROM toast_heap "
477  " UNION ALL "
478  " SELECT * FROM all_index) all_rels "
479  " JOIN pg_catalog.pg_class c "
480  " ON all_rels.reloid = c.oid "
481  " JOIN pg_catalog.pg_namespace n "
482  " ON c.relnamespace = n.oid "
483  " LEFT OUTER JOIN pg_catalog.pg_tablespace t "
484  " ON c.reltablespace = t.oid "
485  "ORDER BY 1;");
486 
487  res = executeQueryOrDie(conn, "%s", query);
488 
489  ntups = PQntuples(res);
490 
491  relinfos = (RelInfo *) pg_malloc(sizeof(RelInfo) * ntups);
492 
493  i_reloid = PQfnumber(res, "reloid");
494  i_indtable = PQfnumber(res, "indtable");
495  i_toastheap = PQfnumber(res, "toastheap");
496  i_nspname = PQfnumber(res, "nspname");
497  i_relname = PQfnumber(res, "relname");
498  i_relfilenode = PQfnumber(res, "relfilenode");
499  i_reltablespace = PQfnumber(res, "reltablespace");
500  i_spclocation = PQfnumber(res, "spclocation");
501 
502  for (relnum = 0; relnum < ntups; relnum++)
503  {
504  RelInfo *curr = &relinfos[num_rels++];
505 
506  curr->reloid = atooid(PQgetvalue(res, relnum, i_reloid));
507  curr->indtable = atooid(PQgetvalue(res, relnum, i_indtable));
508  curr->toastheap = atooid(PQgetvalue(res, relnum, i_toastheap));
509 
510  nspname = PQgetvalue(res, relnum, i_nspname);
511  curr->nsp_alloc = false;
512 
513  /*
514  * Many of the namespace and tablespace strings are identical, so we
515  * try to reuse the allocated string pointers where possible to reduce
516  * memory consumption.
517  */
518  /* Can we reuse the previous string allocation? */
519  if (last_namespace && strcmp(nspname, last_namespace) == 0)
520  curr->nspname = last_namespace;
521  else
522  {
523  last_namespace = curr->nspname = pg_strdup(nspname);
524  curr->nsp_alloc = true;
525  }
526 
527  relname = PQgetvalue(res, relnum, i_relname);
528  curr->relname = pg_strdup(relname);
529 
530  curr->relfilenode = atooid(PQgetvalue(res, relnum, i_relfilenode));
531  curr->tblsp_alloc = false;
532 
533  /* Is the tablespace oid non-default? */
534  if (atooid(PQgetvalue(res, relnum, i_reltablespace)) != 0)
535  {
536  /*
537  * The tablespace location might be "", meaning the cluster
538  * default location, i.e. pg_default or pg_global.
539  */
540  tablespace = PQgetvalue(res, relnum, i_spclocation);
541 
542  /* Can we reuse the previous string allocation? */
543  if (last_tablespace && strcmp(tablespace, last_tablespace) == 0)
544  curr->tablespace = last_tablespace;
545  else
546  {
547  last_tablespace = curr->tablespace = pg_strdup(tablespace);
548  curr->tblsp_alloc = true;
549  }
550  }
551  else
552  /* A zero reltablespace oid indicates the database tablespace. */
553  curr->tablespace = dbinfo->db_tablespace;
554  }
555  PQclear(res);
556 
557  PQfinish(conn);
558 
559  dbinfo->rel_arr.rels = relinfos;
560  dbinfo->rel_arr.nrels = num_rels;
561 }
#define CppAsString2(x)
Definition: c.h:289
NameData relname
Definition: pg_class.h:38
char * tablespace
Definition: pgbench.c:229
char db_tablespace[MAXPGPATH]
Definition: pg_upgrade.h:175
Oid toastheap
Definition: pg_upgrade.h:140
Oid indtable
Definition: pg_upgrade.h:139
#define FirstNormalObjectId
Definition: transam.h:197

References atooid, cluster(), conn, connectToServer(), CppAsString2, DbInfo::db_name, DbInfo::db_tablespace, executeQueryOrDie(), FirstNormalObjectId, RelInfo::indtable, RelInfoArr::nrels, RelInfo::nsp_alloc, RelInfo::nspname, pg_malloc(), pg_strdup(), PQclear(), PQfinish(), PQfnumber(), PQgetvalue(), PQntuples(), QUERY_ALLOC, DbInfo::rel_arr, RelInfo::relfilenode, RelInfo::relname, relname, RelInfo::reloid, RelInfoArr::rels, res, snprintf, RelInfo::tablespace, tablespace, RelInfo::tblsp_alloc, and RelInfo::toastheap.

Referenced by get_db_and_rel_infos().

◆ print_db_infos()

static void print_db_infos ( DbInfoArr dbinfo)
static

Definition at line 599 of file info.c.

600 {
601  int dbnum;
602 
603  for (dbnum = 0; dbnum < db_arr->ndbs; dbnum++)
604  {
605  pg_log(PG_VERBOSE, "Database: %s\n", db_arr->dbs[dbnum].db_name);
606  print_rel_infos(&db_arr->dbs[dbnum].rel_arr);
607  pg_log(PG_VERBOSE, "\n\n");
608  }
609 }
static void print_rel_infos(RelInfoArr *rel_arr)
Definition: info.c:613

References DbInfo::db_name, DbInfoArr::dbs, DbInfoArr::ndbs, pg_log(), PG_VERBOSE, print_rel_infos(), and DbInfo::rel_arr.

Referenced by get_db_and_rel_infos().

◆ print_rel_infos()

static void print_rel_infos ( RelInfoArr rel_arr)
static

Definition at line 613 of file info.c.

614 {
615  int relnum;
616 
617  for (relnum = 0; relnum < rel_arr->nrels; relnum++)
618  pg_log(PG_VERBOSE, "relname: %s.%s: reloid: %u reltblspace: %s\n",
619  rel_arr->rels[relnum].nspname,
620  rel_arr->rels[relnum].relname,
621  rel_arr->rels[relnum].reloid,
622  rel_arr->rels[relnum].tablespace);
623 }

References RelInfoArr::nrels, RelInfo::nspname, pg_log(), PG_VERBOSE, RelInfo::relname, RelInfo::reloid, RelInfoArr::rels, and RelInfo::tablespace.

Referenced by print_db_infos().

◆ report_unmatched_relation()

static void report_unmatched_relation ( const RelInfo rel,
const DbInfo db,
bool  is_new_db 
)
static

Definition at line 208 of file info.c.

209 {
210  Oid reloid = rel->reloid; /* we might change rel below */
211  char reldesc[1000];
212  int i;
213 
214  snprintf(reldesc, sizeof(reldesc), "\"%s.%s\"",
215  rel->nspname, rel->relname);
216  if (rel->indtable)
217  {
218  for (i = 0; i < db->rel_arr.nrels; i++)
219  {
220  const RelInfo *hrel = &db->rel_arr.rels[i];
221 
222  if (hrel->reloid == rel->indtable)
223  {
224  snprintf(reldesc + strlen(reldesc),
225  sizeof(reldesc) - strlen(reldesc),
226  _(" which is an index on \"%s.%s\""),
227  hrel->nspname, hrel->relname);
228  /* Shift attention to index's table for toast check */
229  rel = hrel;
230  break;
231  }
232  }
233  if (i >= db->rel_arr.nrels)
234  snprintf(reldesc + strlen(reldesc),
235  sizeof(reldesc) - strlen(reldesc),
236  _(" which is an index on OID %u"), rel->indtable);
237  }
238  if (rel->toastheap)
239  {
240  for (i = 0; i < db->rel_arr.nrels; i++)
241  {
242  const RelInfo *brel = &db->rel_arr.rels[i];
243 
244  if (brel->reloid == rel->toastheap)
245  {
246  snprintf(reldesc + strlen(reldesc),
247  sizeof(reldesc) - strlen(reldesc),
248  _(" which is the TOAST table for \"%s.%s\""),
249  brel->nspname, brel->relname);
250  break;
251  }
252  }
253  if (i >= db->rel_arr.nrels)
254  snprintf(reldesc + strlen(reldesc),
255  sizeof(reldesc) - strlen(reldesc),
256  _(" which is the TOAST table for OID %u"), rel->toastheap);
257  }
258 
259  if (is_new_db)
260  pg_log(PG_WARNING, "No match found in old cluster for new relation with OID %u in database \"%s\": %s\n",
261  reloid, db->db_name, reldesc);
262  else
263  pg_log(PG_WARNING, "No match found in new cluster for old relation with OID %u in database \"%s\": %s\n",
264  reloid, db->db_name, reldesc);
265 }
#define _(x)
Definition: elog.c:89
int i
Definition: isn.c:73
unsigned int Oid
Definition: postgres_ext.h:31

References _, DbInfo::db_name, i, RelInfo::indtable, RelInfoArr::nrels, RelInfo::nspname, pg_log(), PG_WARNING, DbInfo::rel_arr, RelInfo::relname, RelInfo::reloid, RelInfoArr::rels, snprintf, and RelInfo::toastheap.

Referenced by gen_db_file_maps().