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