<paramdef>text <parameter>password</parameter></paramdef>
<paramdef>out <parameter>status text</parameter></paramdef>
<paramdef>out <parameter>weight float4</parameter></paramdef>
+ <paramdef>out <parameter>role text</parameter></paramdef>
+ <paramdef>out <parameter>replication_delay bigint</parameter></paramdef>
+ <paramdef>out <parameter>last_status_change timestamp</parameter></paramdef>
</funcprototype>
<funcprototype>
<paramdef>text <parameter>pcp_server</parameter></paramdef>
<paramdef>out <parameter>status text</parameter></paramdef>
<paramdef>out <parameter>weight float4</parameter></paramdef>
+ <paramdef>out <parameter>role text</parameter></paramdef>
+ <paramdef>out <parameter>replication_delay bigint</parameter></paramdef>
+ <paramdef>out <parameter>last_status_change timestamp</parameter></paramdef>
</funcprototype>
</funcsynopsis>
使用例です。
<programlisting>
test=# SELECT * FROM pcp_node_info(0,'',11001,'t-ishii','t-ishii');
- host | port | status | weight
-------+-------+-------------------+--------
- /tmp | 11002 | Connection in use | 0
+ host | port | status | weight | role | replication_delay | last_status_change
+------+-------+-------------------+--------+---------+-------------------+---------------------
+ /tmp | 11002 | Connection in use | 0 | Primary | 0 | 2018-07-04 17:34:39
(1 row)
</programlisting>
</para>
+ <note>
+ <para>
+<!--
+ <parameter>role</parameter>, <parameter>replication_delay</parameter>, <parameter>last_status_change</parameter>
+ out parameters are new
+ from <productname>Pgpool-II</productname> 4.0. If you have
+ already installed pre-4.0 pgpool_adm extension, you can upgrade
+ to the new one by using ALTER EXTENSION SQL command.
+ <programlisting>
+ ALTER EXTENSION pgpool_adm UPDATE;
+ </programlisting>
+-->
+<parameter>role</parameter>, <parameter>replication_delay</parameter>, <parameter>last_status_change</parameter>出力パラメータは<productname>Pgpool-II</productname> 4.0で追加されました。
+すでに4.0以前のpgpool_adm拡張をインストールされている場合は、ALTER EXTENSION SQLコマンドを使って更新が可能です。
+ <programlisting>
+ ALTER EXTENSION pgpool_adm UPDATE;
+ </programlisting>
+ </para>
+ </note>
</refsect1>
</refentry>
<paramdef>text <parameter>password</parameter></paramdef>
<paramdef>out <parameter>status text</parameter></paramdef>
<paramdef>out <parameter>weight float4</parameter></paramdef>
+ <paramdef>out <parameter>role text</parameter></paramdef>
+ <paramdef>out <parameter>replication_delay bigint</parameter></paramdef>
+ <paramdef>out <parameter>last_status_change timestamp</parameter></paramdef>
</funcprototype>
<funcprototype>
<paramdef>text <parameter>pcp_server</parameter></paramdef>
<paramdef>out <parameter>status text</parameter></paramdef>
<paramdef>out <parameter>weight float4</parameter></paramdef>
+ <paramdef>out <parameter>role text</parameter></paramdef>
+ <paramdef>out <parameter>replication_delay bigint</parameter></paramdef>
+ <paramdef>out <parameter>last_status_change timestamp</parameter></paramdef>
</funcprototype>
</funcsynopsis>
Here is an example output:
<programlisting>
test=# SELECT * FROM pcp_node_info(0,'',11001,'t-ishii','t-ishii');
- host | port | status | weight
-------+-------+-------------------+--------
- /tmp | 11002 | Connection in use | 0
+ host | port | status | weight | role | replication_delay | last_status_change
+------+-------+-------------------+--------+---------+-------------------+---------------------
+ /tmp | 11002 | Connection in use | 0 | Primary | 0 | 2018-07-04 17:34:39
(1 row)
</programlisting>
</para>
+ <note>
+ <para>
+ <parameter>role</parameter>, <parameter>replication_delay</parameter>, <parameter>last_status_change</parameter>
+ out parameters are new
+ from <productname>Pgpool-II</productname> 4.0. If you have
+ already installed pre-4.0 pgpool_adm extension, you can upgrade
+ to the new one by using ALTER EXTENSION SQL command.
+ <programlisting>
+ ALTER EXTENSION pgpool_adm UPDATE;
+ </programlisting>
+ </para>
+ </note>
+
</refsect1>
</refentry>
--- /dev/null
+# contrib/pgpool_adm/Makefile
+
+MODULE_big = pgpool_adm
+OBJS = pgpool_adm.o
+PG_CPPFLAGS = -I$(libpq_srcdir) -I../../include/pcp
+
+EXTENSION = pgpool_adm
+DATA = pgpool_adm--1.0.sql pgpool_adm--1.1.sql pgpool_adm--1.0--1.1.sql
+SHLIB_LINK = -L../../libs/pcp/.libs -lpcp -Wl,--as-needed -Wl,-rpath,'${prefix}/lib',--enable-new-dtags
+# if you are using PostgreSQL 8.0 or later,
+# using pg_config is recommended.
+# if you are not, comment out following line and...
+USE_PGXS = true
+# set top_builddir to the PostgreSQL build source tree top.
+# (for example /usr/local/src/postgresql-8.4)
+top_builddir = ../..
+
+ifdef USE_PGXS
+PG_CONFIG ?= pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
+include $(PGXS)
+else
+subdir = contrib/pgpool_adm
+#top_builddir = ../..
+include $(top_builddir)/src/Makefile.global
+include $(top_srcdir)/contrib/contrib-global.mk
+endif
--- /dev/null
+/* contrib/pgpool_adm/pgpool_adm--1.0--1.1.sql */
+
+-- complain if script is sourced in psql, rather than via ALTER EXTENSION
+\echo Use "ALTER EXTENSION pgpool_adm UPDATE TO '1.1'" to load this file. \quit
+
+ALTER EXTENSION pgpool_adm DROP FUNCTION pcp_node_info(integer, text, integer, text, text, OUT host text, OUT port integer, OUT status text, OUT weight float4);
+DROP FUNCTION pcp_node_info(integer, text, integer, text, text, OUT host text, OUT port integer, OUT status text, OUT weight float4);
+
+CREATE FUNCTION pcp_node_info(integer, text, integer, text, text, OUT host text, OUT port integer, OUT status text, OUT weight float4, OUT role text, OUT replication_delay bigint, OUT last_status_change timestamp)
+RETURNS record
+AS 'MODULE_PATHNAME', '_pcp_node_info'
+LANGUAGE C VOLATILE STRICT;
--- /dev/null
+/* contrib/pgpool_adm/pgpool_adm--1.1.sql */
+
+/* ***********************************************
+ * Administrative functions for pgPool
+ * *********************************************** */
+
+/**
+ * input parameters: node_id, host, port, username, password
+ */
+CREATE FUNCTION pcp_node_info(integer, text, integer, text, text, OUT host text, OUT port integer, OUT status text, OUT weight float4, OUT role text, OUT replication_delay bigint, OUT last_status_change timestamp)
+RETURNS record
+AS 'MODULE_PATHNAME', '_pcp_node_info'
+LANGUAGE C VOLATILE STRICT;
+
+/**
+ * input parameters: node_id, server_name
+ */
+CREATE FUNCTION pcp_node_info(integer, text, OUT host text, OUT port integer, OUT status text, OUT weight float4)
+RETURNS record
+AS 'MODULE_PATHNAME', '_pcp_node_info'
+LANGUAGE C VOLATILE STRICT;
+
+/**
+ * input parameters: host, port, username, password
+ */
+CREATE FUNCTION pcp_pool_status(text, integer, text, text, OUT item text, OUT value text, OUT description text)
+RETURNS record
+AS 'MODULE_PATHNAME', '_pcp_pool_status'
+LANGUAGE C VOLATILE STRICT;
+
+/**
+ * input parameters: server_name
+ */
+CREATE FUNCTION pcp_pool_status(text, OUT item text, OUT value text, OUT description text)
+RETURNS record
+AS 'MODULE_PATHNAME', '_pcp_pool_status'
+LANGUAGE C VOLATILE STRICT;
+
+/**
+ * input parameters: host, port, username, password
+ */
+CREATE FUNCTION pcp_node_count(text, integer, text, text, OUT node_count integer)
+RETURNS integer
+AS 'MODULE_PATHNAME', '_pcp_node_count'
+LANGUAGE C VOLATILE STRICT;
+
+/**
+ * input parameters: server_name
+ */
+CREATE FUNCTION pcp_node_count(text, OUT node_count integer)
+RETURNS integer
+AS 'MODULE_PATHNAME', '_pcp_node_count'
+LANGUAGE C VOLATILE STRICT;
+
+/**
+ * input parameters: node_id, host, port, username, password
+ */
+CREATE FUNCTION pcp_attach_node(integer, text, integer, text, text, OUT node_attached boolean)
+RETURNS boolean
+AS 'MODULE_PATHNAME', '_pcp_attach_node'
+LANGUAGE C VOLATILE STRICT;
+
+/**
+ * input parameters: node_id, server_name
+ */
+CREATE FUNCTION pcp_attach_node(integer, text, OUT node_attached boolean)
+RETURNS boolean
+AS 'MODULE_PATHNAME', '_pcp_attach_node'
+LANGUAGE C VOLATILE STRICT;
+
+/**
+ * input parameters: node_id, gracefully, host, port, username, password
+ */
+CREATE FUNCTION pcp_detach_node(integer, boolean, text, integer, text, text, OUT node_detached boolean)
+RETURNS boolean
+AS 'MODULE_PATHNAME', '_pcp_detach_node'
+LANGUAGE C VOLATILE STRICT;
+
+/**
+ * input parameters: node_id, gracefully, server_name
+ */
+CREATE FUNCTION pcp_detach_node(integer, boolean, text, OUT node_detached boolean)
+RETURNS boolean
+AS 'MODULE_PATHNAME', '_pcp_detach_node'
+LANGUAGE C VOLATILE STRICT;
* pgpool_adm.c
*
*
- * Copyright (c) 2002-2015, PostgreSQL Global Development Group
+ * Copyright (c) 2002-2018, PostgreSQL Global Development Group
*
* Author: Jehan-Guillaume (ioguix) de Rorthais <jgdr@dalibo.com>
*
#include "utils/builtins.h"
#include "foreign/foreign.h"
#include "nodes/pg_list.h"
+#include "utils/timestamp.h"
/*
* PostgreSQL 9.3 or later requires htup_details.h to get the definition of
PCPResultInfo* pcpResInfo;
BackendInfo * backend_info = NULL;
- Datum values[4]; /* values to build the returned tuple from */
- bool nulls[] = {false, false, false, false};
+ Datum values[7]; /* values to build the returned tuple from */
+ bool nulls[] = {false, false, false, false, false, false, false};
TupleDesc tupledesc;
HeapTuple tuple;
+ struct tm tm;
+ char datebuf[20];
if (nodeID < 0 || nodeID >= MAX_NUM_BACKENDS)
ereport(ERROR, (0, errmsg("NodeID is out of range.")));
/**
* Construct a tuple descriptor for the result rows.
**/
- tupledesc = CreateTemplateTupleDesc(4, false);
+ tupledesc = CreateTemplateTupleDesc(7, false);
TupleDescInitEntry(tupledesc, (AttrNumber) 1, "hostname", TEXTOID, -1, 0);
TupleDescInitEntry(tupledesc, (AttrNumber) 2, "port", INT4OID, -1, 0);
TupleDescInitEntry(tupledesc, (AttrNumber) 3, "status", TEXTOID, -1, 0);
TupleDescInitEntry(tupledesc, (AttrNumber) 4, "weight", FLOAT4OID, -1, 0);
+ TupleDescInitEntry(tupledesc, (AttrNumber) 5, "role", TEXTOID, -1, 0);
+ TupleDescInitEntry(tupledesc, (AttrNumber) 6, "replication_delay", INT8OID, -1, 0);
+ TupleDescInitEntry(tupledesc, (AttrNumber) 7, "last_status_change", TIMESTAMPOID, -1, 0);
tupledesc = BlessTupleDesc(tupledesc);
backend_info = (BackendInfo *) pcp_get_binary_data(pcpResInfo,0);
values[3] = Float8GetDatum(backend_info->backend_weight/RAND_MAX);
nulls[3] = false;
+ nulls[4] = false;
+ values[4] = backend_info->role == ROLE_PRIMARY?CStringGetTextDatum("Primary"):CStringGetTextDatum("Standby");
+
+ nulls[5] = false;
+ values[5] = Int64GetDatum(backend_info->standby_delay);
+
+ nulls[6] = false;
+ localtime_r(&backend_info->status_changed_time, &tm);
+ strftime(datebuf, sizeof(datebuf), "%F %T", &tm);
+ values[6] = DatumGetTimestamp(DirectFunctionCall3(timestamp_in,
+ CStringGetDatum(datebuf),
+ ObjectIdGetDatum(InvalidOid),
+ Int32GetDatum(-1)));
+
pcp_disconnect(pcpConnInfo);
pcp_free_connection(pcpConnInfo);
# pcp extension
comment = 'Administrative functions for pgPool'
-default_version = '1.0'
+default_version = '1.1'
module_pathname = '$libdir/pgpool_adm'
relocatable = true
* pgpool_adm.h
*
*
- * Copyright (c) 2002-2011, PostgreSQL Global Development Group
+ * Copyright (c) 2002-2018, PostgreSQL Global Development Group
*
* Author: Jehan-Guillaume (ioguix) de Rorthais <jgdr@dalibo.com>
*
/**
* input parameters: node_id, host, port, username, password
*/
-CREATE FUNCTION pcp_node_info(integer, text, integer, text, text, OUT host text, OUT port integer, OUT status text, OUT weight float4)
+CREATE FUNCTION pcp_node_info(integer, text, integer, text, text, OUT host text, OUT port integer, OUT status text, OUT weight float4, OUT role text, OUT replication_delay bigint, OUT last_status_change TIMESTAMP)
RETURNS record
AS 'MODULE_PATHNAME', '_pcp_node_info'
LANGUAGE C VOLATILE STRICT;