13.08.2013 Views

Postgres-XC

Postgres-XC

Postgres-XC

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Postgres</strong>-<strong>XC</strong> Install Manual Version 0.9.5<br />

<strong>Postgres</strong>-<strong>XC</strong><br />

Install Manual<br />

Version 0.9.5<br />

NTT Open Source Software Center<br />

June 30 th , 2011<br />

© 2010-2011 by Nippon Telegraph and Telephone Corporation


Table of Contents<br />

<strong>Postgres</strong>-<strong>XC</strong> Install Manual Version 0.9.5<br />

1. Code Acquisition.................................................................................................................................<br />

3<br />

2. <strong>Postgres</strong>-<strong>XC</strong> Quick Start.....................................................................................................................<br />

3<br />

2.1Recommended environment..........................................................................................................<br />

3<br />

2.2Install commands...........................................................................................................................<br />

4<br />

2.3Environment initialization and setting...........................................................................................<br />

4<br />

2.4Quick Setup....................................................................................................................................<br />

5<br />

2.4.1Configuration file setting........................................................................................................<br />

5<br />

2.4.2pg_hba.conf setting.................................................................................................................<br />

6<br />

2.5Launching Components.................................................................................................................<br />

6<br />

3. <strong>Postgres</strong>-<strong>XC</strong> detailed installation........................................................................................................<br />

7<br />

3.1Configure........................................................................................................................................<br />

7<br />

3.2Make...............................................................................................................................................<br />

8<br />

4. <strong>Postgres</strong>-<strong>XC</strong> setting.............................................................................................................................<br />

8<br />

4.1initdb..............................................................................................................................................<br />

8<br />

4.2Configuration files.........................................................................................................................<br />

9<br />

4.2.1Datanode configuration.........................................................................................................<br />

10<br />

4.2.2Coordinator configuration.....................................................................................................<br />

11<br />

4.3Start up.........................................................................................................................................<br />

15<br />

4.3.1GTM......................................................................................................................................<br />

15<br />

4.3.2GTM proxy...........................................................................................................................<br />

16<br />

4.3.3Launching Data Nodes and Coordinators<br />

............................................................................ 16<br />

5. <strong>Postgres</strong>-<strong>XC</strong> start/stop functions: pg_ctl and gtm_ctl functionalities..............................................<br />

17<br />

5.1pg_ctl module...............................................................................................................................<br />

17<br />

5.2gtm_ctl module............................................................................................................................<br />

17<br />

2


1. Code Acquisition<br />

<strong>Postgres</strong>-<strong>XC</strong> Install Manual Version 0.9.5<br />

Code can be downloaded from the Source Forge <strong>Postgres</strong>-<strong>XC</strong> development page.<br />

It can be taken from the public git repository in Source Forge. Install at least git 1.6.0 (supported by<br />

Source Forge) on your machine, and type the following command:<br />

git clone git://postgres-xc.git.sourceforge.net/gitroot/postgres-xc/postgres-xc<br />

Installing <strong>Postgres</strong>-<strong>XC</strong> from source code requires at least gcc version 4.1 or higher and GNU make.<br />

You may need flex later than 2.5.4 and bison later than 1.875.<br />

2. <strong>Postgres</strong>-<strong>XC</strong> Quick Start<br />

This section presents how to quickly install <strong>Postgres</strong>-<strong>XC</strong>.<br />

Please refer to part 3 for a more detailed procedure.<br />

2.1 Recommended environment<br />

Here is the basic structure used for <strong>Postgres</strong>-<strong>XC</strong> cluster:<br />

Figure 1 <strong>Postgres</strong>-<strong>XC</strong> environment and configuration<br />

3


<strong>Postgres</strong>-<strong>XC</strong> Install Manual Version 0.9.5<br />

This environment structure has been used to make <strong>Postgres</strong>-<strong>XC</strong> run as efficiently as possible by<br />

dividing processes efficiently. With (n+1) servers (n nodes and one GTM) , GTM is on a dedicated<br />

node and each other server is running one coordinator and one data node process of <strong>Postgres</strong>-<strong>XC</strong>.<br />

