docs/content/v2025.1/admin/yb-ctl.md
The yb-ctl utility provides a command line interface for administering local clusters used for development and learning. It invokes the yb-tserver and yb-master servers to perform the necessary orchestration.
yb-ctl is meant for managing local clusters only. This means that a single host machine like a local laptop is used to simulate YugabyteDB clusters even though the YugabyteDB cluster can have 3 nodes or more. For creating multi-host clusters, follow the instructions in the Deploy section.
yb-ctl can manage a cluster if and only if it was initially created via yb-ctl. This means that clusters created through any other means including those in the Deploy section cannot be administered using yb-ctl.
{{% note title="Running on macOS" %}}
Running YugabyteDB on macOS requires additional settings. For more information, refer to Running on macOS.
{{% /note %}}
yb-ctl is installed with YugabyteDB and is located in the bin directory of the YugabyteDB home directory.
Run yb-ctl commands from the YugabyteDB home directory.
./bin/yb-ctl [ command ] [ flag1, flag2, ... ]
To display the online help, run yb-ctl --help from the YugabyteDB home directory.
$ ./bin/yb-ctl --help
Creates a local YugabyteDB cluster. With no flags, creates a 1-node cluster.
For more details and examples, see Create a local cluster, Create a cluster across multiple zones, regions, and clouds, and Create a local cluster with custom flags.
Starts the existing cluster or, if not existing, creates and starts the cluster.
Stops the cluster, if running.
Destroys the current cluster.
For details and examples, see Destroy a local cluster.
Displays the current status of the cluster.
For details and examples, see Check cluster status.
Restarts the current cluster all at once.
For details and examples, see Restart a cluster and Restart with custom flags.
Stops the current cluster, wipes all data files and starts the cluster as before (losing all flags).
For details and examples, see Wipe and restart with placement info flags.
Adds a new node to the current cluster. It also takes an optional flag --master, which denotes that the server to add is a yb-master.
For details and examples, see Add nodes and Create a cluster across multiple zones, regions, and clouds.
Stops a particular node in the running cluster. It also takes an optional flag --master, which denotes that the server is a yb-master.
For details and examples, see Stop and remove nodes.
Starts a specified node in the running cluster. It also takes an optional flag --master, which denotes that the server is a yb-master.
Stops the specified node in the running cluster. It also takes an optional flag --master, which denotes that the server is a yb-master.
For details and examples, see Stop and remove nodes.
Restarts the specified node in a running cluster. It also takes an optional flag --master, which denotes that the server is a yb-master.
For details and examples, see Restart node with placement information.
Shows the help message and then exits.
Specifies the directory in which to find the YugabyteDB yb-master and yb-tserver binary files.
Default: <yugabyte-installation-dir>/bin/
Specifies the data directory for YugabyteDB.
Default: $HOME/yugabyte-data/
Changing the value of this flag after the cluster has already been created is not supported.
Specifies a list of YB-Master flags, separated by commas.
For details and examples, see Create a local cluster with custom flags.
Specifies a list of YB-TServer flags, separated by commas.
For details and examples, see Create a local cluster with custom flags.
Example
To enable YSQL authentication, you can use the --tserver_flags flag to add the yb-tserver --ysql_enable_auth flag to the yb-ctl create | start | restart commands.
$./bin/yb-ctl create --tserver_flags "ysql_enable_auth=true"
Specifies the cloud, region, and zone as cloud.region.zone, separated by commas.
Default: cloud1.datacenter1.rack1
For details and examples, see Create a cluster across multiple zones, regions, and clouds, Restart node with placement information, and Wipe and restart with placement info flags.
Specifies the number of replicas for each tablet. This parameter is also known as Replication Factor (RF). Should be an odd number so that a majority consensus can be established. A minimum value of 3 is needed to create a fault-tolerant cluster as 1 signifies that there is no only 1 replica with no fault tolerance.
This value also sets the default number of YB-Master servers.
Default: 1
Specifies whether YugabyteDB requires clock synchronization between the nodes in the cluster.
Default: false
Specifies the IP address, or port, for a 1-node cluster to listen on. To enable external access of the YugabyteDB APIs and administration ports, set the value to 0.0.0.0. Note that this flag is not applicable to multi-node clusters.
Default: 127.0.0.1
Number of shards (tablets) to start per tablet server for each table.
Default: 2
Timeout, in seconds, for operations that call yb-admin and wait on the cluster.
Timeout, in seconds, for operations that wait on the cluster.
Flag to log internal debug messages to stderr.
macOS Monterey enables AirPlay receiving by default, which listens on port 7000. This conflicts with YugabyteDB and causes yb-ctl start to fail. Use the --master_flags flag when you start the cluster to change the default port number, as follows:
./bin/yb-ctl start --master_flags "webserver_port=7001"
Alternatively, you can disable AirPlay receiving, then start YugabyteDB normally, and then, optionally, re-enable AirPlay receiving.
On macOS, every additional node after the first needs a loopback address configured to simulate the use of multiple hosts or nodes. For example, for a three-node cluster, you add two additional addresses as follows:
sudo ifconfig lo0 alias 127.0.0.2
sudo ifconfig lo0 alias 127.0.0.3
The loopback addresses do not persist upon rebooting your computer.
To create a local YugabyteDB cluster for development and learning, use the yb-ctl create command.
To ensure that all of the replicas for a given tablet can be placed on different nodes, the number of nodes created with the initial create command is always equal to the replication factor. To expand or shrink the cluster, use the add_node and remove_node commands.
Each of these initial nodes run a yb-tserver server and a yb-master server. Note that the number of YB-Master servers in a cluster must equal the replication factor for the cluster to be considered operating normally.
If you are running YugabyteDB on your local computer, you can't run more than one cluster at a time. To set up a new local YugabyteDB cluster using yb-ctl, first destroy the currently running cluster.
$ ./bin/yb-ctl create
Note that the default replication factor is 1.
First create a 3-node cluster with replication factor of 3.
$ ./bin/yb-ctl --rf 3 create
Use yb-ctl add_node command to add a node and make it a 4-node cluster.
$ ./bin/yb-ctl add_node
$ ./bin/yb-ctl --rf 5 create
The following command stops all the nodes and deletes the data directory of the cluster.
$ ./bin/yb-ctl destroy
There are essentially two modes with yb-ctl:
1-node RF1 cluster where the bind IP address for all ports can be bound to 0.0.0.0 using the listen_ip flag. This is the mode you use if you want to have external access for the database APIs and admin UIs.
$ ./bin/yb-ctl create --listen_ip=0.0.0.0
Multi-node (say 3-node RF3) cluster where the bind IP addresses are the loopback IP addresses since binding to 0.0.0.0 is no longer possible. Hence, this mode is only meant for internal access.
To get the status of your local cluster, including the Admin UI URLs for the YB-Master and YB-TServer, run the yb-ctl status command.
$ ./bin/yb-ctl status
Following is the output shown for a 3-node RF3 cluster.
----------------------------------------------------------------------------------------------------
| Node Count: 3 | Replication Factor: 3 |
----------------------------------------------------------------------------------------------------
| JDBC : jdbc:postgresql://127.0.0.1:5433/yugabyte |
| YSQL Shell : bin/ysqlsh |
| YCQL Shell : bin/ycqlsh |
| Web UI : http://127.0.0.1:7000/ |
| Cluster Data : /Users/testuser12/yugabyte-data |
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
| Node 1: yb-tserver (pid 27389), yb-master (pid 27380) |
----------------------------------------------------------------------------------------------------
| JDBC : jdbc:postgresql://127.0.0.1:5433/yugabyte |
| YSQL Shell : bin/ysqlsh |
| YCQL Shell : bin/ycqlsh |
| data-dir[0] : /Users/testuser12/yugabyte-data/node-1/disk-1/yb-data |
| yb-tserver Logs : /Users/testuser12/yugabyte-data/node-1/disk-1/yb-data/tserver/logs |
| yb-master Logs : /Users/testuser12/yugabyte-data/node-1/disk-1/yb-data/master/logs |
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
| Node 2: yb-tserver (pid 27392), yb-master (pid 27383) |
----------------------------------------------------------------------------------------------------
| JDBC : jdbc:postgresql://127.0.0.2:5433/yugabyte |
| YSQL Shell : bin/ysqlsh -h 127.0.0.2 |
| YCQL Shell : bin/ycqlsh 127.0.0.2 |
| data-dir[0] : /Users/testuser12/yugabyte-data/node-2/disk-1/yb-data |
| yb-tserver Logs : /Users/testuser12/yugabyte-data/node-2/disk-1/yb-data/tserver/logs |
| yb-master Logs : /Users/testuser12/yugabyte-data/node-2/disk-1/yb-data/master/logs |
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
| Node 3: yb-tserver (pid 27395), yb-master (pid 27386) |
----------------------------------------------------------------------------------------------------
| JDBC : jdbc:postgresql://127.0.0.3:5433/yugabyte |
| YSQL Shell : bin/ysqlsh -h 127.0.0.3 |
| YCQL Shell : bin/ycqlsh 127.0.0.3 |
| data-dir[0] : /Users/testuser12/yugabyte-data/node-3/disk-1/yb-data |
| yb-tserver Logs : /Users/testuser12/yugabyte-data/node-3/disk-1/yb-data/tserver/logs |
| yb-master Logs : /Users/testuser12/yugabyte-data/node-3/disk-1/yb-data/master/logs |
----------------------------------------------------------------------------------------------------
Start the existing cluster, or create and start a cluster (if one doesn't exist) by running the yb-ctl start command.
$ ./bin/yb-ctl start
Stop a cluster so that you can start it later by running the yb-ctl stop command.
$ ./bin/yb-ctl stop
This will start a new YB-TServer server and give it a new node_id for tracking purposes.
$ ./bin/yb-ctl add_node
We can stop a node by executing the yb-ctl stop command. The command takes the node_id of the node that has to be removed as input. Stop node command expects a node id which denotes the index of the server that needs to be stopped. It also takes an optional flag --master, which denotes that the server is a yb-master.
$ ./bin/yb-ctl stop_node 3
We can also pass an optional flag --master, which denotes that the server is a yb-master.
$ ./bin/yb-ctl stop_node 3 --master
Currently stop_node and remove_node implement exactly the same behavior. So they can be used interchangeably.
You can test the failure of a node in a 3-node RF3 cluster by killing 1 instance of yb-tserver and 1 instance of yb-master by using the following commands.
./bin/yb-ctl destroy
./bin/yb-ctl --rf 3 create
./bin/yb-ctl stop_node 3
./bin/yb-ctl stop_node 3 --master
./bin/yb-ctl start_node 3
./bin/yb-ctl start_node 3 --master
The command ./bin/yb-ctl start_node 3 starts the third YB-TServer. This displays an error, though the command succeeds. This is because only 2 YB-Masters are present in the cluster at this point. This is not an error in the cluster configuration but rather a warning to highlight that the cluster is under-replicated and does not have enough YB-Masters to ensure continued fault tolerance. See issue 3506.
YugabyteDB clusters created using the yb-ctl utility are created locally on the same host and simulate a distributed multi-host cluster.
YugabyteDB cluster data is installed in $HOME/yugabyte-data/, containing the following:
cluster_config.json
initdb.log
node-#/
node-#/disk-#/
For each simulated YugabyteDB node, a yugabyte-data subdirectory, named node-# (where # is the number of the node), is created.
Example: /yugabyte-data/node-#/
Each node-# directory contains the following:
yugabyte-data/node-#/disk-#/
For each simulated disk, a disk-# subdirectory is created in each /yugabyte-data/node-# directory.
Each disk-# directory contains the following:
master.err
master.out
pg_data/
tserver.err
tserver.out
yb-data/
YB-Master logs are added in the following location:
yugabyte-data/node-#/disk-#/master.out
yugabyte-data/node-#/disk-#/yb-data/master/logs
YB-TServer logs are added in the following location:
yugabyte-data/node-#/disk-#/tserver.out
yugabyte-data/node-#/disk-#/yb-data/tserver/logs
You can pass the placement information for nodes in a cluster from the command line. The placement information is provided as a set of (cloud, region, zone) tuples separated by commas. Each cloud, region and zone entry is separated by dots.
$ ./bin/yb-ctl --rf 3 create --placement_info "cloud1.region1.zone1,cloud2.region2.zone2"
The total number of placement information entries cannot be more than the replication factor (this is because you would not be able to satisfy the data placement constraints for this replication factor). If the total number of placement information entries is lesser than the replication factor, the placement information is passed down to the node in a round robin approach.
To add a node:
$ ./bin/yb-ctl add_node --placement_info "cloud1.region1.zone1"
When you use yb-ctl, you can pass "custom" flags (flags unavailable directly in yb-ctl) to the YB-Master and YB-TServer servers.
$ ./bin/yb-ctl --rf 1 create --master_flags "log_cache_size_limit_mb=128,log_min_seconds_to_retain=20,master_backup_svc_queue_length=70" --tserver_flags "log_inject_latency=false,log_segment_size_mb=128,raft_heartbeat_interval_ms=1000"
To add a node with custom YB-TServer flags:
$ ./bin/yb-ctl add_node --tserver_flags "log_inject_latency=false,log_segment_size_mb=128"
To add a node with custom YB-Master flags:
$ ./bin/yb-ctl add_node --master_flags "log_cache_size_limit_mb=128,log_min_seconds_to_retain=20"
To handle flags whose value contains commas or equals, quote the whole key-value pair with double-quotes:
$ ./bin/yb-ctl create --tserver_flags 'ysql_enable_auth=false,"vmodule=tablet_service=1,pg_doc_op=1",ysql_prefetch_limit=1000'
The yb-ctl restart command can be used to restart a cluster. Please note that if you restart the cluster, all custom defined flags and placement information will be lost. Nevertheless, you can pass the placement information and custom flags in the same way as they are passed in the yb-ctl create command.
$ ./bin/yb-ctl restart
$ ./bin/yb-ctl restart --placement_info "cloud1.region1.zone1"
$ ./bin/yb-ctl restart --master_flags "log_cache_size_limit_mb=128,log_min_seconds_to_retain=20,master_backup_svc_queue_length=70" --tserver_flags "log_inject_latency=false,log_segment_size_mb=128,raft_heartbeat_interval_ms=1000"
The yb-ctl restart first stops the node and then starts it again. At this point of time, the node is not decommissioned from the cluster. Thus one of the primary advantages of this command is that it can be used to clear old flags and pass in new ones. Just like create, you can pass the cloud/region/zone and custom flags in the yb-ctl restart command.
$ ./bin/yb-ctl restart_node 2
$ ./bin/yb-ctl restart_node 2 --master
$ ./bin/yb-ctl restart_node 2 --placement_info "cloud1.region1.zone1"
$ ./bin/yb-ctl restart_node 2 --master --master_flags "log_cache_size_limit_mb=128,log_min_seconds_to_retain=20"
The yb-ctl wipe_restart command stops all the nodes, removes the underlying data directories, and then restarts with the same number of nodes that you had in your previous configuration.
Just like the yb-ctl restart command, the custom-defined flags and placement information will be lost during wipe_restart, though you can pass placement information and custom flags in the same way as they are passed in the yb-ctl create command.
$ ./bin/yb-ctl wipe_restart
$ ./bin/yb-ctl wipe_restart --placement_info "cloud1.region1.zone1"
$ ./bin/yb-ctl wipe_restart --master_flags "log_cache_size_limit_mb=128,log_min_seconds_to_retain=20,master_backup_svc_queue_length=70" --tserver_flags "log_inject_latency=false,log_segment_size_mb=128,raft_heartbeat_interval_ms=1000"