1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
|
<!-- doc/src/sgml/add-node.sgml -->
<chapter id="add-node">
<title>Adding a New Node</title>
<indexterm zone="add-node">
<primary>Add a new node</primary>
</indexterm>
<para>
This chapter outlines steps to add a new Coordinator or a Datanode to a running cluster.
Note that an easier way to do this is to make use of the pgxc_ctl utility.
</para>
<para>
</para>
<sect1 id="add-node-coordinator">
<title>Adding a New Coordinator</title>
<indexterm zone="add-node-coordinator">
<primary>Add a new coordinator</primary>
</indexterm>
<para>
The following steps should be performed to add a new coordinator to a running cluster:
</para>
<para>
<orderedlist>
<listitem>
<para>Initialize the new coordinator. The following example initilizes a coordinator named coord_3.</para>
<programlisting>
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data_cord3 --nodename coord_3
</programlisting>
</listitem>
<listitem>
<para>
Make necessary changes in postgresql.conf of the new coordinator,
in particular specify new coordinator name and pooler port.
</para>
</listitem>
<listitem>
<para>
Connect to any of the existing coordinators and lock the cluster for backup, do not close this session.
The following example assumes a coordinator is running on port 5432. Make sure the function call returns true.
The detailed description of the function <function>pgxc_lock_for_backup</> can be found
in <xref linkend="functions-pgxc-add-new-node">
</para>
<programlisting>
./psql postgres -p 5432
select pgxc_lock_for_backup();
</programlisting>
</listitem>
<listitem>
<para>
Connect to any of the existing coordinators and take backup of the database.
Please note that only schema (i.e. no data) is to be dumped.
Also note the use of <option>--include-nodes</>, so that the <command>CREATE TABLE</> contains <command>TO NODE</> clause.
Similarly <option>--dump-nodes</> ensures that the dump does contain existing nodes and node groups.
</para>
<programlisting>
./pg_dumpall -p 5432 -s --include-nodes --dump-nodes --file=/some/valid/path/some_file_name.sql
</programlisting>
</listitem>
<listitem>
<para>
Start the new coordinator specifying <option>--restoremode</> while starting.
The following example starts the new coordinator on port 5455
</para>
<programlisting>
./postgres --restoremode -D ../data_cord3 -p 5455
</programlisting>
<para>
You can use <literal>pg_ctl</literal> with <option>-Z restoremode</option> option.
</para>
<programlisting>
./pg_ctl start -Z restoremode -D ../data_coord3 -p 5455
</programlisting>
</listitem>
<listitem>
<para>
Restore the backup (taken in step 4) by connecting to the new coordinator directly.
</para>
<programlisting>
./psql -d postgres -f /some/valid/path/some_file_name.sql -p 5455
</programlisting>
</listitem>
<listitem>
<para>
Quit the new coordinator.
</para>
</listitem>
<listitem>
<para>
Start the new coordinator specifying <option>--coordinator</> while starting.
The following example starts the new coordinator on port 5455
</para>
<programlisting>
./postgres --coordinator -D ../data_cord3 -p 5455
</programlisting>
</listitem>
<listitem>
<para>
Create the new coordinator on rest of the coordinators and reload configuration.
The following example creates coord_3, with host localhost and port 5455.
</para>
<programlisting>
CREATE NODE COORD_3 WITH (HOST = 'localhost', type = 'coordinator', PORT = 5455);
SELECT pgxc_pool_reload();
</programlisting>
</listitem>
<listitem>
<para>
Quit the session of step 3, this will unlock the cluster. The new coordinator is now ready.
</para>
</listitem>
</orderedlist>
</para>
</sect1>
<sect1 id="add-node-datanode">
<title>Adding a New Datanode</title>
<indexterm zone="add-node-datanode">
<primary>Add a new Datanode</primary>
</indexterm>
<para>
Following steps should be performed to add a new datanode to a running cluster:
</para>
<para>
<orderedlist>
<listitem>
<para>
Initialize the new datanode. The following example initializes a new datanode named data_node_3.
</para>
<programlisting>
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data3 --nodename data_node_3
</programlisting>
</listitem>
<listitem>
<para>
Make the necessary changes in postgresql.conf of the new datanode, in particular specify new datanode name
</para>
</listitem>
<listitem>
<para>
Connect to any of the existing coordinators and lock the cluster for backup, do not close this session.
The following example assumes a coordinator is running on port 5432. Make sure the function call returns true.
The detailed description of the function <function>pgxc_lock_for_backup</> can be found
in <xref linkend="functions-pgxc-add-new-node">
</para>
<programlisting>
./psql postgres -p 5432
select pgxc_lock_for_backup();
</programlisting>
</listitem>
<listitem>
<para>
Connect to any of the existing datanodes and take backup of the database.
Please note that only schema (i.e. no data) is to be dumped.
The following example assumes that a datanode is running on port 15432.
</para>
<programlisting>
./pg_dumpall -p 15432 -s --file=/some/valid/path/some_file_name.sql
</programlisting>
</listitem>
<listitem>
<para>
Start the new datanode specifying <option>--restoremode</> while starting the it.
The following example starts the new datanode on port 35432.
</para>
<programlisting>
./postgres --restoremode -D ../data3 -p 35432
</programlisting>
<para>
You can use <literal>pg_ctl</literal> with <option>-Z restoremode</option> option.
</para>
<programlisting>
./pg_ctl start -Z restoremode -D ../data3 -p 5455
</programlisting>
</listitem>
<listitem>
<para>
Restore the backup (taken in step 4) by connecting to the new datanode directly.
</para>
<programlisting>
./psql -d postgres -f /some/valid/path/some_file_name.sql -p 35432
</programlisting>
</listitem>
<listitem>
<para>
Quit the new datanode.
</para>
</listitem>
<listitem>
<para>
Start the new datanode specifying --datanode while starting.
</para>
<programlisting>
./postgres --datanode -D ../data3 -p 35432
</programlisting>
</listitem>
<listitem>
<para>
Create the new datanode on all the coordinators and reload configuration.
The following example creates data_node_3, with host localhost and port 35432.
</para>
<programlisting>
CREATE NODE DATA_NODE_3 WITH (HOST = 'localhost', type = 'datanode', PORT = 35432);
SELECT pgxc_pool_reload();
</programlisting>
</listitem>
<listitem>
<para>
Create the new datanode on all the other datanodes too and reload configuration.
The following example creates data_node_3, with host localhost and port 35432.
</para>
<programlisting>
EXECUTE DIRECT ON (DATA_NODE_1) 'CREATE NODE DATA_NODE_3 WITH (HOST = ''localhost'', type = ''datanode'', PORT = 35432)';
EXECUTE DIRECT ON (DATA_NODE_2) 'CREATE NODE DATA_NODE_3 WITH (HOST = ''localhost'', type = ''datanode'', PORT = 35432)';
EXECUTE DIRECT ON (DATA_NODE_3) 'ALTER NODE DATA_NODE_3 WITH (HOST = ''localhost'', type = ''datanode'', PORT = 35432)';
EXECUTE DIRECT ON (DATA_NODE_1) 'SELECT pgxc_pool_reload()';
EXECUTE DIRECT ON (DATA_NODE_2) 'SELECT pgxc_pool_reload()';
EXECUTE DIRECT ON (DATA_NODE_3) 'SELECT pgxc_pool_reload()';
</programlisting>
</listitem>
<listitem>
<para>
Quit the session of step 3, this will unlock the cluster.
</para>
</listitem>
<listitem>
<para> The new datanode is now ready.
Redistribute existing data by using <command>ALTER TABLE
<replaceable>my_table</replaceable> ADD NODE (DATA_NODE_3)</>.
</para>
</listitem>
</orderedlist>
</para>
</sect1>
</chapter>
|