Having the Coordinator and Datanode processes together and on each node allow for an even<br />

distribution of workload. Also, reads from replicated tables can happen locally without requiring an<br />

additional network shop.<br />

The (n+1) servers are set on the same IP segment.<br />

The GTM server may be of a different class of server than the other components. It does not require<br />

have the storage requirements of the other components for example.<br />

Note: the user is free to spread the components as he wants. This configuration depends highly on<br />

the application layer used. When testing with a benchmark called DBT-1, classified as CPU-bound,<br />

<strong>Postgres</strong>-<strong>XC</strong> development team witnessed about 25-30% of CPU time being taken up by the<br />

Coordinator processes, and the rest by the Data Node processes.<br />

2.2 Install commands<br />

The software has to be installed from the source code, which can be done easily with the following<br />

commands, operation on to be in each of the (n+1) servers of the cluster:<br />

./configure CFLAGS="-DPG<strong>XC</strong>"<br />

make<br />

make install<br />

Everything will be installed in the folder /usr/local/pgsql by default, unless overridden with –prefix<br />

option when running configure.<br />

“make install” has to be done as user root if installing in /usr/local/pgsql.<br />

Note: <strong>Postgres</strong>-<strong>XC</strong> uses by default a CFLAGS called DPG<strong>XC</strong> when compiled. This flag is activated<br />

by default. In order to disable this flag, A flag UPG<strong>XC</strong> (undefine <strong>Postgres</strong>-<strong>XC</strong>) has to be set as<br />

CFLAGS.<br />

2.3 Environment initialization and setting<br />

Coordinators, Data Nodes and GTM require data directories for storing their data. The coordinator<br />

4


<strong>Postgres</strong>-<strong>XC</strong> Install Manual Version 0.9.5<br />

storage requirements are modest, as it is mainly catalog information, but data nodes may require<br />

much more, depending on the database.<br />

An example for data directories appears below. Assume that the desired root data directory is /data.<br />

mkdir /data<br />

mkdir /data/coord /data/datanode /data/gtm<br />

It can be also necessary for initdb process to allow access to the data directory for a proper<br />

initialization of the environment. Be sure to launch:<br />

chown username /data<br />

chown username /data/datanode /data/gtm /data/coord<br />

Then launch the following commands to initialize your environment:<br />

initdb –D /data/coord<br />

initdb –D /data/datanode<br />

In each coordinator/datanode folder, a postgresql.conf and pg_hba.conf file will appear.<br />

The next step is to set up those files.<br />

Initialization is not required for GTM but the data folder has to be set up when launching the<br />

process.<br />

2.4 Quick Setup<br />

This part explains how to quickly configure the <strong>Postgres</strong>-<strong>XC</strong> cluster.<br />

2.4.1 Configuration file setting<br />

Based on Figure 1, initialize the following values in postgresql.conf file located in the folder<br />

coordinator of server i (i between 1 and n):<br />

- pooler_port = 6667<br />

- num_data_nodes = n<br />

- coordinator_hosts = list of the IP addresses of the n <strong>Postgres</strong>-<strong>XC</strong> servers<br />

- coordinator_ports = 5432<br />

- data_node_hosts = list of the IP addresses of the n <strong>Postgres</strong>-<strong>XC</strong> servers<br />

- data_node_ports = 15432<br />

5


- gtm_host = GTM ip address<br />

- gtm_port = GTM process port<br />

- pgxc_node_id = i<br />

<strong>Postgres</strong>-<strong>XC</strong> Install Manual Version 0.9.5<br />

It doesn't cause any problems if the above values are the same on all nodes. It is actually encouraged,<br />

as it makes maintenance easier.<br />

pgxc_node_id plays an important roles for Coordinator because it permits the local coordinator to<br />

identify itself in the arrays coordinator_ports and coordinator_hosts. For example, by setting<br />

pgxc_node_id at 2, coordinator using this value thinks that its own IP and port are the second<br />

elements in the coordinator setting arrays. Such a definition is thought more simple in the cluster<br />

because it permits to keep the same arrays of data for Coordinators on all the Coordinator nodes.<br />

