Working with Cardano DB Sync
The purpose of this document is to explain how Cardano users can retrieve blockchain data from the database. Here, we look into the ways of working with the PostgreSQL database and explore its various queries.
How to retrieve data from the DB Sync PostgreSQL database
- PostgreSQL library. This can be installed on Linux using e.g.
apt install libpq-dev.
- PostgreSQL server. This can be installed on Linux using e.g.
apt install postgresql.
- Сardano-node package. This provides the core Cardano node functionality and runs as a passive node.
- Сardano-db-sync package. This acts as a library for database support and connects to the Cardano node.
Alternatively, you can run these components using Docker: the
repository contains a
file, which lets you start the node, Postgres, and db-sync with a single
How to set up and access the database
- You will first need to install PostgreSQL.
- Create the database and manage schemas.
- Build and run the cardano-node and cardano-db-sync.
Useful PostgreSQL tutorials:
How to get data from the tables
On-chain data is stored in tables the mapping of which is structured (normalized) in a way that avoids data duplication. However, this also means that to extract certain data (like transaction information, for example), you will need to join multiple tables in a query.
To show all tables, run this command:
To show details about a specific table:
Use the queries from the section below to get the blockchain data you are looking for.
Using DB management tools
Another convenient way to explore database tables is to use a DB management tool like https://www.pgadmin.org/.
This tool allows browsing the tables and their definitions (like foreign key dependencies) or developing and executing complex queries.
Follow the getting started instructions to set everything up. Now you can use the queries listed below to get the blockchain data you are looking for.