DEV Community

Franck Pachot for YugabyteDB Distributed PostgreSQL Database

Posted on • Edited on

Fastest start of YugabyteDB for a small lab

For starting a YugabyteDB lab, the best is running yugabyted. However, it takes some time (few seconds) to check the OS prerequisites. If you want a faster start, you can run directly one yb-master and yb-tserver with --replication_factor=1 (no need for HA in a lab) and the mandatory --fs_data_dirs for the location of logs and data.

The following goes to /var/tmp (it must be clear at this point that this is not for production), downloads the latest preview version, if not already there, and starts YugabyteDB yb-master and yb-server with all defaults.

# needs the following to download the latest version
sudo yum install -y curl jq
# go to working directory
cd /var/tmp

# get the latest preview version (from the docker hub... why not?)
tag=$( curl -Ls "https://registry.hub.docker.com/v2/repositories/yugabytedb/yugabyte/tags?page_size=999" |
 jq -r '."results"[]["name"]' | sort -V | tee /dev/stderr |
 awk -F. '!/latest/ && ($2/2)==preview/2+int($2/2){tag=$0}END{print tag}' \
 preview=1 ) # set preview=0 for stable release

# download and install
[ -f yugabyte-${tag%%-*}/version_metadata.json ] ||
curl -s https://downloads.yugabyte.com/releases/${tag%%-*}/yugabyte-${tag}-linux-x86_64.tar.gz | tar zxvf -
yugabyte-${tag%%-*}/bin/post_install.sh

# kill previous execution if any
pkill yb-tserver ; pkill yb-master ; rm -rf /var/tmp/{yb-,pg_}data

##################################
# Here is the start of YugabyteDB
##################################

# start master
yugabyte-${tag%%-*}/bin/yb-master --fs_data_dirs=/var/tmp   \
 --master_addresses=$(hostname):7100 --replication_factor=1 \
 --default_memory_limit_to_ram_ratio=0.30 &
# start tserver
yugabyte-${tag%%-*}/bin/yb-tserver --fs_data_dirs=/var/tmp \
 --tserver_master_addrs=$(hostname):7100 \
 --default_memory_limit_to_ram_ratio=0.30 &
# show the logs in case it fails
timeout 10 tail -F /var/tmp/yb-data/*/logs/yb-*.INFO &
# wait until available
until yugabyte-${tag%%-*}/bin/ysqlsh -v ON_ERROR_STOP=on -c "
-- you can run any initialization here
select * from yb_servers()
" ; do sleep 0.1
done

Enter fullscreen mode Exit fullscreen mode

This should start in one or two seconds maximum, exposes the UI on http://$(hostname):7000 and PostgreSQL endpoint on postgres://$(hostname):5433/yugabyte. As I run the yb-master and yb-tserver on the same (small) VM, I have limited their memory allocation by adding --default_memory_limit_to_ram_ratio=0.30, which also leaves some memory for the system (including the filesystem cache). A fixed value can also be set with memory_limit_hard_bytes.

Top comments (0)