A similar setting has to be done in postgresql.conf file located in the folder datanode of server i (i<br />

between 1 and n):<br />

- gtm_host = GTM ip address<br />

- gtm_port = GTM process port<br />

- pgxc_node_id = i<br />

2.4.2 pg_hba.conf setting<br />

Add in each pg_hba.conf file of both coordinator and datanode folder the following line at the end<br />

of the file:<br />

host all all segment_IP.0/24 trust<br />

This will allow each component to communicate with other components in the cluster.<br />

If you have stricter security requirements, you can be more precise and modify accordingly. Please<br />

refer to the PostgreSQL documentation for more details.<br />

2.5 Launching Components<br />

Figure 1 shows the minimum options necessary to launch it correctly.<br />

In GTM machine, begin by launching GTM with the following command (it is important to start<br />

GTM before the other components for node registration):<br />

gtm -x 628 -p 6666 -D /data/gtm &<br />

6


<strong>Postgres</strong>-<strong>XC</strong> Install Manual Version 0.9.5<br />

-D option is mandatory for GTM, to make it consistent with PostgreSQL APIs.<br />

It is also possible to launch an additional component called GTM Proxy so as to limit the network<br />

load between Coordinators and GTM. Please refer to section 4.3.2 for detailed explanations.<br />

Then on each of the n <strong>Postgres</strong>-<strong>XC</strong> servers, launch the datanodes:<br />

postgres -X -i -p 15432 -D /data/datanode &<br />

Then on each of the n <strong>Postgres</strong>-<strong>XC</strong> servers, launch the coordinators:<br />

postgres -C -i -D /data/coordinator &<br />

The cluster should run and is ready to be used. In case a customized installation is necessary, please<br />

refer to part 3.<br />

3. <strong>Postgres</strong>-<strong>XC</strong><br />

detailed installation<br />

From the repository where <strong>Postgres</strong>-<strong>XC</strong> code has been saved, the installation is made up of two<br />

steps: configure and make.<br />

<strong>Postgres</strong>-<strong>XC</strong> is based on PostgreSQL code.<br />

3.1 Configure<br />

<strong>Postgres</strong>-<strong>XC</strong> can be configured with this simple command:<br />

./configure<br />

In case of compiling <strong>Postgres</strong>-<strong>XC</strong> with an optimization option, do the following:<br />

export CFLAGS='-O2'<br />

./configure<br />

<strong>Postgres</strong>-<strong>XC</strong> code is easily identifiable in PostgreSQL code thanks to a C flag called PG<strong>XC</strong>.<br />

<strong>Postgres</strong>-<strong>XC</strong> uses the same configuration options as PostgreSQL, here are a couple of useful ones<br />

when setting your environment.<br />

--enable-depend, useful if you are doing some development work. When a header is<br />

changed, the make files will be modified so as that impacted objects will be rebuilt as well in<br />

coordination.<br />

--prefix=/data, so as to set the repository where you want <strong>Postgres</strong>-<strong>XC</strong> to be installed<br />

--enable-debug, to allow debug options when running <strong>Postgres</strong>-<strong>XC</strong><br />

--disable-rpath, in case binaries needs to be moved. This option is particularly useful for<br />

<strong>Postgres</strong>-<strong>XC</strong> as it is designed to be extended to a server cluster.<br />

7


<strong>Postgres</strong>-<strong>XC</strong> Install Manual Version 0.9.5<br />

--enable-cassert, activates assertions in the code. May have an impact on performance.<br />

The user can also set a optimization option in the C flag setting with:<br />

export CFLAGS='-O2'. This option is highly recommended to scale efficiently the cluster !<br />

<strong>Postgres</strong>-<strong>XC</strong> activates by default a compilation flag CFLAGS called DPG<strong>XC</strong>. In order to disable<br />

this flag, a flag UPG<strong>XC</strong> (undefine <strong>Postgres</strong>-<strong>XC</strong>) has to be set as CFLAGS when launching<br />

configure.<br />

or<br />

./configure CFLAGS='-UPG<strong>XC</strong>'<br />

