<p><code>RTS</code> opts are disabled by default in the db-sync build. To enable it add <code>-rtsopts</code> after <code>-with-rtsopts=-N3</code> for the <code>cardano-db-sync</code> executable in the file <code>cardano-db-sync/cardano-db-sync.cabal</code>.</p>

CC BY-SA 4.0
2022-03-13T17:54:27.437Z
thanks for this! hope the others will got help in the future!
wandyyd
CC BY-SA 4.0
2022-03-11T20:12:18.760Z
2022-03-11T20:12:18.760Z
Erik de Castro Lopo
<p>After successfully with <a href="https://cardano.stackexchange.com/q/7435/6616">previous question</a>, where I tried to make <code>cardano-node</code> and <code>cardano-db-sync</code> run as a services, I tried to play around with <code>+RTS ... -RTS</code> option on <code>cardano-db-sync</code>, specifically to reduce the RAM consumption with some option.</p>
<p>Here's the RTS option I tried <code>+RTS -N2 -A16m -qa -qb -qg -M6000M -RTS</code>.</p>
<p>With <code>cardano-node run ...</code>, I can do above RTS options, but with <code>cardano-db-sync ...</code>, I couldn't, here's the sample command</p>
<pre><code>...
...
...
PGPASSFILE=${PGPASSFILE} cardano-db-sync +RTS -N2 -A16m -qa -qb -qg -M4500M -RTS --config ${CONFIG} --socket-path ${CARDANO_NODE_SOCKET_PATH} --state-dir ${STATE_DIR} --schema-dir ${SCHEMA_DIR}
</code></pre>
<p>But, it fails, the error shown as below</p>
<pre><code>Mar 08 09:54:54 cardano-db-sync: Most RTS options are disabled. Link with -rtsopts to enable them.
Mar 08 09:54:54 cardano-db-sync-run.service: Main process exited, code=exited, status=1/FAILURE
Mar 08 09:54:54 cardano-db-sync-run.service: Failed with result 'exit-code'.
</code></pre>
<p>I tried to add <code>-rtsopts</code> as suggested on that error, but it also fails</p>
<pre><code>PGPASSFILE=${PGPASSFILE} cardano-db-sync +RTS -N2 -A16m -qa -qb -qg -M4500M -RTS -rtsopts --config ${CONFIG} --socket-path ${CARDANO_NODE_SOCKET_PATH} --state-dir ${STATE_DIR} --schema-dir ${SCHEMA_DIR}
</code></pre>
<p>Same error is shown</p>
<pre><code>cardano-db-sync: Most RTS options are disabled. Link with -rtsopts to enable them.
</code></pre>
<p>Also, I tried to do that with another way (reference - <a href="https://downloads.haskell.org/%7Eghc/latest/docs/html/users_guide/runtime_control.html?highlight=rtsopts" rel="nofollow noreferrer">on official documentation</a>), <code>-with-rtsopts=&quot;-N2 -A16m -qa -qb -qg -M6000M&quot;</code>, but it also fails with error, as shown below</p>
<pre><code>Invalid option `-with-rtsopts=-N2 -A16m -qa -qb -qg -M4500M'
</code></pre>
<hr>
<br>
<p>Is it possible to add the options <code>+RTS ... -RTS</code> like I tried above?</p>
<p>Or, am I did wrong? Like, it must come sequentially right after/before some command?</p>
<p>Thanks in advance! And, have a great day!</p>
<br>
<hr>
*PS
<ul>
<li><p>The reason I did try to reduce the RAM consumption is because <code>cardano-node run</code> and <code>cardano-db-sync</code> keeps dropped (killed) from the services, since I had limited RAM (16GB) on my test server. I kinda aware with RAM requirement, but I tried to reduce it, due some circumstances, I can't upgrade RAM on my test server, since it has <code>cardano node</code> running too.</p>
</li>
<li><p>I'm not GHC expert or even linux expert. So, if there's some terms or RTS option that I use incorrectly, please let me know, so I can do in a correct way. :)</p>
</li>
</ul>

CC BY-SA 4.0
2022-03-09T11:14:50.387Z
I am the main developer on `db-sync`. Trying to reduce the memory footprint of `db-sync` using RTS options will fail with 100% certainty.

The problem is that both `node` and `db-sync` have a data structure called ledger state (which is huge, like 8 Gigabytes huge) that is basically identical. Long term, we want to reduce that so that `db-sync` does not need to maintain that. Until then, you need to just live with the high memory usage.
Erik de Castro Lopo
CC BY-SA 4.0
2022-03-10T16:10:57.417Z
Hi @ErikdeCastroLopo - thanks for your comment & explanation. Want to confirm for your statement - "Trying to reduce the memory footprint of db-sync using RTS options will fail with 100% certainty." - is that meant I couldn't use RTS options, like I used on `cardano-node run`? || And, "Until then, you need to just live with the high memory usage." - you mean, the **only way** is to upgrade RAM?
wandyyd
CC BY-SA 4.0
2022-03-10T21:36:31.747Z
`RTS` options might allow you to shave as much as 20% off the memory usage at the cost of a performance hit (because the garbage collector will need to run more often). Unfortunately the only current solution is more RAM.
Erik de Castro Lopo
CC BY-SA 4.0
2022-03-11T01:49:16.157Z
Do you know what `RTS` options that might be available for me to use? since, from what I test around from initial options `+RTS -N2 -A16m -qa -qb -qg -M6000M -RTS` it gives me error message `Most RTS options are disabled. Link with -rtsopts to enable them.`. Anyway, thanks for your comments.
wandyyd
CC BY-SA 4.0
2022-03-11T01:58:33.370Z
Oh, sorry, `RTS` opts are disabled by default in the `db-sync` build.

To enable it add `-rtsopts` after `-with-rtsopts=-N3` for the `cardano-db-sync` executable in the file `cardano-db-sync/cardano-db-sync.cabal`
Erik de Castro Lopo
CC BY-SA 4.0
2022-03-11T02:40:03.757Z
Thanks for your guide! seems it kinda works, but unsure if it will fail or not, since I just started the `cardano-node run` again, so it needs time to catch-up. Have a great day! :)
wandyyd
CC BY-SA 4.0
2022-03-11T02:41:55.073Z
It will like work really well for the vast majority of the mainnet chain. You are really only likely to run into problems later on the chain where there is just orders of magnitude more data on the chain.
Erik de Castro Lopo
CC BY-SA 4.0
2022-03-11T08:05:01.687Z
Ahh yes.. I tried to tweak around the RTS options, but on some options, it will be dropped (service killed since it needs more RAM consumption). Anyway, your comment to add "-rtsopts" is correct, do you mind to `post it as answer` perhaps? so I can mark it as the correct answer on this post. :)
wandyyd
<haskell><cabal><cardano-db-sync><ubuntu>
Cardano DB Sync - RTS Options
# Cardano DB Sync - RTS Options

(Asked by: username_0 on 2022-03-09)

After successfully with previous question, where I tried to make cardano-node and cardano-db-sync run as a services, I tried to play around with +RTS ... -RTS option on cardano-db-sync, specifically to reduce the RAM consumption with some option.
Here's the RTS option I tried +RTS -N2 -A16m -qa -qb -qg -M6000M -RTS.
With cardano-node run ..., I can do above RTS options, but with cardano-db-sync ..., I couldn't, here's the sample command
...
...
...
PGPASSFILE=${PGPASSFILE} cardano-db-sync +RTS -N2 -A16m -qa -qb -qg -M4500M -RTS --config ${CONFIG} --socket-path ${CARDANO_NODE_SOCKET_PATH} --state-dir ${STATE_DIR} --schema-dir ${SCHEMA_DIR}

But, it fails, the error shown as below
Mar 08 09:54:54 cardano-db-sync: Most RTS options are disabled. Link with -rtsopts to enable them.
Mar 08 09:54:54 cardano-db-sync-run.service: Main process exited, code=exited, status=1/FAILURE
Mar 08 09:54:54 cardano-db-sync-run.service: Failed with result 'exit-code'.

I tried to add -rtsopts as suggested on that error, but it also fails
PGPASSFILE=${PGPASSFILE} cardano-db-sync +RTS -N2 -A16m -qa -qb -qg -M4500M -RTS -rtsopts --config ${CONFIG} --socket-path ${CARDANO_NODE_SOCKET_PATH} --state-dir ${STATE_DIR} --schema-dir ${SCHEMA_DIR}

Same error is shown
cardano-db-sync: Most RTS options are disabled. Link with -rtsopts to enable them.

Also, I tried to do that with another way (reference - on official documentation), -with-rtsopts="-N2 -A16m -qa -qb -qg -M6000M", but it also fails with error, as shown below
Invalid option `-with-rtsopts=-N2 -A16m -qa -qb -qg -M4500M'



