Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit68de499

Browse files
committed
New SQL functons pg_backup_in_progress() and pg_backup_start_time()
Darold Gilles, reviewed by Gabriele Bartolini and others, rebased byMarco Nenciarini. Stylistic cleanup and OID fixes by me.
1 parentcd80073 commit68de499

File tree

5 files changed

+99
-2
lines changed

5 files changed

+99
-2
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14455,6 +14455,12 @@ SELECT set_config('log_statement_stats', 'off', false);
1445514455
<indexterm>
1445614456
<primary>pg_stop_backup</primary>
1445714457
</indexterm>
14458+
<indexterm>
14459+
<primary>pg_is_in_backup</primary>
14460+
</indexterm>
14461+
<indexterm>
14462+
<primary>pg_backup_start_time</primary>
14463+
</indexterm>
1445814464
<indexterm>
1445914465
<primary>pg_switch_xlog</primary>
1446014466
</indexterm>
@@ -14519,6 +14525,20 @@ SELECT set_config('log_statement_stats', 'off', false);
1451914525
<entry><type>text</type></entry>
1452014526
<entry>Finish performing on-line backup (restricted to superusers or replication roles)</entry>
1452114527
</row>
14528+
<row>
14529+
<entry>
14530+
<literal><function>pg_is_in_backup()</function></literal>
14531+
</entry>
14532+
<entry><type>bool</type></entry>
14533+
<entry>True if an on-line exclusive backup is still in progress.</entry>
14534+
</row>
14535+
<row>
14536+
<entry>
14537+
<literal><function>pg_backup_start_time()</function></literal>
14538+
</entry>
14539+
<entry><type>timestamp with time zone</type></entry>
14540+
<entry>Get start time of an online exclusive backup in progress.</entry>
14541+
</row>
1452214542
<row>
1452314543
<entry>
1452414544
<literal><function>pg_switch_xlog()</function></literal>

‎src/backend/access/transam/xlogfuncs.c

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include"utils/numeric.h"
3030
#include"utils/guc.h"
3131
#include"utils/timestamp.h"
32-
32+
#include"storage/fd.h"
3333

3434
staticvoidvalidate_xlog_location(char*str);
3535

@@ -563,3 +563,74 @@ pg_xlog_location_diff(PG_FUNCTION_ARGS)
563563

564564
PG_RETURN_NUMERIC(result);
565565
}
566+
567+
/*
568+
* Returns bool with current on-line backup mode, a global state.
569+
*/
570+
Datum
571+
pg_is_in_backup(PG_FUNCTION_ARGS)
572+
{
573+
PG_RETURN_BOOL(BackupInProgress());
574+
}
575+
576+
/*
577+
* Returns start time of an online exclusive backup.
578+
*
579+
* When there's no exclusive backup in progress, the function
580+
* returns NULL.
581+
*/
582+
Datum
583+
pg_backup_start_time(PG_FUNCTION_ARGS)
584+
{
585+
Datumxtime;
586+
FILE*lfp;
587+
charfline[MAXPGPATH];
588+
charbackup_start_time[30];
589+
590+
/*
591+
* See if label file is present
592+
*/
593+
lfp=AllocateFile(BACKUP_LABEL_FILE,"r");
594+
if (lfp==NULL)
595+
{
596+
if (errno!=ENOENT)
597+
ereport(ERROR,
598+
(errcode_for_file_access(),
599+
errmsg("could not read file \"%s\": %m",
600+
BACKUP_LABEL_FILE)));
601+
PG_RETURN_NULL();
602+
}
603+
604+
/*
605+
* Parse the file to find the the START TIME line.
606+
*/
607+
backup_start_time[0]='\0';
608+
while (fgets(fline,sizeof(fline),lfp)!=NULL)
609+
{
610+
if (sscanf(fline,"START TIME: %25[^\n]\n",backup_start_time)==1)
611+
break;
612+
}
613+
614+
/*
615+
* Close the backup label file.
616+
*/
617+
if (ferror(lfp)||FreeFile(lfp))
618+
ereport(ERROR,
619+
(errcode_for_file_access(),
620+
errmsg("could not read file \"%s\": %m",BACKUP_LABEL_FILE)));
621+
622+
if (strlen(backup_start_time)==0)
623+
ereport(ERROR,
624+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
625+
errmsg("invalid data in file \"%s\"",BACKUP_LABEL_FILE)));
626+
627+
/*
628+
* Convert the time string read from file to TimestampTz form.
629+
*/
630+
xtime=DirectFunctionCall3(timestamptz_in,
631+
CStringGetDatum(backup_start_time),
632+
ObjectIdGetDatum(InvalidOid),
633+
Int32GetDatum(-1));
634+
635+
PG_RETURN_DATUM(xtime);
636+
}

‎src/include/access/xlog_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,5 +282,7 @@ extern Datum pg_xlog_replay_pause(PG_FUNCTION_ARGS);
282282
externDatumpg_xlog_replay_resume(PG_FUNCTION_ARGS);
283283
externDatumpg_is_xlog_replay_paused(PG_FUNCTION_ARGS);
284284
externDatumpg_xlog_location_diff(PG_FUNCTION_ARGS);
285+
externDatumpg_is_in_backup(PG_FUNCTION_ARGS);
286+
externDatumpg_backup_start_time(PG_FUNCTION_ARGS);
285287

286288
#endif/* XLOG_INTERNAL_H */

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO201204301
56+
#defineCATALOG_VERSION_NO201206141
5757

5858
#endif

‎src/include/catalog/pg_proc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2936,6 +2936,10 @@ DATA(insert OID = 2172 ( pg_start_backupPGNSP PGUID 12 1 0 0 0 f f f f t f v 2
29362936
DESCR("prepare for taking an online backup");
29372937
DATA(insertOID=2173 (pg_stop_backupPGNSPPGUID121000fffftfv0025""_null__null__null__null_pg_stop_backup_null__null__null_ ));
29382938
DESCR("finish taking an online backup");
2939+
DATA(insertOID=3813 (pg_is_in_backupPGNSPPGUID121000fffftfv0016""_null__null__null__null_pg_is_in_backup_null__null__null_ ));
2940+
DESCR("true if server is in online backup");
2941+
DATA(insertOID=3814 (pg_backup_start_timePGNSPPGUID121000fffftfs001184""_null__null__null__null_pg_backup_start_time_null__null__null_ ));
2942+
DESCR("start time of an online backup");
29392943
DATA(insertOID=2848 (pg_switch_xlogPGNSPPGUID121000fffftfv0025""_null__null__null__null_pg_switch_xlog_null__null__null_ ));
29402944
DESCR("switch to new xlog file");
29412945
DATA(insertOID=3098 (pg_create_restore_pointPGNSPPGUID121000fffftfv1025"25"_null__null__null__null_pg_create_restore_point_null__null__null_ ));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp