30.2. Adding a New Datanode

Following steps should be performed to add a new datanode to a running cluster:

  1. 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
            
  2. Make the necessary changes in postgresql.conf of the new datanode, in particular specify new datanode name

  3. 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 Table 9-68

              ./psql postgres -p 5432
              select pgxc_lock_for_backup();
            
  4. 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
            
  5. Start the new datanode specifying --restoremode while starting the it. The following example starts the new datanode on port 35432.

              ./postgres --restoremode -D ../data3 -p 35432
            

    You can use pg_ctl with -Z restoremode option.

    	     ./pg_ctl start -Z restoremode -D ../data3 -p 5455
    	    
  6. 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
            
  7. Quit the new datanode.

  8. Start the new datanode specifying --datanode while starting.

              ./postgres --datanode -D ../data3 -p 35432
            
  9. 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();
            
  10. Quit the session of step 3, this will unlock the cluster.

  11. Redistribute existing data by using ALTER TABLE REDISTRIBUTE. The new datanode is now ready.