A component that follows the Cardano chain and stores blocks and transactions in PostgreSQL
Haskell
318
3,127 commits
updated Sep 17, 2026
Note: Anyone wishing to build and run anything in this repository should avoid the master branch and build/run from the latest release tag.
The purpose of Cardano DB Sync is to follow the Cardano chain and take information from the chain and an internally maintained copy of ledger state. Data is then extracted from the chain and inserted into a PostgreSQL database. SQL queries can then be written directly against the database schema or as queries embedded in any language with libraries for interacting with an SQL database.
Examples of what someone would be able to do via an SQL query against a Cardano DB Sync instance fully synced to a specific network is:
The doc/ directory, offers essential resources for users, including guides for installation with and without Nix, configuration. Key files cover, Docker usage, PostgreSQL example queries, command-line options and database migrations. There's also a troubleshooting guide for common issues. These documents provide users with the necessary steps to effectively set up and maintain the Cardano DB Sync.
The cardano-db-sync component consists of a set of components:
cardano-db which defines common data types and functions used by any application that needs
to interact with the data base from Haskell. In particular, it defines the database schema.cardano-db-tool a tool used to manage the databases of cardano-db-sync (create
and run migrations, validate and analyse)cardano-db-sync which acts as a Cardano node, following the chain and inserting
data from the chain into a PostgreSQL database.The db-sync node is written in a highly modular fashion to allow it to be as flexible as possible.
The cardano-db-sync node connects to a locally running cardano-node (ie one connected to other
nodes in the Cardano network over the internet with TCP/IP) using a Unix domain socket, retrieves
blocks, updates its internal ledger state and stores parts of each block in a local PostgreSQL
database. The database does not store things like cryptographic signatures but does store enough
information to follow the chain of blocks and look at the transactions within blocks.
The PostgreSQL database is designed to be accessed in a read-only fashion from other applications. The database schema is highly normalised which helps prevent data inconsistencies (specifically with the use of foreign keys from one table to another). More user friendly database queries can be implemented using Postgres Views to implement joins between tables.
The system requirements for cardano-db-sync (with both db-sync and the node running
on the same machine are:
mainnet).Stats for configuration:
"insert_options": {
"tx_cbor": "disable",
"tx_out": {
"value": "enable",
"force_tx_in": false,
"use_address_table": false
},
"ledger": "enable",
"shelley": {
"enable": true
},
"multi_asset": {
"enable": true
},
"metadata": {
"enable": true
},
"plutus": {
"enable": true
},
"governance": "enable",
"offchain_pool_data": "enable",
"json_type": "text"
}
mainnetcardano-node database size: 203 GBcardano-db-sync total ledger state files size: ~ 10 GBPostgres database mainnet_13.6.0.5 total size: 438 GBcardano-node RAM: 24 GBcardano-db-sync RSS RAM: 21 GBpreprodcardano-node database size: 12 GBcardano-db-sync total ledger state files size: ~ 2 GBPostgres database preprod_13.6.0.5 total size: 16 GBcardano-node RSS RAM: 5,5 GBcardano-db-sync RSS RAM: 3,5 GBpreviewcardano-node database size: 12 GBcardano-db-sync total ledger state files size: ~ 2 GBPostgres database preview_13.6.0.5 total size: 21 GBcardano-node RSS RAM: 2,8 GBcardano-db-sync RSS RAM: 3,5 GBThe recommended configuration is to have the db-sync and the PostgreSQL server on the same
machine. During syncing (getting historical data from the blockchain) there is a HUGE amount
of data traffic between db-sync and the database. Traffic to a local database is significantly
faster than traffic to a database on the LAN or remotely to another location.
When building an application that will be querying the database, remember that for fast queries, low latency disk access is far more important than high throughput (assuming the minimal IOPS above is met).
You can discuss development or find help at the following places:
Install db-sync with one of the following methods:
Once installed, start db-sync by following the Running Guide.
If you have any issues with this project, consult the Troubleshooting page for possible solutions.
(top 30 of 70)
Haskell
89.9%
PLpgSQL
6.2%
Nix
2.5%
Shell
1.5%
A component that follows the Cardano chain and stores blocks and transactions in PostgreSQL
Haskell
318
3,127 commits
updated Sep 17, 2026
Note: Anyone wishing to build and run anything in this repository should avoid the master branch and build/run from the latest release tag.
The purpose of Cardano DB Sync is to follow the Cardano chain and take information from the chain and an internally maintained copy of ledger state. Data is then extracted from the chain and inserted into a PostgreSQL database. SQL queries can then be written directly against the database schema or as queries embedded in any language with libraries for interacting with an SQL database.
Examples of what someone would be able to do via an SQL query against a Cardano DB Sync instance fully synced to a specific network is:
The doc/ directory, offers essential resources for users, including guides for installation with and without Nix, configuration. Key files cover, Docker usage, PostgreSQL example queries, command-line options and database migrations. There's also a troubleshooting guide for common issues. These documents provide users with the necessary steps to effectively set up and maintain the Cardano DB Sync.
The cardano-db-sync component consists of a set of components:
cardano-db which defines common data types and functions used by any application that needs
to interact with the data base from Haskell. In particular, it defines the database schema.cardano-db-tool a tool used to manage the databases of cardano-db-sync (create
and run migrations, validate and analyse)cardano-db-sync which acts as a Cardano node, following the chain and inserting
data from the chain into a PostgreSQL database.The db-sync node is written in a highly modular fashion to allow it to be as flexible as possible.
The cardano-db-sync node connects to a locally running cardano-node (ie one connected to other
nodes in the Cardano network over the internet with TCP/IP) using a Unix domain socket, retrieves
blocks, updates its internal ledger state and stores parts of each block in a local PostgreSQL
database. The database does not store things like cryptographic signatures but does store enough
information to follow the chain of blocks and look at the transactions within blocks.
The PostgreSQL database is designed to be accessed in a read-only fashion from other applications. The database schema is highly normalised which helps prevent data inconsistencies (specifically with the use of foreign keys from one table to another). More user friendly database queries can be implemented using Postgres Views to implement joins between tables.
The system requirements for cardano-db-sync (with both db-sync and the node running
on the same machine are:
mainnet).Stats for configuration:
"insert_options": {
"tx_cbor": "disable",
"tx_out": {
"value": "enable",
"force_tx_in": false,
"use_address_table": false
},
"ledger": "enable",
"shelley": {
"enable": true
},
"multi_asset": {
"enable": true
},
"metadata": {
"enable": true
},
"plutus": {
"enable": true
},
"governance": "enable",
"offchain_pool_data": "enable",
"json_type": "text"
}
mainnetcardano-node database size: 203 GBcardano-db-sync total ledger state files size: ~ 10 GBPostgres database mainnet_13.6.0.5 total size: 438 GBcardano-node RAM: 24 GBcardano-db-sync RSS RAM: 21 GBpreprodcardano-node database size: 12 GBcardano-db-sync total ledger state files size: ~ 2 GBPostgres database preprod_13.6.0.5 total size: 16 GBcardano-node RSS RAM: 5,5 GBcardano-db-sync RSS RAM: 3,5 GBpreviewcardano-node database size: 12 GBcardano-db-sync total ledger state files size: ~ 2 GBPostgres database preview_13.6.0.5 total size: 21 GBcardano-node RSS RAM: 2,8 GBcardano-db-sync RSS RAM: 3,5 GBThe recommended configuration is to have the db-sync and the PostgreSQL server on the same
machine. During syncing (getting historical data from the blockchain) there is a HUGE amount
of data traffic between db-sync and the database. Traffic to a local database is significantly
faster than traffic to a database on the LAN or remotely to another location.
When building an application that will be querying the database, remember that for fast queries, low latency disk access is far more important than high throughput (assuming the minimal IOPS above is met).
You can discuss development or find help at the following places:
Install db-sync with one of the following methods:
Once installed, start db-sync by following the Running Guide.
If you have any issues with this project, consult the Troubleshooting page for possible solutions.
(top 30 of 70)
Haskell
89.9%
PLpgSQL
6.2%
Nix
2.5%
Shell
1.5%