-<!-- $Id: adminscripts.sgml,v 1.52.2.1 2008-12-15 23:30:58 cbbrowne Exp $ -->
+<!-- $Id: adminscripts.sgml,v 1.52.2.2 2009-06-09 21:38:27 cbbrowne Exp $ -->
<sect1 id="adminscripts">
<title>&slony1; Administration Scripts</title>
<listitem><para> It may be desirable later, after the subscription process is complete, to revise subscriptions. </para> </listitem>
</itemizedlist>
+</sect2>
+<sect2 id="slonikconfdump"> <title>slonikconfdump.sh</title>
+
+<indexterm><primary>slonik configuration dump</primary></indexterm>
+
+<para> The tool <filename>tools/slonikconfdump.sh</filename> was
+created to help dump out a &lslonik; script to duplicate the
+configuration of a functioning &slony1; cluster.</para>
+
+<para> It dumps out: </para>
+
+<itemizedlist>
+<listitem><para>Cluster name </para> </listitem>
+<listitem><para>Node connection information </para> <para> Note that it uses the first value it finds (<emphasis>e.g.</emphasis> - for the lowest numbered client node). </para> </listitem>
+<listitem><para> Nodes </para> </listitem>
+<listitem><para> Sets </para> </listitem>
+<listitem><para> Tables </para> </listitem>
+<listitem><para> Sequences </para> </listitem>
+<listitem><para> Subscriptions </para> </listitem>
+</itemizedlist>
+
+<para> It may be run as follows: </para>
+<programlisting>
+chris@dba2:Slony-I/CMD/slony1-2.0/tools> SLONYCLUSTER=slony_regress1 PGDATABASE=slonyregress1 bash slonikconfdump.sh
+# building slonik config files for cluster slony_regress1
+# generated by: slonikconfdump.sh
+# Generated on: Tue Jun 9 17:34:12 EDT 2009
+cluster name=slony_regress1;
+include <admin-conninfos.slonik>; # Draw in ADMIN CONNINFO lines
+node 1 admin conninfo='dbname=slonyregress1 host=localhost user=chris port=7083';
+node 2 admin conninfo='dbname=slonyregress2 host=localhost user=chris port=7083';
+init cluster (id=1, comment='Regress test node');
+store node (id=2, comment='node 2');
+store path (server=1, client=2, conninfo='dbname=slonyregress1 host=localhost user=chris port=7083', connretry=10);
+store path (server=2, client=1, conninfo='dbname=slonyregress2 host=localhost user=chris port=7083', connretry=10);
+create set (id=1, origin=1, comment='All test1 tables');
+set add table (id=1, set id=1, origin=1, fully qualified name='"public"."table1"', comment='accounts table, key='table1_pkey');
+set add table (id=2, set id=1, origin=1, fully qualified name='"public"."table2"', comment='public.table2, key='table2_id_key');
+set add table (id=4, set id=1, origin=1, fully qualified name='"public"."table4"', comment='a table of many types, key='table4_pkey');
+set add table (id=5, set id=1, origin=1, fully qualified name='"public"."table5"', comment='a table with composite PK strewn across the table, key='table5_pkey');
+subscribe set (id=1, provider=1, receiver=2, forward=YES);
+chris@dba2:Slony-I/CMD/slony1-2.0/tools>
+</programlisting>
+
+<para> The output should be reviewed before it is applied elsewhere;
+particular attention should be paid to the <command>ADMIN
+CONNINFO</command> statements, as it picks the first value that it
+sees for each node; in a complex environment, it may not pull out the
+right value.</para>
+
</sect2>
</sect1>
<!-- Keep this comment at the end of the file
--- /dev/null
+#!/bin/bash
+# $Id: slonikconfdump.sh,v 1.1.2.1 2009-06-09 21:38:27 cbbrowne Exp $
+# This tool rummages through a Slony-I cluster, generating a slonik script
+# suitable to recreate the cluster
+
+# Start with:
+# SLONYCLUSTER indicating the cluster name
+echo "# building slonik config files for cluster ${SLONYCLUSTER}"
+echo "# generated by: slonikconfdump.sh"
+echo "# Generated on: " `date`
+SS="\"_${SLONYCLUSTER}\""
+echo "cluster name=${SLONYCLUSTER};"
+
+echo "include <admin-conninfos.slonik>; # Draw in ADMIN CONNINFO lines"
+Q="select distinct pa_server from ${SS}.sl_path order by pa_server;"
+PATHS=`psql -qtA -F ":" -c "${Q}"`
+for svr in `echo ${PATHS}`; do
+ SQ="select pa_conninfo from ${SS}.sl_path where pa_server=${svr} order by pa_client asc limit 1;"
+ conninfo=`psql -qtA -F ":" -c "${SQ}"`
+ echo "node ${svr} admin conninfo='${conninfo}';"
+done
+
+Q="select no_id, no_comment from ${SS}.sl_node order by no_id limit 1;"
+
+NODE1=`psql -qtA -F ":" -c "${Q}"`
+nn=`echo ${NODE1} | cut -d : -f 1`
+comment=`echo ${NODE1} | cut -d : -f 2-`
+echo "init cluster (id=${nn}, comment='${comment}');"
+
+Q="select no_id from ${SS}.sl_node order by no_id offset 1;"
+NODES=`psql -qtA -F ":" -c "${Q}"`
+for node in `echo ${NODES}`; do
+ CQ="select no_comment from ${SS}.sl_node where no_id = ${node};"
+ comment=`psql -qtA -c "${CQ}"`
+ echo "store node (id=${node}, comment='${comment}');"
+done
+
+#slonyregress1=# select * from sl_path;
+# pa_server | pa_client | pa_conninfo | pa_connretry
+#-----------+-----------+----------------------------------------------------------+--------------
+# 2 | 1 | dbname=slonyregress2 host=localhost user=chris port=7083 | 10
+# 1 | 2 | dbname=slonyregress1 host=localhost user=chris port=7083 | 10
+#(2 rows)
+
+Q="select pa_server, pa_client, pa_connretry from ${SS}.sl_path order by pa_server, pa_client;"
+PATHS=`psql -qtA -F ":" -R " " -c "${Q}"`
+for sc in `echo $PATHS`; do
+ server=`echo $sc | cut -d : -f 1`
+ client=`echo $sc | cut -d : -f 2`
+ retry=`echo $sc | cut -d : -f 3`
+ Q2="select pa_conninfo from ${SS}.sl_path where pa_server=${server} and pa_client=${client};"
+ conninfo=`psql -qtA -c "${Q2}"`
+ echo "store path (server=${server}, client=${client}, conninfo='${conninfo}', connretry=${retry});"
+done
+
+Q="select set_id, set_origin from ${SS}.sl_set order by set_id;"
+SETS=`psql -qtA -F ":" -R " " -c "${Q}"`
+for sc in `echo ${SETS}`; do
+ set=`echo ${sc} | cut -d : -f 1`
+ origin=`echo ${sc} | cut -d : -f 2`
+ Q2="select set_comment from ${SS}.sl_set where set_id=${set};"
+ comment=`psql -qtA -c "${Q2}"`
+ echo "create set (id=${set}, origin=${origin}, comment='${comment}');"
+done
+
+Q="select tab_id,tab_set, set_origin from ${SS}.sl_table, ${SS}.sl_set where tab_set = set_id order by tab_id;"
+TABS=`psql -qtA -F ":" -R " " -c "${Q}"`
+for tb in `echo ${TABS}`; do
+ tab=`echo ${tb} | cut -d : -f 1`
+ set=`echo ${tb} | cut -d : -f 2`
+ origin=`echo ${tb} | cut -d : -f 3`
+ RQ="select tab_relname from ${SS}.sl_table where tab_id = ${tab};"
+ relname=`psql -qtA -c "${RQ}"`
+ NSQ="select tab_nspname from ${SS}.sl_table where tab_id = ${tab};"
+ nsp=`psql -qtA -c "${NSQ}"`
+ IDX="select tab_idxname from ${SS}.sl_table where tab_id = ${tab};"
+ idx=`psql -qtA -c "${IDX}"`
+ COM="select tab_comment from ${SS}.sl_table where tab_id = ${tab};"
+ comment=`psql -qtA -c "${COM}"`
+ echo "set add table (id=${tab}, set id=${set}, origin=${origin}, fully qualified name='\"${nsp}\".\"${relname}\"', comment='${comment}, key='${idx}');"
+done
+
+
+Q="select seq_id,seq_set,set_origin from ${SS}.sl_sequence, ${SS}.sl_set where seq_set = set_id order by seq_id;"
+SEQS=`psql -qtA -F ":" -R " " -c "${Q}"`
+for sq in `echo ${SEQS}`; do
+ seq=`echo ${sq} | cut -d : -f 1`
+ set=`echo ${sq} | cut -d : -f 2`
+ origin=`echo ${sq} | cut -d : -f 3`
+ RQ="select seq_relname from ${SS}.sl_sequence where seq_id = ${seq};"
+ relname=`psql -qtA -c "${RQ}"`
+ NSQ="select seq_nspname from ${SS}.sl_sequence where seq_id = ${seq};"
+ nsp=`psql -qtA -c "${NSQ}"`
+ COM="select seq_comment from ${SS}.sl_sequence where seq_id = ${seq};"
+ comment=`psql -qtA -c "${COM}"`
+ echo "set add sequence(id=${seq}, set id=${set}, origin=${origin}, fully qualified name='\"${nsp}\".\"${relname}\"', comment='${comment}');"
+done
+
+Q="select sub_set,sub_provider,sub_receiver,case when sub_forward then 'YES' else 'NO' end from ${SS}.sl_subscribe;"
+SUBS=`psql -qtA -F ":" -R " " -c "${Q}"`
+for sb in `echo ${SUBS}`; do
+ set=`echo ${sb} | cut -d : -f 1`
+ prov=`echo ${sb} | cut -d : -f 2`
+ recv=`echo ${sb} | cut -d : -f 3`
+ forw=`echo ${sb} | cut -d : -f 4`
+ echo "subscribe set (id=${set}, provider=${prov}, receiver=${recv}, forward=${forw});"
+done