Skip to content

Commit

Permalink
[pgmoneta#5] SQL: CHECKPOINT
Browse files Browse the repository at this point in the history
  • Loading branch information
GuChad369 committed May 27, 2024
1 parent 0985840 commit 406278d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
7 changes: 4 additions & 3 deletions doc/manual/user-03-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ CREATE EXTENSION pgmoneta_ext;

## Extension functions

| Function | Description |
|--------------------------|--------------------------------------------------------|
| `pgmoneta_ext_version()` | Return the version number of `pgmoneta_ext` as a Datum.|
| Function | Description |
|-----------------------------|--------------------------------------------------------|
| `pgmoneta_ext_version()` | Return the version number of `pgmoneta_ext` as a Datum.|
| `pgmoneta_ext_checkpoint()` | A function which forces a checkpoint. |
8 changes: 6 additions & 2 deletions sql/pgmoneta_ext--0.1.0.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
CREATE FUNCTION pgmoneta_ext_version() RETURNS text
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;

CREATE FUNCTION pgmoneta_ext_checkpoint() RETURNS text
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;
24 changes: 24 additions & 0 deletions src/pgmoneta_ext/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@
/* PostgreSQL */
#include "postgres.h"
#include "fmgr.h"
#include "access/xlog.h"
#include "miscadmin.h"
#include "utils/builtins.h"

PG_MODULE_MAGIC;

PG_FUNCTION_INFO_V1(pgmoneta_ext_version);
PG_FUNCTION_INFO_V1(pgmoneta_ext_checkpoint);

Datum
pgmoneta_ext_version(PG_FUNCTION_ARGS)
Expand All @@ -52,3 +55,24 @@ pgmoneta_ext_version(PG_FUNCTION_ARGS)

PG_RETURN_DATUM(version);
}

#ifndef RequestCheckpoint
extern void RequestCheckpoint(int flags);
#endif

Datum
pgmoneta_ext_checkpoint(PG_FUNCTION_ARGS)
{
Datum check_point;
char cp[1024];

memset(&cp, 0, sizeof(cp));
snprintf(&cp[0], sizeof(cp), "%s", "CHECKPOINT");

// Perform the checkpoint
RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_WAIT | CHECKPOINT_FORCE);

check_point = CStringGetTextDatum(cp);

PG_RETURN_DATUM(check_point);
}

0 comments on commit 406278d

Please sign in to comment.