pg_reorg version 1.1.0.
- Add wait-timeout option and use SET statement_timeout instead of NOWAIT. This can avoid infinite NOWAIT loops to reorganize heavily accessed tables. - Support native build with MSVC on Windows.
This commit is contained in:
@ -118,7 +118,7 @@ CREATE VIEW reorg.tables AS
|
||||
reorg.get_create_trigger(R.oid, PK.indexrelid) AS create_trigger,
|
||||
'CREATE TABLE reorg.table_' || R.oid || ' WITH (' || array_to_string(array_append(R.reloptions, 'oids=' || CASE WHEN R.relhasoids THEN 'true' ELSE 'false' END), ',') || ') TABLESPACE ' || coalesce(quote_ident(S.spcname), 'pg_default') || ' AS SELECT * FROM ONLY ' || reorg.oid2text(R.oid) AS create_table,
|
||||
'DELETE FROM reorg.log_' || R.oid AS delete_log,
|
||||
'LOCK TABLE ' || reorg.oid2text(R.oid) || ' IN ACCESS EXCLUSIVE MODE NOWAIT' AS lock_table,
|
||||
'LOCK TABLE ' || reorg.oid2text(R.oid) || ' IN ACCESS EXCLUSIVE MODE' AS lock_table,
|
||||
reorg.get_index_keys(CK.indexrelid, R.oid) AS ckey,
|
||||
'SELECT * FROM reorg.log_' || R.oid || ' ORDER BY id LIMIT $1' AS sql_peek,
|
||||
'INSERT INTO reorg.table_' || R.oid || ' VALUES ($1.*)' AS sql_insert,
|
||||
|
@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
#include "fmgr.h"
|
||||
#include "access/heapam.h"
|
||||
#include "pgut-be.h"
|
||||
|
||||
#if PG_VERSION_NUM < 80400
|
||||
@ -42,4 +42,11 @@ cstring_to_text(const char *s)
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc,
|
||||
Datum *values, bool *isnull)
|
||||
{
|
||||
tuplestore_puttuple(state, heap_form_tuple(tdesc, values, isnull));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -10,6 +10,48 @@
|
||||
#ifndef PGUT_BE_H
|
||||
#define PGUT_BE_H
|
||||
|
||||
#include "fmgr.h"
|
||||
#include "utils/tuplestore.h"
|
||||
|
||||
#ifndef WIN32
|
||||
|
||||
#define PGUT_EXPORT
|
||||
|
||||
#else
|
||||
|
||||
#define PGUT_EXPORT __declspec(dllexport)
|
||||
|
||||
/*
|
||||
* PG_MODULE_MAGIC and PG_FUNCTION_INFO_V1 macros seems to be broken.
|
||||
* It uses PGDLLIMPORT, but those objects are not imported from postgres
|
||||
* and exported from the user module. So, it should be always dllexported.
|
||||
*/
|
||||
|
||||
#undef PG_MODULE_MAGIC
|
||||
#define PG_MODULE_MAGIC \
|
||||
extern PGUT_EXPORT const Pg_magic_struct *PG_MAGIC_FUNCTION_NAME(void); \
|
||||
const Pg_magic_struct * \
|
||||
PG_MAGIC_FUNCTION_NAME(void) \
|
||||
{ \
|
||||
static const Pg_magic_struct Pg_magic_data = PG_MODULE_MAGIC_DATA; \
|
||||
return &Pg_magic_data; \
|
||||
} \
|
||||
extern int no_such_variable
|
||||
|
||||
#undef PG_FUNCTION_INFO_V1
|
||||
#define PG_FUNCTION_INFO_V1(funcname) \
|
||||
extern PGUT_EXPORT const Pg_finfo_record * CppConcat(pg_finfo_,funcname)(void); \
|
||||
const Pg_finfo_record * \
|
||||
CppConcat(pg_finfo_,funcname) (void) \
|
||||
{ \
|
||||
static const Pg_finfo_record my_finfo = { 1 }; \
|
||||
return &my_finfo; \
|
||||
} \
|
||||
extern int no_such_variable
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if PG_VERSION_NUM < 80300
|
||||
|
||||
#define PGDLLIMPORT DLLIMPORT
|
||||
@ -33,8 +75,6 @@
|
||||
#define GetCurrentCommandId(used) GetCurrentCommandId()
|
||||
#define stringToQualifiedNameList(str) \
|
||||
stringToQualifiedNameList((str), "pg_bulkload")
|
||||
#define setNewRelfilenode(rel, xid) \
|
||||
setNewRelfilenode((rel))
|
||||
#define PageAddItem(page, item, size, offnum, overwrite, is_heap) \
|
||||
PageAddItem((page), (item), (size), (offnum), LP_USED)
|
||||
|
||||
@ -56,32 +96,75 @@
|
||||
#define GetBulkInsertState() (NULL)
|
||||
#define FreeBulkInsertState(bistate) ((void)0)
|
||||
#define FreeExprContext(econtext, isCommit) FreeExprContext((econtext))
|
||||
#define FuncnameGetCandidates(names, nargs, argnames, variadic, defaults) \
|
||||
FuncnameGetCandidates((names), (nargs))
|
||||
#define pgstat_init_function_usage(fcinfo, fcu) ((void)0)
|
||||
#define pgstat_end_function_usage(fcu, finalize) ((void)0)
|
||||
|
||||
#define makeRangeVar(schemaname, relname, location) \
|
||||
makeRangeVar((schemaname), (relname))
|
||||
#define pgstat_track_activity_query_size PGBE_ACTIVITY_SIZE
|
||||
typedef void *BulkInsertState;
|
||||
|
||||
#define DefineCustomBoolVariable(name, short_desc, long_desc, valueAddr, bootValue, context, flags, assign_hook, show_hook) \
|
||||
do { \
|
||||
*(valueAddr) = (bootValue); \
|
||||
DefineCustomBoolVariable((name), (short_desc), (long_desc), (valueAddr), (context), (assign_hook), (show_hook)); \
|
||||
} while(0)
|
||||
#define DefineCustomIntVariable(name, short_desc, long_desc, valueAddr, bootValue, minValue, maxValue, context, flags, assign_hook, show_hook) \
|
||||
do { \
|
||||
*(valueAddr) = (bootValue); \
|
||||
DefineCustomIntVariable((name), (short_desc), (long_desc), (valueAddr), (minValue), (maxValue), (context), (assign_hook), (show_hook)); \
|
||||
} while(0)
|
||||
#define DefineCustomRealVariable(name, short_desc, long_desc, valueAddr, bootValue, minValue, maxValue, context, flags, assign_hook, show_hook) \
|
||||
do { \
|
||||
*(valueAddr) = (bootValue); \
|
||||
DefineCustomRealVariable((name), (short_desc), (long_desc), (valueAddr), (minValue), (maxValue), (context), (assign_hook), (show_hook)); \
|
||||
} while(0)
|
||||
#define DefineCustomStringVariable(name, short_desc, long_desc, valueAddr, bootValue, context, flags, assign_hook, show_hook) \
|
||||
do { \
|
||||
*(valueAddr) = (char *) (bootValue); \
|
||||
DefineCustomStringVariable((name), (short_desc), (long_desc), (valueAddr), (context), (assign_hook), (show_hook)); \
|
||||
} while(0)
|
||||
|
||||
struct config_enum_entry
|
||||
{
|
||||
const char *name;
|
||||
int val;
|
||||
bool hidden;
|
||||
};
|
||||
|
||||
extern char *text_to_cstring(const text *t);
|
||||
extern text *cstring_to_text(const char *s);
|
||||
extern void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc,
|
||||
Datum *values, bool *isnull);
|
||||
|
||||
#define CStringGetTextDatum(s) PointerGetDatum(cstring_to_text(s))
|
||||
#define TextDatumGetCString(d) text_to_cstring((text *) DatumGetPointer(d))
|
||||
|
||||
#elif PG_VERSION_NUM < 80500
|
||||
|
||||
#define FuncnameGetCandidates(names, nargs, argnames, variadic, defaults) \
|
||||
FuncnameGetCandidates((names), (nargs), (variadic), (defaults))
|
||||
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM < 80500
|
||||
#if PG_VERSION_NUM < 90000
|
||||
|
||||
#define reindex_index(indexId, skip_constraint_checks) \
|
||||
reindex_index((indexId))
|
||||
#define func_signature_string(funcname, nargs, argnames, argtypes) \
|
||||
func_signature_string((funcname), (nargs), (argtypes))
|
||||
#define GetConfigOption(name, restrict_superuser) GetConfigOption((name))
|
||||
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM < 80300
|
||||
#define RelationSetNewRelfilenode(rel, xid) \
|
||||
setNewRelfilenode((rel))
|
||||
#elif PG_VERSION_NUM < 90000
|
||||
#define RelationSetNewRelfilenode(rel, xid) \
|
||||
setNewRelfilenode((rel), (xid))
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM < 80400
|
||||
#define FuncnameGetCandidates(names, nargs, argnames, variadic, defaults) \
|
||||
FuncnameGetCandidates((names), (nargs))
|
||||
#elif PG_VERSION_NUM < 90000
|
||||
#define FuncnameGetCandidates(names, nargs, argnames, variadic, defaults) \
|
||||
FuncnameGetCandidates((names), (nargs), (variadic), (defaults))
|
||||
#endif
|
||||
|
||||
#endif /* PGUT_BE_H */
|
||||
|
18
lib/reorg.c
18
lib/reorg.c
@ -30,14 +30,14 @@
|
||||
|
||||
PG_MODULE_MAGIC;
|
||||
|
||||
Datum reorg_version(PG_FUNCTION_ARGS);
|
||||
Datum reorg_trigger(PG_FUNCTION_ARGS);
|
||||
Datum reorg_apply(PG_FUNCTION_ARGS);
|
||||
Datum reorg_get_index_keys(PG_FUNCTION_ARGS);
|
||||
Datum reorg_indexdef(PG_FUNCTION_ARGS);
|
||||
Datum reorg_swap(PG_FUNCTION_ARGS);
|
||||
Datum reorg_drop(PG_FUNCTION_ARGS);
|
||||
Datum reorg_disable_autovacuum(PG_FUNCTION_ARGS);
|
||||
extern Datum PGUT_EXPORT reorg_version(PG_FUNCTION_ARGS);
|
||||
extern Datum PGUT_EXPORT reorg_trigger(PG_FUNCTION_ARGS);
|
||||
extern Datum PGUT_EXPORT reorg_apply(PG_FUNCTION_ARGS);
|
||||
extern Datum PGUT_EXPORT reorg_get_index_keys(PG_FUNCTION_ARGS);
|
||||
extern Datum PGUT_EXPORT reorg_indexdef(PG_FUNCTION_ARGS);
|
||||
extern Datum PGUT_EXPORT reorg_swap(PG_FUNCTION_ARGS);
|
||||
extern Datum PGUT_EXPORT reorg_drop(PG_FUNCTION_ARGS);
|
||||
extern Datum PGUT_EXPORT reorg_disable_autovacuum(PG_FUNCTION_ARGS);
|
||||
|
||||
PG_FUNCTION_INFO_V1(reorg_version);
|
||||
PG_FUNCTION_INFO_V1(reorg_trigger);
|
||||
@ -75,7 +75,7 @@ static void RenameRelationInternal(Oid myrelid, const char *newrelname, Oid name
|
||||
Datum
|
||||
reorg_version(PG_FUNCTION_ARGS)
|
||||
{
|
||||
return CStringGetTextDatum("pg_reorg 1.0.8");
|
||||
return CStringGetTextDatum("pg_reorg 1.1.0");
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user