Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c8b9ac6

Browse files
committed
check pgpro edition
1 parent a42fff0 commit c8b9ac6

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

src/bin/pg_dump/pg_backup.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ typedef struct _dumpOptions
162162
char *outputSuperuser;
163163
} DumpOptions;
164164

165+
typedef enum _pgproEdition
166+
{
167+
NONE,
168+
STANDART,
169+
STANDART_CERTIFIED,
170+
ENTERPRISE,
171+
} pgproEdition;
172+
165173
/*
166174
* We may want to have some more user-readable data, but in the mean
167175
* time this gives us some abstraction and type checking.
@@ -175,6 +183,7 @@ typedef struct Archive
175183
char *remoteVersionStr; /* server's version string */
176184
int remoteVersion; /* same in numeric form */
177185
int pgproremoteVersion; /* pgpro server's version in numeric form */
186+
pgproEdition pgproremoteEdition; /* pgpro server's edition. */
178187
bool isStandby; /* is server a standby node */
179188

180189
int minRemoteVersion; /* allowable range */

src/bin/pg_dump/pg_backup_db.c

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ static void _check_database_version(ArchiveHandle *AH);
3434
static PGconn *_connectDB(ArchiveHandle *AH, const char *newdbname, const char *newUser);
3535
static void notice_processor(void *arg, const char *message);
3636
static void get_pgpro_version(ArchiveHandle *AH);
37+
static void get_pgpro_edition(ArchiveHandle *AH);
3738

3839
static void
3940
get_pgpro_version(ArchiveHandle *AH)
@@ -59,6 +60,49 @@ get_pgpro_version(ArchiveHandle *AH)
5960
PQclear(res);
6061
}
6162

63+
static void
64+
get_pgpro_edition(ArchiveHandle *AH)
65+
{
66+
char *query = "SELECT pgpro_edition()";
67+
PGresult *res;
68+
const char *pgpro_remoteEdition_str;
69+
70+
res = PQexec(AH->connection, query);
71+
/* If the query failed, it means that remote cluster is not PgPro. */
72+
if (PQresultStatus(res) != PGRES_TUPLES_OK)
73+
{
74+
AH->public.pgproremoteEdition = NONE;
75+
fprintf(stdout, "pgpro server edition: 0; %s version: %s\n", progname, PG_VERSION);
76+
}
77+
else
78+
{
79+
pgpro_remoteEdition_str = pg_strdup(PQgetvalue(res, 0, 0));
80+
81+
fprintf(stdout, "pgpro server edition: %s; %s version: %s\n",
82+
pgpro_remoteEdition_str, progname, PG_VERSION);
83+
84+
if (strcmp(pgpro_remoteEdition_str, "standard") == 0)
85+
AH->public.pgproremoteEdition = STANDART;
86+
else if (strcmp(pgpro_remoteEdition_str, "standard-certified") == 0)
87+
AH->public.pgproremoteEdition = STANDART_CERTIFIED;
88+
else if (strcmp(pgpro_remoteEdition_str, "enterprise") == 0)
89+
{
90+
AH->public.pgproremoteEdition = ENTERPRISE;
91+
if (AH->public.remoteVersion >= 90600)
92+
exit_horribly(NULL, "pg_upgrade for 64bit-xid is not implemented yet"
93+
"Use pg_dump/pg_restore instead.\n");
94+
}
95+
else
96+
{
97+
write_msg(NULL, "Unrecognized pgpro edition: %s\n",
98+
pgpro_remoteEdition_str);
99+
exit_horribly(NULL, "aborting because of unrecognized pgpro edition\n");
100+
}
101+
}
102+
PQclear(res);
103+
exit_horribly(NULL, "aborting because of unrecognized pgpro edition\n");
104+
}
105+
62106
static void
63107
_check_database_version(ArchiveHandle *AH)
64108
{
@@ -71,9 +115,6 @@ _check_database_version(ArchiveHandle *AH)
71115
if (remoteversion == 0 || !remoteversion_str)
72116
exit_horribly(modulename, "could not get server_version from libpq\n");
73117

74-
/* TODO select pgpro_version, pgpro_edition */
75-
get_pgpro_version(AH);
76-
77118
AH->public.remoteVersionStr = pg_strdup(remoteversion_str);
78119
AH->public.remoteVersion = remoteversion;
79120
if (!AH->archiveRemoteVersion)
@@ -88,6 +129,9 @@ _check_database_version(ArchiveHandle *AH)
88129
exit_horribly(NULL, "aborting because of server version mismatch\n");
89130
}
90131

132+
get_pgpro_version(AH);
133+
get_pgpro_edition(AH);
134+
91135
/*
92136
* When running against 9.0 or later, check if we are in recovery mode,
93137
* which means we are on a hot standby.

src/bin/pg_dump/pg_dump.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6280,11 +6280,10 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
62806280
* is not.
62816281
*/
62826282
resetPQExpBuffer(query);
6283-
/* TODO check pgpro_version instead of just remoteVersion */
62846283
if (fout->remoteVersion >= 90600 && fout->pgproremoteVersion > 0)
62856284
{
62866285
/*
6287-
* In 9.6 we add INCLUDING columns functionality
6286+
* In PGPRO9_6 we add INCLUDING columns functionality
62886287
* that requires new fields to be added.
62896288
* i.indnkeyattrs is new, and besides we should use
62906289
* i.indnatts instead of t.relnatts for index relations.

0 commit comments

Comments
 (0)