This patch contains repack_cleanup_callback() which calls to repack_drop() for cleaning temporary objects. repack_cleanup_callback() will be pushed on stack using pgut_atexit_push() at beginning so that it will pop on abort or exit of program.
This patch includes one global counter (temp_obj_num) which counts number of temporary objects created by pg_repack. Correct order of deletion of temporary object as per count avoids unintentional error messages.
This commit is contained in:
@ -247,7 +247,7 @@ CREATE FUNCTION repack.repack_swap(oid) RETURNS void AS
|
||||
'MODULE_PATHNAME', 'repack_swap'
|
||||
LANGUAGE C VOLATILE STRICT;
|
||||
|
||||
CREATE FUNCTION repack.repack_drop(oid) RETURNS void AS
|
||||
CREATE FUNCTION repack.repack_drop(oid, int) RETURNS void AS
|
||||
'MODULE_PATHNAME', 'repack_drop'
|
||||
LANGUAGE C VOLATILE STRICT;
|
||||
|
||||
|
57
lib/repack.c
57
lib/repack.c
@ -928,6 +928,7 @@ Datum
|
||||
repack_drop(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Oid oid = PG_GETARG_OID(0);
|
||||
int numobj = PG_GETARG_INT32(1);
|
||||
const char *relname = get_quoted_relname(oid);
|
||||
const char *nspname = get_quoted_nspname(oid);
|
||||
|
||||
@ -943,14 +944,38 @@ repack_drop(PG_FUNCTION_ARGS)
|
||||
/* connect to SPI manager */
|
||||
repack_init();
|
||||
|
||||
/* drop log table */
|
||||
if(numobj > 0)
|
||||
{
|
||||
execute_with_format(
|
||||
SPI_OK_UTILITY,
|
||||
"DROP TABLE IF EXISTS repack.log_%u CASCADE",
|
||||
oid);
|
||||
--numobj;
|
||||
}
|
||||
|
||||
/* drop type for pk type */
|
||||
if(numobj > 0)
|
||||
{
|
||||
execute_with_format(
|
||||
SPI_OK_UTILITY,
|
||||
"DROP TYPE IF EXISTS repack.pk_%u",
|
||||
oid);
|
||||
--numobj;
|
||||
}
|
||||
|
||||
/*
|
||||
* drop repack trigger: We have already dropped the trigger in normal
|
||||
* cases, but it can be left on error.
|
||||
*/
|
||||
execute_with_format(
|
||||
SPI_OK_UTILITY,
|
||||
"DROP TRIGGER IF EXISTS z_repack_trigger ON %s.%s CASCADE",
|
||||
nspname, relname);
|
||||
if(numobj > 0)
|
||||
{
|
||||
execute_with_format(
|
||||
SPI_OK_UTILITY,
|
||||
"DROP TRIGGER IF EXISTS z_repack_trigger ON %s.%s CASCADE",
|
||||
nspname, relname);
|
||||
--numobj;
|
||||
}
|
||||
|
||||
#if PG_VERSION_NUM < 80400
|
||||
/* delete autovacuum settings */
|
||||
@ -965,23 +990,15 @@ repack_drop(PG_FUNCTION_ARGS)
|
||||
oid, oid);
|
||||
#endif
|
||||
|
||||
/* drop log table */
|
||||
execute_with_format(
|
||||
SPI_OK_UTILITY,
|
||||
"DROP TABLE IF EXISTS repack.log_%u CASCADE",
|
||||
oid);
|
||||
|
||||
/* drop temp table */
|
||||
execute_with_format(
|
||||
SPI_OK_UTILITY,
|
||||
"DROP TABLE IF EXISTS repack.table_%u CASCADE",
|
||||
oid);
|
||||
|
||||
/* drop type for log table */
|
||||
execute_with_format(
|
||||
SPI_OK_UTILITY,
|
||||
"DROP TYPE IF EXISTS repack.pk_%u CASCADE",
|
||||
oid);
|
||||
if(numobj > 0)
|
||||
{
|
||||
execute_with_format(
|
||||
SPI_OK_UTILITY,
|
||||
"DROP TABLE IF EXISTS repack.table_%u CASCADE",
|
||||
oid);
|
||||
--numobj;
|
||||
}
|
||||
|
||||
SPI_finish();
|
||||
|
||||
|
Reference in New Issue
Block a user