Adding a New Node Add a new node 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. Adding a New Coordinator Add a new coordinator The following steps should be performed to add a new coordinator to a running cluster: Initialize the new coordinator. The following example initilizes a coordinator named coord_3. /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data_cord3 --nodename coord_3 Make necessary changes in postgresql.conf of the new coordinator, in particular specify new coordinator name and pooler port. 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 pgxc_lock_for_backup can be found in ./psql postgres -p 5432 select pgxc_lock_for_backup(); 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 ./pg_dumpall -p 5432 -s --include-nodes --dump-nodes --file=/some/valid/path/some_file_name.sql Start the new coordinator specifying ./postgres --restoremode -D ../data_cord3 -p 5455 You can use pg_ctl with option. ./pg_ctl start -Z restoremode -D ../data_coord3 -p 5455 Restore the backup (taken in step 4) by connecting to the new coordinator directly. ./psql -d postgres -f /some/valid/path/some_file_name.sql -p 5455 Quit the new coordinator. Start the new coordinator specifying ./postgres --coordinator -D ../data_cord3 -p 5455 Create the new coordinator on rest of the coordinators and reload configuration. The following example creates coord_3, with host localhost and port 5455. CREATE NODE COORD_3 WITH (HOST = 'localhost', type = 'coordinator', PORT = 5455); SELECT pgxc_pool_reload(); Quit the session of step 3, this will unlock the cluster. The new coordinator is now ready. Adding a New Datanode Add a new Datanode Following steps should be performed to add a new datanode to a running cluster: Initialize the new datanode. The following example initializes a new datanode named data_node_3. /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data3 --nodename data_node_3 Make the necessary changes in postgresql.conf of the new datanode, in particular specify new datanode name 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 pgxc_lock_for_backup can be found in ./psql postgres -p 5432 select pgxc_lock_for_backup(); 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. ./pg_dumpall -p 15432 -s --file=/some/valid/path/some_file_name.sql Start the new datanode specifying ./postgres --restoremode -D ../data3 -p 35432 You can use pg_ctl with option. ./pg_ctl start -Z restoremode -D ../data3 -p 5455 Restore the backup (taken in step 4) by connecting to the new datanode directly. ./psql -d postgres -f /some/valid/path/some_file_name.sql -p 35432 Quit the new datanode. Start the new datanode specifying --datanode while starting. ./postgres --datanode -D ../data3 -p 35432 Create the new datanode on all the coordinators and reload configuration. The following example creates data_node_3, with host localhost and port 35432. CREATE NODE DATA_NODE_3 WITH (HOST = 'localhost', type = 'datanode', PORT = 35432); SELECT pgxc_pool_reload(); 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. 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()'; Quit the session of step 3, this will unlock the cluster. The new datanode is now ready. Redistribute existing data by using ALTER TABLE my_table ADD NODE (DATA_NODE_3).