# Json API and postgres

**URL:** <https://forum.canton.network/t/json-api-and-postgres/4416>\
**Category:** App Development\
**Tags:** ledger-api\
**Created:** [April 25, 2022, 2:05pm UTC](https://forum.canton.network/t/json-api-and-postgres/4416 "2022-04-25T14:05:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bernardo](https://avatars.discourse-cdn.com/v4/letter/b/c0e974/32.png) [@Bernardo](https://forum.canton.network/u/Bernardo)\
**Post date:** [April 25, 2022, 2:05pm UTC](https://forum.canton.network/t/json-api-and-postgres/4416/1 "2022-04-25T14:05:09Z")

</div>

Hi, i tried persistence with postgres for my daml contracts with these commands:

daml deploy --host localhost --port 6865

java -jar daml-on-sql-1.17.1.jar --ledgerid=test --sql-backend-jdbcurl=“jdbc:postgresql://localhost/damlledger?user=daml&password=daml”

Those worked for me, but now i want to run JSON API and have postgres persistence, i tried these command but it doesnt store the contracts, any clue?

daml sandbox --wall-clock-time --ledgerid test\_ledger ./.daml/dist/Tese-0.0.1.dar

daml json-api --ledger-host localhost --ledger-port 6865 --http-port 7575 --query-store-jdbc-config “driver=org.postgresql.Driver,url=jdbc:postgresql://localhost:5432/damltest?&ssl=false,user=usertest,password=usertest,createSchema=false” --allow-insecure-tokens

---

<div class="post-metadata">

**Author:** ![Stephen](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/stephen/32/102_2.png) [@Stephen](https://forum.canton.network/u/Stephen)\
**Post date:** [April 25, 2022, 3:58pm UTC](https://forum.canton.network/t/json-api-and-postgres/4416/2 "2022-04-25T15:58:52Z")

</div>

Welcome, @Bernardo. This could be one of several things; to clarify, when you say

> [@Bernardo](#):
>
> it doesnt store the contracts

where are you looking? That is, where are you expecting the contracts to be stored?

(NB: daml-on-sql.jar is not part of the Daml 2 product, [as previously discussed here](https://discuss.daml.com/t/what-became-of-daml-on-sql-jar-in-2-x-x/4402). Keep that in mind for your future deployment plans.)

---

<div class="post-metadata">

**Author:** ![Bernardo](https://avatars.discourse-cdn.com/v4/letter/b/c0e974/32.png) [@Bernardo](https://forum.canton.network/u/Bernardo)\
**Post date:** [April 25, 2022, 6:14pm UTC](https://forum.canton.network/t/json-api-and-postgres/4416/3 "2022-04-25T18:14:55Z")

</div>

The contracts should be stored in postgres, When i reboot the sandbox, they should be visible in navigator and they are not. It doesn´t happend when i execute daml-on-sql.jar commands.

---

<div class="post-metadata">

**Author:** ![Stephen](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/stephen/32/102_2.png) [@Stephen](https://forum.canton.network/u/Stephen)\
**Post date:** [April 25, 2022, 6:41pm UTC](https://forum.canton.network/t/json-api-and-postgres/4416/4 "2022-04-25T18:41:44Z")

</div>

Thanks for the clarifying details; I think I see what you’re saying now.

The JSON API’s use of Postgres is not _an alternative_ to the ledger server (on-sql in your first case, sandbox in your second) storage. [It is an orthogonal _cache_, meant to improve the performance of queries](https://docs.daml.com/2.1.1/json-api/#with-query-store); the ledger server is always its source of ledger data. Since the JSON API is, in reality, an ordinary ledger client, it cannot influence the configuration of the ledger server.

So the contracts disappear in your second example because only the sandbox’s storage matters, and sandbox is in-memory only; it cannot consult the JSON API to retrieve the ledger, which doesn’t keep the full ledger data anyway.

[A production setup with JSON API](https://docs.daml.com/2.1.1/json-api/production-setup.html#query-store) and a Postgres-backed ledger server, such as Canton with Daml 2, will have Postgres for the ledger server, as well as a separate database for the JSON API’s cache.

---

<div class="post-metadata">

**Author:** ![Bernardo](https://avatars.discourse-cdn.com/v4/letter/b/c0e974/32.png) [@Bernardo](https://forum.canton.network/u/Bernardo)\
**Post date:** [April 25, 2022, 6:48pm UTC](https://forum.canton.network/t/json-api-and-postgres/4416/5 "2022-04-25T18:48:35Z")

</div>

Thank you Stephen i think i understood, i will try it with Daml 2
