Attached patch implements a function called pg_primary_conninfo() that
returns, well, the primary_conninfo used on the standby when in
streaming replication mode (otherwise NULL).
Objections?
--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/
*** a/doc/src/sgml/func.sgml
--- b/doc/src/sgml/func.sgml
***************
*** 14098,14103 **** postgres=# SELECT * FROM pg_xlogfile_name_offset(pg_stop_backup());
--- 14098,14106 ----
<indexterm>
<primary>pg_last_xact_replay_timestamp</primary>
</indexterm>
+ <indexterm>
+ <primary>pg_primary_conninfo</primary>
+ </indexterm>
<para>
The functions shown in <xref
***************
*** 14168,14173 **** postgres=# SELECT * FROM pg_xlogfile_name_offset(pg_stop_backup());
--- 14171,14187 ----
the function returns NULL.
</entry>
</row>
+ <row>
+ <entry>
+ <literal><function>pg_primary_conninfo()</function></literal>
+ </entry>
+ <entry><type>text</type></entry>
+ <entry>Gets the connection string used to connect to the primary
+ when using streaming replication. When the server has been started
+ normally without recovery, or when file based recovery is in
+ progress, the function returns NULL.
+ </entry>
+ </row>
</tbody>
</tgroup>
</table>
*** a/src/backend/access/transam/xlog.c
--- b/src/backend/access/transam/xlog.c
***************
*** 8829,8834 **** pg_last_xlog_replay_location(PG_FUNCTION_ARGS)
--- 8829,8857 ----
}
/*
+ * Report the connection info that the walreceiver is using to talk to the
+ * primary.
+ */
+ Datum
+ pg_primary_conninfo(PG_FUNCTION_ARGS)
+ {
+ /* use volatile pointer to prevent code rearrangement */
+ volatile WalRcvData *walrcv = WalRcv;
+ XLogRecPtr recptr;
+ char conninfo[MAXCONNINFO];
+
+ SpinLockAcquire(&walrcv->mutex);
+ recptr = walrcv->receivedUpto;
+ memcpy(conninfo, walrcv->conninfo, MAXCONNINFO);
+ SpinLockRelease(&walrcv->mutex);
+
+ if (recptr.xlogid == 0 && recptr.xrecoff == 0 && conninfo[0] != '\0')
+ PG_RETURN_NULL();
+
+ PG_RETURN_TEXT_P(cstring_to_text(conninfo));
+ }
+
+ /*
* Compute an xlog file name and decimal byte offset given a WAL location,
* such as is returned by pg_stop_backup() or pg_xlog_switch().
*
*** a/src/include/catalog/pg_proc.h
--- b/src/include/catalog/pg_proc.h
***************
*** 3386,3392 **** DESCR("xlog filename, given an xlog location");
DATA(insert OID = 3810 ( pg_is_in_recovery PGNSP PGUID 12 1 0 0 f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pg_is_in_recovery _null_ _null_ _null_ ));
DESCR("true if server is in recovery");
!
DATA(insert OID = 3820 ( pg_last_xlog_receive_location PGNSP PGUID 12 1 0 0 f f f t f v 0 0 25 "" _null_ _null_ _null_ _null_ pg_last_xlog_receive_location _null_ _null_ _null_ ));
DESCR("current xlog flush location");
DATA(insert OID = 3821 ( pg_last_xlog_replay_location PGNSP PGUID 12 1 0 0 f f f t f v 0 0 25 "" _null_ _null_ _null_ _null_ pg_last_xlog_replay_location _null_ _null_ _null_ ));
--- 3386,3393 ----
DATA(insert OID = 3810 ( pg_is_in_recovery PGNSP PGUID 12 1 0 0 f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pg_is_in_recovery _null_ _null_ _null_ ));
DESCR("true if server is in recovery");
! DATA(insert OID = 3819 ( pg_primary_conninfo PGNSP PGUID 12 1 0 0 f f f t f v 0 0 25 "" _null_ _null_ _null_ _null_ pg_primary_conninfo _null_ _null_ _null_ ));
! DESCR("connection string for primary");
DATA(insert OID = 3820 ( pg_last_xlog_receive_location PGNSP PGUID 12 1 0 0 f f f t f v 0 0 25 "" _null_ _null_ _null_ _null_ pg_last_xlog_receive_location _null_ _null_ _null_ ));
DESCR("current xlog flush location");
DATA(insert OID = 3821 ( pg_last_xlog_replay_location PGNSP PGUID 12 1 0 0 f f f t f v 0 0 25 "" _null_ _null_ _null_ _null_ pg_last_xlog_replay_location _null_ _null_ _null_ ));
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers