To start an instance of cardano-db-sync we are going to use Docker as manager and deployment of this instance. Before continuing make sure you have Docker installed.
First we uninstall possible old versions of Docker:
If we look at the configuration we see that Docker is going to use the postgres_db, postgres_password and postgres_user credentials. It will look for them in the /home/cardano/cardano-db-sync/config/secrets folder. The default repository brings these files under the suffix * _example, we just have to replace or duplicate the examples.
Before running Docker we need to add our user to the docker group:
sudo usermod -aG docker $USER
Start the instance with the log messages activated:
docker-compose up -d && docker-compose logs -f
With this we have started a cardano-node services, the postgresql database, and the cardano-db-sync tool. We can access these services through the default port: 5432.
A more optimal execution
We are going to use tmux to run docker in the background and show the machine status live.
Create the script that starts the service in the background:
cd /home/cardano/cardano-db-sync
vim start.sh
#!/bin/bash
session="cardano-db-sync"
# Check if the session exists, discarding output
# We can check $? for the exit status (zero for success, non-zero for failure)
tmux has-session -t $session 2>/dev/null
if [ $? != 0 ]; then
tmux attach-session -t $session
tmux new -s "cardano-db-sync" -n "node" -d
tmux split-window -v
tmux select-pane -t 'cardano-db-sync:node.0'
tmux split-window -h
tmux send-keys -t 'cardano-db-sync:node.0' './init-cardano-db.sh' Enter
tmux send-keys -t 'cardano-db-sync:node.1' 'htop' Enter
tmux send-keys -t 'cardano-db-sync.2' 'nload' Enter
fi
tmux attach-session -t $session
Create the script that executes docker:
cd /home/cardano/cardano-db-sync
vim init-cardano-db.sh
#!/bin/bash
docker-compose up -d && docker-compose logs -f
Create the script that ends the service associated with the "cardano-db-sync" session.
cardano-db-sync
vim stop.sh
#!/bin/bash
# Check if the session exists, discarding output
# We can check $? for the exit status (zero for success, non-zero for failure)
session="cardano-db-sync"
# Check if the session exists, discarding output
# We can check $? for the exit status (zero for success, non-zero for failure)
tmux has-session -t $session 2>/dev/null
if [ $? != 0 ]; then
echo "Session not found."
else
echo "Killing session"
tmux kill-session -t cardano-db-sync
fi
Add execution permissions to the scripts:
chmod +x start.sh stop.sh init-cardano-db.sh
Finally, start the service:
./start.sh
Once started we can launch queries to the address localhost: 5432.
List all the containers:
docker container ls -a
Delete a specific container by its ID:
docker container rm 661525b875a1
Terminate all instances:
docker-compose down -v
Relaunch the instances:
docker-compose up --remove-orphans --force-recreate