export CFLAGS='-UPG<strong>XC</strong>'<br />

3.2 Make<br />

The two following commands have to be entered in the base folder where <strong>Postgres</strong>-<strong>XC</strong> has been<br />

saved.<br />

make<br />

make install<br />

After installation in the desired folder, <strong>Postgres</strong>-<strong>XC</strong> is divided into 4 subdirectories. The format is<br />

the same as a regular PostgreSQL install:<br />

- bin, containing all the call functions<br />

- include, for the APIs<br />

- library, containing <strong>Postgres</strong>-<strong>XC</strong> libraries<br />

- share, for sample files and time zone management<br />

4. <strong>Postgres</strong>-<strong>XC</strong> setting<br />

<strong>Postgres</strong>-<strong>XC</strong> is divided into the following major components: Coordinator, Datanode, Global<br />

Transaction Manager (GTM as cited below) and GTM proxy.<br />

All are available in the bin subdirectory of the installation directory.<br />

4.1 initdb<br />

It is necessary to setup Coordinator and Datanode environment folders with initdb on all the servers<br />

where <strong>Postgres</strong>-<strong>XC</strong> will be run.<br />

The initialization is made simply with initdb -D folder_name, for a coordinator<br />

It can also use the same options as PostgreSQL.<br />

8


<strong>Postgres</strong>-<strong>XC</strong> Install Manual Version 0.9.5<br />

Depending on the folders where data is located, it can be necessary to grant access for initdb to data<br />

folders. Be sure to launch the following commands:<br />

chown username coord_folder<br />

chown username datanode_folder<br />

It is important not to forget to divide Coordinator and Datanode folders as they are separate entities,<br />

using as well separate configuration files.<br />

initdb -D coord_folder<br />

initdb -D datanode_folder<br />

For example, for a Datanode:<br />

for a Coordinator:<br />

initdb -D /data/datanode<br />

initdb -D /data/coordinator<br />

Now the basic environment is set up.<br />

Before launching <strong>Postgres</strong>-<strong>XC</strong> components, they must be configured to allow the whole system to<br />

work properly.<br />

4.2 Configuration files<br />

The next step concerns configuration files. <strong>Postgres</strong>-<strong>XC</strong>, as a database cluster product, has to be set<br />

up depending on the environment where it is used.<br />

Two files have to be modified for both the data node and coordinator.<br />

- pg_hba.conf so as to allow all the <strong>Postgres</strong>-<strong>XC</strong> components to interact properly<br />

- postgresql.conf, which is the biggest part to modify.<br />

All the configuration files are found where coordinator and datanode data directories have been set<br />

up with initdb, as in regular PostgreSQL.<br />

9


4.2.1 Datanode configuration<br />

4.2.1.1 pg_hba.conf<br />

<strong>Postgres</strong>-<strong>XC</strong> Install Manual Version 0.9.5<br />

This configuration is exactly the same as for PostgreSQL. It allows to define restrictions and<br />

authorizations for the access of <strong>Postgres</strong>-<strong>XC</strong> elements. In the case of the Datanode, it allows<br />

controlling the accesses from coordinators.<br />

The user has just to write in this file the list of access allowed for this Datanode with the following<br />

syntax.<br />

# TYPE DATABASE USER CIDR-ADDRESS METHOD<br />

If <strong>Postgres</strong>-<strong>XC</strong> architecture is defined locally in a same segment, for instance 84.147.16.*, for all the<br />

users and all the databases, it is enough to write:<br />

host all all 84.147.16.0/24 trust.<br />

The user can restrict the access to one Datanode for one database or one user also thanks to this file.<br />

For example, if a Datanode's pg_hba configuration file has the following line in it:<br />

host flight pilot 84.147.16.16 trust<br />

Only coordinator at address 84.147.16.16 from the user pilot and the database flight can have an<br />

access to this Datanode.<br />

This permits to have a high control on the system security.<br />

4.2.1.2 postgresql.conf<br />

The configuration file of <strong>Postgres</strong>-<strong>XC</strong> is based on the one of PostgreSQL. It basically uses the same<br />

