---
title: "Enable or Disable JIT Compilation"
description: "Decide whether JIT compilation helps your workload on Managed PostgreSQL and turn it on or off for the service, a database, a role or a session."
url: https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/enable-jit/
product: "PostgreSQL"
section: product
last_updated: 2026-11-10
---
> For AI agents: the documentation index is at https://community.exoscale.com/llms.txt. Every page is available as markdown at `<page URL>index.md` or with `Accept: text/markdown`.

# Enable or Disable JIT Compilation

Check whether Just-in-Time (JIT) compilation helps your queries on Managed PostgreSQL, and turn it on or off for the whole service, one database, one role or one session.

## What JIT Does

With JIT, PostgreSQL compiles parts of a query to machine code with LLVM before running it:
expression evaluation (`WHERE` clauses, target lists, aggregates) and tuple deforming (extracting
column values from stored rows). For costlier queries it also inlines small functions and runs
LLVM optimization passes.

Compilation takes time before the first row is produced, and it is repeated at every execution.
It pays off on long analytical queries and costs time on short ones.

## Defaults

JIT is on for new services. Read the current values:

```sql
SHOW jit;
SHOW jit_above_cost;
SHOW jit_inline_above_cost;
SHOW jit_optimize_above_cost;
```

| Parameter | Default | Above this planner cost |
| --- | --- | --- |
| `jit_above_cost` | `100000` | The query is compiled |
| `jit_inline_above_cost` | `500000` | Functions and operators are inlined |
| `jit_optimize_above_cost` | `500000` | LLVM optimization passes run |

The thresholds compare with the planner's estimated cost, not with the measured run time. `-1`
disables a stage.

All four parameters can be changed by `avnadmin` per session, per database and per role. Only
`jit` itself is also a service setting.

## When JIT Helps and When It Hurts

JIT tends to help:

- Analytical queries over millions of rows.
- Queries with many expressions per row: long target lists, several aggregates, `CASE` chains.
- Wide tables, where extracting columns dominates.
- Long batch and reporting jobs, where tens of milliseconds of compilation do not matter.

JIT tends to hurt:

- Short queries whose estimated cost is inflated, for example by stale statistics. They pay for
  compilation they never recover.
- Queries on partitioned tables with many partitions: code is generated per partition.
- Queries that run many times per second: compilation is repeated each time.

> [!TIP]
> When latency and CPU rise without a code change, after a table has grown, check whether the
> plan now shows a `JIT` section: the estimated cost may have crossed `jit_above_cost`.

## Measure

Run the query with `EXPLAIN ANALYZE` and look for the `JIT` section at the end of the plan:

```sql
EXPLAIN (ANALYZE, BUFFERS)
SELECT customer_id, sum(amount), count(*)
FROM public.orders
WHERE created_at >= now() - interval '90 days'
GROUP BY customer_id;
```

```text
JIT:
  Functions: 34
  Options: Inlining false, Optimization false, Expressions true, Deforming true
  Timing: Generation 2.767 ms (Deform 0.703 ms), Inlining 0.000 ms, Optimization 10.702 ms, Emission 77.226 ms, Total 90.695 ms
Execution Time: 1984.149 ms
```

Compare `Total` with `Execution Time`. With parallel workers, each worker also prints its own
`JIT` section. Then run the same query with JIT off in your session and compare:

```sql
SET jit = off;
EXPLAIN (ANALYZE, BUFFERS) SELECT ...;
RESET jit;
```

`Functions` is the number of compiled functions. Hundreds of functions usually point to a
partitioned table.

## Change the Setting for the Service

```bash
exo dbaas update SERVICE_NAME -z ZONE -f --pg-settings '{"jit":false}'
```

Parameters:

- `SERVICE_NAME`: name of the service.
- `ZONE`: zone of the service, for example `ch-gva-2`.
- `jit`: `true` or `false`.

The change applies without a restart. Settings sent with `--pg-settings` are merged with the
stored ones; to turn JIT back on, send `'{"jit":true}'`. Read the stored settings:

```bash
exo api get-dbaas-service-pg SERVICE_NAME -z ZONE -q '"pg-settings"'
```

See [Configure PostgreSQL Settings](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/configure-settings/index.md)
for how service settings work.

## Change the Setting for a Database, a Role or a Session

For new sessions on one database:

```sql
ALTER DATABASE DATABASE_NAME SET jit = off;
```

For new sessions of one role, in any database:

```sql
ALTER ROLE ROLE_NAME SET jit = on;
ALTER ROLE ROLE_NAME SET jit_above_cost = 500000;
```

Parameters:

- `DATABASE_NAME`: the database, for example `defaultdb`.
- `ROLE_NAME`: the role, for example the one used by a reporting tool.

A common pattern is JIT off for the application role that runs short queries, and on for the
reporting role.

For the current session only:

```sql
SET jit = on;
```

Database and role settings apply to new sessions only. A connection pool keeps its server
connections open, so they keep the old value until they are recycled. See
[Manage connection pools](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/manage-connection-pools/index.md).

Check what a session uses:

```sql
SELECT current_setting('jit'), current_setting('jit_above_cost');
```

## Raise the Threshold Instead

Rather than turning JIT off, raise the cost threshold so that only expensive queries are
compiled:

```sql
ALTER DATABASE DATABASE_NAME SET jit_above_cost = 1000000;
```

Keep statistics current with `ANALYZE`, so that cost estimates stay realistic.

## Related Pages

- [Configure PostgreSQL Settings](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/configure-settings/index.md)
- [Prepare for high load](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/prepare-for-high-load/index.md)
- [Connect with psql](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/connect-with-psql/index.md)
- [JIT in the PostgreSQL documentation](https://www.postgresql.org/docs/current/jit.html) ↗

