Skip to content

Commit

Permalink
[pgmoneta#22] Get LSN
Browse files Browse the repository at this point in the history
  • Loading branch information
GuChad369 committed Sep 3, 2024
1 parent dc7fea7 commit 78b372e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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 @@ -28,6 +28,10 @@ CREATE FUNCTION pgmoneta_ext_get_file(file_path TEXT) RETURNS TEXT
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;

CREATE OR REPLACE FUNCTION pgmoneta_ext_get_files(file_path TEXT) RETURNS text[]
CREATE FUNCTION pgmoneta_ext_get_files(file_path TEXT) RETURNS text[]
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;

CREATE FUNCTION pgmoneta_ext_get_lsn() RETURNS text
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;
14 changes: 14 additions & 0 deletions src/pgmoneta_ext/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ PG_FUNCTION_INFO_V1(pgmoneta_ext_get_oid);
PG_FUNCTION_INFO_V1(pgmoneta_ext_get_oids);
PG_FUNCTION_INFO_V1(pgmoneta_ext_get_file);
PG_FUNCTION_INFO_V1(pgmoneta_ext_get_files);
PG_FUNCTION_INFO_V1(pgmoneta_ext_get_lsn);

Datum
pgmoneta_ext_version(PG_FUNCTION_ARGS)
Expand Down Expand Up @@ -449,3 +450,16 @@ list_files(const char* name, ArrayBuildState* astate)
}
closedir(dir);
}

Datum
pgmoneta_ext_get_lsn(PG_FUNCTION_ARGS)
{
XLogRecPtr lsn;
char lsn_str[64];

lsn = GetXLogWriteRecPtr();

snprintf(lsn_str, sizeof(lsn_str), "%X/%X", (uint32)(lsn >> 32), (uint32)lsn);

PG_RETURN_TEXT_P(cstring_to_text(lsn_str));
}

0 comments on commit 78b372e

Please sign in to comment.