options in terms of logs or vacuum for instance.<br />

Additional parameters have been added to set up properly <strong>Postgres</strong>-<strong>XC</strong> components.<br />

The additional parameters are classified into 2 categories.<br />

The first category is related to the Data Node internal setting.<br />

The second is related to GTM connection settings.<br />

1) Datanode parameter<br />

Parameter name Description Default value<br />

port Datanode port 5432<br />

10


2) GTM connection parameters<br />

<strong>Postgres</strong>-<strong>XC</strong> Install Manual Version 0.9.5<br />

Parameter name Description Default value<br />

gtm_host IP address or host name where GTM or GTM<br />

proxy is localized<br />

*<br />

gtm_port GTM or GTM proxy port 6666<br />

pgxc_node_id Parameter used for node registration. This<br />

number has to be defined uniquely in each<br />

Datanode so as to avoid confusions at the GTM<br />

level. Coordinator and Datanodes can use same<br />

values though. If a Datanode uses the same ID as<br />

another node already registered, it cannot start.<br />

1<br />

Note about pgxc_node_id:<br />

If a Coordinator or a Datanode goes through a GTM proxy to connect to GTM. The Proxy ID used<br />

by the node is also registered on GTM as well as the node ID. If node connects directly to GTM, the<br />

Proxy ID associated to node when it registers is equal to 0.<br />

4.2.2 Coordinator configuration<br />

4.2.2.1 pg_hba.conf<br />

The setup is more or less the same as for the Data Node. pg_hba.conf permits to restrict and to<br />

authorize the access to the coordinator server from an application server.<br />

As for PostgreSQL and the Datanode, the syntax is the same:<br />

# TYPE DATABASE USER CIDR-ADDRESS METHOD<br />

For example, if a coordinator has as authorization configuration:<br />

host flight pilot 84.214.18.55 trust<br />

This coordinator will only accept connections from the application server 84.214.18.55 for the table<br />

flight from the user pilot.<br />

As for the Data Node, this permits us to have a high control on the system security.<br />

However, this setting has to be made in accordance with the other <strong>Postgres</strong>-<strong>XC</strong> components or the<br />

system would encounter authentication/permission errors.<br />

11


4.2.2.2 postgresql.conf<br />

<strong>Postgres</strong>-<strong>XC</strong> Install Manual Version 0.9.5<br />

The Coordinator's default configuration file is identical to the data node's. It uses as a base all the<br />

PostgreSQL configuration parameters. Logs use for instance the same setup as normal PostgreSQL.<br />

However, different parameters have to be set as Coordinator interacts with GTM, pooler, application<br />

servers and Data Nodes when running.<br />

They are classified in 4 categories: internal Coordinator configuration, pooler setting, connections to<br />

Data Nodes, connection to GTM or GTM proxy.<br />

1) Coordinator configuration:<br />

Parameter name Description Default value<br />

port Coordinator port 5432<br />

preferred_data_nodes Possibility to set a data node number. For<br />

replicated tables on several Datanodes, the<br />

Coordinator will go in priority to this one. It<br />

reduces particularly the traffic if Coordinator<br />

targets a local Datanode. This should be set<br />

to the local data node and can effect<br />

performance<br />

strict_statement_checking Blocking statements like CREATE<br />

TRIGGER, DECLARE CURSOR. Set at on,<br />

it allows those statements to be executed on<br />

all data nodes and coordinator.<br />

strict_select_checking Temporary parameter while <strong>Postgres</strong>-<strong>XC</strong> is<br />

still being developed. It is intended to limit<br />

the use of multi-node ORDER BY. GROUP<br />

BY and DISTINCT are still checked<br />

whatever strict_select_checking is on or off.<br />

coordinator_hosts List of Coordinator hosts used in <strong>Postgres</strong>-<br />

<strong>XC</strong> system. The total number of host<br />

addresses written has to be the same as<br />

num_coordinators.<br />

The input format is<br />

12<br />

none<br />

on<br />

off<br />

none


<strong>Postgres</strong>-<strong>XC</strong> Install Manual Version 0.9.5<br />

