<!--
doc/src/sgml/ref/pgpool_setup.sgml
Pgpool-II documentation
-->

<refentry id="PGPOOL-SETUP">
 <indexterm zone="pgpool-setup">
  <primary>pgpool_setup</primary>
 </indexterm>

 <refmeta>
  <refentrytitle>pgpool_setup</refentrytitle>
  <manvolnum>1</manvolnum>
  <refmiscinfo>Other Commands</refmiscinfo>
 </refmeta>

 <refnamediv>
  <refname>pgpool_setup</refname>
  <refpurpose>
  Create a temporary installation of Pgpool-II cluster</refpurpose>
 </refnamediv>

 <refsynopsisdiv>
  <cmdsynopsis>
   <command>pgpool_setup</command>
   <arg rep="repeat"><replaceable>option</replaceable></arg>
  </cmdsynopsis>
 </refsynopsisdiv>

 <refsect1 id="R1-PGPOOL-SETUP-1">
  <title>
   Description
  </title>
  <para>
  <application>pgpool_setup</application> creates a temporary
  installation of <productname>Pgpool-II</productname> cluster, which
  includes a <productname>Pgpool-II</productname> installation and
  specified number of <productname>PostgreSQL</productname>
  installations under current directory.
  Current directory must be empty before running <application>pgpool_setup</application>.
  </para>
  <para>
    <application>pgpool_setup</application> is for testing purpose
    only and should not be used to create production installations.
  </para>

  <para>
    Currently <application>pgpool_setup</application> supports streaming replication mode, native replication mode and raw mode.
    To support watchdog, see <xref linkend="WATCHDOG-SETUP"> for details.
  </para>
 </refsect1>

 <refsect1>
  <title>Options</title>
   <para>
    <application>pgpool_setup</application> accepts the following command-line arguments:

    <variablelist>

     <varlistentry>
      <term><option>-m <replaceable class="parameter">mode</replaceable></option></term>
      <listitem>
       <para>
        Specifies the running mode.  <replaceable>mode</replaceable>
        can be <literal>r</literal> (native replication mode), <literal>s</literal> (streaming replication mode), or
        <literal>n</literal> (raw mode).
	If this is omitted, <literal>s</literal> is used.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>-n <replaceable class="parameter">num_clusters</replaceable></option></term>
      <listitem>
       <para>
        Specifies the number of PostgreSQL installations.
	If this is omitted, <literal>2</literal> is used.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>-p <replaceable class="parameter">base_port</replaceable></option></term>
      <listitem>
       <para>
	 Specify the base port number used by Pgpool-II and PostgreSQL.
	 Pgpool-II port is base_port. pcp port is base_port + 1. The
	 first PostgreSQL node's port is base_port + 2, second
	 PostgreSQL node's port is base_port + 3 and so on.
       </para>
       <para>
	 If -pg option is specified, the first PostgreSQL node's port is
	 assigned to pg_base_port, the second PostgreSQL node's port is
	 pg_base_port + 1 and so on.
       </para>
       <para>
	If this is omitted, <literal>11000</literal> is used.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>-pg <replaceable class="parameter">pg_base_port</replaceable></option></term>
      <listitem>
       <para>
	 Specify the base port number used by PostgreSQL.
	 The first PostgreSQL node's port is base_port + 2, second
	 PostgreSQL node's port is base_port + 3 and so on.
       </para>
       <para>
	If this is omitted, <literal>base_port</literal>+2 is used.
       </para>

      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>--no-stop</option></term>
      <listitem>
       <para>
	 Do not stop pgpool and PostgreSQL after the work.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>-d</option></term>
      <listitem>
       <para>
	 Start pgpool with debug mode.
       </para>
      </listitem>
     </varlistentry>
    </variablelist>
   </para>
 </refsect1>

 <refsect1>
  <title>Environment variables</title>
   <para>
    <application>pgpool_setup</application> recognizes following environment variables:

    <variablelist>

     <varlistentry>
      <term><option>PGPOOL_INSTALL_DIR</option></term>
      <listitem>
       <para>
        Specifies the Pgpool-II installation directory. Pgpool-II
        binaries is expected to be placed under PGPOOL_INSTALL_DIR/bin
        and pgpool.conf and pool_hba.conf etc. are expected to be placed under
        PGPOOL_INSTALL_DIR/etc. The default is /usr/local.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>PGPOOLDIR</option></term>
      <listitem>
       <para>
        Specifies the path to Pgpool-II configuration files.
        The default is PGPOOL_INSTALL_DIR/etc.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>PGBIN</option></term>
      <listitem>
       <para>
        Specifies the path to PostgreSQL commands such as initdb, pg_ctl and psql.
        The default is /usr/local/pgsql/bin.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>PGLIB</option></term>
      <listitem>
       <para>
        Specifies the path to PostgreSQL shared libraries.
        The default is /usr/local/pgsql/lib.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>PGSOCKET_DIR</option></term>
      <listitem>
       <para>
        Specifies the path to Unix socket directory.
        The default is /tmp.
       </para>
      </listitem>
     </varlistentry>
     <varlistentry>
      <term><option>INITDBARG</option></term>
      <listitem>
       <para>
	 Specifies the arguments for initdb command.
        The default is "--no-locale -E UTF_8".
       </para>
      </listitem>
     </varlistentry>

    </variablelist>

   </para>
 </refsect1>

 <refsect1>
  <title>Example</title>
   <para>
