• cryptoginger29

How to setup cardano-db-sync?


I wanted to pull some data from the cardano blockchain, and after some extensive research I wasn't being able to find any places that had a open API to call I decided to put a cardano-db-sync up myself, so that I could start to get the data I wanted.

After trying to follow the official guides, and falling into the different traps and not being able to find any guides that helped, I decided I would make the guide that I needed. So following the steps laid out below, you should be able to set up your cardano-db-sync on one of your nodes.

My plan for the future is to set up the API service that I was looking for to enable Non-cardano people to analyze the block chain and hopefully provide more transparency to the network for the uninitiated.


Installing PostgreSQL dependencies

Since the database we are setting up is a PostgreSQL database we need to install the dependencies for PostgreSQL on the node

sudo apt update
sudo apt install postgresql postgresql-contrib

After installing the PostgreSQL dependencies we need to added the current user as a superuser in PostgreSQL, this is used when setting up the cardano-db-sync later:

sudo -u postgres createuser -s -i -d -r -l -w whoami

You can choose to add a password to your user, it isn't required, but always a good practice.

Installing nix build

The build of the the cardano-db-sync is done using the nix library, so following the official guide, run the following:

curl -L >
chmod +x

Setting up IOHK binary cache

This is a REALLY good idea to do, since it will save you hours of waiting, but not a requirement. I tried it without the cache setup and after running for 6 hours it still didn't work, but after setting up the cache it worked.

sudo mkdir -p /etc/nix
cat <<EOF | sudo tee /etc/nix/nix.conf
substituters =
trusted-public-keys =

Setting up the db-sync node

Following the official guide once again we go to home-dir and run the following command

cd ${HOME}
git clone
cd cardano-db-sync
nix-build -A cardano-db-sync -o db-sync-node

Change the rights to the password file, other with the creation of the database will create a warning:

sudo chmod 700 ./config/pgpass-mainnet

We then create the database

PGPASSFILE=config/pgpass-mainnet scripts/ --createdb

This should yield a "ALL GOOD!" message.

Change the node config path in the config file to point to the cardano nodes config file. If you've followed the CoinCashew guide you should be able to get the path using the following command

echo ${NODE_HOME}/main-config.json

Expected output:


We then need to added the config path to the cardano node config file in the config file for the db-sync node:

cd config/
nano mainnet-config.yaml

And lastly we sync it, with some customization to the official script:

PGPASSFILE=config/pgpass-mainnet db-sync-node/bin/cardano-db-sync \
    --config config/mainnet-config.yaml \
    --socket-path ${NODE_HOME}/db/socket \
    --state-dir ledger-state/mainnet \
    --schema-dir schema/

And boom!

You should now see your cardano-db-sync node synchronizing with the cardano-my-node.


Coin cashew installation guide:

Official guide:

Stackoverflow credits:

288 views0 comments

Recent Posts

See All