'host(1),host(2),...,host(n)' for n =<br />

num_coordinators hosts<br />

coordinator_ports List of Data Node ports. Their number has to<br />

be the same as num_coordinators. If only one<br />

port number is defined, <strong>Postgres</strong>-<strong>XC</strong> assumes<br />

that all the Coordinator are using the same<br />

port number.<br />

The input format is 'port(1),port(2),...,port(n)<br />

num_coordinators Number of Coordinators used in <strong>Postgres</strong>-<br />

<strong>XC</strong> cluster<br />

none<br />

These parameters can be set easily by connecting to a coordinator via psql and to use SET query.<br />

2) Pooler parameters<br />

Parameter name Description Default value<br />

max_pool_size Maximum size of pool. This parameter has to be high<br />

enough so as to have a sufficient number of pooler<br />

connections in the system. It depends on the number of<br />

backends at each coordinator too.<br />

min_pool_size Minimum size of pool 1<br />

pooler_port Pooler port to use for communication between the<br />

persistent_datanode_co<br />

nnections<br />

3) Data Node settings<br />

Coordinator backend proceses and pooler.<br />

Parameter to be set at on or off. If it is set to on, the<br />

connection used by a transaction is not put back in the<br />

pool and held by the session. If it is set at off (the<br />

default), when a transaction is committed, the<br />

coordinator puts the connections back in the pool.<br />

1<br />

1000<br />

6667<br />

By default, port at position 1 is associated to the host listed at position 1, port(2) to host(2), etc.<br />

Those parameters are linked to the catalog where Data Nodes are identified through integer numbers.<br />

host(1) is in the catalog datanode 1,... host(n) is called in the catalog Datanode n.<br />

If only one port is defined in data_node_port, <strong>Postgres</strong>-<strong>XC</strong> assumes that all the Data Nodes are using<br />

the same port number (recommended for simplicity if each data node is on a separate physical<br />

13<br />

off


server).<br />

For example, in the configuration case:<br />

num_data_nodes = 3<br />

<strong>Postgres</strong>-<strong>XC</strong> Install Manual Version 0.9.5<br />

data_node_hosts = 'datanode1,datanode2,datanode3'<br />

data_node_ports = '12345,51234,45123'<br />

By setting those parameters in a Coordinator configuration file, the Coordinator can connect to 3<br />

servers called:<br />

• datanode1, using port 12345. This server is identified in catalog with number 1.<br />

• datanode2, using port 51234. This server is identified in catalog with number 2.<br />

• datanode3, using port 45123. This server is identified in catalog with number 3.<br />

As in PostgreSQL, <strong>Postgres</strong>-<strong>XC</strong> provides support for both SET and SHOW so as to be able to set<br />

guc parameters among the cluster efficiently and easily.<br />

4) GTM connection parameters<br />

Parameter name Description Default value<br />

gtm_host IP address or host name where GTM or GTM<br />

proxy is located<br />

*<br />

gtm_port GTM or GTM proxy port 6666<br />

pgxc_node_id <strong>Postgres</strong>-<strong>XC</strong> Node identifier on GTM, used for<br />

node registration. This value has to be unique for<br />

each Coordinator in the cluster. Coordinator also<br />

uses this parameter to determine which is his<br />

position in the array coordinator_hosts,<br />

coordinator_ports. If Coordinator starts with the<br />

ID which is the same of another Coordinator<br />

already registered, it cannot start.<br />

1<br />

Note about pgxc_node_id:<br />

The use of pgxc_node_id is critic so as to run correctly DDL and utilities in the cluster. For example,<br />

on a <strong>Postgres</strong>-<strong>XC</strong> Coordinator, setting pgxc_node_id at a value equal to 2 will make the Coordinator<br />

think that its own position in coordinator_* arrays is the second. If this is not set correctly, DDL and<br />

utility statements cannot be run correctly.<br />

This permit to keep the same values in coordinator_hosts and coordinator_ports for each Coordinator<br />

node and this facilitates the maintenance of the system.<br />

14


<strong>Postgres</strong>-<strong>XC</strong> Install Manual Version 0.9.5<br />

