Home Explore Blog CI



nixpkgs

6th chunk of `nixos/modules/services/databases/postgresql.md`
58c115ee01aa06d2a5b20ef83b20a53b7b5bde4b3f21cad100000001000008fa
self: super: {
  postgresql_15 = super.postgresql_15// {
    pkgs = super.postgresql_15.pkgs // {
      pg_repack = super.postgresql_15.pkgs.pg_repack.overrideAttrs (_: {
        name = "pg_repack-v20181024";
        src = self.fetchzip {
          url = "https://github.com/reorg/pg_repack/archive/923fa2f3c709a506e111cc963034bf2fd127aa00.tar.gz";
          sha256 = "17k6hq9xaax87yz79j773qyigm4fwk8z4zh5cyp6z0sxnwfqxxw5";
        };
      });
    };
  };
}
```

## Procedural Languages {#module-services-postgres-pls}

PostgreSQL ships the additional procedural languages PL/Perl, PL/Python and PL/Tcl as extensions.
They are packaged as plugins and can be made available in the same way as external extensions:
```nix
{
  services.postgresql.extensions = ps: with ps; [
    plperl
    plpython3
    pltcl
  ];
}
```

Each procedural language plugin provides a `.withPackages` helper to make language specific packages available at run-time.

For example, to make `python3Packages.base58` available:
```nix
{
  services.postgresql.extensions = pgps: with pgps; [
    (plpython3.withPackages (pyps: with pyps; [ base58 ]))
  ];
}
```

This currently works for:
- `plperl` by re-using `perl.withPackages`
- `plpython3` by re-using `python3.withPackages`
- `plr` by exposing `rPackages`
- `pltcl` by exposing `tclPackages`

## JIT (Just-In-Time compilation) {#module-services-postgres-jit}

[JIT](https://www.postgresql.org/docs/current/jit-reason.html)-support in the PostgreSQL package
is disabled by default because of the ~600MiB closure-size increase from the LLVM dependency. It
can be optionally enabled in PostgreSQL with the following config option:

```nix
{
  services.postgresql.enableJIT = true;
}
```

This makes sure that the [`jit`](https://www.postgresql.org/docs/current/runtime-config-query.html#GUC-JIT)-setting
is set to `on` and a PostgreSQL package with JIT enabled is used. Further tweaking of the JIT compiler, e.g. setting a different
query cost threshold via [`jit_above_cost`](https://www.postgresql.org/docs/current/runtime-config-query.html#GUC-JIT-ABOVE-COST)
can be done manually via [`services.postgresql.settings`](#opt-services.postgresql.settings).

The attribute-names of JIT-enabled PostgreSQL packages are suffixed with `_jit`, i.e. for each `pkgs.postgresql`

Title: PostgreSQL Procedural Languages and JIT Compilation
Summary
This section explains how to configure PostgreSQL to use procedural languages like PL/Perl, PL/Python, and PL/Tcl as extensions. It details how to make language-specific packages available at runtime using the `.withPackages` helper provided by each language plugin, giving an example using `python3Packages.base58` with `plpython3`. It also describes how to enable JIT (Just-In-Time) compilation in PostgreSQL, which is disabled by default due to its large closure size (LLVM dependency). Enabling JIT can be done via the `services.postgresql.enableJIT` option. The attribute names of JIT-enabled PostgreSQL packages are suffixed with `_jit`.