PostgreSQL Source Code  git master
version.c File Reference
#include "postgres_fe.h"
#include "fe_utils/string_utils.h"
#include "pg_upgrade.h"
Include dependency graph for version.c:

Go to the source code of this file.

Functions

bool jsonb_9_4_check_applicable (ClusterInfo *cluster)
 
void old_9_6_invalidate_hash_indexes (ClusterInfo *cluster, bool check_mode)
 
static void process_extension_updates (DbInfo *dbinfo, PGresult *res, void *arg)
 
void report_extension_updates (ClusterInfo *cluster)
 

Function Documentation

◆ jsonb_9_4_check_applicable()

bool jsonb_9_4_check_applicable ( ClusterInfo cluster)

Definition at line 21 of file version.c.

22 {
23  /* JSONB changed its storage format during 9.4 beta */
24  if (GET_MAJOR_VERSION(cluster->major_version) == 904 &&
25  cluster->controldata.cat_ver < JSONB_FORMAT_CHANGE_CAT_VER)
26  return true;
27 
28  return false;
29 }
void cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel)
Definition: cluster.c:107
#define GET_MAJOR_VERSION(v)
Definition: pg_upgrade.h:27
#define JSONB_FORMAT_CHANGE_CAT_VER
Definition: pg_upgrade.h:126

References cluster(), GET_MAJOR_VERSION, and JSONB_FORMAT_CHANGE_CAT_VER.

◆ old_9_6_invalidate_hash_indexes()

void old_9_6_invalidate_hash_indexes ( ClusterInfo cluster,
bool  check_mode 
)

Definition at line 37 of file version.c.

