- Notifications
You must be signed in to change notification settings - Fork163
A component that follows the Cardano chain and stores blocks and transactions in PostgreSQL
License
IntersectMBO/cardano-db-sync
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Note: Anyone wishing to build and run anything in this repository should avoid themaster
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 chainand an internally maintained copy of ledger state. Data is then extracted from the chain andinserted into a PostgreSQL database. SQL queries can then be written directly against the databaseschema 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 Syncinstance fully synced to a specific network is:
- Look up any block, transaction, address, stake pool etc on that network, usually by the hash thatidentifies that item or the index into another table.
- Look up the balance of any stake address for any Shelley or later epoch.
- Look up the amount of ADA delegated to each pool for any Shelley or later epoch.
Thedoc/ 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 needsto 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 (createand run migrations, validate and analyse)cardano-db-sync
which acts as a Cardano node, following the chain and insertingdata 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.
Thecardano-db-sync
node connects to a locally runningcardano-node
(ie one connected to othernodes in the Cardano network over the internet with TCP/IP) using a Unix domain socket, retrievesblocks, updates its internal ledger state and stores parts of each block in a local PostgreSQLdatabase. The database does not store things like cryptographic signatures but does store enoughinformation 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 (specificallywith the use of foreign keys from one table to another). More user friendly database queries can beimplemented usingPostgres Views to implement joins between tables.
The system requirements forcardano-db-sync
(with bothdb-sync
and thenode
runningon the same machine are:
- Any of the big well known Linux distributions (eg, Debian, Ubuntu, RHEL, CentOS, Archetc).
- 64 Gigabytes of RAM or more (for
mainnet
). - 4 CPU cores or more.
- Ensure that the machine has sufficient IOPS (Input/Output Operations per Second). Ie it should be60k IOPS or better. Lower IOPS ratings will result in slower sync times and/or falling behind thechain tip.
- 700 Gigabytes or more of disk storage (preferably SSD which are 2-5 times faster thanelectro-mechanical disks).
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" }
cardano-node
database size: 203 GBcardano-db-sync
total ledger state files size: ~ 10 GBPostgres
databasemainnet_13.6.0.5
total size: 438 GB
cardano-node
RAM: 24 GBcardano-db-sync
RSS RAM: 21 GB
cardano-node
database size: 12 GBcardano-db-sync
total ledger state files size: ~ 2 GBPostgres
databasepreprod_13.6.0.5
total size: 16 GB
cardano-node
RSS RAM: 5,5 GBcardano-db-sync
RSS RAM: 3,5 GB
cardano-node
database size: 12 GBcardano-db-sync
total ledger state files size: ~ 2 GBPostgres
databasepreview_13.6.0.5
total size: 21 GB
cardano-node
RSS RAM: 2,8 GBcardano-db-sync
RSS RAM: 3,5 GB
The recommended configuration is to have thedb-sync
and the PostgreSQL server on the samemachine. During syncing (getting historical data from the blockchain) there is aHUGE amountof data traffic betweendb-sync
and the database. Traffic to a local database is significantlyfaster 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 IOPSabove is met).
You can discuss development or find help at the following places:
- Intersect Discord#db-sync channel, if new to server invitehere
- GitHub Issues
Install db-sync with one of the following methods:
Once installed, start db-sync by following theRunning Guide.
If you have any issues with this project, consult theTroubleshooting page forpossible solutions.
- BuildingRunning: Building and running the db-sync node.
- Docker: Instruction for docker-compose, and building the images using nix.
- ERD: The entity relationship diagram.
- Example SQL queries: Some example SQL and Haskell/Esqueleto queries.
- OffChainPoolData: Explanation of how stake pool offchain data is retried.
- Schema Documentation: The database schema documentation.
- Schema Management: How the database schema is managed and modified.
- StateSnapshot: Document the creation and restoration of state snapshot files.
- Upgrading PostgreSQL
- Validation: Explanation of validation done by the db-sync node and assumptions made.
About
A component that follows the Cardano chain and stores blocks and transactions in PostgreSQL
Resources
License
Code of conduct
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.