diff --git a/doc/manual/user-03-functions.md b/doc/manual/user-03-functions.md index 08edbf3..bfa159e 100644 --- a/doc/manual/user-03-functions.md +++ b/doc/manual/user-03-functions.md @@ -22,4 +22,4 @@ CREATE EXTENSION pgmoneta_ext; | Function | Description | |-----------------------------|--------------------------------------------------------| | `pgmoneta_ext_version()` | Return the version number of `pgmoneta_ext` as a Datum.| -| `pgmoneta_ext_switch_wal()` | A function for switching to a new WAL file. | +| `pgmoneta_ext_checkpoint()` | A function which forces a checkpoint. | diff --git a/sql/pgmoneta_ext--0.1.0.sql b/sql/pgmoneta_ext--0.1.0.sql index 8df4360..8f3cb84 100644 --- a/sql/pgmoneta_ext--0.1.0.sql +++ b/sql/pgmoneta_ext--0.1.0.sql @@ -2,6 +2,6 @@ CREATE FUNCTION pgmoneta_ext_version() RETURNS text AS 'MODULE_PATHNAME' LANGUAGE C STRICT; -CREATE FUNCTION pgmoneta_ext_switch_wal() RETURNS text +CREATE FUNCTION pgmoneta_ext_checkpoint() RETURNS text AS 'MODULE_PATHNAME' -LANGUAGE C STRICT; \ No newline at end of file +LANGUAGE C STRICT; diff --git a/src/pgmoneta_ext/lib.c b/src/pgmoneta_ext/lib.c index 8c88bf8..e6339fa 100644 --- a/src/pgmoneta_ext/lib.c +++ b/src/pgmoneta_ext/lib.c @@ -33,15 +33,15 @@ /* PostgreSQL */ #include "postgres.h" #include "fmgr.h" -#include "utils/builtins.h" -#include "miscadmin.h" #include "access/xlog.h" -#include "access/xlog_internal.h" +#include "miscadmin.h" +#include "utils/builtins.h" PG_MODULE_MAGIC; PG_FUNCTION_INFO_V1(pgmoneta_ext_version); PG_FUNCTION_INFO_V1(pgmoneta_ext_switch_wal); +PG_FUNCTION_INFO_V1(pgmoneta_ext_checkpoint); Datum pgmoneta_ext_version(PG_FUNCTION_ARGS) @@ -57,19 +57,23 @@ pgmoneta_ext_version(PG_FUNCTION_ARGS) PG_RETURN_DATUM(version); } +#ifndef RequestCheckpoint +extern void RequestCheckpoint(int flags); +#endif + Datum -pgmoneta_ext_switch_wal(PG_FUNCTION_ARGS) +pgmoneta_ext_checkpoint(PG_FUNCTION_ARGS) { - Datum wal_filename; - XLogRecPtr recptr; - char walfile[1024]; + Datum check_point; + char cp[1024]; - // Call the RequestXLogSwitch function with mark_unimportant as false - recptr = RequestXLogSwitch(false); + memset(&cp, 0, sizeof(cp)); + snprintf(&cp[0], sizeof(cp), "%s", "CHECKPOINT"); - snprintf(walfile, sizeof(walfile), "%X/%X", (uint32) (recptr >> 32), (uint32) recptr); + // Perform the checkpoint + RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_WAIT | CHECKPOINT_FORCE); - wal_filename = CStringGetTextDatum(walfile); + check_point = CStringGetTextDatum(cp); - PG_RETURN_DATUM(wal_filename); + PG_RETURN_DATUM(check_point); } \ No newline at end of file