Overview
This tutorial shows how to:- connect a PQS instance to a Daml ledger
- connect a PQS instance to a PostgreSQL database
- query contracts that get exported with SQL API
Prerequisites
Before running this tutorial, ensure you meet the following prerequisites:- successful completion of the Canton and the JSON Ledger API tutorial
- a running Daml ledger with non-empty ACS
-
Docker- installation instructions: https://docs.docker.com/engine/install/ -
Java 17or later - installation instructions: https://docs.oracle.com/en/java/javase/17/install/overview-jdk-installation.html -
scribe.jar- download instructions: Install and download
Existing canton
We assume that the referenced tutorial has been completed successfully and that you still have a running Canton instance with a Daml ledger and any created contracts.Starting PostgreSQL
We will use official PostgreSQL Docker image to run a PostgreSQL instance. The following command will start a PostgreSQL instance with the default userpostgres and password postgres:
5432 to the host’s port 5432.
Starting PQS
Now we can start the PQS instance. The following command will run PQS, connecting it to the ledger and the database we just started:Exploring data with SQL
Now that we have all components connected and operational, we can start querying the data using SQL. We will use thepsql command-line tool (supplied by the official PostgreSQL Docker image) to connect to the
PostgreSQL instance and run SQL queries.
In a new terminal, run the following command to connect to the PostgreSQL instance:
psql into the extended mode to improve readability of the output:
Next steps
In this tutorial, we have successfully connected a PQS instance to a Daml ledger and a PostgreSQL database, and we have explored the ledger data using SQL. You can refer to the following resources for more information:- SQL API - for more details on the SQL API provided by PQS
- How to query contracts and transactions using SQL - for more examples of querying contracts and transactions using SQL