]> granicus.if.org Git - postgresql/commitdiff
Add new user fn pg_current_xlog_flush_location()
authorSimon Riggs <simon@2ndQuadrant.com>
Tue, 12 Jan 2016 07:54:52 +0000 (07:54 +0000)
committerSimon Riggs <simon@2ndQuadrant.com>
Tue, 12 Jan 2016 07:54:52 +0000 (07:54 +0000)
Tomas Vondra, reviewed by Michael Paquier and Amit Kapila
Minor edits by me

doc/src/sgml/func.sgml
src/backend/access/transam/xlogfuncs.c
src/include/access/xlog_fn.h
src/include/catalog/pg_proc.h

index 8591aa3e5a5b0a604f87eb59a6d57190516fa7fb..0af01d9f10b2788a9fe377463fdf5bab3e01c598 100644 (file)
@@ -16788,6 +16788,9 @@ SELECT set_config('log_statement_stats', 'off', false);
    <indexterm>
     <primary>pg_create_restore_point</primary>
    </indexterm>
+   <indexterm>
+    <primary>pg_current_xlog_flush_location</primary>
+   </indexterm>
    <indexterm>
     <primary>pg_current_xlog_insert_location</primary>
    </indexterm>
@@ -16843,6 +16846,13 @@ SELECT set_config('log_statement_stats', 'off', false);
        <entry><type>pg_lsn</type></entry>
        <entry>Create a named point for performing restore (restricted to superusers)</entry>
       </row>
+      <row>
+       <entry>
+        <literal><function>pg_current_xlog_flush_location()</function></literal>
+        </entry>
+       <entry><type>pg_lsn</type></entry>
+       <entry>Get current transaction log flush location</entry>
+      </row>
       <row>
        <entry>
         <literal><function>pg_current_xlog_insert_location()</function></literal>
@@ -16977,13 +16987,14 @@ postgres=# select pg_start_backup('label_goes_here');
     <function>pg_current_xlog_location</> displays the current transaction log write
     location in the same format used by the above functions.  Similarly,
     <function>pg_current_xlog_insert_location</> displays the current transaction log
-    insertion point.  The insertion point is the <quote>logical</> end
-    of the transaction log
-    at any instant, while the write location is the end of what has actually
-    been written out from the server's internal buffers.  The write location
-    is the end of what can be examined from outside the server, and is usually
+    insertion point and <function>pg_current_xlog_flush_location</> displays the
+    current transaction log flush point. The insertion point is the <quote>logical</>
+    end of the transaction log at any instant, while the write location is the end of
+    what has actually been written out from the server's internal buffers and flush
+    location is the location guaranteed to be written to durable storage. The write
+    location is the end of what can be examined from outside the server, and is usually
     what you want if you are interested in archiving partially-complete transaction log
-    files.  The insertion point is made available primarily for server
+    files.  The insertion and flush points are made available primarily for server
     debugging purposes.  These are both read-only operations and do not
     require superuser permissions.
    </para>
index 42168985e0c459beab128688b54d8a505a352298..31cbb01ce47122fc179cff6814e6c5ec69f59871 100644 (file)
@@ -215,6 +215,27 @@ pg_current_xlog_insert_location(PG_FUNCTION_ARGS)
        PG_RETURN_LSN(current_recptr);
 }
 
+/*
+ * Report the current WAL flush location (same format as pg_start_backup etc)
+ *
+ * This function is mostly for debugging purposes.
+ */
+Datum
+pg_current_xlog_flush_location(PG_FUNCTION_ARGS)
+{
+       XLogRecPtr      current_recptr;
+
+       if (RecoveryInProgress())
+               ereport(ERROR,
+                               (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+                                errmsg("recovery is in progress"),
+                                errhint("WAL control functions cannot be executed during recovery.")));
+
+       current_recptr = GetFlushRecPtr();
+
+       PG_RETURN_LSN(current_recptr);
+}
+
 /*
  * Report the last WAL receive location (same format as pg_start_backup etc)
  *
index 73046b0a4fa3d10881c629903ffbccf8793357d5..762df8bea30d489b56d5309634bb14330ba20abb 100644 (file)
@@ -19,6 +19,7 @@ extern Datum pg_switch_xlog(PG_FUNCTION_ARGS);
 extern Datum pg_create_restore_point(PG_FUNCTION_ARGS);
 extern Datum pg_current_xlog_location(PG_FUNCTION_ARGS);
 extern Datum pg_current_xlog_insert_location(PG_FUNCTION_ARGS);
+extern Datum pg_current_xlog_flush_location(PG_FUNCTION_ARGS);
 extern Datum pg_last_xlog_receive_location(PG_FUNCTION_ARGS);
 extern Datum pg_last_xlog_replay_location(PG_FUNCTION_ARGS);
 extern Datum pg_last_xact_replay_timestamp(PG_FUNCTION_ARGS);
index 95d683c8ff5dc9eb639d8af78f579d293dd9ea63..f58672e4a7c408cf8fb7fb851cf217686f456ef9 100644 (file)
@@ -3158,6 +3158,8 @@ DATA(insert OID = 2849 ( pg_current_xlog_location PGNSP PGUID 12 1 0 0 0 f f f f
 DESCR("current xlog write location");
 DATA(insert OID = 2852 ( pg_current_xlog_insert_location       PGNSP PGUID 12 1 0 0 0 f f f f t f v s 0 0 3220 "" _null_ _null_ _null_ _null_ _null_ pg_current_xlog_insert_location _null_ _null_ _null_ ));
 DESCR("current xlog insert location");
+DATA(insert OID = 3330 ( pg_current_xlog_flush_location        PGNSP PGUID 12 1 0 0 0 f f f f t f v s 0 0 3220 "" _null_ _null_ _null_ _null_ _null_ pg_current_xlog_flush_location _null_ _null_ _null_ ));
+DESCR("current xlog flush location");
 DATA(insert OID = 2850 ( pg_xlogfile_name_offset       PGNSP PGUID 12 1 0 0 0 f f f f t f i s 1 0 2249 "3220" "{3220,25,23}" "{i,o,o}" "{wal_location,file_name,file_offset}" _null_ _null_ pg_xlogfile_name_offset _null_ _null_ _null_ ));
 DESCR("xlog filename and byte offset, given an xlog location");
 DATA(insert OID = 2851 ( pg_xlogfile_name                      PGNSP PGUID 12 1 0 0 0 f f f f t f i s 1 0 25 "3220" _null_ _null_ _null_ _null_ _null_ pg_xlogfile_name _null_ _null_ _null_ ));