Added check for target tablespace existence
This commit is contained in:
parent
a6e50515ce
commit
43dfe229c9
@ -53,7 +53,7 @@ WHERE relname ~ '^testts1';
|
|||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
-- can move the table together with the indexes
|
-- can move the table together with the indexes
|
||||||
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace pg_default --moveidx
|
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts --moveidx
|
||||||
SELECT relname, spcname
|
SELECT relname, spcname
|
||||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
||||||
WHERE relname ~ '^testts1';
|
WHERE relname ~ '^testts1';
|
||||||
|
@ -172,6 +172,7 @@ typedef struct repack_index
|
|||||||
} repack_index;
|
} repack_index;
|
||||||
|
|
||||||
static bool is_superuser(void);
|
static bool is_superuser(void);
|
||||||
|
static void check_tablespace(void);
|
||||||
static void repack_all_databases(const char *order_by);
|
static void repack_all_databases(const char *order_by);
|
||||||
static bool repack_one_database(const char *order_by, char *errbuf, size_t errsize);
|
static bool repack_one_database(const char *order_by, char *errbuf, size_t errsize);
|
||||||
static void repack_one_table(const repack_table *table, const char *order_by);
|
static void repack_one_table(const repack_table *table, const char *order_by);
|
||||||
@ -238,6 +239,8 @@ main(int argc, char *argv[])
|
|||||||
(errcode(EINVAL),
|
(errcode(EINVAL),
|
||||||
errmsg("too many arguments")));
|
errmsg("too many arguments")));
|
||||||
|
|
||||||
|
check_tablespace();
|
||||||
|
|
||||||
if (noorder)
|
if (noorder)
|
||||||
orderby = "";
|
orderby = "";
|
||||||
|
|
||||||
@ -258,12 +261,6 @@ main(int argc, char *argv[])
|
|||||||
errmsg("%s", errbuf)));
|
errmsg("%s", errbuf)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (moveidx && tablespace == NULL)
|
|
||||||
{
|
|
||||||
ereport(ERROR,
|
|
||||||
(errcode(EINVAL),
|
|
||||||
errmsg("cannot specify --moveidx (-S) without --tablespace (-s)")));
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,6 +288,56 @@ is_superuser(void)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check if the tablespace requested exists.
|
||||||
|
*
|
||||||
|
* Raise an exception on error.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
check_tablespace()
|
||||||
|
{
|
||||||
|
PGresult *res = NULL;
|
||||||
|
const char *params[1];
|
||||||
|
|
||||||
|
if (tablespace == NULL)
|
||||||
|
{
|
||||||
|
/* nothing to check, but let's see the options */
|
||||||
|
if (moveidx)
|
||||||
|
{
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(EINVAL),
|
||||||
|
errmsg("cannot specify --moveidx (-S) without --tablespace (-s)")));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check if the tablespace exists */
|
||||||
|
reconnect(ERROR);
|
||||||
|
params[0] = tablespace;
|
||||||
|
res = execute_elevel(
|
||||||
|
"select spcname from pg_tablespace where spcname = $1",
|
||||||
|
1, params, DEBUG2);
|
||||||
|
|
||||||
|
if (PQresultStatus(res) == PGRES_TUPLES_OK)
|
||||||
|
{
|
||||||
|
if (PQntuples(res) == 0)
|
||||||
|
{
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(EINVAL),
|
||||||
|
errmsg("the tablespace \"%s\" doesn't exist", tablespace)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(EINVAL),
|
||||||
|
errmsg("error checking the namespace: %s",
|
||||||
|
PQerrorMessage(connection))));
|
||||||
|
}
|
||||||
|
|
||||||
|
CLEARPGRES(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Call repack_one_database for each database.
|
* Call repack_one_database for each database.
|
||||||
|
@ -38,7 +38,7 @@ FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
|||||||
WHERE relname ~ '^testts1';
|
WHERE relname ~ '^testts1';
|
||||||
|
|
||||||
-- can move the table together with the indexes
|
-- can move the table together with the indexes
|
||||||
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace pg_default --moveidx
|
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts --moveidx
|
||||||
|
|
||||||
SELECT relname, spcname
|
SELECT relname, spcname
|
||||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
||||||
|
Loading…
x
Reference in New Issue
Block a user