PostgreSQL Source Code git master
Loading...
Searching...
No Matches
version.c
Go to the documentation of this file.
1/*
2 * version.c
3 *
4 * Postgres-version-specific routines
5 *
6 * Copyright (c) 2010-2026, PostgreSQL Global Development Group
7 * src/bin/pg_upgrade/version.c
8 */
9
10#include "postgres_fe.h"
11
13#include "pg_upgrade.h"
14
15/*
16 * Older servers can't support newer protocol versions, so their connection
17 * strings will need to lock max_protocol_version to 3.0.
18 */
19bool
21{
22 /*
23 * The February 2018 patch release (9.3.21, 9.4.16, 9.5.11, 9.6.7, and
24 * 10.2) added support for NegotiateProtocolVersion. But ClusterInfo only
25 * has information about the major version number. To ensure we can still
26 * upgrade older unpatched servers, just assume anything prior to PG11
27 * can't negotiate. It's not possible for those servers to make use of
28 * newer protocols anyway, so nothing is lost.
29 */
30 return (GET_MAJOR_VERSION(cluster->major_version) >= 1100);
31}
32
33/*
34 * Callback function for processing results of query for
35 * report_extension_updates()'s UpgradeTask. If the query returned any rows,
36 * write the details to the report file.
37 */
38static void
40{
41 int ntups = PQntuples(res);
42 int i_name = PQfnumber(res, "name");
45
46 if (ntups == 0)
47 return;
48
49 if (report->file == NULL &&
50 (report->file = fopen_priv(report->path, "w")) == NULL)
51 pg_fatal("could not open file \"%s\": %m", report->path);
52
55 fputs(connectbuf.data, report->file);
57
58 for (int rowno = 0; rowno < ntups; rowno++)
59 fprintf(report->file, "ALTER EXTENSION %s UPDATE;\n",
61}
62
63/*
64 * report_extension_updates()
65 * Report extensions that should be updated.
66 */
67void
69{
70 UpgradeTaskReport report;
72 const char *query = "SELECT name "
73 "FROM pg_available_extensions "
74 "WHERE installed_version != default_version";
75
76 prep_status("Checking for extension updates");
77
78 report.file = NULL;
79 strcpy(report.path, "update_extensions.sql");
80
82 true, &report);
83
86
87 if (report.file)
88 {
89 fclose(report.file);
90 report_status(PG_REPORT, "notice");
91 pg_log(PG_REPORT, "\n"
92 "Your installation contains extensions that should be updated\n"
93 "with the ALTER EXTENSION command. The file\n"
94 " %s\n"
95 "when executed by psql by the database superuser will update\n"
96 "these extensions.",
97 report.path);
98 }
99 else
100 check_ok();
101}
void report_extension_updates(ClusterInfo *cluster)
Definition version.c:68
static void process_extension_updates(DbInfo *dbinfo, PGresult *res, void *arg)
Definition version.c:39
bool protocol_negotiation_supported(const ClusterInfo *cluster)
Definition version.c:20
#define fprintf(file, fmt, msg)
Definition cubescan.l:21
Datum arg
Definition elog.c:1323
int PQfnumber(const PGresult *res, const char *field_name)
Definition fe-exec.c:3620
static void check_ok(void)
Definition initdb.c:2138
#define PQgetvalue
#define PQntuples
#define pg_fatal(...)
UpgradeTask * upgrade_task_create(void)
Definition task.c:117
void upgrade_task_run(const UpgradeTask *task, const ClusterInfo *cluster)
Definition task.c:421
void void pg_log(eLogType type, const char *fmt,...) pg_attribute_printf(2
void upgrade_task_free(UpgradeTask *task)
Definition task.c:133
#define fopen_priv(path, mode)
Definition pg_upgrade.h:413
@ PG_REPORT
Definition pg_upgrade.h:259
#define GET_MAJOR_VERSION(v)
Definition pg_upgrade.h:27
void prep_status(const char *fmt,...) pg_attribute_printf(1
void report_status(eLogType type, const char *fmt,...) pg_attribute_printf(2
void upgrade_task_add_step(UpgradeTask *task, const char *query, UpgradeTaskProcessCB process_cb, bool free_result, void *arg)
Definition task.c:151
void initPQExpBuffer(PQExpBuffer str)
Definition pqexpbuffer.c:90
void termPQExpBuffer(PQExpBuffer str)
static int fb(int x)
const char * quote_identifier(const char *ident)
void appendPsqlMetaConnect(PQExpBuffer buf, const char *dbname)
char * db_name
Definition pg_upgrade.h:182
char path[MAXPGPATH]
Definition pg_upgrade.h:510