Stop database processing if library version doesn't match the binary
Actually this leaves out the case of the SQL schema not consistent with the library/binary installed, and this is a relatively likely case: the user has run "make install" but the repack schema was already loaded from an older version.
This commit is contained in:
parent
c43b6bdceb
commit
1bcaf267b3
@ -229,7 +229,7 @@ getoid(PGresult *res, int row, int col)
|
|||||||
static bool
|
static bool
|
||||||
repack_one_database(const char *orderby, const char *table, char *errbuf, size_t errsize)
|
repack_one_database(const char *orderby, const char *table, char *errbuf, size_t errsize)
|
||||||
{
|
{
|
||||||
bool ret = true;
|
bool ret = false;
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
int i;
|
int i;
|
||||||
int num;
|
int num;
|
||||||
@ -239,6 +239,43 @@ repack_one_database(const char *orderby, const char *table, char *errbuf, size_t
|
|||||||
|
|
||||||
reconnect(ERROR);
|
reconnect(ERROR);
|
||||||
|
|
||||||
|
/* Query the extension version. Exit if no match */
|
||||||
|
res = execute_elevel("select repack.version()", 0, NULL, DEBUG2);
|
||||||
|
if (PQresultStatus(res) == PGRES_TUPLES_OK)
|
||||||
|
{
|
||||||
|
const char *libver;
|
||||||
|
char buf[64];
|
||||||
|
|
||||||
|
/* the string is something like "pg_repack 1.1.7" */
|
||||||
|
libver = getstr(res, 0, 0);
|
||||||
|
snprintf(buf, sizeof(buf), "%s %s", PROGRAM_NAME, PROGRAM_VERSION);
|
||||||
|
if (0 != strcmp(buf, libver))
|
||||||
|
{
|
||||||
|
if (errbuf)
|
||||||
|
snprintf(errbuf, errsize,
|
||||||
|
"program '%s' does not match database library '%s'",
|
||||||
|
buf, libver);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (sqlstate_equals(res, SQLSTATE_INVALID_SCHEMA_NAME))
|
||||||
|
{
|
||||||
|
/* Schema repack does not exist. Skip the database. */
|
||||||
|
if (errbuf)
|
||||||
|
snprintf(errbuf, errsize,
|
||||||
|
"%s is not installed in the database", PROGRAM_NAME);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Return the error message otherwise */
|
||||||
|
if (errbuf)
|
||||||
|
snprintf(errbuf, errsize, "%s", PQerrorMessage(connection));
|
||||||
|
}
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
/* Disable statement timeout. */
|
/* Disable statement timeout. */
|
||||||
command("SET statement_timeout = 0", 0, NULL);
|
command("SET statement_timeout = 0", 0, NULL);
|
||||||
|
|
||||||
@ -346,6 +383,7 @@ repack_one_database(const char *orderby, const char *table, char *errbuf, size_t
|
|||||||
|
|
||||||
repack_one_table(&table, orderby);
|
repack_one_table(&table, orderby);
|
||||||
}
|
}
|
||||||
|
ret = true;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
|
@ -281,6 +281,15 @@ ERROR: pg_repack is not installed
|
|||||||
|
|
||||||
Do register pg_repack to the database.
|
Do register pg_repack to the database.
|
||||||
|
|
||||||
|
ERROR: program 'pg_repack V1' does not match database library 'pg_repack V2'
|
||||||
|
There is a mismatch between the ``pg_repack`` binary and the database
|
||||||
|
library (``.so`` or ``.dll``).
|
||||||
|
|
||||||
|
The mismatch could be due to the wrong binary in the ``$PATH`` or the
|
||||||
|
wrong database being addressed. Check the program directory and the
|
||||||
|
database; if they are what expected you may need to repeat pg_repack
|
||||||
|
installation.
|
||||||
|
|
||||||
ERROR: relation "table" has no primary key
|
ERROR: relation "table" has no primary key
|
||||||
The target table doesn't have PRIMARY KEY.
|
The target table doesn't have PRIMARY KEY.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user