<screen>
$ pgpool_setup
Satrting set up in streaming replication mode
creating startall and shutdownall
creating failover script
creating database cluster /home/t-ishii/tmp/test/data0...done.
update postgreql.conf
creating pgpool_remote_start
creating basebackup.sh
creating recovery.conf
creating database cluster /home/t-ishii/tmp/test/data1...done.
update postgreql.conf
creating pgpool_remote_start
creating basebackup.sh
creating recovery.conf
temporarily start data0 cluster to create extensions
temporarily start pgpool-II to create standby nodes
INFO:  unrecognized configuration parameter "debug_level"
 node_id | hostname | port  | status | lb_weight |  role   | select_cnt | load_balance_node | replication_delay
---------+----------+-------+--------+-----------+---------+------------+-------------------+-------------------
 0       | /tmp     | 11002 | up     | 0.500000  | primary | 0          | true              | 0
 1       | /tmp     | 11003 | down   | 0.500000  | standby | 0          | false             | 0
(2 rows)

recovery node 1...pcp_recovery_node -- Command Successful
done.
creating follow master script
Pager usage is off.
 node_id | hostname | port  | status | lb_weight |  role   | select_cnt | load_balance_node | replication_delay
---------+----------+-------+--------+-----------+---------+------------+-------------------+-------------------
 0       | /tmp     | 11002 | up     | 0.500000  | primary | 0          | false             | 0
 1       | /tmp     | 11003 | up     | 0.500000  | standby | 0          | true              | 0
(2 rows)

shutdown all

pgpool-II setting for streaming replication mode is done.
To start the whole system, use /home/t-ishii/tmp/test/startall.
To shutdown the whole system, use /home/t-ishii/tmp/test/shutdownall.
pcp command user name is "t-ishii", password is "t-ishii".
Each PostgreSQL, pgpool-II and pcp port is as follows:
#1 port is 11002
#2 port is 11003
pgpool port is 11000
pcp port is 11001
The info above is in README.port.

$ ls
README.port  bashrc.ports  data1  log	   pgpool_reload     run	  startall
archivedir   data0	   etc	  pcppass  pgpool_setup.log  shutdownall

$ ./startall
waiting for server to start....11840 2016-08-18 13:08:51 JST LOG:  redirecting log output to logging collector process
11840 2016-08-18 13:08:51 JST HINT:  Future log output will appear in directory "pg_log".
 done
server started
waiting for server to start....11853 2016-08-18 13:08:52 JST LOG:  redirecting log output to logging collector process
11853 2016-08-18 13:08:52 JST HINT:  Future log output will appear in directory "pg_log".
 done
server started
$ psql -p 11000 test
Pager usage is off.
psql (9.5.4)
Type "help" for help.

test=# show pool_nodes;
 node_id | hostname | port  | status | lb_weight |  role   | select_cnt | load_balance_node | replication_delay
---------+----------+-------+--------+-----------+---------+------------+-------------------+-------------------
 0       | /tmp     | 11002 | up     | 0.500000  | primary | 0          | false             | 0
 1       | /tmp     | 11003 | up     | 0.500000  | standby | 0          | true              | 0
(2 rows)

</screen>
</para>
 </refsect1>

</refentry>
