PostgreSQL Source Code  git master
info.c
Go to the documentation of this file.
1 /*
2  * info.c
3  *
4  * information support functions
5  *
6  * Copyright (c) 2010-2023, PostgreSQL Global Development Group
7  * src/bin/pg_upgrade/info.c
8  */
9 
10 #include "postgres_fe.h"
11 
12 #include "access/transam.h"
13 #include "catalog/pg_class_d.h"
14 #include "pg_upgrade.h"
15 
16 static void create_rel_filename_map(const char *old_data, const char *new_data,
17  const DbInfo *old_db, const DbInfo *new_db,
18  const RelInfo *old_rel, const RelInfo *new_rel,
19  FileNameMap *map);
20 static void report_unmatched_relation(const RelInfo *rel, const DbInfo *db,
21  bool is_new_db);
22 static void free_db_and_rel_infos(DbInfoArr *db_arr);
24 static void get_db_infos(ClusterInfo *cluster);
25 static void get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo);
26 static void free_rel_infos(RelInfoArr *rel_arr);
27 static void print_db_infos(DbInfoArr *db_arr);
28 static void print_rel_infos(RelInfoArr *rel_arr);
29 
30 
31 /*
32  * gen_db_file_maps()
33  *
34  * generates a database mapping from "old_db" to "new_db".
35  *
36  * Returns a malloc'ed array of mappings. The length of the array
37  * is returned into *nmaps.
38  */
40 gen_db_file_maps(DbInfo *old_db, DbInfo *new_db,
41  int *nmaps,
42  const char *old_pgdata, const char *new_pgdata)
43 {
45  int old_relnum,
46  new_relnum;
47  int num_maps = 0;
48  bool all_matched = true;
49 
50  /* There will certainly not be more mappings than there are old rels */
51  maps = (FileNameMap *) pg_malloc(sizeof(FileNameMap) *
52  old_db->rel_arr.nrels);
53 
54  /*
55  * Each of the RelInfo arrays should be sorted by OID. Scan through them
56  * and match them up. If we fail to match everything, we'll abort, but
57  * first print as much info as we can about mismatches.
58  */
59  old_relnum = new_relnum = 0;
60  while (old_relnum < old_db->rel_arr.nrels ||
61  new_relnum < new_db->rel_arr.nrels)
62  {
63  RelInfo *old_rel = (old_relnum < old_db->rel_arr.nrels) ?
64  &old_db->rel_arr.rels[old_relnum] : NULL;
65  RelInfo *new_rel = (new_relnum < new_db->rel_arr.nrels) ?
66  &new_db->rel_arr.rels[new_relnum] : NULL;
67 
68  /* handle running off one array before the other */
69  if (!new_rel)
70  {
71  /*
72  * old_rel is unmatched. This should never happen, because we
73  * force new rels to have TOAST tables if the old one did.
74  */
75  report_unmatched_relation(old_rel, old_db, false);
76  all_matched = false;
77  old_relnum++;
78  continue;
79  }
80  if (!old_rel)
81  {
82  /*
83  * new_rel is unmatched. This shouldn't really happen either, but
84  * if it's a TOAST table, we can ignore it and continue
85  * processing, assuming that the new server made a TOAST table
86  * that wasn't needed.
87  */
88  if (strcmp(new_rel->nspname, "pg_toast") != 0)
89  {
90  report_unmatched_relation(new_rel, new_db, true);
91  all_matched = false;
92  }
93  new_relnum++;
94  continue;
95  }
96 
97  /* check for mismatched OID */
98  if (old_rel->reloid < new_rel->reloid)
99  {
100  /* old_rel is unmatched, see comment above */
101  report_unmatched_relation(old_rel, old_db, false);
102  all_matched = false;
103  old_relnum++;
104  continue;
105  }
106  else if (old_rel->reloid > new_rel->reloid)
107  {
108  /* new_rel is unmatched, see comment above */
109  if (strcmp(new_rel->nspname, "pg_toast") != 0)
110  {
111  report_unmatched_relation(new_rel, new_db, true);
112  all_matched = false;
113  }
114  new_relnum++;
115  continue;
116  }
117 
118  /*
119  * Verify that rels of same OID have same name. The namespace name
120  * should always match, but the relname might not match for TOAST
121  * tables (and, therefore, their indexes).
122  */
123  if (strcmp(old_rel->nspname, new_rel->nspname) != 0 ||
124  strcmp(old_rel->relname, new_rel->relname) != 0)
125  {
126  pg_log(PG_WARNING, "Relation names for OID %u in database \"%s\" do not match: "
127  "old name \"%s.%s\", new name \"%s.%s\"",
128  old_rel->reloid, old_db->db_name,
129  old_rel->nspname, old_rel->relname,
130  new_rel->nspname, new_rel->relname);
131  all_matched = false;
132  old_relnum++;
133  new_relnum++;
134  continue;
135  }
136 
137  /* OK, create a mapping entry */
138  create_rel_filename_map(old_pgdata, new_pgdata, old_db, new_db,
139  old_rel, new_rel, maps + num_maps);
140  num_maps++;
141  old_relnum++;
142  new_relnum++;
143  }
144 
145  if (!all_matched)
146  pg_fatal("Failed to match up old and new tables in database \"%s\"",
147  old_db->db_name);
148 
149  *nmaps = num_maps;
150  return maps;
151 }
152 
153 
154 /*
155  * create_rel_filename_map()
156  *
157  * fills a file node map structure and returns it in "map".
158  */
159 static void
160 create_rel_filename_map(const char *old_data, const char *new_data,
161  const DbInfo *old_db, const DbInfo *new_db,
162  const RelInfo *old_rel, const RelInfo *new_rel,
163  FileNameMap *map)
164 {
165  /* In case old/new tablespaces don't match, do them separately. */
166  if (strlen(old_rel->tablespace) == 0)
167  {
168  /*
169  * relation belongs to the default tablespace, hence relfiles should
170  * exist in the data directories.
171  */
172  map->old_tablespace = old_data;
173  map->old_tablespace_suffix = "/base";
174  }
175  else
176  {
177  /* relation belongs to a tablespace, so use the tablespace location */
178  map->old_tablespace = old_rel->tablespace;
180  }
181 
182  /* Do the same for new tablespaces */
183  if (strlen(new_rel->tablespace) == 0)
184  {
185  map->new_tablespace = new_data;
186  map->new_tablespace_suffix = "/base";
187  }
188  else
189  {
190  map->new_tablespace = new_rel->tablespace;
192  }
193 
194  /* DB oid and relfilenumbers are preserved between old and new cluster */
195  map->db_oid = old_db->db_oid;
196  map->relfilenumber = old_rel->relfilenumber;
197 
198  /* used only for logging and error reporting, old/new are identical */
199  map->nspname = old_rel->nspname;
200  map->relname = old_rel->relname;
201 }
202 
203 
204 /*
205  * Complain about a relation we couldn't match to the other database,
206  * identifying it as best we can.
207  */
208 static void
209 report_unmatched_relation(const RelInfo *rel, const DbInfo *db, bool is_new_db)
210 {
211  Oid reloid = rel->reloid; /* we might change rel below */
212  char reldesc[1000];
213  int i;
214 
215  snprintf(reldesc, sizeof(reldesc), "\"%s.%s\"",
216  rel->nspname, rel->relname);
217  if (rel->indtable)
218  {
219  for (i = 0; i < db->rel_arr.nrels; i++)
220  {
221  const RelInfo *hrel = &db->rel_arr.rels[i];
222 
223  if (hrel->reloid == rel->indtable)
224  {
225  snprintf(reldesc + strlen(reldesc),
226  sizeof(reldesc) - strlen(reldesc),
227  _(" which is an index on \"%s.%s\""),
228  hrel->nspname, hrel->relname);
229  /* Shift attention to index's table for toast check */
230  rel = hrel;
231  break;
232  }
233  }
234  if (i >= db->rel_arr.nrels)
235  snprintf(reldesc + strlen(reldesc),
236  sizeof(reldesc) - strlen(reldesc),
237  _(" which is an index on OID %u"), rel->indtable);
238  }
239  if (rel->toastheap)
240  {
241  for (i = 0; i < db->rel_arr.nrels; i++)
242  {
243  const RelInfo *brel = &db->rel_arr.rels[i];
244 
245  if (brel->reloid == rel->toastheap)
246  {
247  snprintf(reldesc + strlen(reldesc),
248  sizeof(reldesc) - strlen(reldesc),
249  _(" which is the TOAST table for \"%s.%s\""),
250  brel->nspname, brel->relname);
251  break;
252  }
253  }
254  if (i >= db->rel_arr.nrels)
255  snprintf(reldesc + strlen(reldesc),
256  sizeof(reldesc) - strlen(reldesc),
257  _(" which is the TOAST table for OID %u"), rel->toastheap);
258  }
259 
260  if (is_new_db)
261  pg_log(PG_WARNING, "No match found in old cluster for new relation with OID %u in database \"%s\": %s",
262  reloid, db->db_name, reldesc);
263  else
264  pg_log(PG_WARNING, "No match found in new cluster for old relation with OID %u in database \"%s\": %s",
265  reloid, db->db_name, reldesc);
266 }
267 
268 /*
269  * get_db_and_rel_infos()
270  *
271  * higher level routine to generate dbinfos for the database running
272  * on the given "port". Assumes that server is already running.
273  */
274 void
276 {
277  int dbnum;
278 
279  if (cluster->dbarr.dbs != NULL)
281 
284 
285  for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
286  get_rel_infos(cluster, &cluster->dbarr.dbs[dbnum]);
287 
288  if (cluster == &old_cluster)
289  pg_log(PG_VERBOSE, "\nsource databases:");
290  else
291  pg_log(PG_VERBOSE, "\ntarget databases:");
292 
293  if (log_opts.verbose)
294  print_db_infos(&cluster->dbarr);
295 }
296 
297 
298 /*
299  * Get information about template0, which will be copied from the old cluster
300  * to the new cluster.
301  */
302 static void
304 {
305  PGconn *conn = connectToServer(cluster, "template1");
307  PGresult *dbres;
308  int i_datencoding;
309  int i_datlocprovider;
310  int i_datcollate;
311  int i_datctype;
312  int i_daticulocale;
313 
314  if (GET_MAJOR_VERSION(cluster->major_version) >= 1500)
315  dbres = executeQueryOrDie(conn,
316  "SELECT encoding, datlocprovider, "
317  " datcollate, datctype, daticulocale "
318  "FROM pg_catalog.pg_database "
319  "WHERE datname='template0'");
320  else
321  dbres = executeQueryOrDie(conn,
322  "SELECT encoding, 'c' AS datlocprovider, "
323  " datcollate, datctype, NULL AS daticulocale "
324  "FROM pg_catalog.pg_database "
325  "WHERE datname='template0'");
326 
327 
328  if (PQntuples(dbres) != 1)
329  pg_fatal("template0 not found");
330 
331  locale = pg_malloc(sizeof(DbLocaleInfo));
332 
333  i_datencoding = PQfnumber(dbres, "encoding");
334  i_datlocprovider = PQfnumber(dbres, "datlocprovider");
335  i_datcollate = PQfnumber(dbres, "datcollate");
336  i_datctype = PQfnumber(dbres, "datctype");
337  i_daticulocale = PQfnumber(dbres, "daticulocale");
338 
339  locale->db_encoding = atoi(PQgetvalue(dbres, 0, i_datencoding));
340  locale->db_collprovider = PQgetvalue(dbres, 0, i_datlocprovider)[0];
341  locale->db_collate = pg_strdup(PQgetvalue(dbres, 0, i_datcollate));
342  locale->db_ctype = pg_strdup(PQgetvalue(dbres, 0, i_datctype));
343  if (PQgetisnull(dbres, 0, i_daticulocale))
344  locale->db_iculocale = NULL;
345  else
346  locale->db_iculocale = pg_strdup(PQgetvalue(dbres, 0, i_daticulocale));
347 
348  cluster->template0 = locale;
349 
350  PQclear(dbres);
351  PQfinish(conn);
352 }
353 
354 
355 /*
356  * get_db_infos()
357  *
358  * Scans pg_database system catalog and populates all user
359  * databases.
360  */
361 static void
363 {
364  PGconn *conn = connectToServer(cluster, "template1");
365  PGresult *res;
366  int ntups;
367  int tupnum;
368  DbInfo *dbinfos;
369  int i_datname,
370  i_oid,
371  i_spclocation;
372  char query[QUERY_ALLOC];
373 
374  snprintf(query, sizeof(query),
375  "SELECT d.oid, d.datname, d.encoding, d.datcollate, d.datctype, ");
376  if (GET_MAJOR_VERSION(cluster->major_version) < 1500)
377  snprintf(query + strlen(query), sizeof(query) - strlen(query),
378  "'c' AS datlocprovider, NULL AS daticulocale, ");
379  else
380  snprintf(query + strlen(query), sizeof(query) - strlen(query),
381  "datlocprovider, daticulocale, ");
382  snprintf(query + strlen(query), sizeof(query) - strlen(query),
383  "pg_catalog.pg_tablespace_location(t.oid) AS spclocation "
384  "FROM pg_catalog.pg_database d "
385  " LEFT OUTER JOIN pg_catalog.pg_tablespace t "
386  " ON d.dattablespace = t.oid "
387  "WHERE d.datallowconn = true "
388  "ORDER BY 1");
389 
390  res = executeQueryOrDie(conn, "%s", query);
391 
392  i_oid = PQfnumber(res, "oid");
393  i_datname = PQfnumber(res, "datname");
394  i_spclocation = PQfnumber(res, "spclocation");
395 
396  ntups = PQntuples(res);
397  dbinfos = (DbInfo *) pg_malloc(sizeof(DbInfo) * ntups);
398 
399  for (tupnum = 0; tupnum < ntups; tupnum++)
400  {
401  dbinfos[tupnum].db_oid = atooid(PQgetvalue(res, tupnum, i_oid));
402  dbinfos[tupnum].db_name = pg_strdup(PQgetvalue(res, tupnum, i_datname));
403  snprintf(dbinfos[tupnum].db_tablespace, sizeof(dbinfos[tupnum].db_tablespace), "%s",
404  PQgetvalue(res, tupnum, i_spclocation));
405  }
406  PQclear(res);
407 
408  PQfinish(conn);
409 
410  cluster->dbarr.dbs = dbinfos;
411  cluster->dbarr.ndbs = ntups;
412 }
413 
414 
415 /*
416  * get_rel_infos()
417  *
418  * gets the relinfos for all the user tables and indexes of the database
419  * referred to by "dbinfo".
420  *
421  * Note: the resulting RelInfo array is assumed to be sorted by OID.
422  * This allows later processing to match up old and new databases efficiently.
423  */
424 static void
426 {
428  dbinfo->db_name);
429  PGresult *res;
430  RelInfo *relinfos;
431  int ntups;
432  int relnum;
433  int num_rels = 0;
434  char *nspname = NULL;
435  char *relname = NULL;
436  char *tablespace = NULL;
437  int i_spclocation,
438  i_nspname,
439  i_relname,
440  i_reloid,
441  i_indtable,
442  i_toastheap,
443  i_relfilenumber,
444  i_reltablespace;
445  char query[QUERY_ALLOC];
446  char *last_namespace = NULL,
447  *last_tablespace = NULL;
448 
449  query[0] = '\0'; /* initialize query string to empty */
450 
451  /*
452  * Create a CTE that collects OIDs of regular user tables and matviews,
453  * but excluding toast tables and indexes. We assume that relations with
454  * OIDs >= FirstNormalObjectId belong to the user. (That's probably
455  * redundant with the namespace-name exclusions, but let's be safe.)
456  *
457  * pg_largeobject contains user data that does not appear in pg_dump
458  * output, so we have to copy that system table. It's easiest to do that
459  * by treating it as a user table.
460  */
461  snprintf(query + strlen(query), sizeof(query) - strlen(query),
462  "WITH regular_heap (reloid, indtable, toastheap) AS ( "
463  " SELECT c.oid, 0::oid, 0::oid "
464  " FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n "
465  " ON c.relnamespace = n.oid "
466  " WHERE relkind IN (" CppAsString2(RELKIND_RELATION) ", "
467  CppAsString2(RELKIND_MATVIEW) ") AND "
468  /* exclude possible orphaned temp tables */
469  " ((n.nspname !~ '^pg_temp_' AND "
470  " n.nspname !~ '^pg_toast_temp_' AND "
471  " n.nspname NOT IN ('pg_catalog', 'information_schema', "
472  " 'binary_upgrade', 'pg_toast') AND "
473  " c.oid >= %u::pg_catalog.oid) OR "
474  " (n.nspname = 'pg_catalog' AND "
475  " relname IN ('pg_largeobject') ))), ",
477 
478  /*
479  * Add a CTE that collects OIDs of toast tables belonging to the tables
480  * selected by the regular_heap CTE. (We have to do this separately
481  * because the namespace-name rules above don't work for toast tables.)
482  */
483  snprintf(query + strlen(query), sizeof(query) - strlen(query),
484  " toast_heap (reloid, indtable, toastheap) AS ( "
485  " SELECT c.reltoastrelid, 0::oid, c.oid "
486  " FROM regular_heap JOIN pg_catalog.pg_class c "
487  " ON regular_heap.reloid = c.oid "
488  " WHERE c.reltoastrelid != 0), ");
489 
490  /*
491  * Add a CTE that collects OIDs of all valid indexes on the previously
492  * selected tables. We can ignore invalid indexes since pg_dump does.
493  * Testing indisready is necessary in 9.2, and harmless in earlier/later
494  * versions.
495  */
496  snprintf(query + strlen(query), sizeof(query) - strlen(query),
497  " all_index (reloid, indtable, toastheap) AS ( "
498  " SELECT indexrelid, indrelid, 0::oid "
499  " FROM pg_catalog.pg_index "
500  " WHERE indisvalid AND indisready "
501  " AND indrelid IN "
502  " (SELECT reloid FROM regular_heap "
503  " UNION ALL "
504  " SELECT reloid FROM toast_heap)) ");
505 
506  /*
507  * And now we can write the query that retrieves the data we want for each
508  * heap and index relation. Make sure result is sorted by OID.
509  */
510  snprintf(query + strlen(query), sizeof(query) - strlen(query),
511  "SELECT all_rels.*, n.nspname, c.relname, "
512  " c.relfilenode, c.reltablespace, "
513  " pg_catalog.pg_tablespace_location(t.oid) AS spclocation "
514  "FROM (SELECT * FROM regular_heap "
515  " UNION ALL "
516  " SELECT * FROM toast_heap "
517  " UNION ALL "
518  " SELECT * FROM all_index) all_rels "
519  " JOIN pg_catalog.pg_class c "
520  " ON all_rels.reloid = c.oid "
521  " JOIN pg_catalog.pg_namespace n "
522  " ON c.relnamespace = n.oid "
523  " LEFT OUTER JOIN pg_catalog.pg_tablespace t "
524  " ON c.reltablespace = t.oid "
525  "ORDER BY 1;");
526 
527  res = executeQueryOrDie(conn, "%s", query);
528 
529  ntups = PQntuples(res);
530 
531  relinfos = (RelInfo *) pg_malloc(sizeof(RelInfo) * ntups);
532 
533  i_reloid = PQfnumber(res, "reloid");
534  i_indtable = PQfnumber(res, "indtable");
535  i_toastheap = PQfnumber(res, "toastheap");
536  i_nspname = PQfnumber(res, "nspname");
537  i_relname = PQfnumber(res, "relname");
538  i_relfilenumber = PQfnumber(res, "relfilenode");
539  i_reltablespace = PQfnumber(res, "reltablespace");
540  i_spclocation = PQfnumber(res, "spclocation");
541 
542  for (relnum = 0; relnum < ntups; relnum++)
543  {
544  RelInfo *curr = &relinfos[num_rels++];
545 
546  curr->reloid = atooid(PQgetvalue(res, relnum, i_reloid));
547  curr->indtable = atooid(PQgetvalue(res, relnum, i_indtable));
548  curr->toastheap = atooid(PQgetvalue(res, relnum, i_toastheap));
549 
550  nspname = PQgetvalue(res, relnum, i_nspname);
551  curr->nsp_alloc = false;
552 
553  /*
554  * Many of the namespace and tablespace strings are identical, so we
555  * try to reuse the allocated string pointers where possible to reduce
556  * memory consumption.
557  */
558  /* Can we reuse the previous string allocation? */
559  if (last_namespace && strcmp(nspname, last_namespace) == 0)
560  curr->nspname = last_namespace;
561  else
562  {
563  last_namespace = curr->nspname = pg_strdup(nspname);
564  curr->nsp_alloc = true;
565  }
566 
567  relname = PQgetvalue(res, relnum, i_relname);
568  curr->relname = pg_strdup(relname);
569 
570  curr->relfilenumber = atooid(PQgetvalue(res, relnum, i_relfilenumber));
571  curr->tblsp_alloc = false;
572 
573  /* Is the tablespace oid non-default? */
574  if (atooid(PQgetvalue(res, relnum, i_reltablespace)) != 0)
575  {
576  /*
577  * The tablespace location might be "", meaning the cluster
578  * default location, i.e. pg_default or pg_global.
579  */
580  tablespace = PQgetvalue(res, relnum, i_spclocation);
581 
582  /* Can we reuse the previous string allocation? */
583  if (last_tablespace && strcmp(tablespace, last_tablespace) == 0)
584  curr->tablespace = last_tablespace;
585  else
586  {
587  last_tablespace = curr->tablespace = pg_strdup(tablespace);
588  curr->tblsp_alloc = true;
589  }
590  }
591  else
592  /* A zero reltablespace oid indicates the database tablespace. */
593  curr->tablespace = dbinfo->db_tablespace;
594  }
595  PQclear(res);
596 
597  PQfinish(conn);
598 
599  dbinfo->rel_arr.rels = relinfos;
600  dbinfo->rel_arr.nrels = num_rels;
601 }
602 
603 
604 static void
606 {
607  int dbnum;
608 
609  for (dbnum = 0; dbnum < db_arr->ndbs; dbnum++)
610  {
611  free_rel_infos(&db_arr->dbs[dbnum].rel_arr);
612  pg_free(db_arr->dbs[dbnum].db_name);
613  }
614  pg_free(db_arr->dbs);
615  db_arr->dbs = NULL;
616  db_arr->ndbs = 0;
617 }
618 
619 
620 static void
622 {
623  int relnum;
624 
625  for (relnum = 0; relnum < rel_arr->nrels; relnum++)
626  {
627  if (rel_arr->rels[relnum].nsp_alloc)
628  pg_free(rel_arr->rels[relnum].nspname);
629  pg_free(rel_arr->rels[relnum].relname);
630  if (rel_arr->rels[relnum].tblsp_alloc)
631  pg_free(rel_arr->rels[relnum].tablespace);
632  }
633  pg_free(rel_arr->rels);
634  rel_arr->nrels = 0;
635 }
636 
637 
638 static void
640 {
641  int dbnum;
642 
643  for (dbnum = 0; dbnum < db_arr->ndbs; dbnum++)
644  {
645  pg_log(PG_VERBOSE, "Database: \"%s\"", db_arr->dbs[dbnum].db_name);
646  print_rel_infos(&db_arr->dbs[dbnum].rel_arr);
647  }
648 }
649 
650 
651 static void
653 {
654  int relnum;
655 
656  for (relnum = 0; relnum < rel_arr->nrels; relnum++)
657  pg_log(PG_VERBOSE, "relname: \"%s.%s\", reloid: %u, reltblspace: \"%s\"",
658  rel_arr->rels[relnum].nspname,
659  rel_arr->rels[relnum].relname,
660  rel_arr->rels[relnum].reloid,
661  rel_arr->rels[relnum].tablespace);
662 }
#define CppAsString2(x)
Definition: c.h:316
void cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel)
Definition: cluster.c:110
#define _(x)
Definition: elog.c:91
void PQfinish(PGconn *conn)
Definition: fe-connect.c:4602
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3395
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3790
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3503
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3815
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void pg_free(void *ptr)
Definition: fe_memutils.c:105
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static void get_template0_info(ClusterInfo *cluster)
Definition: info.c:303
static void report_unmatched_relation(const RelInfo *rel, const DbInfo *db, bool is_new_db)
Definition: info.c:209
static void get_db_infos(ClusterInfo *cluster)
Definition: info.c:362
static void free_rel_infos(RelInfoArr *rel_arr)
Definition: info.c:621
static void print_rel_infos(RelInfoArr *rel_arr)
Definition: info.c:652
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:160
FileNameMap * gen_db_file_maps(DbInfo *old_db, DbInfo *new_db, int *nmaps, const char *old_pgdata, const char *new_pgdata)
Definition: info.c:40
static void free_db_and_rel_infos(DbInfoArr *db_arr)
Definition: info.c:605
static void print_db_infos(DbInfoArr *db_arr)
Definition: info.c:639
void get_db_and_rel_infos(ClusterInfo *cluster)
Definition: info.c:275
static void get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
Definition: info.c:425
static char * locale
Definition: initdb.c:140
int i
Definition: isn.c:73
#define pg_fatal(...)
NameData relname
Definition: pg_class.h:38
ClusterInfo new_cluster
Definition: pg_upgrade.c:64
ClusterInfo old_cluster
Definition: pg_upgrade.c:63
#define QUERY_ALLOC
Definition: pg_upgrade.h:23
void void pg_log(eLogType type, const char *fmt,...) pg_attribute_printf(2
LogOpts log_opts
Definition: util.c:17
@ PG_WARNING
Definition: pg_upgrade.h:249
@ PG_VERBOSE
Definition: pg_upgrade.h:245
PGconn * connectToServer(ClusterInfo *cluster, const char *db_name)
Definition: server.c:28
#define GET_MAJOR_VERSION(v)
Definition: pg_upgrade.h:27
PGresult * executeQueryOrDie(PGconn *conn, const char *fmt,...) pg_attribute_printf(2
char * tablespace
Definition: pgbench.c:216
#define snprintf
Definition: port.h:238
unsigned int Oid
Definition: postgres_ext.h:31
#define atooid(x)
Definition: postgres_ext.h:42
PGconn * conn
Definition: streamutil.c:54
const char * tablespace_suffix
Definition: pg_upgrade.h:275
DbInfo * dbs
Definition: pg_upgrade.h:195
char db_tablespace[MAXPGPATH]
Definition: pg_upgrade.h:176
char * db_name
Definition: pg_upgrade.h:175
RelInfoArr rel_arr
Definition: pg_upgrade.h:178
Oid db_oid
Definition: pg_upgrade.h:174
const char * new_tablespace
Definition: pg_upgrade.h:159
const char * old_tablespace_suffix
Definition: pg_upgrade.h:160
const char * old_tablespace
Definition: pg_upgrade.h:158
RelFileNumber relfilenumber
Definition: pg_upgrade.h:163
char * relname
Definition: pg_upgrade.h:166
char * nspname
Definition: pg_upgrade.h:165
const char * new_tablespace_suffix
Definition: pg_upgrade.h:161
bool verbose
Definition: pg_upgrade.h:285
RelInfo * rels
Definition: pg_upgrade.h:149
RelFileNumber relfilenumber
Definition: pg_upgrade.h:139
Oid toastheap
Definition: pg_upgrade.h:141
bool tblsp_alloc
Definition: pg_upgrade.h:144
Oid reloid
Definition: pg_upgrade.h:138
char * nspname
Definition: pg_upgrade.h:136
char * tablespace
Definition: pg_upgrade.h:142
Oid indtable
Definition: pg_upgrade.h:140
bool nsp_alloc
Definition: pg_upgrade.h:143
char * relname
Definition: pg_upgrade.h:137
#define FirstNormalObjectId
Definition: transam.h:197
static const pg_conv_map maps[]