Aller au contenu

Linux - Installation de Cardano DB Sync

Guide complet pour installer Cardano DB Sync sur Debian 12 avec base de données PostgreSQL et gestionnaire de paquets NIX, incluant la configuration du service

Debian 12Cardano DB SyncPostgreSQLNIXBlockchainDatabase

Étapes d'Installation

1

Install PostgreSQL

Installation and configuration of PostgreSQL database for Cardano DB Sync.

Install PostgreSQL and additional extensions

sudo apt install postgresql postgresql-contrib

Enable PostgreSQL service for automatic startup

sudo systemctl enable postgresql

Start PostgreSQL service

sudo systemctl start postgresql
2

Setup Database

Creating database user and database with appropriate permissions.

Connect to PostgreSQL console as postgres user

sudo -u postgres psql

Create Cardano database user with password

CREATE USER cardano WITH PASSWORD 'PASSWORD';

Use a strong, secure password

Create Cardano Explorer database

CREATE DATABASE cexplorer OWNER cardano;

Grant all privileges for the database

GRANT ALL PRIVILEGES ON DATABASE cexplorer TO cardano;
3

Clone Repository and Install DB Sync

Cloning the official Cardano DB Sync repository from GitHub and installation with NIX.

Switch to cardano user account

sudo -i -u cardano

Clone Cardano DB Sync repository

git clone https://github.com/IntersectMBO/cardano-db-sync.git

Change to cardano-db-sync directory

cd cardano-db-sync/

List available version tags

git tag | sort -V

Switch to specific version tag

git switch -d tags/13.6.0.5

Install Cardano DB Sync with NIX

nix profile install .

This installation may take some time

4

Database Authentication

Setting up PostgreSQL authentication with .pgpass file.

Create PostgreSQL password file

.pgpass
localhost:5432:cexplorer:cardano:PASSWORD

Set file permissions for security

chmod 600 ~/cardano-config/.pgpass
5

System Integration

Creating system-wide symbolic links for Cardano DB Sync.

Create system-wide symbolic link

sudo ln -sf /home/cardano/.nix-profile/bin/cardano-db-sync /usr/local/bin/cardano-db-sync
6

Systemd Service

Configuring systemd service for automatic startup and management.

Create systemd service configuration file

cardano-db-sync.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[Unit]Description=Cardano DB SyncAfter=network.target cardano-node.serviceRequires=cardano-node.service [Service]User=cardanoGroup=cardanoWorkingDirectory=/home/cardano/cardano-configEnvironment="PGPASSFILE=/home/cardano/cardano-config/.pgpass"ExecStart=/usr/local/bin/cardano-db-sync \  --config /home/cardano/cardano-config/db-sync-config.json \  --socket-path /home/cardano/cardano-db/node.socket \  --state-dir /home/cardano/cardano-db-sync-state \  --schema-dir /home/cardano/cardano-db-sync/schema Restart=on-failureRestartSec=10LimitNOFILE=32768 [Install]WantedBy=multi-user.target

Reload systemd for new service

sudo systemctl daemon-reload

Enable service for automatic startup

sudo systemctl enable cardano-db-sync

Start Cardano DB Sync service

sudo systemctl start cardano-db-sync
7

Monitoring

Checking service status and setting up log monitoring.

Check service status

sudo systemctl status cardano-db-sync

Follow service logs in real-time

journalctl -u cardano-db-sync -f

Conseils Supplémentaires

Commandes et conseils utiles pour une meilleure gestion

Synchronization Status

Query metadata table for synchronization status

sudo -u postgres psql -d cexplorer -c "SELECT * FROM meta;"

Troubleshooting

Restart Cardano DB Sync service

sudo systemctl restart cardano-db-sync

Disk Space

Check available disk space

df -h /home/cardano/

Ressources Supplémentaires

Documentation officielle et liens utiles

Cardano DB Sync Repository

Official GitHub repository with source code and documentation

PostgreSQL Documentation

Official PostgreSQL documentation for database administration

Cardano Developer Portal

Official Cardano developer portal with DB Sync documentation