If a Coordinator or a Datanode goes through a GTM proxy to connect to GTM. The Proxy ID used<br />

by the node is also registered on GTM as well as the node ID. If node connects directly to GTM, the<br />

Proxy ID associated to node when it registers is equal to 0.<br />

4.3 Start up<br />

The following activation order has to be respected when activated <strong>Postgres</strong>-<strong>XC</strong>:<br />

• GTM<br />

• GTM proxy (if necessary)<br />

• Data Node/Coordinators<br />

4.3.1 GTM<br />

GTM can be activated with the following arguments:<br />

• x option, first gxid used, by default 628 so as to correspond to initdb.<br />

• l option, log file of GTM. Default value is “/tmp/gtmlog”.<br />

• p option, port number of GTM. Default value is 6666.<br />

• D option, data folder repository. In this folder are kept PID file, option file and control file.<br />

Control file is a file defining the sequence used in GTM as well as the last used GXID at<br />

GTM shutdown. If GTM is stopped, it writes down to this file the sequence names and<br />

number at stop time. There is no default value, as it has to be set at GTM launching.<br />

A GTM instance can also be started as a standby, this instance would be in charge of continuing<br />

cluster operations (snapshot and GXID feed) in case of a GTM failure.<br />

• S option, to start GTM instance as a Standby<br />

• -i option, host name or IP of GTM active instance to connect to<br />

• -q port, port of GTM active instance to connect to<br />

For example, to start an active GTM instance:<br />

gtm -x 628 -l /data/log/gtmlog -p 6680 –D /data/gtm &<br />

To start a GTM standby instance.<br />

gtm -x 628 -l /data/log/standbylog -p 6681 –D /data/standby -i localhost -q 6680 &<br />

A GTM Standby is not necessary when building the cluster. It may only be used as an HA solution in<br />

case of a GTM failure.<br />

15


4.3.2 GTM proxy<br />

<strong>Postgres</strong>-<strong>XC</strong> Install Manual Version 0.9.5<br />

GTM proxy is an optional component used betwenn GTM and coordinator used to group queries<br />

from Coordinators to GTM. It is usually launched as a sublayer of Coordinator in the same server.<br />

GTM proxy can be activated with the following options:<br />

• h option, list of listened IPs of the GTM proxy, Default value is * (it should be able to hear<br />

everything by default).<br />

• p option, GTM proxy port, this is targeted by Coordinator and Datanode in their<br />

postgresql.conf file. Default value is 6666.<br />

• s option, host of GTM. Default value is *.<br />

• t option, port of the GTM in its host server. Default value is 6666.<br />

• n option, number of worker threads between GTM and GTM proxy. Default value is 2<br />

• l option, log file of GTM proxy. Default value is “/tmp/gtmlog”<br />

• D option, data directory for GTM proxy. In this folder are located PID and option files.<br />

• i option, gtm_proxy node id. ID used for GTM Proxy registration. It has to be unique in the<br />

cluster or Proxy cannot start properly.<br />

It is normally launched on the same server as a Coordinator, to efficiently group together requests.<br />

For example:<br />

/data/gtm -i 1 &<br />

gtm_proxy -h localhost -p 6541 -s gtm -t 6680 -n 2 -l /data/log/gtmproxylog –D<br />

In this case GTM is located in a server called “gtm” with port 6680 open. This gtm_proxy will be<br />

registered as “1” in the gtm.<br />

Proxy is launched locally with 2 worker threads to GTM created, and a proxy log file in the directory<br />

written above.<br />

4.3.3 Launching Data Nodes and Coordinators<br />

The launch function of those two components is more or less the same as original PostgreSQL. It<br />

uses the same options and an additional mode argument.<br />

The only difference is that a -C option has to be used when launching a Coordinator, and the<br />

-X option has to be used when launching a Datanode.<br />

Here is a list of recommended parameters adapted to <strong>Postgres</strong>-<strong>XC</strong> cluster:<br />

16


<strong>Postgres</strong>-<strong>XC</strong> Install Manual Version 0.9.5<br />

