{question}
How to change the default data directory path using SingleStore Tools?
{question}
{answer}
Changing the default data directory is performed for many reasons. One of the main reasons is moving it to a bigger File System directory or restructuring the directories as part of a clean-up process.
Here’s an example SingleStore DB cluster configuration. We have used SigleStore 7.3.4 for the below example; the same procedure applies to any version of SingleStore using Toolbox. We have two Nodes below an MA and a Leaf. Now we are going to change the default data directory for the Leaf node. In HA Setup, we can perform the activity by just stopping one leaf node at a time, But in Non-HA setup Its recommended to stop all the nodes from performing the below operations. This is an example of changing the data directory for one leaf node. The same procedure needed to be repeated for each node as required.
The below command is used to list the nodes,
sdb-admin list-nodes
The default SingleStore data directory is: /var/lib/<memsql_folder>/
Let us check the current default data directory on the demo cluster with the following command:
sdb-admin describe-node --memsql-id <MemSQL ID>
$ sdb-admin describe-node --memsql-id 03B971A485
+--------------------+---------------------------------------------------------------------------------+
| memsqlId | 03B971A485195AF2372E728D71025EE6E7192B6A |
| host | 10.0.3.97 |
| role | Leaf |
| port | 3307 |
| bindAddress | 0.0.0.0 |
| processState | Running |
| version | 7.3.4 |
| memsqlConfig | /ebs/memsql/leaf-3307-MIb95ecc7a/memsql.cnf |
| datadir | /ebs/memsql/leaf-3307-MIb95ecc7a/data |
| plancachedir | /ebs/memsql/leaf-3307-MIb95ecc7a/plancache |
| tracelogsdir | /ebs/memsql/leaf-3307-MIb95ecc7a/tracelogs |
| auditlogsdir | /ebs/memsql/leaf-3307-MIb95ecc7a/auditlogs |
| memsqld | /ebs/memsql/leaf-3307-MIb95ecc7a/memsqld |
| nodeID | 3 |
| pid | -- |
| dpid | 5181 |
| autoRestartEnabled | -- |
| isConnectable | true |
| recoveryState | Online |
| availabilityGroup | 1 |
| config | Omitted from table view. Use 'sdb-admin describe-node ... --property config' |
| variables | Omitted from table view. Use 'sdb-admin describe-node ... --property variables' |
+--------------------+---------------------------------------------------------------------------------+
In this example We are planning to change the data directory from /ebs/memsql/leaf-3307-MIb95ecc7a/data to /ebs/leaf_data
Note: Update the new data directory permission and owner similar to the current data folder. Default memsql user should be able to access the new directory.
Let's get into the steps needed to be followed to change the default data directory:
1. On the master aggregator, list nodes. Note down memsql ID and IP for nodes we intended to change data directory.
sdb-admin list-nodes
we can stop the target node for data directory change in case if it's a HA Environment,
sdb-admin stop-node --memsql-id <MEMSQL_ID>
If it's not an HA Setup Its recommended to stop all the nodes using the below command and then perform the data directory change on each node,
sdb-admin stop-node --all
Example: Read the command line instruction and choose the options as required,
$ sdb-admin stop-node --memsql-id 03B971A485
Continue to stop the node(s) without taking a database snapshot?
Select 'Y' to stop the node(s) without taking a database snapshot.
Select 'N' to take a snapshot of all databases and then stop the node(s).
Taking a database snapshot will reduce the time it takes for the node(s) to recover after being restarted, but may increase the time it takes for the node(s) to stop. [Y/n]: n
Toolbox is about to perform the following actions on host 10.0.3.97:
· Run 'memsqlctl stop-node --memsql-id 03B971A485'
Would you like to continue? [y/N]: y
✓ Snapshots completed
✓ Stopped node on 10.0.3.97
Operation completed successfully
2. Login into the specific node which we stopped earlier, copy the data directory to the new path,
sudo cp -R -p <source_data_directory> <new_data_directory_path>
$ sudo cp -R -p /ebs/memsql/leaf-3307-MIb95ecc7a/data /ebs/leaf_data/
3. Now update the new data directory config value from MA,
sdb-admin update-config --key datadir --value <Path to data> --memsql-id <Node Memsql ID>
$ sdb-admin update-config --key datadir --value /ebs/leaf_data/data --memsql-id 03B971A485
Toolbox is about to run 'memsqlctl update-config --key datadir --value /ebs/leaf_data/data' on the following nodes:
- On host 10.0.3.97:
+ 03B971A485
Would you like to continue? [y/N]: y
✓ Updated configuration on 10.0.3.97
Operation completed successfully
4. Validate the above change by describing the node,
sdb-admin describe-node --memsql-id <Node Memsql ID>
master-agg-and-leaf-ip-10-0-3-97 /home/admin $ sdb-admin describe-node --memsql-id 03B971A485
+--------------------+------------------------------------------------------------------------------+
| memsqlId | 03B971A485195AF2372E728D71025EE6E7192B6A |
| host | 10.0.3.97 |
| role | Leaf |
| port | 3307 |
| bindAddress | 0.0.0.0 |
| processState | Stopped |
| version | 7.3.4 |
| memsqlConfig | /ebs/memsql/leaf-3307-MIb95ecc7a/memsql.cnf |
| datadir | /ebs/leaf_data/data |
| plancachedir | /ebs/memsql/leaf-3307-MIb95ecc7a/plancache |
| tracelogsdir | /ebs/memsql/leaf-3307-MIb95ecc7a/tracelogs |
| auditlogsdir | /ebs/memsql/leaf-3307-MIb95ecc7a/auditlogs |
| memsqld | /opt/memsql-server-7.3.4-d596a2867a/memsqld |
| nodeID | -- |
| pid | -- |
| dpid | -- |
| autoRestartEnabled | -- |
| isConnectable | -- |
| recoveryState | -- |
| availabilityGroup | -- |
| config | Omitted from table view. Use 'sdb-admin describe-node ... --property config' |
| variables | -- |
+--------------------+------------------------------------------------------------------------------+
5. Now start the leaf node,
sdb-admin start-node --memsql-id <MEMSQL_ID>
$ sdb-admin start-node --memsql-id 03B971A485
Toolbox is about to perform the following actions on host 10.0.3.97:
· Run 'memsqlctl start-node --memsql-id 03B971A485'
Would you like to continue? [y/N]: y
✓ Started nodes on 10.0.3.97 (1/1)
✓ Successfully started nodes on 1 host
✓ Successfully connected to node
Operation completed successfully
If it is a Non-HA Setup, Start all nodes
sdb-admin start-node --all
6. Verify the status of the node by listing the nodes,
sdb-admin list-nodes
master-agg-and-leaf-ip-10-0-3-97 /home/admin $ sdb-admin list-nodes
+------------+--------+-----------+------+---------------+--------------+---------+----------------+--------------------+--------------+
| MemSQL ID | Role | Host | Port | Process State | Connectable? | Version | Recovery State | Availability Group | Bind Address |
+------------+--------+-----------+------+---------------+--------------+---------+----------------+--------------------+--------------+
| 31038D93AB | Master | 10.0.3.97 | 3306 | Running | True | 7.3.4 | Online | | 0.0.0.0 |
| 03B971A485 | Leaf | 10.0.3.97 | 3307 | Running | True | 7.3.4 | Online | 1 | 0.0.0.0 |
+------------+--------+-----------+------+---------------+--------------+---------+----------------+--------------------+--------------+
Follow the above steps for each node.
{answer}