Is it possible to add the options +RTS ... -RTS like I tried above?
Or, am I did wrong? Like, it must come sequentially right after/before some command?
Thanks in advance! And, have a great day!


*PS

The reason I did try to reduce the RAM consumption is because cardano-node run and cardano-db-sync keeps dropped (killed) from the services, since I had limited RAM (16GB) on my test server. I kinda aware with RAM requirement, but I tried to reduce it, due some circumstances, I can't upgrade RAM on my test server, since it has cardano node running too.

I'm not GHC expert or even linux expert. So, if there's some terms or RTS option that I use incorrectly, please let me know, so I can do in a correct way. :)

**Tags:** haskell, cabal, cardano-db-sync, ubuntu
> **Comments:**
> **username_1**: I am the main developer on `db-sync`. Trying to reduce the memory footprint of `db-sync` using RTS options will fail with 100% certainty.  The problem is that both `node` and `db-sync` have a data structure called ledger state (which is huge, like 8 Gigabytes huge) that is basically identical. Long term, we want to reduce that so that `db-sync` does not need to maintain that. Until then, you need to just live with the high memory usage.  
> **username_0**: Hi @ErikdeCastroLopo - thanks for your comment & explanation. Want to confirm for your statement - "Trying to reduce the memory footprint of db-sync using RTS options will fail with 100% certainty." - is that meant I couldn't use RTS options, like I used on `cardano-node run`? || And, "Until then, you need to just live with the high memory usage." - you mean, the **only way** is to upgrade RAM?  
> **username_1**: `RTS` options might allow you to shave as much as 20% off the memory usage at the cost of a performance hit (because the garbage collector will need to run more often). Unfortunately the only current solution is more RAM.  
> **username_0**: Do you know what `RTS` options that might be available for me to use? since, from what I test around from initial options `+RTS -N2 -A16m -qa -qb -qg -M6000M -RTS` it gives me error message `Most RTS options are disabled. Link with -rtsopts to enable them.`. Anyway, thanks for your comments.  
> **username_1**: Oh, sorry, `RTS` opts are disabled by default in the `db-sync` build.  To enable it add `-rtsopts` after `-with-rtsopts=-N3` for the `cardano-db-sync` executable in the file `cardano-db-sync/cardano-db-sync.cabal`  
> **username_0**: Thanks for your guide! seems it kinda works, but unsure if it will fail or not, since I just started the `cardano-node run` again, so it needs time to catch-up. Have a great day! :)  
> **username_1**: It will like work really well for the vast majority of the mainnet chain. You are really only likely to run into problems later on the chain where there is just orders of magnitude more data on the chain.  
> **username_0**: Ahh yes.. I tried to tweak around the RTS options, but on some options, it will be dropped (service killed since it needs more RAM consumption). Anyway, your comment to add "-rtsopts" is correct, do you mind to `post it as answer` perhaps? so I can mark it as the correct answer on this post. :)  

---

## 1 answers

### Answer by username_1 on 2022-03-11. Score: 2 | Accepted answer

`RTS` opts are disabled by default in the db-sync build. To enable it add `-rtsopts` after `-with-rtsopts=-N3` for the `cardano-db-sync` executable in the file `cardano-db-sync/cardano-db-sync.cabal`.

> **Comments:**
> **username_0**: thanks for this! hope the others will got help in the future!  

---

