BACK TO PRODUCTS

DB-Sync

By

By IOG

About DB Sync

DB Sync follows the Cardano chain and takes information from the chain and an internally maintained copy of the 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. DB-Sync is a tool developed by IntersectMBO under Apache 2.0 license. Examples, schema, and documentation can be found in the GitHub repository.

Demeter Implementation

Demeter is serverless, you don't need to provision any infrastructure.

It provides highly-available, multi-tenant instances of Cardano DB Sync. You can run your queries securely connecting to the PostgreSQL engine directly from your servers using your private credentials. All queries are load-balanced across multiple instances, ensuring both performance and resilience. Demeter eliminates the need for manual infrastructure management by handling monitoring, security, and version upgrades.

Demeter Pricing

Demeter price scales to zero, you only pay for what you use.

Usage is measured by aggregated time of open connections to the PostgreSQL. If no connections are made, you incur no charges, except for minimum fees in Tiers with reserved throughput. Demeter offers different Tiers for DB Sync Ports, allowing you to reserve throughput and scale your usage to meet the specific demands of your project. Service is limited by concurrent open connections. Leverage Demeter Free Tier to get started.

TierFreeFlexPro IPro II
Minimum fee$0$0$100$300
Price per 24hs of connection$0$0.64$0.58$0.48
Max concurrent open connections152575

Getting Started

Once created, your Cardano DB Sync Port resource will present you with the required information to access the PostgreSQL instance:

  • public hostname: the publicly accesible hostname of the PostgreSQL instance (eg: dbynsc-v3.demeter.run)
  • public port number: the publicly accesible port of the PostgreSQL instance (eg: 5432)
  • database name: the name of the PostgreSQL database (eg: dbsync-mainnet)
  • username: the username for authenticating against PostgreSQL (eg: dmtr_dbsync1jjv9pyqyna)
  • password: the password for authenticating against PostgreSQL

The above value will change for each project depending on your configuration.

  • Python
  • NodeJS
  • pgAdmin

You can use a library like psycopg2 to connect to a PostgreSQL instance in Python. Here's a basic example:

import psycopg2

# replace the following values with the ones provided in Demeter's console
connection = psycopg2.connect(
    host="dbsync-v3.demeter.run",
    port=5432,
    user="dmtr_dbsync1jjv9pyqyna", 
    password="your_password", 
    dbname="dbsync-mainnet", 
)

# Create a cursor object
cursor = connection.cursor()

# Execute a query
cursor.execute("SELECT * FROM block ORDER BY id DESC LIMIT 10")

# Fetch and print the results
rows = cursor.fetchall()
for row in rows:
    print(row)

In this code, replace host, port, user, password and dbname with your actual PostgreSQL details that you can find on Demeter's resource detail.

This will connect to the PostgreSQL server, run a query to fetch the latest 5 blocks in the DBSync, and print them to the console.

1. Select type

2. Select project