diff --git a/nixos/tests/postgresql.nix b/nixos/tests/postgresql.nix index 091e64294ac5b..6fb27be3eb4b1 100644 --- a/nixos/tests/postgresql.nix +++ b/nixos/tests/postgresql.nix @@ -21,6 +21,14 @@ let CREATE TABLE xmltest ( doc xml ); INSERT INTO xmltest (doc) VALUES ('ok'); -- check if libxml2 enabled ''; + + jit-test-sql = pkgs.writeText "postgresql-jit-test" '' + SET jit_above_cost = 1; + SET jit = 1; + EXPLAIN ANALYZE SELECT CONCAT('jit result = ', SUM(id)) FROM sth; + SELECT CONCAT('jit result = ', SUM(id)) from sth; + ''; + make-postgresql-test = postgresql-name: postgresql-package: backup-all: makeTest { name = postgresql-name; meta = with pkgs.lib.maintainers; { @@ -76,6 +84,16 @@ let "stat -c '%a' /var/backup/postgresql/${backupName}.sql.gz | grep 600", ) + ${optionalString (versionAtLeast postgresql-package.version "11") '' + with subtest("Postgresql JIT should work on postgresql >= 11"): + output = machine.succeed( + "cat ${jit-test-sql} | sudo -u postgres psql" + ) + assert "JIT:" in output + assert "jit result = 5" in output + ''} + + with subtest("Initdb works"): machine.succeed("sudo -u postgres initdb -D /tmp/testpostgres2") diff --git a/pkgs/servers/sql/postgresql/default.nix b/pkgs/servers/sql/postgresql/default.nix index 63446a684b256..6800e88a0c560 100644 --- a/pkgs/servers/sql/postgresql/default.nix +++ b/pkgs/servers/sql/postgresql/default.nix @@ -10,6 +10,10 @@ let , enableSystemd ? (lib.versionAtLeast version "9.6" && !stdenv.isDarwin) , gssSupport ? with stdenv.hostPlatform; !isWindows && !isStatic, libkrb5 + # enable JIT support + , supportJIT ? (lib.versionAtLeast version "11") + , llvm, clang + # for postgreql.pkgs , this, self, newScope, buildEnv @@ -43,7 +47,9 @@ let ++ lib.optionals gssSupport [ libkrb5 ] ++ lib.optionals (!stdenv.isDarwin) [ libossp_uuid ]; - nativeBuildInputs = [ makeWrapper ] ++ lib.optionals icuEnabled [ pkg-config ]; + nativeBuildInputs = [ makeWrapper ] + ++ lib.optionals icuEnabled [ pkg-config ] + ++ lib.optionals supportJIT [ llvm clang ]; enableParallelBuilding = !stdenv.isDarwin; @@ -66,7 +72,8 @@ let (lib.optionalString enableSystemd "--with-systemd") (if stdenv.isDarwin then "--with-uuid=e2fs" else "--with-ossp-uuid") ] ++ lib.optionals icuEnabled [ "--with-icu" ] - ++ lib.optionals gssSupport [ "--with-gssapi" ]; + ++ lib.optionals gssSupport [ "--with-gssapi" ] + ++ lib.optionals supportJIT [ "--with-llvm" ]; patches = [ (if atLeast "9.4" then ./patches/disable-resolve_symlinks-94.patch else ./patches/disable-resolve_symlinks.patch)