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 c5d39dd commit dd1585b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions doc/manual/user-03-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ CREATE EXTENSION pgmoneta_ext;
|-----------------------------|--------------------------------------------------------|
| `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. |
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 @@ -4,4 +4,8 @@ LANGUAGE C STRICT;

CREATE FUNCTION pgmoneta_ext_switch_wal() RETURNS text
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;
LANGUAGE C STRICT;

CREATE FUNCTION pgmoneta_ext_checkpoint() RETURNS text
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;
26 changes: 24 additions & 2 deletions src/pgmoneta_ext/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@
/* 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)
Expand Down Expand Up @@ -72,4 +73,25 @@ pgmoneta_ext_switch_wal(PG_FUNCTION_ARGS)
wal_filename = CStringGetTextDatum(walfile);

PG_RETURN_DATUM(wal_filename);
}

#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 dd1585b

Please sign in to comment.