• i option, so as to let the Data Node or coordinator accept tcp-ip connections, essential in a<br />

cluster.<br />

• D option, so as to use the correct initialized directory with the correct option (for example<br />

not set -C with a repository initialized for a Data Node!).<br />

Example of Data Node launch:<br />

postgres -X -i -p 15451 -D /data/datanode &<br />

Example of Coordinator launch:<br />

postgres -C -i -p 5451 -D /data/coordinator &<br />

5. <strong>Postgres</strong>-<strong>XC</strong> start/stop functions: pg_ctl and gtm_ctl functionalities<br />

5.1 pg_ctl module<br />

pg_ctl uses the same functionalities as its implementation in PostgreSQL.<br />

The only addition is a startup option –S coordinator|datanode which permits to choose whether to<br />

start a <strong>Postgres</strong>-<strong>XC</strong> Coordinator or a <strong>Postgres</strong>-<strong>XC</strong> Data Node. This option is only necessary for start<br />

and restart commands.<br />

It is possible to start, stop, restart, reload GUC parameters as for a PostgreSQL server.<br />

Examples:<br />

Start/restart a coordinator/data node server:<br />

pg_ctl –S coordinator/datanode –D datafolder –o ‘options wanted’<br />

Stop a coordinator or data node server:<br />

pg_ctl stop –D datafolder<br />

5.2 gtm_ctl module<br />

gtm_ctl is a module implemented to manipulate exclusively GTM and GTM proxy features of<br />

<strong>Postgres</strong>-<strong>XC</strong>.<br />

It permits to stop, start and restart those components efficiently. Its options are close to PostgreSQL<br />

functionalities. They are listed above.<br />

Option Description<br />

D Data folder for GTM or GTM proxy<br />

l Log file for gtm_ctl<br />

17


<strong>Postgres</strong>-<strong>XC</strong> Install Manual Version 0.9.5<br />

m Set mode, can be smart, fast or immediate<br />

o Option method. Permits to pass down to gtm or gtm_proxy applications some additional<br />

options. Input options are set with a single quotation mark.<br />

In case of customized options (gtm port/IP-address or proxy port/IP-address/Proxy ID),<br />

following options have to be passed down like this for gtm proxy:<br />

-o '-h localhost -p 6541 -s gtm -t 6680 -n 2 -i 1'<br />

In the case of gtm, options can be passed down like this:<br />

-o '-x 628 -l log_file -p 6680 –D /data/gtm'<br />

Please REFER to gtm_proxy and gtm reference page for all the option details.<br />

p Set up postgres bin repository<br />

S Start/restart/stop option. Has to be set with gtm or gtm_proxy so as to launch one of those<br />

server processes.<br />

t Wait time in seconds<br />

W or w Wait option.<br />

Examples:<br />

Start/restart a GTM/GTM proxy server:<br />

gtm_ctl start/restart –S gtm/gtm_proxy –D datafolder –o ‘options wanted’<br />

gtm_ctl start/restart –S gtm/gtm_proxy –D datafolder –o ‘-h proxy_IP -p proxy_port -s<br />

GTM_IP -t GTM_port -n worker_thread_number -i id_number’<br />

Stop a GTM/GTM proxy server:<br />

gtm_ctl stop –S gtm/gtm_proxy –D datafolder<br />

With stop used as a command, option –S is needed because GTM and GTM proxy pid files are<br />

named differently.<br />

Look at the status of a GTM instance<br />

gtm_ctl status –S gtm –D datafolder<br />

If the data folder scanned is the one of an active GTM instance, status prints 1 as value.<br />

If the data folder scanned is the one of a standby GTM instance, status prints 0 as value.<br />

Promote a standby GTM instance to become active.<br />

gtm_ctl promote -S gtm -D datafolder<br />

Reconnect a GTM Proxy to an other GTM instance, in this case it is mandatory to specify the new<br />

host and port values to connect to the new GTM instance.<br />

standby_port'<br />

gtm_ctl reconnect -S gtm_proxy -D datafolder_proxy -o '-s standby_host -t<br />

18<br />

[End]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!