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 Jun 2, 2024
1 parent 5628ab1 commit 0385fb0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/manual/user-03-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ After you create the extension `pgmoneta_ext` using the `postgres` role, you can
|-----------------------------|-----------|--------------------------------------------------------|
| `pgmoneta_ext_version()` | false | Return the version number of `pgmoneta_ext` as a Datum.|
| `pgmoneta_ext_switch_wal()` | true | A function for switching to a new WAL file. |
| `pgmoneta_ext_checkpoint()` | true | A function which forces a checkpoint. |
6 changes: 5 additions & 1 deletion sql/pgmoneta_ext--0.1.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ CREATE FUNCTION pgmoneta_ext_switch_wal(OUT success bool,
)
RETURNS record
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;
LANGUAGE C STRICT;

CREATE FUNCTION pgmoneta_ext_checkpoint() RETURNS text
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;
22 changes: 22 additions & 0 deletions src/pgmoneta_ext/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ 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)
Expand Down Expand Up @@ -115,4 +116,25 @@ pgmoneta_ext_switch_wal(PG_FUNCTION_ARGS)
result = HeapTupleGetDatum(tuple);

PG_RETURN_DATUM(result);
}

#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 0385fb0

Please sign in to comment.