38 {
39  int dbnum;
40  FILE *script = NULL;
41  bool found = false;
42  char *output_path = "reindex_hash.sql";
43 
44  prep_status("Checking for hash indexes");
45 
46  for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
47  {
48  PGresult *res;
49  bool db_used = false;
50  int ntups;
51  int rowno;
52  int i_nspname,
53  i_relname;
54  DbInfo *active_db = &cluster->dbarr.dbs[dbnum];
55  PGconn *conn = connectToServer(cluster, active_db->db_name);
56 
57  /* find hash indexes */
59  "SELECT n.nspname, c.relname "
60  "FROM pg_catalog.pg_class c, "
61  " pg_catalog.pg_index i, "
62  " pg_catalog.pg_am a, "
63  " pg_catalog.pg_namespace n "
64  "WHERE i.indexrelid = c.oid AND "
65  " c.relam = a.oid AND "
66  " c.relnamespace = n.oid AND "
67  " a.amname = 'hash'"
68  );
69 
70  ntups = PQntuples(res);
71  i_nspname = PQfnumber(res, "nspname");
72  i_relname = PQfnumber(res, "relname");
73  for (rowno = 0; rowno < ntups; rowno++)
74  {
75  found = true;
76  if (!check_mode)
77  {
78  if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
79  pg_fatal("could not open file \"%s\": %m", output_path);
80  if (!db_used)
81  {
82  PQExpBufferData connectbuf;
83 
84  initPQExpBuffer(&connectbuf);
85  appendPsqlMetaConnect(&connectbuf, active_db->db_name);
86  fputs(connectbuf.data, script);
87  termPQExpBuffer(&connectbuf);
88  db_used = true;
89  }
90  fprintf(script, "REINDEX INDEX %s.%s;\n",
91  quote_identifier(PQgetvalue(res, rowno, i_nspname)),
92  quote_identifier(PQgetvalue(res, rowno, i_relname)));
93  }
94  }
95 
96  PQclear(res);
97 
98  if (!check_mode && db_used)
99  {
100  /* mark hash indexes as invalid */
102  "UPDATE pg_catalog.pg_index i "
103  "SET indisvalid = false "
104  "FROM pg_catalog.pg_class c, "
105  " pg_catalog.pg_am a, "
106  " pg_catalog.pg_namespace n "
107  "WHERE i.indexrelid = c.oid AND "
108  " c.relam = a.oid AND "
109  " c.relnamespace = n.oid AND "
110  " a.amname = 'hash'"));
111  }
112 
113  PQfinish(conn);
114  }
115 
116  if (script)
117  fclose(script);
118 
119  if (found)
120  {
121  report_status(PG_WARNING, "warning");
122  if (check_mode)
123  pg_log(PG_WARNING, "\n"
124  "Your installation contains hash indexes. These indexes have different\n"
125  "internal formats between your old and new clusters, so they must be\n"
126  "reindexed with the REINDEX command. After upgrading, you will be given\n"
127  "REINDEX instructions.");
128  else
129  pg_log(PG_WARNING, "\n"
130  "Your installation contains hash indexes. These indexes have different\n"
131  "internal formats between your old and new clusters, so they must be\n"
132  "reindexed with the REINDEX command. The file\n"
133  " %s\n"
134  "when executed by psql by the database superuser will recreate all invalid\n"
135  "indexes; until then, none of these indexes will be used.",
136  output_path);
137  }
138  else
139  check_ok();
140 }
void PQfinish(PGconn *conn)
Definition: fe-connect.c:4879
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3481
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3876
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3589
static void check_ok(void)
Definition: initdb.c:2091
#define pg_fatal(...)
void void pg_log(eLogType type, const char *fmt,...) pg_attribute_printf(2
#define fopen_priv(path, mode)
Definition: pg_upgrade.h:419
@ PG_WARNING
Definition: pg_upgrade.h:270
PGconn * connectToServer(ClusterInfo *cluster, const char *db_name)
Definition: server.c:28
void prep_status(const char *fmt,...) pg_attribute_printf(1
void report_status(eLogType type, const char *fmt,...) pg_attribute_printf(2
PGresult * executeQueryOrDie(PGconn *conn, const char *fmt,...) pg_attribute_printf(2
#define fprintf
Definition: port.h:242
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:90
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:129
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:12868
PGconn * conn
Definition: streamutil.c:53
void appendPsqlMetaConnect(PQExpBuffer buf, const char *dbname)
Definition: string_utils.c:590
char * db_name
Definition: pg_upgrade.h:194

References appendPsqlMetaConnect(), check_ok(), cluster(), conn, connectToServer(), PQExpBufferData::data, DbInfo::db_name, executeQueryOrDie(), fopen_priv, fprintf, initPQExpBuffer(), pg_fatal, pg_log(), PG_WARNING, PQclear(), PQfinish(), PQfnumber(), PQgetvalue(), PQntuples(), prep_status(), quote_identifier(), report_status(), res, and termPQExpBuffer().

Referenced by check_and_dump_old_cluster(), and issue_warnings_and_set_wal_level().

◆ process_extension_updates()

static void process_extension_updates ( DbInfo dbinfo,
PGresult res,
void *  arg 
)
static

Definition at line 148 of file version.c.

149 {
150  int ntups = PQntuples(res);
151  int i_name = PQfnumber(res, "name");
153  PQExpBufferData connectbuf;
154 
156 
157  if (ntups == 0)
158  return;
159 
160  if (report->file == NULL &&
161  (report->file = fopen_priv(report->path, "w")) == NULL)
162  pg_fatal("could not open file \"%s\": %m", report->path);
163 
164  initPQExpBuffer(&connectbuf);
165  appendPsqlMetaConnect(&connectbuf, dbinfo->db_name);
166  fputs(connectbuf.data, report->file);
167  termPQExpBuffer(&connectbuf);
168 
169  for (int rowno = 0; rowno < ntups; rowno++)
170  fprintf(report->file, "ALTER EXTENSION %s UPDATE;\n",
171  quote_identifier(PQgetvalue(res, rowno, i_name)));
172 }
static void process_extension_updates(DbInfo *dbinfo, PGresult *res, void *arg)
Definition: version.c:148
#define AssertVariableIsOfType(varname, typename)
Definition: c.h:935
void * arg
static struct LogicalRepInfo * dbinfo
void(* UpgradeTaskProcessCB)(DbInfo *dbinfo, PGresult *res, void *arg)
Definition: pg_upgrade.h:500
char path[MAXPGPATH]
Definition: pg_upgrade.h:516

References appendPsqlMetaConnect(), arg, AssertVariableIsOfType, PQExpBufferData::data, dbinfo, UpgradeTaskReport::file, fopen_priv, fprintf, initPQExpBuffer(), UpgradeTaskReport::path, pg_fatal, PQfnumber(), PQgetvalue(), PQntuples(), quote_identifier(), res, and termPQExpBuffer().

Referenced by report_extension_updates().

◆ report_extension_updates()

void report_extension_updates ( ClusterInfo cluster)

Definition at line 179 of file version.c.

180 {
181  UpgradeTaskReport report;
183  const char *query = "SELECT name "
184  "FROM pg_available_extensions "
185  "WHERE installed_version != default_version";
186 
187  prep_status("Checking for extension updates");
188 
189  report.file = NULL;
190  strcpy(report.path, "update_extensions.sql");
191 
193  true, &report);
194 
195  upgrade_task_run(task, cluster);
196  upgrade_task_free(task);
197 
198  if (report.file)
199  {
200  fclose(report.file);
201  report_status(PG_REPORT, "notice");
202  pg_log(PG_REPORT, "\n"
203  "Your installation contains extensions that should be updated\n"
204  "with the ALTER EXTENSION command. The file\n"
205  " %s\n"
206  "when executed by psql by the database superuser will update\n"
207  "these extensions.",
208  report.path);
209  }
210  else
211  check_ok();
212 }
UpgradeTask * upgrade_task_create(void)
Definition: task.c:117
void upgrade_task_run(const UpgradeTask *task, const ClusterInfo *cluster)
Definition: task.c:420
void upgrade_task_free(UpgradeTask *task)
Definition: task.c:133
@ PG_REPORT
Definition: pg_upgrade.h:269
void upgrade_task_add_step(UpgradeTask *task, const char *query, UpgradeTaskProcessCB process_cb, bool free_result, void *arg)
Definition: task.c:151

References check_ok(), cluster(), UpgradeTaskReport::file, UpgradeTaskReport::path, pg_log(), PG_REPORT, prep_status(), process_extension_updates(), report_status(), upgrade_task_add_step(), upgrade_task_create(), upgrade_task_free(), and upgrade_task_run().

Referenced by issue_warnings_and_set_wal_level().