├── .envrc.recommended ├── .github └── workflows │ ├── cache-upload.yml │ ├── docker.yml │ └── nix-build.yml ├── .gitignore ├── INTERNAL.md ├── README.md ├── TODO.md ├── docker └── init.sh.in ├── docs ├── README.md ├── adding-tests.md ├── build-postgres.md ├── docker.md ├── migration-tests.md ├── new-major-postgres.md ├── nix-overlays.md ├── receipt-files.md ├── references.md ├── start-client-server.md ├── start-here.md ├── update-extension.md └── use-direnv.md ├── ext ├── 0001-build-Allow-using-V8-from-system.patch ├── citus.nix ├── hypopg.nix ├── orioledb.nix ├── pg_graphql.nix ├── pg_hashids.nix ├── pg_jsonschema.nix ├── pg_net.nix ├── pg_plan_filter.nix ├── pg_stat_monitor.nix ├── pg_tle.nix ├── pgsodium.nix ├── pgsql-http.nix ├── pgvector.nix ├── plv8.nix ├── supautils.nix ├── vault.nix └── wrappers │ └── default.nix ├── flake.lock ├── flake.nix ├── justfile ├── overlays ├── cargo-pgrx.nix ├── gdal-small.nix └── psql_16-oriole.nix ├── tests ├── migrations │ └── data.sql ├── postgresql.conf.in ├── prime.sql ├── smoke │ ├── 0000-hello-world.sql │ ├── 0001-pg_graphql.sql │ ├── 0002-supautils.sql │ └── 0003-pgsodium-vault.sql └── util │ └── pgsodium_getkey.sh └── tools ├── README.md ├── migrate-tool.sh.in ├── run-client.sh.in ├── run-replica.sh.in └── run-server.sh.in /.envrc.recommended: -------------------------------------------------------------------------------- 1 | # To use: echo "source_env .envrc.recommended" >> .envrc 2 | 3 | if ! has nix_direnv_version || ! nix_direnv_version 2.3.0; then 4 | source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.3.0/direnvrc" "sha256-Dmd+j63L84wuzgyjITIfSxSD57Tx7v51DMxVZOsiUD8=" 5 | fi 6 | 7 | use flake 8 | 9 | nix_direnv_watch_file tools/run-client.sh 10 | nix_direnv_watch_file tools/run-server.sh 11 | -------------------------------------------------------------------------------- /.github/workflows/cache-upload.yml: -------------------------------------------------------------------------------- 1 | name: Cache upload 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | permissions: 9 | contents: write 10 | packages: write 11 | id-token: write 12 | 13 | jobs: 14 | build: 15 | strategy: 16 | fail-fast: false 17 | runs-on: ubuntu-latest 18 | name: nix-build 19 | steps: 20 | - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 21 | with: 22 | fetch-depth: 0 23 | - uses: DeterminateSystems/nix-installer-action@65d7c888b2778e8cf30a07a88422ccb23499bfb8 24 | - uses: DeterminateSystems/magic-nix-cache-action@749fc5bbc9fa49d60c2b93f6c4bc867b82e1d295 25 | - name: configure aws credentials for s3 26 | uses: aws-actions/configure-aws-credentials@v1 27 | with: 28 | role-to-assume: ${{ secrets.DEV_AWS_ROLE }} 29 | aws-region: "us-east-1" 30 | kvm: true 31 | extra-conf: | 32 | system-features = kvm 33 | 34 | - name: write secret key 35 | # use python so we don't interpolate the secret into the workflow logs, in case of bugs 36 | run: | 37 | python -c "import os; file = open('nix-secret-key', 'w'); file.write(os.environ['NIX_SIGN_SECRET_KEY']); file.close()" 38 | env: 39 | NIX_SIGN_SECRET_KEY: ${{ secrets.NIX_SIGN_SECRET_KEY }} 40 | 41 | - name: build and copy to S3 42 | run: | 43 | for x in 15 16 orioledb_16; do 44 | nix build .#psql_$x/bin -o result-$x 45 | done 46 | nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./result* 47 | -------------------------------------------------------------------------------- /.github/workflows/docker.yml: -------------------------------------------------------------------------------- 1 | name: Docker 2 | 3 | on: 4 | push: 5 | branches: [ 'main' ] 6 | 7 | env: 8 | REGISTRY: ghcr.io 9 | IMAGE_NAME: ${{ github.repository }} 10 | 11 | jobs: 12 | build: 13 | name: "update: build and deploy postgres server images" 14 | runs-on: ubuntu-latest 15 | permissions: 16 | contents: write 17 | packages: write 18 | steps: 19 | - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 20 | with: 21 | fetch-depth: 0 22 | - uses: DeterminateSystems/nix-installer-action@main 23 | - uses: DeterminateSystems/magic-nix-cache-action@main 24 | - uses: actions/checkout@v3 25 | 26 | - name: Build images 27 | run: | 28 | nix build .#psql_15/docker -o result-docker-15 29 | nix build .#psql_16/docker -o result-docker-16 30 | nix build .#psql_orioledb_16/docker -o result-docker-orioledb-16 31 | - name: Log in to the Container registry 32 | uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0 33 | with: 34 | registry: ${{ env.REGISTRY }} 35 | username: ${{ github.actor }} 36 | password: ${{ secrets.GITHUB_TOKEN }} 37 | 38 | - name: Push image to the Container registry 39 | run: | 40 | set -x 41 | for x in 15 16 orioledb_16; do 42 | nix build .#psql_$x/docker.copyToRegistry 43 | done 44 | -------------------------------------------------------------------------------- /.github/workflows/nix-build.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | 9 | permissions: read-all 10 | 11 | jobs: 12 | build: 13 | strategy: 14 | fail-fast: false 15 | matrix: 16 | os: [ ubuntu-latest ] 17 | cmd: [ "nix flake check -L --show-trace", "nix run nixpkgs#just -- build-all" ] 18 | runs-on: ${{ matrix.os }} 19 | name: nix-build 20 | steps: 21 | - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 22 | with: 23 | fetch-depth: 0 24 | - uses: DeterminateSystems/nix-installer-action@65d7c888b2778e8cf30a07a88422ccb23499bfb8 25 | - uses: DeterminateSystems/magic-nix-cache-action@749fc5bbc9fa49d60c2b93f6c4bc867b82e1d295 26 | - run: ${{ matrix.cmd }} 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # nix puts stuff under the symlink name 'result*' 2 | result* 3 | 4 | # direnv 5 | .envrc 6 | .direnv 7 | *.swp 8 | 9 | # left around by pg_upgrade 10 | /delete_old_cluster.sh 11 | 12 | # shell history 13 | .history 14 | container.sh 15 | sbom.spdx.json 16 | sbom.cdx.json 17 | sbom.csv 18 | graph*.png 19 | init.sh 20 | postgres* 21 | build.log 22 | -------------------------------------------------------------------------------- /INTERNAL.md: -------------------------------------------------------------------------------- 1 | # Nix Postgres Prototype 2 | 3 | This repository contains **experimental code** to package PostgreSQL using nix. 4 | 5 | ## Install Nix 6 | Follow installation guide at [installation](./docs/start-here.md). 7 | 8 | # Evaluation Criteria 9 | 10 | ## Building multiple versions of PostgreSQL: 14, 15 and future versions 11 | 12 | Supported major versions of Postgres are defined in [flake.nix basePackages](https://github.com/supabase/nix-postgres/blob/648e31bc7b629c6644b07ad378d04d3334403d78/flake.nix#L245-L246). 13 | 14 | Each major version can be built independently. 15 | ```bash 16 | nix build .#psql_14/bin -o result-14 17 | nix build .#psql_15/bin -o result-15 18 | ``` 19 | 20 | Builds Postgres 14 & 15 with all of our extensions and symlinks the resulting build artifacts e.g. `psql`, `pg_dump` etc at `result-14` and `result-15` respectively. 21 | 22 | 23 | On first run these commands will take a long time to complete. Intermediate results are cached and reused leading to significantly reduced built times on subsequent runs. 24 | 25 | The Postgres build itself is defined upstream in [nixpkgs#postgresqlXX](https://github.com/NixOS/nixpkgs/blob/master/pkgs/servers/sql/postgresql/default.nix). That distribution is frequently updated and historically has released minor and major updates within 10 days. We can optionally override the version number or vendor the derivation to support additional versions. 26 | 27 | Note that nixpkgs supports 1 minor version (the most recent) for each major version. 28 | 29 | 30 | To launch a psql repl with the built version, first start the server: 31 | 32 | ```bash 33 | nix run .#start-server 15 34 | ``` 35 | Next, launch the psql client. 36 | 37 | ```bash 38 | nix run .#start-client 15 39 | ``` 40 | 41 | Both commands are defined in [flake.nix](./flake.nix) 42 | 43 | ## Building multiple versions of an extension: e.g. pgvector 44 | 45 | Extensions included with the Postgres distribution come from two sources: 46 | 47 | - Upstream in [nixpkgs](https://github.com/NixOS/nixpkgs/tree/a996f7185eaaa8ae261adbc6b772761d62869796/pkgs/servers/sql/postgresql/ext) 48 | - Locally in [./ext](./ext) 49 | 50 | Each extension has a default version that can be easily updated or overriden. Multiple versions can be managed on git branches or concurrently with unique names e.g. `supautils-1.1`, `supautils-1.2`. 51 | 52 | ## Testing 53 | 54 | ### Extension Tests 55 | 56 | Extension pgTap tests are defined in [`./tests/smoke`](./tests/smoke) and can be run via: 57 | 58 | ``` 59 | nix flake check 60 | ``` 61 | 62 | Tests execute against Postgres 14 and 15. 63 | 64 | ### Upgrade Tests 65 | 66 | The nix command `migration-test` supports testing across arbitrary versions (major and minor) using `pg_upgrade` and `pg_dumpall` 67 | 68 | It takes the form: 69 | ``` 70 | nix run .#migration-test 71 | ``` 72 | 73 | For example, to test `pg_upgrade` as the method for upgrading between the current version of pg14 and current version of pg15, you can run: 74 | 75 | ``` 76 | nix run .#migration-test 14 15 pg_upgrade 77 | ``` 78 | 79 | The files that define the test database to be migrated are: 80 | 81 | - [postgresql.conf](./tests/postgresql.conf) 82 | - [prime.sql](./tests/prime.sql) 83 | - [data.sql](./tests/migrations/data.sql) 84 | 85 | Since nix allows refering to derivations defined on github, we can test upgrades between any arbitrary prior commits 86 | 87 | For example, to upgrade from the postgres 14 version defined in commit 388659fcc3c857f2c45eeb397f67b5b7bf9a1b84 to the current version of postgres 14, run: 88 | ``` 89 | nix run github:supabase/nix-postgres#migration-test \ 90 | $(nix build github:supabase/nix-postgres/388659fcc3c857f2c45eeb397f67b5b7bf9a1b84#psql_14/bin 91 | 14 92 | ``` 93 | 94 | The `data.sql` file is currently very minimal. We would extend that to exercise large parts of a complex schema to ensure tests have significant coverage. 95 | 96 | 97 | ## Integrated with Github CI workflows 98 | 99 | GitHub Actions produces: 100 | - [builds](https://github.com/supabase/nix-postgres/blob/main/.github/workflows/nix-build.yml) 101 | - [docker images](https://github.com/supabase/nix-postgres/blob/main/.github/workflows/docker.yml) 102 | - [reusable cache artifacs in s3](https://github.com/supabase/nix-postgres/blob/main/.github/workflows/cache-upload.yml) 103 | 104 | ## Produce an AWS AMI 105 | 106 | (Not yet implemented) 107 | 108 | The working plan for AMIs is to use `nix copy` to move CI build artifacts from s3 to the AMI. There is a detailed write-up in [issue 17](https://github.com/supabase/nix-postgres/issues/17) 109 | 110 | 111 | ## Produce a Docker image 112 | 113 | Docker images can be produced from the binary assets generated with `nix build` 114 | 115 | Locally, you can produce a docker image using: 116 | 117 | ```shell 118 | nix build .#psql_15/docker -o result-15 119 | docker load -i ./result-15 120 | ``` 121 | 122 | Which creates an image named `postgresql-15:latest` tagged in local image 123 | registry. 124 | 125 | You can run that image with: 126 | 127 | ```shell 128 | docker run --rm \ 129 | --name supa_nix_local \ 130 | -p 5441:5432 \ 131 | -d \ 132 | -e POSTGRES_DB=postgres \ 133 | -e POSTGRES_PASSWORD=password \ 134 | -e POSTGRES_USER=postgres \ 135 | -d postgresql-15:latest 136 | ``` 137 | 138 | and connect through psql 139 | ```shell 140 | docker exec -it supa_nix_local psql -U postgres 141 | ``` 142 | 143 | 144 | ## Workflows: 145 | 146 | ### A developer adds a new version of an extension, CI builds it and runs tests 147 | 148 | [ref](https://github.com/supabase/nix-postgres/pull/16/files) 149 | 150 | ### A developers adds a new version of PostgreSQL, CI builds it and runs tests. 151 | 152 | Once available upstream, new versions can be added [here](https://github.com/supabase/nix-postgres/blob/648e31bc7b629c6644b07ad378d04d3334403d78/flake.nix#L245-L246) 153 | 154 | ### A pushed git tag produces an AWS AMI + docker image. 155 | 156 | Not in prototype 157 | 158 | ## Consider that we have the following PostgreSQL targets: 159 | 160 | ### Supported PostgreSQL versions (14), these are older versions not yet migrated to latest 161 | 162 | Builtin and runs in CI 163 | 164 | ```shell 165 | nix build .#psql_14/bin -o result-14 166 | ``` 167 | 168 | ### Latest PostgreSQL version (15) 169 | 170 | Builtin and runs in CI 171 | 172 | ```shell 173 | nix build .#psql_15/bin -o result-15 174 | ``` 175 | 176 | ### Future major PostgreSQL version (e.g. 16 beta 2) 177 | 178 | Support pending upstream merge of [PR](https://github.com/NixOS/nixpkgs/pull/249030) or can be vendored. 179 | 180 | ### Future patch PostgreSQL version (14.x, 15.y) 181 | 182 | These occur upstream. If we want to stay on the outdated version we can add an override to this repo. 183 | 184 | ### Each version will be tested against all extensions 185 | 186 | Builtin and runs in CI 187 | 188 | ## Limitations 189 | 190 | - Lack of darwin-arm support: This is blocked by pgrx extensions. Everything except those extensions is functional. 191 | - Difficulty producing docker images in Github Actions CI: solvable with changes to our custom runners 192 | 193 | 194 | 195 | ## Other 196 | 197 | ### Nix binary cache 198 | 199 | There is a nix binary cache located at the following URL: 200 | 201 | - https://nix-postgres-artifacts.s3.amazonaws.com/ 202 | 203 | Binaries are signed with the public key: 204 | 205 | - `nix-cache.supabase.com-1:ZfEc7Qb7SN+qOTJGMtCz54rnVQ1W2ZI2ROCSSD6YQYc=` 206 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ARCHIVED: prototype nix package for supabase postgres 2 | 3 | > ⚠️ 🚧 **NOTE** 🚧 4 | > 5 | > This repository is archived 6 | > 7 | > Development of this functionality has moved to [supabase/postgres](https://github.com/supabase/postgres/tree/develop/nix) 8 | 9 | -------------------- 10 | 11 | This repository contains **experimental code** to package PostgreSQL using 12 | **[Nix]**, and tooling and infrastructure for deploying it. Read the rest of 13 | this README for some basic overview of the high level components. 14 | 15 | Don't know Nix? Want to understand some of the thinking here? To learn about Nix 16 | and some of the design constraints this repository are under, please see the 17 | [`docs/`](./docs/) directory which should help get you up to speed. 18 | 19 | If you want to install Nix and play along quickly, check out the 20 | [Start Here](./docs/start-here.md) page. 21 | 22 | [Nix]: https://nixos.org 23 | 24 | ## Fundamental components of this repository 25 | 26 | This repository contains a few major high level components, which are outlined below. 27 | 28 | ### PostgreSQL Binary Distributions 29 | 30 | The following PostgreSQL releases are packaged up, along with extensions (read 31 | below) in order to create "fully self contained" binary distributions. In order to get ahold of them, you can use `nix build`: 32 | 33 | ``` 34 | nix build .#psql_14/bin -o result-14 35 | nix build .#psql_15/bin -o result-15 36 | ``` 37 | 38 | This will create two symlinks named `result-14` (resp. `result-15`). You can use the resulting symlinks as a binary distribution; as if they were unpacked tarballs. 39 | 40 | ### PostgreSQL Docker Images 41 | 42 | From the binary images generated by `nix build`, we also create Docker images. You can create 43 | and load an image like so: 44 | 45 | ``` 46 | nix build .#psql_15/docker -o result-15 47 | docker load -i ./result-15 48 | ``` 49 | 50 | There will then be an image named `postgresql-15:latest` tagged in local image 51 | registry. 52 | 53 | This repository also provides pre-packaged docker images hosted via GitHub Packages; simply download them with: 54 | 55 | ``` 56 | docker pull ghcr.io/supabase/nix-postgres-14:latest 57 | docker pull ghcr.io/supabase/nix-postgres-15:latest 58 | ``` 59 | 60 | ### A full suite of extensions 61 | 62 | The binary distributions have many extensions enabled; these include: 63 | 64 | - postgis 65 | - pgrouting 66 | - pgtap 67 | - pg_cron 68 | - pgaudit 69 | - pgjwt 70 | - plpgsql_check 71 | - pg_safeupdate 72 | - timescaledb 73 | - wal2json 74 | - plv8 75 | - rum 76 | - pgvector 77 | - pg_repack 78 | - pgroonga 79 | - pgsql 80 | - pg_plan_filter 81 | - pg_net 82 | - pg_hashids 83 | - pgsodium 84 | - pg_graphql 85 | - pg_stat_monitor 86 | - pg_jsonschema 87 | - vault 88 | - hypopg 89 | - pg_tle 90 | - wrappers 91 | - supautils 92 | - citus 93 | 94 | You can just use `CREATE EXTENSION` to enable most of these. Some may require 95 | tweaks to [postgresql.conf.in](./tests/postgresql.conf.in) to enable. 96 | 97 | ### Helpful development utilities 98 | 99 | Want to start a postgresql-15 server with a bunch of extensions? You don't even 100 | need to download this repository; just use `nix run`: 101 | 102 | ``` 103 | nix run github:supabase/nix-postgres#start-server 15 104 | ``` 105 | 106 | This will start PostgreSQL 15 on port `5435` on localhost with a temporary directory created by `mktemp -d`. Connect to it: 107 | 108 | ``` 109 | austin@GANON:~$ nix run github:supabase/nix-postgres#start-client 14 110 | Starting server for PSQL 14 111 | psql (14.8, server 15.3) 112 | WARNING: psql major version 14, server major version 15. 113 | Some psql features might not work. 114 | Type "help" for help. 115 | 116 | postgres=# 117 | ``` 118 | 119 | The first argument of both commands simply specifies `14` or `15` to get the 120 | major version. This will be expanded in the future. 121 | 122 | ### Migration testing tools 123 | 124 | You can test database migrations (using some artificial data schemas); 125 | it uses the following data to set up the database: 126 | 127 | - [postgresql.conf.in](./tests/postgresql.conf.in) 128 | - [prime.sql](./tests/prime.sql) 129 | - [data.sql](./tests/migrations/data.sql) 130 | 131 | Then, run the following: 132 | 133 | ``` 134 | nix run github:supabase/nix-postgres#migration-test 14 15 135 | ``` 136 | 137 | This will do a migration between versions 14 and 15, at the time of the latest commit to the `nix-postgres` repository. 138 | 139 | You can also test arbitrary `/nix/store` paths; for example the following works: 140 | 141 | ``` 142 | nix run github:supabase/nix-postgres#migration-test \ 143 | $(nix build github:supabase/nix-postgres#psql_14/bin --no-link --print-out-paths) \ 144 | $(nix build github:supabase/nix-postgres#psql_15/bin --no-link --print-out-paths) 145 | ``` 146 | 147 | Thus, you can arbitrarily mix and match various versions that might have been 148 | built in CI, and test their upgrade paths. 149 | 150 | Note that the `data.sql` files and whatnot aren't complete; tweaks are very 151 | welcome to cover as many edge cases as possible. 152 | 153 | ### Nix binary cache 154 | 155 | There is a nix binary cache located at the following URL: 156 | 157 | - https://nix-postgres-artifacts.s3.amazonaws.com/ 158 | 159 | Binaries are signed with the public key: 160 | 161 | - `nix-cache.supabase.com-1:ZfEc7Qb7SN+qOTJGMtCz54rnVQ1W2ZI2ROCSSD6YQYc=` 162 | 163 | ## Other notes 164 | 165 | - This repository should work "in perpetuity" (assuming Nix doesn't horribly 166 | break years down the line), but will probably be migrated elsewhere if it's 167 | successful, so don't get too cozy or familiar. 168 | - Austin uses **[jujutsu]** to develop this repository; but you don't have to 169 | (you should try it, though!) The workflow used for this repo is "linear 170 | commits, no merges." If you submit PRs, they'll be rebased on top of the 171 | existing history to match that. (YMMV but I prefer this style.) 172 | 173 | [jujutsu]: https://github.com/martinvonz/jj 174 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | Austin's todo list, in no particular order: 2 | 3 | - [ ] Upstream: Some work for missing extensions 4 | - [ ] Upstream: create a `buildPostgresPackage` function 5 | - [ ] Upstream: **cross version checks** to make sure our extensions are up to 6 | date with Supabase 7 | 8 | 9 | -------------------------------------------------------------------------------- /docker/init.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # shellcheck shell=bash 3 | /bin/initdb --locale=C -D /data/postgresql 4 | ln -s /etc/postgresql.conf /data/postgresql/postgresql.conf 5 | /bin/postgres -p @PGSQL_DEFAULT_PORT@ -D /data/postgresql 6 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Documentation 2 | 3 | This directory contains most of the "runbooks" and documentation on how to use 4 | this repository. 5 | 6 | You probably want to start with the [starting guide](./start-here.md). Then, 7 | learn how to play with `postgres` in the [build guide](./build-postgres.md). 8 | After that, you can probe around a bit. 9 | -------------------------------------------------------------------------------- /docs/adding-tests.md: -------------------------------------------------------------------------------- 1 | There are basically two types of tests you can add: 2 | 3 | - pgTAP based tests, and 4 | - Migration tests. 5 | 6 | In both cases, a number of extensions may be installed into the database for 7 | use; you can see those in both [postgresql.conf.in](../tests/postgresql.conf.in) 8 | and [prime.sql](../tests/prime.sql) (extensions may be enabled in either place.) 9 | 10 | ## pgTAP tests 11 | 12 | These are super easy: simply add `.sql` files to the 13 | [tests/smoke](./../tests/smoke/) directory, then: 14 | 15 | ``` 16 | nix flake check -L 17 | ``` 18 | 19 | (`-L` prints logs to stderrr, for more details see `man nix`) 20 | 21 | These files are run using `pg_prove`; they pretty much behave exactly like how 22 | you expect; you can read 23 | [the pgTAP documentation](https://pgtap.org/documentation.html) for more. 24 | 25 | For a good example of a pgTAP test as a pull request, check out 26 | [pull request #4](https://github.com/supabase/nix-postgres/pull/4/files). 27 | 28 | ## Re-running tests 29 | 30 | `nix flake check` gets its results cached, so if you do it again the tests won't rerun. If you change a file then it will run again. 31 | 32 | If you want to force rerun without modifying a file, you can do: 33 | 34 | ``` 35 | nix build .#checks.x86_64-linux.psql_14 --rebuild 36 | nix build .#checks.x86_64-linux.psql_15 --rebuild 37 | ``` 38 | 39 | Limitation: currently there's no way to rerun all the tests, so you have to specify the check attribute. 40 | 41 | To get the correct attribute (`#checks.x86_64-linux.psql_15` above), you can do `nix flake show`. This will show a tree with all the output attributes. 42 | 43 | ## Migration tests 44 | 45 | > **NOTE**: Currently, migration tests _do not happen in CI_. They can only be 46 | > run manually. 47 | 48 | Migration tests are pretty simple in the sense they follow a very simple 49 | principle: 50 | 51 | - You put data in the database 52 | - Run the migration procedure 53 | - It should probably not fail 54 | 55 | Step 1 and 2 are easy, and for various reasons (e.g. mistakes from upstream 56 | extension authors), step 3 isn't guaranteed, so that's what the whole idea is 57 | designed to test. 58 | 59 | To add data into the database, modify the 60 | [data.sql](../tests/migrations/data.sql) script and add whatever you want into 61 | it. This script gets loaded into the old version of the database at startup, and 62 | it's expected that the new version of the database can handle it. 63 | 64 | To run the `migration-test` tool, check out the documentation on 65 | [migration-tests](./migration-tests.md). 66 | -------------------------------------------------------------------------------- /docs/build-postgres.md: -------------------------------------------------------------------------------- 1 | # 01 — Use this repository 2 | 3 | Let's clone this repo: 4 | 5 | ```bash 6 | git clone https://github.com/supabase/nix-postgres $HOME/tmp-nix-postgres 7 | cd $HOME/tmp-nix-postgres 8 | ``` 9 | 10 | ## Hashes for everyone 11 | 12 | But how do we build stuff within it? With `nix build`, of course! For example, 13 | the following command will, when completed, create a symlink named `result` that 14 | points to a path which contains an entire PostgreSQL 15 installation — 15 | extensions and all: 16 | 17 | ``` 18 | nix build .#psql_15/bin 19 | ``` 20 | 21 | ``` 22 | $ readlink result 23 | /nix/store/ybf48481x033649mgdzk5dyaqv9dppzx-postgresql-and-plugins-15.3 24 | ``` 25 | 26 | ``` 27 | $ ls result 28 | bin include lib share 29 | ``` 30 | 31 | ``` 32 | $ ll result/bin/ 33 | total 9928 34 | dr-xr-xr-x 2 root root 4096 Dec 31 1969 ./ 35 | dr-xr-xr-x 5 root root 4096 Dec 31 1969 ../ 36 | lrwxrwxrwx 1 root root 79 Dec 31 1969 .initdb-wrapped -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/.initdb-wrapped* 37 | -r-xr-xr-x 1 root root 9829624 Dec 31 1969 .postgres-wrapped* 38 | lrwxrwxrwx 1 root root 73 Dec 31 1969 clusterdb -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/clusterdb* 39 | lrwxrwxrwx 1 root root 72 Dec 31 1969 createdb -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/createdb* 40 | lrwxrwxrwx 1 root root 74 Dec 31 1969 createuser -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/createuser* 41 | lrwxrwxrwx 1 root root 70 Dec 31 1969 dropdb -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/dropdb* 42 | lrwxrwxrwx 1 root root 72 Dec 31 1969 dropuser -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/dropuser* 43 | lrwxrwxrwx 1 root root 68 Dec 31 1969 ecpg -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/ecpg* 44 | lrwxrwxrwx 1 root root 70 Dec 31 1969 initdb -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/initdb* 45 | lrwxrwxrwx 1 root root 72 Dec 31 1969 oid2name -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/oid2name* 46 | lrwxrwxrwx 1 root root 74 Dec 31 1969 pg_amcheck -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/pg_amcheck* 47 | lrwxrwxrwx 1 root root 81 Dec 31 1969 pg_archivecleanup -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/pg_archivecleanup* 48 | lrwxrwxrwx 1 root root 77 Dec 31 1969 pg_basebackup -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/pg_basebackup* 49 | lrwxrwxrwx 1 root root 76 Dec 31 1969 pg_checksums -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/pg_checksums* 50 | -r-xr-xr-x 1 root root 53432 Dec 31 1969 pg_config* 51 | lrwxrwxrwx 1 root root 78 Dec 31 1969 pg_controldata -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/pg_controldata* 52 | -r-xr-xr-x 1 root root 82712 Dec 31 1969 pg_ctl* 53 | lrwxrwxrwx 1 root root 71 Dec 31 1969 pg_dump -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/pg_dump* 54 | lrwxrwxrwx 1 root root 74 Dec 31 1969 pg_dumpall -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/pg_dumpall* 55 | lrwxrwxrwx 1 root root 74 Dec 31 1969 pg_isready -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/pg_isready* 56 | lrwxrwxrwx 1 root root 77 Dec 31 1969 pg_receivewal -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/pg_receivewal* 57 | lrwxrwxrwx 1 root root 78 Dec 31 1969 pg_recvlogical -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/pg_recvlogical* 58 | lrwxrwxrwx 1 root root 73 Dec 31 1969 pg_repack -> /nix/store/bi9i5ns4cqxk235qz3srs9p4x1qfxfna-pg_repack-1.4.8/bin/pg_repack* 59 | lrwxrwxrwx 1 root root 75 Dec 31 1969 pg_resetwal -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/pg_resetwal* 60 | lrwxrwxrwx 1 root root 74 Dec 31 1969 pg_restore -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/pg_restore* 61 | lrwxrwxrwx 1 root root 73 Dec 31 1969 pg_rewind -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/pg_rewind* 62 | lrwxrwxrwx 1 root root 77 Dec 31 1969 pg_test_fsync -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/pg_test_fsync* 63 | lrwxrwxrwx 1 root root 78 Dec 31 1969 pg_test_timing -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/pg_test_timing* 64 | lrwxrwxrwx 1 root root 74 Dec 31 1969 pg_upgrade -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/pg_upgrade* 65 | lrwxrwxrwx 1 root root 79 Dec 31 1969 pg_verifybackup -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/pg_verifybackup* 66 | lrwxrwxrwx 1 root root 74 Dec 31 1969 pg_waldump -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/pg_waldump* 67 | lrwxrwxrwx 1 root root 71 Dec 31 1969 pgbench -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/pgbench* 68 | lrwxrwxrwx 1 root root 71 Dec 31 1969 pgsql2shp -> /nix/store/4wwzd3c136g6j7aqva2gyiqgwy784qjv-postgis-3.3.3/bin/pgsql2shp* 69 | lrwxrwxrwx 1 root root 77 Dec 31 1969 pgsql2shp-3.3.3 -> /nix/store/4wwzd3c136g6j7aqva2gyiqgwy784qjv-postgis-3.3.3/bin/pgsql2shp-3.3.3* 70 | lrwxrwxrwx 1 root root 75 Dec 31 1969 pgtopo_export -> /nix/store/4wwzd3c136g6j7aqva2gyiqgwy784qjv-postgis-3.3.3/bin/pgtopo_export* 71 | lrwxrwxrwx 1 root root 81 Dec 31 1969 pgtopo_export-3.3.3 -> /nix/store/4wwzd3c136g6j7aqva2gyiqgwy784qjv-postgis-3.3.3/bin/pgtopo_export-3.3.3* 72 | lrwxrwxrwx 1 root root 75 Dec 31 1969 pgtopo_import -> /nix/store/4wwzd3c136g6j7aqva2gyiqgwy784qjv-postgis-3.3.3/bin/pgtopo_import* 73 | lrwxrwxrwx 1 root root 81 Dec 31 1969 pgtopo_import-3.3.3 -> /nix/store/4wwzd3c136g6j7aqva2gyiqgwy784qjv-postgis-3.3.3/bin/pgtopo_import-3.3.3* 74 | -r-xr-xr-x 1 root root 286 Dec 31 1969 postgres* 75 | lrwxrwxrwx 1 root root 74 Dec 31 1969 postmaster -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/postmaster* 76 | lrwxrwxrwx 1 root root 68 Dec 31 1969 psql -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/psql* 77 | lrwxrwxrwx 1 root root 74 Dec 31 1969 raster2pgsql -> /nix/store/4wwzd3c136g6j7aqva2gyiqgwy784qjv-postgis-3.3.3/bin/raster2pgsql* 78 | lrwxrwxrwx 1 root root 80 Dec 31 1969 raster2pgsql-3.3.3 -> /nix/store/4wwzd3c136g6j7aqva2gyiqgwy784qjv-postgis-3.3.3/bin/raster2pgsql-3.3.3* 79 | lrwxrwxrwx 1 root root 73 Dec 31 1969 reindexdb -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/reindexdb* 80 | lrwxrwxrwx 1 root root 71 Dec 31 1969 shp2pgsql -> /nix/store/4wwzd3c136g6j7aqva2gyiqgwy784qjv-postgis-3.3.3/bin/shp2pgsql* 81 | lrwxrwxrwx 1 root root 77 Dec 31 1969 shp2pgsql-3.3.3 -> /nix/store/4wwzd3c136g6j7aqva2gyiqgwy784qjv-postgis-3.3.3/bin/shp2pgsql-3.3.3* 82 | lrwxrwxrwx 1 root root 72 Dec 31 1969 vacuumdb -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/vacuumdb* 83 | lrwxrwxrwx 1 root root 72 Dec 31 1969 vacuumlo -> /nix/store/kdjdxnyhpwpvb11da8s99ylqilspcmzl-postgresql-15.3/bin/vacuumlo* 84 | ``` 85 | 86 | As we can see, these files all point to paths under `/nix/store`. We're actually 87 | looking at a "farm" of symlinks to various paths, but collectively they form an 88 | entire installation directory we can reuse as much as we want. 89 | 90 | The path 91 | `/nix/store/ybf48481x033649mgdzk5dyaqv9dppzx-postgresql-and-plugins-15.3` 92 | ultimately is a cryptographically hashed, unique name for our installation of 93 | PostgreSQL with those plugins. This hash includes _everything_ used to build it, 94 | so even a single change anywhere to any extension or version would result in a 95 | _new_ hash. 96 | 97 | The ability to refer to a piece of data by its hash, by some notion of 98 | _content_, is a very powerful primitive, as we'll see later. 99 | 100 | ## Build a different version: v14 101 | 102 | What if we wanted PostgreSQL 14 and plugins? Just replace `_15` with `_14`: 103 | 104 | ``` 105 | nix build .#psql_14/bin 106 | ``` 107 | 108 | You're done: 109 | 110 | ``` 111 | $ readlink result 112 | /nix/store/p7ziflx0000s28bfb213jsghrczknkc4-postgresql-and-plugins-14.8 113 | ``` 114 | 115 | ## Do it all at once: using `just` 116 | 117 | But remembering that long name is tedious. (Don't worry, there's a method to 118 | query the names, and we will go over it later.) What if we just wanted to build 119 | something quickly? 120 | 121 | There's a great tool for this. It's called 122 | [**Just**](https://github.com/casey/just), and all it does is make it easy to 123 | run commands. Let's use that. 124 | 125 | Luckily, there's a `justfile` that can be used to build multiple things. Here's 126 | the `build-all` rule in our [`justfile`](../justfile). It should be obvious if 127 | you're familiar with `make` and `Makefile`s: 128 | 129 | ``` 130 | build-all: 131 | nix build .#psql_14/bin .#psql_14/docker 132 | nix build .#psql_15/bin .#psql_15/docker 133 | ``` 134 | 135 | So this actually builds _four_ things: v14 and v15 of Postgres, both as a binary 136 | distribution _and_ as a Docker image. That's handy, instead of writing it all 137 | out. So we run `just build-all`, and... 138 | 139 | ``` 140 | $ just build-all 141 | Command 'just' not found, did you mean: 142 | ... 143 | ``` 144 | 145 | Ouch. So we have to install `just` using Cargo or something else first. Or do 146 | we? 147 | 148 | ## Using `nix develop` 149 | 150 | Nope! Here's how we can add `just` to our `$PATH`, transparently in a subshell: 151 | 152 | ``` 153 | $ which just 154 | 155 | $ echo $$ 156 | 766420 157 | 158 | $ nix develop 159 | 160 | $ which just 161 | /nix/store/1di6nb4qsv86907l3xarw4llzdss2g89-just-1.14.0/bin/just 162 | 163 | $ echo $$ 164 | 996868 165 | 166 | $ just build-all 167 | ... 168 | 169 | $ exit 170 | 171 | $ echo $$ 172 | 766420 173 | ``` 174 | 175 | Done! As you can see, `nix develop .` will just drop you in a subshell with 176 | tools you need _ready to go instantly_. That's all you need to do! And once that 177 | shell goes away, `just` will be removed from your `$PATH` as well. 178 | 179 | There's an even easier way to do this 180 | [that is completely transparent to you, as well](./use-direnv.md). 181 | -------------------------------------------------------------------------------- /docs/docker.md: -------------------------------------------------------------------------------- 1 | Docker images are pushed to `ghcr.io` on every commit. Try the following: 2 | 3 | ``` 4 | docker run --rm -it ghcr.io/supabase/nix-postgres-15:latest 5 | ``` 6 | 7 | Every Docker image that is built on every push is given a tag that exactly 8 | corresponds to a Git commit in the repository — for example commit 9 | [d3e0c39d34e1bb4d37e058175a7bc376620f6868](https://github.com/supabase/nix-postgres/commit/d3e0c39d34e1bb4d37e058175a7bc376620f6868) 10 | in this repository has a tag in the container registry which can be used to pull 11 | exactly that version. 12 | 13 | This just starts the server. Client container images are not provided; you can 14 | use `nix run` for that, as outlined [here](./start-client-server.md). 15 | -------------------------------------------------------------------------------- /docs/migration-tests.md: -------------------------------------------------------------------------------- 1 | Migration tests are run similar to running the client and server; see 2 | [more on that here](./start-client-server.md). 3 | 4 | Instead, you use the following format to specify the upgrade: 5 | 6 | ``` 7 | nix run .#migration-test [pg_dumpall|pg_upgrade] 8 | ``` 9 | 10 | The arguments are: 11 | 12 | - The version to upgrade from 13 | - The version to upgrade to 14 | - The upgrade mechanism: either `pg_dumpall` or `pg_upgrade` 15 | 16 | ## Specifying the version 17 | 18 | The versions for upgrading can be one of two forms: 19 | 20 | - A major version number, e.g. `14` or `15` 21 | - A path to `/nix/store`, which points to _any_ version of PostgreSQL, as long 22 | as it has the "expected" layout and is a postgresql install. 23 | 24 | ## Always use the latest version of the migration tool 25 | 26 | Unlike the method for starting the client or server, you probably always want to 27 | use the latest version of the `migration-test` tool from the repository. This is 28 | because it can ensure forwards and backwards compatibility if necessary. 29 | 30 | ## Upgrading between arbitrary `/nix/store` versions 31 | 32 | If you want to test migrations from arbitrary versions built by the repository, 33 | you can combine `nix build` and `nix run` to do so. You can use the syntax from 34 | the runbook on [running the server & client](./start-client-server.md) to refer 35 | to arbitrary git revisions. 36 | 37 | For example, if you updated an extension in this repository, and you want to 38 | test a migration from PostgreSQL 14 to PostgreSQL 14 + (updated extension), 39 | using `pg_upgrade` — simply record the two git commits you want to 40 | compare, and you could do something like the following: 41 | 42 | ``` 43 | OLD_GIT_VERSION=... 44 | NEW_GIT_VERSION=... 45 | 46 | nix run github:supabase/nix-postgres#migration-test \ 47 | $(nix build "github:supabase/nix-postgres/$OLD_GIT_VERSION#psql_14/bin") \ 48 | $(nix build "github:supabase/nix-postgres/$NEW_GIT_VERSION#psql_14/bin") \ 49 | pg_upgrade 50 | ``` 51 | -------------------------------------------------------------------------------- /docs/new-major-postgres.md: -------------------------------------------------------------------------------- 1 | PostgreSQL versions are managed in upstream nixpkgs. 2 | 3 | See this example PR to add a new version of PostgreSQL; this version is for 16 4 | beta3, but any version is roughly the same. In short, you need to: 5 | 6 | - Add a new version and hash 7 | - Possibly patch the source code for minor refactorings 8 | - In this example, an old patch had to be rewritten because a function was 9 | split into two different functions; the patch is functionally equivalent but 10 | textually different 11 | - Add the changes to `all-packages.nix` 12 | - Integrate inside the CI and get code review 13 | - Run `nix flake update` to get a new version, once it's ready 14 | 15 | https://github.com/NixOS/nixpkgs/pull/249030 16 | 17 | ## Adding the major version to this repository 18 | 19 | It isn't well abstracted, unfortunately. In short: look for the strings `14` and 20 | `15` under `flake.nix` and `tools/`. More specifically: 21 | 22 | - Add `psql_XX` to `basePackages` in `flake.nix` 23 | - Ditto with `checks` in `flake.nix` 24 | - Modify the tools under `tools/` to understand the new major version 25 | - Make sure the CI is integrated under the GitHub Actions. 26 | 27 | The third step and fourth steps are the most annoying, really. The first two are 28 | easy and by that point you can run `nix flake check` in order to test the build, 29 | at least. 30 | 31 | ## Other notes 32 | 33 | See also issue [#6](https://github.com/supabase/nix-postgres/issues/6), which 34 | would make it possible to define PostgreSQL versions inside this repository. 35 | -------------------------------------------------------------------------------- /docs/nix-overlays.md: -------------------------------------------------------------------------------- 1 | Overlays are a feature of Nixpkgs that allow you to: 2 | 3 | - Add new packages with new names to the namespace _without_ modifying upstream 4 | - For example, if there is a package `foobar`, you might add `foobar-1_2_3` to 5 | add a specific version for backwards compatibility 6 | - Globally override _existing_ package names, in terms of other packages. 7 | - For example, if you want to globally override a package to enable a 8 | disabled-by-default feature. 9 | 10 | First, you need to define a file for the overlay under 11 | [overlays/](../overlays/), and then import it in `flake.nix`. There is an 12 | example pull request in 13 | [#14](https://github.com/supabase/nix-postgres/issues/14) for this; an overlay 14 | typically looks like this: 15 | 16 | ``` 17 | final: prev: { 18 | gdal = prev.gdalMinimal; 19 | } 20 | ``` 21 | 22 | This says "globally override `gdal` with a different version, named 23 | `gdalMinimal`". In this case `gdalMinimal` is a build with less features 24 | enabled. 25 | 26 | The most important part is that there is an equation of the form `lhs = rhs;` 27 | — if the `lhs` refers to an existing name, it's overwritten. If it refers 28 | to a new name, it's introduced. Overwriting an existing name acts as if you 29 | changed the files upstream: so the above example _globally_ overrides GDAL for 30 | anything that depends on it. 31 | 32 | The names `final` and `prev` are used to refer to packages in terms of other 33 | overlays. For more information about this, see the 34 | [NixOS Wiki Page for Overlays](https://nixos.wiki/wiki/Overlays). 35 | -------------------------------------------------------------------------------- /docs/receipt-files.md: -------------------------------------------------------------------------------- 1 | Every time you run `nix build` on this repository to build PostgreSQL, the 2 | installation directory comes with a _receipt_ file that tells you what's inside 3 | of it. Primarily, this tells you: 4 | 5 | - The version of PostgreSQL, 6 | - The installed extensions, and 7 | - The version of nixpkgs. 8 | 9 | The intent of the receipt file is to provide a mechanism for tooling to 10 | understand installation directories and provide things like upgrade paths or 11 | upgrade mechanisms. 12 | 13 | ## Example receipt 14 | 15 | For example: 16 | 17 | ``` 18 | nix build .#psql_15/bin 19 | ``` 20 | 21 | ``` 22 | austin@GANON:~/work/nix-postgres$ nix build .#psql_15/bin 23 | austin@GANON:~/work/nix-postgres$ ls result 24 | bin include lib receipt.json share 25 | ``` 26 | 27 | The receipt is in JSON format, under `receipt.json`. Here's an example of what 28 | it would look like: 29 | 30 | ```json 31 | { 32 | "extensions": [ 33 | { 34 | "name": "pgsql-http", 35 | "version": "1.5.0" 36 | }, 37 | { 38 | "name": "pg_plan_filter", 39 | "version": "unstable-2021-09-23" 40 | }, 41 | { 42 | "name": "pg_net", 43 | "version": "0.7.2" 44 | }, 45 | { 46 | "name": "pg_hashids", 47 | "version": "unstable-2022-09-17" 48 | }, 49 | { 50 | "name": "pgsodium", 51 | "version": "3.1.8" 52 | }, 53 | { 54 | "name": "pg_graphql", 55 | "version": "unstable-2023-08-01" 56 | }, 57 | { 58 | "name": "pg_stat_monitor", 59 | "version": "1.0.1" 60 | }, 61 | { 62 | "name": "pg_jsonschema", 63 | "version": "unstable-2023-07-23" 64 | }, 65 | { 66 | "name": "vault", 67 | "version": "0.2.9" 68 | }, 69 | { 70 | "name": "hypopg", 71 | "version": "1.3.1" 72 | }, 73 | { 74 | "name": "pg_tle", 75 | "version": "1.0.4" 76 | }, 77 | { 78 | "name": "supabase-wrappers", 79 | "version": "unstable-2023-07-31" 80 | }, 81 | { 82 | "name": "supautils", 83 | "version": "1.7.3" 84 | } 85 | ], 86 | "nixpkgs": { 87 | "extensions": [ 88 | { 89 | "name": "postgis", 90 | "version": "3.3.3" 91 | }, 92 | { 93 | "name": "pgrouting", 94 | "version": "3.5.0" 95 | }, 96 | { 97 | "name": "pgtap", 98 | "version": "1.2.0" 99 | }, 100 | { 101 | "name": "pg_cron", 102 | "version": "1.5.2" 103 | }, 104 | { 105 | "name": "pgaudit", 106 | "version": "1.7.0" 107 | }, 108 | { 109 | "name": "pgjwt", 110 | "version": "unstable-2021-11-13" 111 | }, 112 | { 113 | "name": "plpgsql_check", 114 | "version": "2.3.4" 115 | }, 116 | { 117 | "name": "pg-safeupdate", 118 | "version": "1.4" 119 | }, 120 | { 121 | "name": "timescaledb", 122 | "version": "2.11.1" 123 | }, 124 | { 125 | "name": "wal2json", 126 | "version": "2.5" 127 | }, 128 | { 129 | "name": "plv8", 130 | "version": "3.1.5" 131 | }, 132 | { 133 | "name": "rum", 134 | "version": "1.3.13" 135 | }, 136 | { 137 | "name": "pgvector", 138 | "version": "0.4.4" 139 | }, 140 | { 141 | "name": "pg_repack", 142 | "version": "1.4.8" 143 | }, 144 | { 145 | "name": "pgroonga", 146 | "version": "3.0.8" 147 | } 148 | ], 149 | "revision": "750fc50bfd132a44972aa15bb21937ae26303bc4" 150 | }, 151 | "psql-version": "15.3", 152 | "receipt-version": "1", 153 | "revision": "vcs=d250647+20230814" 154 | } 155 | ``` 156 | -------------------------------------------------------------------------------- /docs/references.md: -------------------------------------------------------------------------------- 1 | Nix references and other useful tools: 2 | 3 | - **Zero to Nix**: Start here to get your feet wet with how Nix works, and how 4 | to use Nixpkgs: https://zero-to-nix.com/ 5 | - `nix-installer`: My recommended way to install Nix 6 | - https://github.com/DeterminateSystems/nix-installer 7 | - Nix manual https://nixos.org/manual/nix/stable/ 8 | - Useful primarily for option and command references 9 | - Flake schema reference https://nixos.wiki/wiki/Flakes 10 | - Useful to know what `flake.nix` is referring to 11 | - Example pull requests for this repo: 12 | - Adding smoke tests for an extension: 13 | https://github.com/supabase/nix-postgres/pull/2 14 | - Extension smoke tests, part 2: 15 | https://github.com/supabase/nix-postgres/pull/3 16 | - Adding an extension and a smoke test at once: 17 | https://github.com/supabase/nix-postgres/pull/4/files 18 | - Updating an extension to trunk: 19 | https://github.com/supabase/nix-postgres/pull/7 20 | - Updating an extension to the latest release: 21 | https://github.com/supabase/nix-postgres/pull/9 22 | - Contributing to [nixpkgs](https://github.com/nixos/nixpkgs) 23 | - Adding a PGRX-powered extension: 24 | https://github.com/NixOS/nixpkgs/pull/246803 25 | - Adding a normal extension: https://github.com/NixOS/nixpkgs/pull/249000 26 | - Adding new PostgreSQL versions: https://github.com/NixOS/nixpkgs/pull/249030 27 | - NixOS Discourse: https://discourse.nixos.org/ 28 | - Useful for community feedback, guidance, and help 29 | - `nix-update`: https://github.com/Mic92/nix-update 30 | - Used in this repository to help update extensions 31 | - pgTAP for testing: https://pgtap.org/documentation.html 32 | -------------------------------------------------------------------------------- /docs/start-client-server.md: -------------------------------------------------------------------------------- 1 | ## Running the server 2 | 3 | If you want to run a postgres server, just do this from the root of the 4 | repository: 5 | 6 | ``` 7 | nix run .#start-server 14 8 | ``` 9 | 10 | Replace the `14` with a `15`, and you'll be using a different version. Optionally you can specify a second argument for the port. 11 | 12 | You likely have a running postgres, so to not cause a conflict, this uses port 5435 by default. 13 | 14 | Actually, you don't even need the repository. You can do this from arbitrary 15 | directories, if the left-hand side of the hash character (`.` in this case) is a 16 | valid "flake reference": 17 | 18 | ``` 19 | # from any arbitrary directory 20 | nix run github:supabase/nix-postgres#start-server 14 21 | ``` 22 | 23 | ### Arbitrary versions at arbitrary git revisions 24 | 25 | Let's say you want to use a PostgreSQL build from a specific version of the 26 | repository. You can change the syntax of the above to use _any_ version of the 27 | repository, at any time, by adding the commit hash after the repository name: 28 | 29 | ``` 30 | # use postgresql 15 build at commit a9989d4800dd6038827afed27456f19ba4b2ae0a 31 | nix run github:supabase/nix-postgres/a9989d4800dd6038827afed27456f19ba4b2ae0a#start-server 15 32 | ``` 33 | 34 | ## Running the client 35 | 36 | All of the same rules apply, but try using `start-client` on the right-hand side 37 | of the hash character, instead. For example: 38 | 39 | ``` 40 | nix run github:supabase/nix-postgres#start-server 14 & 41 | sleep 5 42 | nix run github:supabase/nix-postgres#start-client 15 43 | ``` 44 | 45 | ## Running a server replica 46 | 47 | To start a replica you can use the `start-postgres-replica` command. 48 | 49 | - first argument: the master version 50 | - second argument: the master port 51 | - third argument: the replica server port 52 | 53 | First start a server and a couple of replicas: 54 | 55 | ``` 56 | $ start-postgres-server 15 5435 57 | 58 | $ start-postgres-replica 15 5439 59 | 60 | $ start-postgres-replica 15 5440 61 | ``` 62 | 63 | Now check the master server: 64 | 65 | ``` 66 | $ start-postgres-client 15 5435 67 | ``` 68 | 69 | ```sql 70 | SELECT client_addr, state 71 | FROM pg_stat_replication; 72 | client_addr | state 73 | -------------+----------- 74 | ::1 | streaming 75 | ::1 | streaming 76 | (2 rows) 77 | 78 | create table items as select x::int from generate_series(1,100) x; 79 | ``` 80 | 81 | And a replica: 82 | 83 | ``` 84 | $ start-postgres-client 15 5439 85 | ``` 86 | 87 | ```sql 88 | select count(*) from items; 89 | count 90 | ------- 91 | 100 92 | (1 row) 93 | ``` 94 | -------------------------------------------------------------------------------- /docs/start-here.md: -------------------------------------------------------------------------------- 1 | Let's go ahead and install Nix. To do that, we'll use the 2 | **[nix-installer tool]** by Determinate Systems. This works on many platforms, 3 | but most importantly it works on **aarch64 Linux** and **x86_64 Linux**. Use the 4 | following command in your shell, **it should work on any Linux distro of your 5 | choice**: 6 | 7 | [nix-installer tool]: https://github.com/DeterminateSystems/nix-installer 8 | 9 | ```bash 10 | curl \ 11 | --proto '=https' --tlsv1.2 \ 12 | -sSf -L https://install.determinate.systems/nix \ 13 | | sh -s -- install 14 | ``` 15 | 16 | After you do this, **you must log in and log back out of your desktop 17 | environment** to get a new login session. This is so that your shell can have 18 | the Nix tools installed on `$PATH` and so that your user shell can see some 19 | extra settings. 20 | 21 | You should now be able to do something like the following; try running these 22 | same commands on your machine: 23 | 24 | ``` 25 | $ nix --version 26 | nix (Nix) 2.16.1 27 | ``` 28 | 29 | ``` 30 | $ nix run nixpkgs#nix-info -- -m 31 | - system: `"x86_64-linux"` 32 | - host os: `Linux 5.15.90.1-microsoft-standard-WSL2, Ubuntu, 22.04.2 LTS (Jammy Jellyfish), nobuild` 33 | - multi-user?: `yes` 34 | - sandbox: `yes` 35 | - version: `nix-env (Nix) 2.16.1` 36 | - channels(root): `"nixpkgs"` 37 | - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs` 38 | ``` 39 | 40 | If the above worked, you're now cooking with gas! 41 | 42 | > _**NOTE**_: While there is an upstream tool to install Nix, written in Bash, 43 | > we use the Determinate Systems installer — which will hopefully replace the 44 | > original — because it's faster, and takes care of several extra edge cases 45 | > that the original one couldn't handle, and makes several changes to the 46 | > default installed configuration to make things more user friendly. Determinate 47 | > Systems is staffed by many long-time Nix contributors and the creator of Nix, 48 | > and is trustworthy. 49 | 50 | ## Do some fun stuff 51 | 52 | One of the best things about Nix that requires _very little_ knowledge of it is 53 | that it lets you install the latest and greatest versions of many tools _on any 54 | Linux distribution_. We'll explain more about that later on. But just as a few 55 | examples: 56 | 57 | - **Q**: I want the latest version of Deno. Can we get that? 58 | - **A**: `nix profile install nixpkgs#deno`, and you're done! 59 | 60 | 61 | 62 | - **Q**: What about HTTPie? A nice Python application? 63 | - **A**: Same idea: `nix profile install nixpkgs#httpie` 64 | 65 | 66 | 67 | - **Q**: What about my favorite Rust applications, like ripgrep and bat? 68 | - **A.1**: `nix profile install nixpkgs#ripgrep` 69 | - **A.2**: `nix profile install nixpkgs#bat` 70 | - **A.3**: And yes, you also have exa, fd, hyperfine, and more! 71 | -------------------------------------------------------------------------------- /docs/update-extension.md: -------------------------------------------------------------------------------- 1 | Extensions are managed in two places: upstream, and this repository. Therefore 2 | there are two update strategies available. 3 | 4 | ## Updating extensions in this repository 5 | 6 | Assuming that you run `nix develop` to get a development shell, there is a tool 7 | named `nix-update` that is available: 8 | 9 | ``` 10 | austin@GANON:~/work/nix-postgres$ which nix-update 11 | /nix/store/2jyq6h0ln3f5vlgz2had80l2crdkjmdy-nix-update-0.19.2/bin/nix-update 12 | ``` 13 | 14 | Run something like this to update the extension `pg_foobar`: 15 | 16 | ```bash 17 | nix-update --flake psql_15/exts/pg_foobar 18 | git commit -asm "pg_foobar: update to latest release" 19 | ``` 20 | 21 | It doesn't matter if you use `psql_14` or `psql_15` here, because `nix-update` 22 | will look at the _file_ that extension is defined in, in order to update the 23 | source code. 24 | 25 | ## Updating extensions upstream 26 | 27 | You can use the same tool, `nix-update`, to do this. If you're sitting in the 28 | root of the nixpkgs repository, try this: 29 | 30 | ``` 31 | nix run nixpkgs#nix-update -- postgresqlPackages.pg_foobar 32 | git commit -asm "pg_foobar: update to latest release" 33 | ``` 34 | 35 | Because the tool may not be in your shell by default, we use `nix run` to run it 36 | for us. 37 | 38 | The full list of available names to substitute for `pg_foobar` is available in 39 | the file 40 | [pkgs/servers/sql/postgresql/packages.nix](https://github.com/NixOS/nixpkgs/blob/master/pkgs/servers/sql/postgresql/packages.nix) 41 | 42 | ### Updating the Nixpkgs snapshot 43 | 44 | Now that your change is merged upstream, you need to update the version of 45 | `nixpkgs` used in this repository: 46 | 47 | - Check the `nixpkgs-unstable` branch: 48 | https://github.com/nixos/nixpkgs/tree/nixpkgs-unstable 49 | - Wait until your commit is fast-forwarded and part of that branch 50 | - Run `nix flake update` 51 | 52 | ## Release tags versus latest trunk 53 | 54 | By default, `nix-update` will update an expression to the latest tagged release. 55 | No extra arguments are necessary. You can specify an exact release tag using the 56 | `--version=` flag. Using the syntax `--version=branch` means "update to the 57 | latest version on the default branch." 58 | 59 | ## Example PRs 60 | 61 | - https://github.com/supabase/nix-postgres/pull/9 updates `pg_net` to the latest 62 | release 63 | - https://github.com/supabase/nix-postgres/pull/7 updates `pg_hashids` to the 64 | latest `trunk` tip 65 | 66 | ## Other notes 67 | 68 | See issue [#5](https://github.com/supabase/nix-postgres/issues/5) for more 69 | information about extension management. 70 | -------------------------------------------------------------------------------- /docs/use-direnv.md: -------------------------------------------------------------------------------- 1 | Have you ever used a tool like `pip`'s `bin/activate` script, or `rbenv`? These 2 | tools populate your shell environment with the right tools and scripts and 3 | dependencies (e.g. `PYTHONPATH`) to run your software. 4 | 5 | What if I told you there was a magical tool that worked like that, and could do 6 | it for arbitrary languages and tools? 7 | 8 | That tool is called **[direnv](https://direnv.net)**. 9 | 10 | ## Install direnv and use it in your shell 11 | 12 | First, install `direnv`: 13 | 14 | ``` 15 | $ nix profile install nixpkgs#direnv 16 | ``` 17 | 18 | ``` 19 | $ which direnv 20 | /home/austin/.nix-profile/bin/direnv 21 | ``` 22 | 23 | Now, you need to activate it in your shell by hooking into it. If you're using 24 | **Bash**, try putting this in your `.bashrc` and starting up a new interactive 25 | shell: 26 | 27 | ``` 28 | eval "$(direnv hook bash)" 29 | ``` 30 | 31 | Not using bash? Check the 32 | [direnv hook documentation](https://direnv.net/docs/hook.html) for more. 33 | 34 | ## Set up `nix-postgres` 35 | 36 | Let's go back to the `nix-postgres` source code. 37 | 38 | ``` 39 | cd $HOME/tmp-nix-postgres 40 | ``` 41 | 42 | Now, normally, direnv is going to look for a file called `.envrc` and load that 43 | if it exists. But to be polite, we don't do that by default; we keep a file 44 | named `.envrc.recommended` in the repository instead, and encourage people to do 45 | this: 46 | 47 | ``` 48 | echo "source_env .envrc.recommended" >> .envrc 49 | ``` 50 | 51 | All this says is "Load the code from `.envrc.recommended` directly", just like a 52 | normal bash script using `source`. The idea of this pattern is to allow users to 53 | have their own customized `.envrc` and piggyback on the committed code for 54 | utility — and `.envrc` is `.gitignore`'d, so you can put e.g. secret 55 | tokens inside without fear of committing them. 56 | 57 | Run the above command, and then... 58 | 59 | ## What just happened? 60 | 61 | Oops, a big red error appeared? 62 | 63 | ``` 64 | $ echo "source_env .envrc.recommended" >> .envrc 65 | direnv: error /home/austin/work/nix-postgres/.envrc is blocked. Run `direnv allow` to approve its content 66 | ``` 67 | 68 | What happened? By default, as a security measure, `direnv` _does not_ load or 69 | execute any code from an `.envrc` file, and instead it MUST be allowed 70 | explicitly. 71 | 72 | ## `direnv allow` 73 | 74 | Our `.envrc.recommended` file will integrate with Nix directly. So run 75 | `direnv allow`, and you'll suddenly see the following: 76 | 77 | ``` 78 | $ direnv allow 79 | direnv: loading ~/work/nix-postgres/.envrc 80 | direnv: loading ~/work/nix-postgres/.envrc.recommended 81 | direnv: loading https://raw.githubusercontent.com/nix-community/nix-direnv/2.3.0/direnvrc (sha256-Dmd+j63L84wuzgyjITIfSxSD57Tx7v51DMxVZOsiUD8=) 82 | direnv: using flake 83 | direnv: nix-direnv: renewed cache 84 | direnv: export +AR +AS +CC +CONFIG_SHELL +CXX +DETERMINISTIC_BUILD +HOST_PATH +IN_NIX_SHELL +LD +NIX_BINTOOLS +NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu +NIX_BUILD_CORES +NIX_CC +NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu +NIX_CFLAGS_COMPILE +NIX_ENFORCE_NO_NATIVE +NIX_HARDENING_ENABLE +NIX_LDFLAGS +NIX_STORE +NM +OBJCOPY +OBJDUMP +PYTHONHASHSEED +PYTHONNOUSERSITE +PYTHONPATH +RANLIB +READELF +SIZE +SOURCE_DATE_EPOCH +STRINGS +STRIP +_PYTHON_HOST_PLATFORM +_PYTHON_SYSCONFIGDATA_NAME +__structuredAttrs +buildInputs +buildPhase +builder +cmakeFlags +configureFlags +depsBuildBuild +depsBuildBuildPropagated +depsBuildTarget +depsBuildTargetPropagated +depsHostHost +depsHostHostPropagated +depsTargetTarget +depsTargetTargetPropagated +doCheck +doInstallCheck +dontAddDisableDepTrack +mesonFlags +name +nativeBuildInputs +out +outputs +patches +phases +preferLocalBuild +propagatedBuildInputs +propagatedNativeBuildInputs +shell +shellHook +stdenv +strictDeps +system ~PATH ~XDG_DATA_DIRS 85 | ``` 86 | 87 | What just happened is that we populated the ambient shell environment with tools 88 | specified inside of `flake.nix` — we'll cover Flakes later. But for now, 89 | your tools are provisioned! 90 | 91 | ## Run `just` to build the code 92 | 93 | Previously, we needed to run `nix develop` to get access to the `just` command. 94 | No longer! It's now available in your shell: 95 | 96 | ``` 97 | $ which just 98 | /nix/store/1di6nb4qsv86907l3xarw4llzdss2g89-just-1.14.0/bin/just 99 | ``` 100 | 101 | ``` 102 | $ just b 103 | ... 104 | ``` 105 | 106 | Viola, done! 107 | 108 | ## Go back `$HOME` and return again 109 | 110 | When you `cd ~`, direnv will automatically unload the `.envrc` file for you: 111 | 112 | ``` 113 | $ cd ~ 114 | direnv: unloading 115 | ``` 116 | 117 | Now, `just` is no longer available: 118 | 119 | ``` 120 | $ just build-all 121 | just: command not found 122 | ``` 123 | 124 | And if you go back, it is! 125 | 126 | ``` 127 | $ cd $HOME/nix-postgres 128 | direnv: loading ~/work/nix-postgres/.envrc 129 | direnv: loading ~/work/nix-postgres/.envrc.recommended 130 | direnv: loading https://raw.githubusercontent.com/nix-community/nix-direnv/2.3.0/direnvrc (sha256-Dmd+j63L84wuzgyjITIfSxSD57Tx7v51DMxVZOsiUD8=) 131 | direnv: using flake 132 | ... 133 | ``` 134 | 135 | ``` 136 | $ just build-all 137 | ... 138 | ``` 139 | 140 | ## The power of `direnv` 141 | 142 | `direnv` with Nix is a frighteningly good development combination for many 143 | purposes. This is its main power: you can use it to create on-demand developer 144 | shells for any language, tool, or environment, and all you need to do is `cd` to 145 | the right directory. 146 | 147 | This is the power of `direnv`: your projects always, on demand, will have the 148 | right tools configured and available, no matter if you last worked on them a day 149 | ago or a year ago, or it was done by your teammate, or you have a brand new 150 | computer that you've never programmed on. 151 | -------------------------------------------------------------------------------- /ext/0001-build-Allow-using-V8-from-system.patch: -------------------------------------------------------------------------------- 1 | diff --git a/Makefile b/Makefile 2 | index 38879cc..6e78eeb 100644 3 | --- a/Makefile 4 | +++ b/Makefile 5 | @@ -20,6 +20,7 @@ OBJS = $(SRCS:.cc=.o) 6 | MODULE_big = plv8-$(PLV8_VERSION) 7 | EXTENSION = plv8 8 | PLV8_DATA = plv8.control plv8--$(PLV8_VERSION).sql $(wildcard upgrade/*.sql) 9 | +USE_SYSTEM_V8 = 0 10 | 11 | 12 | # Platform detection 13 | @@ -41,6 +42,7 @@ PGXS := $(shell $(PG_CONFIG) --pgxs) 14 | PG_VERSION_NUM := $(shell cat `$(PG_CONFIG) --includedir-server`/pg_config*.h \ 15 | | perl -ne 'print $$1 and exit if /PG_VERSION_NUM\s+(\d+)/') 16 | 17 | +ifeq ($(USE_SYSTEM_V8),0) 18 | AUTOV8_DIR = build/v8 19 | AUTOV8_OUT = build/v8/out.gn/obj 20 | AUTOV8_STATIC_LIBS = -lv8_libplatform -lv8_libbase 21 | @@ -66,6 +68,7 @@ v8: 22 | make -f Makefiles/Makefile.macos v8 23 | endif 24 | endif 25 | +endif 26 | 27 | # enable direct jsonb conversion by default 28 | CCFLAGS += -DJSONB_DIRECT_CONVERSION 29 | @@ -83,6 +86,7 @@ ifdef BIGINT_GRACEFUL 30 | endif 31 | 32 | 33 | +ifeq ($(USE_SYSTEM_V8),0) 34 | # We're gonna build static link. Rip it out after include Makefile 35 | SHLIB_LINK := $(filter-out -lv8, $(SHLIB_LINK)) 36 | 37 | @@ -101,6 +105,7 @@ else 38 | SHLIB_LINK += -lrt -std=c++14 39 | endif 40 | endif 41 | +endif 42 | 43 | DATA = $(PLV8_DATA) 44 | ifndef DISABLE_DIALECT 45 | -- 46 | 2.37.3 47 | -------------------------------------------------------------------------------- /ext/citus.nix: -------------------------------------------------------------------------------- 1 | { lib, curl, lz4, zstd, krb5, icu, stdenv, fetchFromGitHub, postgresql }: 2 | #FIXME we have decided deactivate this for now, as it is not used in production 3 | # if we decide to use it later we may need to look at this documentation 4 | # https://docs.citusdata.com/en/stable/admin_guide/upgrading_citus.html#upgrading-postgresql-version-from-15-to-16 5 | stdenv.mkDerivation rec { 6 | pname = "citus"; 7 | version = "12.1.2"; 8 | 9 | buildInputs = [ curl lz4 zstd krb5 icu.dev postgresql ]; 10 | 11 | src = fetchFromGitHub { 12 | owner = "citusdata"; 13 | repo = pname; 14 | rev = "refs/tags/v${version}"; 15 | hash = "sha256-0uYNMLAYigtGlDRvOEkQeC5i58QfXcdSVjTQwWVFX+8="; 16 | }; 17 | 18 | installPhase = '' 19 | mkdir -p $out/{lib,share/postgresql/extension} 20 | 21 | cp src/backend/columnar/citus_columnar.so $out/lib 22 | cp src/backend/columnar/citus_columnar.control $out/share/postgresql/extension 23 | cp src/backend/columnar/build/sql/*.sql $out/share/postgresql/extension 24 | 25 | cp src/backend/distributed/citus.so $out/lib 26 | cp src/backend/distributed/citus.control $out/share/postgresql/extension 27 | cp src/backend/distributed/build/sql/*.sql $out/share/postgresql/extension 28 | ''; 29 | 30 | meta = with lib; { 31 | description = "Distributed PostgreSQL as an extension"; 32 | homepage = "https://github.com/citusdata/${pname}"; 33 | maintainers = with maintainers; [ olirice ]; 34 | platforms = postgresql.meta.platforms; 35 | license = licenses.agpl3Plus; 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /ext/hypopg.nix: -------------------------------------------------------------------------------- 1 | { lib, stdenv, fetchFromGitHub, postgresql }: 2 | 3 | stdenv.mkDerivation rec { 4 | pname = "hypopg"; 5 | version = "1.3.1"; 6 | 7 | buildInputs = [ postgresql ]; 8 | 9 | src = fetchFromGitHub { 10 | owner = "HypoPG"; 11 | repo = pname; 12 | rev = "refs/tags/${version}"; 13 | hash = "sha256-AIBXy+LxyHUo+1hd8gQTwaBdFiTEzKaCVc4cx5tZgME="; 14 | }; 15 | 16 | installPhase = '' 17 | mkdir -p $out/{lib,share/postgresql/extension} 18 | 19 | cp *.so $out/lib 20 | cp *.sql $out/share/postgresql/extension 21 | cp *.control $out/share/postgresql/extension 22 | ''; 23 | 24 | meta = with lib; { 25 | description = "Hypothetical Indexes for PostgreSQL"; 26 | homepage = "https://github.com/HypoPG/${pname}"; 27 | maintainers = with maintainers; [ thoughtpolice ]; 28 | platforms = postgresql.meta.platforms; 29 | license = licenses.postgresql; 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /ext/orioledb.nix: -------------------------------------------------------------------------------- 1 | {lib, stdenv, fetchFromGitHub, curl, libkrb5, postgresql, python3, openssl}: 2 | 3 | stdenv.mkDerivation rec { 4 | pname = "orioledb"; 5 | name = pname; 6 | src = fetchFromGitHub { 7 | owner = "orioledb"; 8 | repo = "orioledb"; 9 | rev = "main"; 10 | sha256 = "sha256-QbDp9S8JXO66sfaHZIQ3wFCVRxsAaaNSRgC6hvL3EKY="; 11 | }; 12 | version = "patches16_23"; 13 | buildInputs = [ curl libkrb5 postgresql python3 openssl ]; 14 | buildPhase = "make USE_PGXS=1 ORIOLEDB_PATCHSET_VERSION=23"; 15 | installPhase = '' 16 | runHook preInstall 17 | mkdir -p $out/{lib,share/postgresql/extension} 18 | 19 | cp *.so $out/lib 20 | cp *.sql $out/share/postgresql/extension 21 | cp *.control $out/share/postgresql/extension 22 | 23 | runHook postInstall 24 | ''; 25 | doCheck = true; 26 | meta = with lib; { 27 | description = "orioledb"; 28 | maintainers = with maintainers; [ samrose ]; 29 | platforms = postgresql.meta.platforms; 30 | license = licenses.postgresql; 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /ext/pg_graphql.nix: -------------------------------------------------------------------------------- 1 | { lib, stdenv, fetchFromGitHub, postgresql, buildPgrxExtension }: 2 | 3 | buildPgrxExtension rec { 4 | pname = "pg_graphql"; 5 | version = "unstable-1.5.0"; 6 | inherit postgresql; 7 | 8 | src = fetchFromGitHub { 9 | owner = "supabase"; 10 | repo = pname; 11 | rev = "v1.5.0"; 12 | hash = "sha256-28ANRZyF22qF2YAxNAAkPfGOM3+xiO6IHdXsTp0CTQE="; 13 | }; 14 | 15 | cargoHash = "sha256-CUiGs0m9aUeqjpdPyOSjz91cP7TT6kjJqnw7ImGnQuo="; 16 | 17 | # FIXME (aseipp): disable the tests since they try to install .control 18 | # files into the wrong spot, aside from that the one main test seems 19 | # to work, though 20 | doCheck = false; 21 | 22 | meta = with lib; { 23 | description = "GraphQL support for PostreSQL"; 24 | homepage = "https://github.com/supabase/${pname}"; 25 | maintainers = with maintainers; [ thoughtpolice ]; 26 | platforms = postgresql.meta.platforms; 27 | license = licenses.postgresql; 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /ext/pg_hashids.nix: -------------------------------------------------------------------------------- 1 | { lib, stdenv, fetchFromGitHub, postgresql }: 2 | 3 | stdenv.mkDerivation rec { 4 | pname = "pg_hashids"; 5 | version = "unstable-2022-09-17"; 6 | 7 | buildInputs = [ postgresql ]; 8 | 9 | src = fetchFromGitHub { 10 | owner = "iCyberon"; 11 | repo = pname; 12 | rev = "cd0e1b31d52b394a0df64079406a14a4f7387cd6"; 13 | hash = "sha256-Nmb7XLqQflYZfqj0yrewfb1Hl5YgEB5wfjBunPwIuOU="; 14 | }; 15 | 16 | installPhase = '' 17 | mkdir -p $out/{lib,share/postgresql/extension} 18 | 19 | cp *.so $out/lib 20 | cp *.sql $out/share/postgresql/extension 21 | cp *.control $out/share/postgresql/extension 22 | ''; 23 | 24 | meta = with lib; { 25 | description = "Generate short unique IDs in PostgreSQL"; 26 | homepage = "https://github.com/iCyberon/pg_hashids"; 27 | maintainers = with maintainers; [ thoughtpolice ]; 28 | platforms = postgresql.meta.platforms; 29 | license = licenses.postgresql; 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /ext/pg_jsonschema.nix: -------------------------------------------------------------------------------- 1 | { lib, stdenv, fetchFromGitHub, postgresql, buildPgrxExtension }: 2 | 3 | buildPgrxExtension rec { 4 | pname = "pg_jsonschema"; 5 | version = "unstable-v0.3.0"; 6 | inherit postgresql; 7 | 8 | src = fetchFromGitHub { 9 | owner = "supabase"; 10 | repo = pname; 11 | rev = "v0.3.0"; 12 | hash = "sha256-am6Ye+pOoAsOr9L4vJXw4iIOJ9x0VkUjqH6PdXMUZrk="; 13 | }; 14 | 15 | cargoHash = "sha256-tiiWzu/mTKL5ruvWn6IxrXVhVqS4LXzjfacdFT9rbOY="; 16 | 17 | # FIXME (aseipp): testsuite tries to write files into /nix/store; we'll have 18 | # to fix this a bit later. 19 | doCheck = false; 20 | 21 | meta = with lib; { 22 | description = "JSON Schema Validation for PostgreSQL"; 23 | homepage = "https://github.com/supabase/${pname}"; 24 | maintainers = with maintainers; [ thoughtpolice ]; 25 | platforms = postgresql.meta.platforms; 26 | license = licenses.postgresql; 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /ext/pg_net.nix: -------------------------------------------------------------------------------- 1 | { lib, stdenv, fetchFromGitHub, curl, postgresql }: 2 | 3 | stdenv.mkDerivation rec { 4 | pname = "pg_net"; 5 | version = "0.7.2"; 6 | 7 | buildInputs = [ curl postgresql ]; 8 | 9 | src = fetchFromGitHub { 10 | owner = "supabase"; 11 | repo = pname; 12 | rev = "refs/tags/v${version}"; 13 | hash = "sha256-9Ki3fyinHTYrfckxAY0fCTlzJd9l+n7QRUV7mIWrqmc="; 14 | }; 15 | 16 | installPhase = '' 17 | mkdir -p $out/{lib,share/postgresql/extension} 18 | 19 | cp *.so $out/lib 20 | cp sql/*.sql $out/share/postgresql/extension 21 | cp *.control $out/share/postgresql/extension 22 | ''; 23 | 24 | meta = with lib; { 25 | description = "Async networking for Postgres"; 26 | homepage = "https://github.com/supabase/pg_net"; 27 | maintainers = with maintainers; [ thoughtpolice ]; 28 | platforms = postgresql.meta.platforms; 29 | license = licenses.postgresql; 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /ext/pg_plan_filter.nix: -------------------------------------------------------------------------------- 1 | { lib, stdenv, fetchFromGitHub, postgresql }: 2 | 3 | stdenv.mkDerivation rec { 4 | pname = "pg_plan_filter"; 5 | version = "unstable-2021-09-23"; 6 | 7 | buildInputs = [ postgresql ]; 8 | 9 | src = fetchFromGitHub { 10 | owner = "pgexperts"; 11 | repo = pname; 12 | rev = "5081a7b5cb890876e67d8e7486b6a64c38c9a492"; 13 | hash = "sha256-YNeIfmccT/DtOrwDmpYFCuV2/P6k3Zj23VWBDkOh6sw="; 14 | }; 15 | 16 | installPhase = '' 17 | mkdir -p $out/{lib,share/postgresql/extension} 18 | 19 | cp *.so $out/lib 20 | cp *.sql $out/share/postgresql/extension 21 | ''; 22 | 23 | meta = with lib; { 24 | description = "Filter PostgreSQL statements by execution plans"; 25 | homepage = "https://github.com/pgexperts/${pname}"; 26 | maintainers = with maintainers; [ thoughtpolice ]; 27 | platforms = postgresql.meta.platforms; 28 | license = licenses.postgresql; 29 | }; 30 | } 31 | -------------------------------------------------------------------------------- /ext/pg_stat_monitor.nix: -------------------------------------------------------------------------------- 1 | { lib, stdenv, fetchFromGitHub, postgresql }: 2 | 3 | let 4 | # NOTE (aseipp): the 1.x series of pg_stat_monitor has some non-standard and 5 | # weird build logic (Percona projects in general seem to have their own 6 | # strange build harness) where it will try to pick the right .sql file to 7 | # install into the extension dir based on the postgresql major version. for 8 | # our purposes, we only need to support v13 and v14+, so just replicate this 9 | # logic from the makefile and pick the right file here. 10 | # 11 | # this seems to all be cleaned up in version 2.0 of the extension, so ideally 12 | # we could upgrade to it later on and nuke this. 13 | # sqlFilename = if lib.versionOlder postgresql.version "14" 14 | # then "pg_stat_monitor--1.0.13.sql.in" 15 | # else "pg_stat_monitor--1.0.14.sql.in"; 16 | 17 | in 18 | stdenv.mkDerivation rec { 19 | pname = "pg_stat_monitor"; 20 | version = "2.0.4"; 21 | 22 | buildInputs = [ postgresql ]; 23 | 24 | src = fetchFromGitHub { 25 | owner = "percona"; 26 | repo = pname; 27 | rev = "refs/tags/${version}"; 28 | hash = "sha256-57Ji/KltIHNf81OxT0+4JIDqydST5RKMqrybNBZochg="; 29 | }; 30 | 31 | makeFlags = [ "USE_PGXS=1" ]; 32 | 33 | installPhase = '' 34 | mkdir -p $out/{lib,share/postgresql/extension} 35 | 36 | cp pg_stat_monitor--2.0.sql pg_stat_monitor--1.0--2.0.sql 37 | 38 | cp *.so $out/lib 39 | cp *.sql $out/share/postgresql/extension 40 | cp *.control $out/share/postgresql/extension 41 | ''; 42 | 43 | meta = with lib; { 44 | description = "Query Performance Monitoring Tool for PostgreSQL"; 45 | homepage = "https://github.com/percona/${pname}"; 46 | maintainers = with maintainers; [ thoughtpolice ]; 47 | platforms = postgresql.meta.platforms; 48 | license = licenses.postgresql; 49 | broken = lib.versionOlder postgresql.version "15"; 50 | }; 51 | } 52 | -------------------------------------------------------------------------------- /ext/pg_tle.nix: -------------------------------------------------------------------------------- 1 | { lib, stdenv, fetchFromGitHub, postgresql, flex }: 2 | 3 | stdenv.mkDerivation rec { 4 | pname = "pg_tle"; 5 | version = "1.0.4"; 6 | 7 | nativeBuildInputs = [ flex ]; 8 | buildInputs = [ postgresql ]; 9 | 10 | src = fetchFromGitHub { 11 | owner = "aws"; 12 | repo = pname; 13 | rev = "refs/tags/v${version}"; 14 | hash = "sha256-W/7pLy/27VatCdzUh1NZ4K2FRMD1erfHiFV2eY2x2W0="; 15 | }; 16 | 17 | makeFlags = [ "FLEX=flex" ]; 18 | 19 | installPhase = '' 20 | mkdir -p $out/{lib,share/postgresql/extension} 21 | 22 | cp *.so $out/lib 23 | cp *.sql $out/share/postgresql/extension 24 | cp *.control $out/share/postgresql/extension 25 | ''; 26 | 27 | meta = with lib; { 28 | description = "Framework for 'Trusted Language Extensions' in PostgreSQL"; 29 | homepage = "https://github.com/aws/${pname}"; 30 | maintainers = with maintainers; [ thoughtpolice ]; 31 | platforms = postgresql.meta.platforms; 32 | license = licenses.postgresql; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /ext/pgsodium.nix: -------------------------------------------------------------------------------- 1 | { lib, stdenv, fetchFromGitHub, libsodium, postgresql }: 2 | 3 | stdenv.mkDerivation rec { 4 | pname = "pgsodium"; 5 | version = "3.1.8"; 6 | 7 | buildInputs = [ libsodium postgresql ]; 8 | 9 | src = fetchFromGitHub { 10 | owner = "michelp"; 11 | repo = pname; 12 | rev = "refs/tags/v${version}"; 13 | hash = "sha256-j5F1PPdwfQRbV8XJ8Mloi8FvZF0MTl4eyIJcBYQy1E4="; 14 | }; 15 | 16 | installPhase = '' 17 | mkdir -p $out/{lib,share/postgresql/extension} 18 | 19 | cp *.so $out/lib 20 | cp sql/*.sql $out/share/postgresql/extension 21 | cp *.control $out/share/postgresql/extension 22 | ''; 23 | 24 | meta = with lib; { 25 | description = "Modern cryptography for PostgreSQL"; 26 | homepage = "https://github.com/michelp/${pname}"; 27 | maintainers = with maintainers; [ thoughtpolice ]; 28 | platforms = postgresql.meta.platforms; 29 | license = licenses.postgresql; 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /ext/pgsql-http.nix: -------------------------------------------------------------------------------- 1 | { lib, stdenv, fetchFromGitHub, curl, postgresql }: 2 | 3 | stdenv.mkDerivation rec { 4 | pname = "pgsql-http"; 5 | version = "1.6.0"; 6 | 7 | buildInputs = [ curl postgresql ]; 8 | 9 | src = fetchFromGitHub { 10 | owner = "pramsey"; 11 | repo = pname; 12 | rev = "refs/tags/v${version}"; 13 | hash = "sha256-CPHfx7vhWfxkXsoKTzyFuTt47BPMvzi/pi1leGcuD60="; 14 | }; 15 | 16 | installPhase = '' 17 | mkdir -p $out/{lib,share/postgresql/extension} 18 | 19 | cp *.so $out/lib 20 | cp *.sql $out/share/postgresql/extension 21 | cp *.control $out/share/postgresql/extension 22 | ''; 23 | 24 | meta = with lib; { 25 | description = "HTTP client for Postgres"; 26 | homepage = "https://github.com/pramsey/${pname}"; 27 | maintainers = with maintainers; [ thoughtpolice ]; 28 | platforms = postgresql.meta.platforms; 29 | license = licenses.postgresql; 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /ext/pgvector.nix: -------------------------------------------------------------------------------- 1 | { lib, stdenv, fetchFromGitHub, postgresql }: 2 | 3 | stdenv.mkDerivation rec { 4 | pname = "pgvector"; 5 | version = "0.5.1"; 6 | 7 | buildInputs = [ postgresql ]; 8 | 9 | src = fetchFromGitHub { 10 | owner = "pgvector"; 11 | repo = pname; 12 | rev = "refs/tags/v${version}"; 13 | hash = "sha256-ZNzq+dATZn9LUgeOczsaadr5hwdbt9y/+sAOPIdr77U="; 14 | }; 15 | 16 | installPhase = '' 17 | mkdir -p $out/{lib,share/postgresql/extension} 18 | 19 | cp *.so $out/lib 20 | cp sql/*.sql $out/share/postgresql/extension 21 | cp *.control $out/share/postgresql/extension 22 | ''; 23 | 24 | meta = with lib; { 25 | description = "Open-source vector similarity search for Postgres"; 26 | homepage = "https://github.com/${src.owner}/${src.repo}"; 27 | maintainers = with maintainers; [ olirice ]; 28 | platforms = postgresql.meta.platforms; 29 | license = licenses.postgresql; 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /ext/plv8.nix: -------------------------------------------------------------------------------- 1 | { stdenv 2 | , lib 3 | , fetchFromGitHub 4 | , v8 5 | , perl 6 | , postgresql 7 | # For test 8 | , runCommand 9 | , coreutils 10 | , gnugrep 11 | }: 12 | 13 | stdenv.mkDerivation (finalAttrs: { 14 | pname = "plv8"; 15 | # plv8 latest is https://github.com/plv8/plv8/releases/tag/v3.2.2 16 | # FIXME we need to increment this build toward 3.2.2 17 | # 3.1.7 is the highest version that can be built with pg 16 18 | version = "3.1.7"; 19 | 20 | src = fetchFromGitHub { 21 | owner = "plv8"; 22 | repo = "plv8"; 23 | rev = "v${finalAttrs.version}"; 24 | hash = "sha256-kTID3Zo3YwNZUno8kdQE7ihtiddsIAZNuBN91IKgaC4="; 25 | }; 26 | 27 | patches = [ 28 | # Allow building with system v8. 29 | # https://github.com/plv8/plv8/pull/505 (rejected) 30 | ./0001-build-Allow-using-V8-from-system.patch 31 | ]; 32 | 33 | nativeBuildInputs = [ 34 | perl 35 | ]; 36 | 37 | buildInputs = [ 38 | v8 39 | postgresql 40 | ]; 41 | 42 | buildFlags = [ "all" ]; 43 | 44 | makeFlags = [ 45 | # Nixpkgs build a v8 monolith instead of separate v8_libplatform. 46 | "USE_SYSTEM_V8=1" 47 | "SHLIB_LINK=-lv8" 48 | "V8_OUTDIR=${v8}/lib" 49 | ]; 50 | 51 | installFlags = [ 52 | # PGXS only supports installing to postgresql prefix so we need to redirect this 53 | "DESTDIR=${placeholder "out"}" 54 | ]; 55 | 56 | # No configure script. 57 | dontConfigure = true; 58 | 59 | postPatch = '' 60 | patchShebangs ./generate_upgrade.sh 61 | # https://github.com/plv8/plv8/pull/506 62 | substituteInPlace generate_upgrade.sh \ 63 | --replace " 2.3.10 " " 2.3.10 2.3.11 2.3.12 2.3.13 2.3.14 2.3.15 " 64 | ''; 65 | 66 | postInstall = '' 67 | # Move the redirected to proper directory. 68 | # There appear to be no references to the install directories 69 | # so changing them does not cause issues. 70 | mv "$out/nix/store"/*/* "$out" 71 | rmdir "$out/nix/store"/* "$out/nix/store" "$out/nix" 72 | ''; 73 | 74 | passthru = { 75 | tests = 76 | let 77 | postgresqlWithSelf = postgresql.withPackages (_: [ 78 | finalAttrs.finalPackage 79 | ]); 80 | in 81 | { 82 | smoke = runCommand "plv8-smoke-test" { } '' 83 | export PATH=${lib.makeBinPath [ 84 | postgresqlWithSelf 85 | coreutils 86 | gnugrep 87 | ]} 88 | db="$PWD/testdb" 89 | initdb "$db" 90 | postgres -k "$db" -D "$db" & 91 | pid="$!" 92 | 93 | for i in $(seq 1 100); do 94 | if psql -h "$db" -d postgres -c "" 2>/dev/null; then 95 | break 96 | elif ! kill -0 "$pid"; then 97 | exit 1 98 | else 99 | sleep 0.1 100 | fi 101 | done 102 | 103 | psql -h "$db" -d postgres -c 'CREATE EXTENSION plv8; DO $$ plv8.elog(NOTICE, plv8.version); $$ LANGUAGE plv8;' 2> "$out" 104 | grep -q "${finalAttrs.version}" "$out" 105 | kill -0 "$pid" 106 | ''; 107 | 108 | regression = stdenv.mkDerivation { 109 | name = "plv8-regression"; 110 | inherit (finalAttrs) src patches nativeBuildInputs buildInputs dontConfigure; 111 | 112 | buildPhase = '' 113 | runHook preBuild 114 | 115 | # The regression tests need to be run in the order specified in the Makefile. 116 | echo -e "include Makefile\nprint_regress_files:\n\t@echo \$(REGRESS)" > Makefile.regress 117 | REGRESS_TESTS=$(make -f Makefile.regress print_regress_files) 118 | 119 | ${postgresql}/lib/pgxs/src/test/regress/pg_regress \ 120 | --bindir='${postgresqlWithSelf}/bin' \ 121 | --temp-instance=regress-instance \ 122 | --dbname=contrib_regression \ 123 | $REGRESS_TESTS 124 | 125 | runHook postBuild 126 | ''; 127 | 128 | installPhase = '' 129 | runHook preInstall 130 | 131 | touch "$out" 132 | 133 | runHook postInstall 134 | ''; 135 | }; 136 | }; 137 | }; 138 | 139 | meta = with lib; { 140 | description = "V8 Engine Javascript Procedural Language add-on for PostgreSQL"; 141 | homepage = "https://plv8.github.io/"; 142 | maintainers = with maintainers; [ marsam ]; 143 | platforms = [ "x86_64-linux" "aarch64-linux" ]; 144 | license = licenses.postgresql; 145 | broken = postgresql.jitSupport; 146 | }; 147 | }) 148 | -------------------------------------------------------------------------------- /ext/supautils.nix: -------------------------------------------------------------------------------- 1 | { lib, stdenv, fetchFromGitHub, postgresql }: 2 | 3 | stdenv.mkDerivation rec { 4 | pname = "supautils"; 5 | version = "1.8.0"; 6 | 7 | buildInputs = [ postgresql ]; 8 | 9 | src = fetchFromGitHub { 10 | owner = "supabase"; 11 | repo = pname; 12 | rev = "refs/tags/v${version}"; 13 | hash = "sha256-cQ294UNhlPtnqngGTVLYPMbGcqhqjFk5y6WBz6nCZhI="; 14 | }; 15 | 16 | installPhase = '' 17 | mkdir -p $out/lib 18 | 19 | install -D supautils.so -t $out/lib 20 | ''; 21 | 22 | meta = with lib; { 23 | description = "PostgreSQL extension for enhanced security"; 24 | homepage = "https://github.com/supabase/${pname}"; 25 | maintainers = with maintainers; [ steve-chavez ]; 26 | platforms = postgresql.meta.platforms; 27 | license = licenses.postgresql; 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /ext/vault.nix: -------------------------------------------------------------------------------- 1 | { lib, stdenv, fetchFromGitHub, postgresql }: 2 | 3 | stdenv.mkDerivation rec { 4 | pname = "vault"; 5 | version = "0.2.9"; 6 | 7 | buildInputs = [ postgresql ]; 8 | 9 | src = fetchFromGitHub { 10 | owner = "supabase"; 11 | repo = pname; 12 | rev = "refs/tags/v${version}"; 13 | hash = "sha256-kXTngBW4K6FkZM8HvJG2Jha6OQqbejhnk7tchxy031I="; 14 | }; 15 | 16 | installPhase = '' 17 | mkdir -p $out/{lib,share/postgresql/extension} 18 | 19 | cp sql/*.sql $out/share/postgresql/extension 20 | cp *.control $out/share/postgresql/extension 21 | ''; 22 | 23 | meta = with lib; { 24 | description = "Store encrypted secrets in PostgreSQL"; 25 | homepage = "https://github.com/supabase/${pname}"; 26 | maintainers = with maintainers; [ thoughtpolice ]; 27 | platforms = postgresql.meta.platforms; 28 | license = licenses.postgresql; 29 | }; 30 | } 31 | -------------------------------------------------------------------------------- /ext/wrappers/default.nix: -------------------------------------------------------------------------------- 1 | { lib 2 | , stdenv 3 | , fetchFromGitHub 4 | , openssl 5 | , pkg-config 6 | , postgresql 7 | , buildPgrxExtension_0_11_2 8 | }: 9 | 10 | buildPgrxExtension_0_11_2 rec { 11 | pname = "supabase-wrappers"; 12 | version = "unstable-2024-02-26"; 13 | inherit postgresql; 14 | 15 | src = fetchFromGitHub { 16 | owner = "supabase"; 17 | repo = "wrappers"; 18 | #rev pinned for now to the HEAD of the main branch to achieve cargo-pgrx 0.11.2 compat 19 | rev = "5b5c2622268c75bec834a38b2ff967f781511188"; 20 | hash = "sha256-VwEFJD0yD+gvXCTzq9NfjCPEkh/lDQdEOPfk8LwK4z4="; 21 | }; 22 | 23 | nativeBuildInputs = [ pkg-config ]; 24 | buildInputs = [ openssl ]; 25 | 26 | # Needed to get openssl-sys to use pkg-config. 27 | OPENSSL_NO_VENDOR = 1; 28 | 29 | cargoLock = { 30 | lockFile = "${src}/Cargo.lock"; 31 | outputHashes = { 32 | "clickhouse-rs-1.0.0-alpha.1" = "sha256-0zmoUo/GLyCKDLkpBsnLAyGs1xz6cubJhn+eVqMEMaw="; 33 | }; 34 | }; 35 | postPatch = "cp ${cargoLock.lockFile} Cargo.lock"; 36 | 37 | buildAndTestSubdir = "wrappers"; 38 | buildFeatures = [ 39 | "helloworld_fdw" 40 | "bigquery_fdw" 41 | "clickhouse_fdw" 42 | "stripe_fdw" 43 | "firebase_fdw" 44 | "s3_fdw" 45 | "airtable_fdw" 46 | "logflare_fdw" 47 | ]; 48 | 49 | # FIXME (aseipp): disable the tests since they try to install .control 50 | # files into the wrong spot, aside from that the one main test seems 51 | # to work, though 52 | doCheck = false; 53 | 54 | meta = with lib; { 55 | description = "Various Foreign Data Wrappers (FDWs) for PostreSQL"; 56 | homepage = "https://github.com/supabase/wrappers"; 57 | maintainers = with maintainers; [ thoughtpolice ]; 58 | platforms = postgresql.meta.platforms; 59 | license = licenses.postgresql; 60 | }; 61 | } 62 | -------------------------------------------------------------------------------- /flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "flake-utils": { 4 | "inputs": { 5 | "systems": "systems" 6 | }, 7 | "locked": { 8 | "lastModified": 1705309234, 9 | "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", 10 | "owner": "numtide", 11 | "repo": "flake-utils", 12 | "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", 13 | "type": "github" 14 | }, 15 | "original": { 16 | "owner": "numtide", 17 | "repo": "flake-utils", 18 | "type": "github" 19 | } 20 | }, 21 | "flake-utils_2": { 22 | "inputs": { 23 | "systems": "systems_2" 24 | }, 25 | "locked": { 26 | "lastModified": 1694529238, 27 | "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", 28 | "owner": "numtide", 29 | "repo": "flake-utils", 30 | "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", 31 | "type": "github" 32 | }, 33 | "original": { 34 | "owner": "numtide", 35 | "repo": "flake-utils", 36 | "type": "github" 37 | } 38 | }, 39 | "nix2container": { 40 | "inputs": { 41 | "flake-utils": "flake-utils_2", 42 | "nixpkgs": "nixpkgs" 43 | }, 44 | "locked": { 45 | "lastModified": 1708764364, 46 | "narHash": "sha256-+pOtDvmuVTg0Gi58hKDUyrNla5NbyUvt3Xs3gLR0Fws=", 47 | "owner": "nlewo", 48 | "repo": "nix2container", 49 | "rev": "c891f90d2e3c48a6b33466c96e4851e0fc0cf455", 50 | "type": "github" 51 | }, 52 | "original": { 53 | "owner": "nlewo", 54 | "repo": "nix2container", 55 | "type": "github" 56 | } 57 | }, 58 | "nixpkgs": { 59 | "locked": { 60 | "lastModified": 1697269602, 61 | "narHash": "sha256-dSzV7Ud+JH4DPVD9od53EgDrxUVQOcSj4KGjggCDVJI=", 62 | "owner": "NixOS", 63 | "repo": "nixpkgs", 64 | "rev": "9cb540e9c1910d74a7e10736277f6eb9dff51c81", 65 | "type": "github" 66 | }, 67 | "original": { 68 | "owner": "NixOS", 69 | "repo": "nixpkgs", 70 | "type": "github" 71 | } 72 | }, 73 | "nixpkgs_2": { 74 | "locked": { 75 | "lastModified": 1709386671, 76 | "narHash": "sha256-VPqfBnIJ+cfa78pd4Y5Cr6sOWVW8GYHRVucxJGmRf8Q=", 77 | "owner": "nixos", 78 | "repo": "nixpkgs", 79 | "rev": "fa9a51752f1b5de583ad5213eb621be071806663", 80 | "type": "github" 81 | }, 82 | "original": { 83 | "owner": "nixos", 84 | "ref": "nixpkgs-unstable", 85 | "repo": "nixpkgs", 86 | "type": "github" 87 | } 88 | }, 89 | "root": { 90 | "inputs": { 91 | "flake-utils": "flake-utils", 92 | "nix2container": "nix2container", 93 | "nixpkgs": "nixpkgs_2" 94 | } 95 | }, 96 | "systems": { 97 | "locked": { 98 | "lastModified": 1681028828, 99 | "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 100 | "owner": "nix-systems", 101 | "repo": "default", 102 | "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 103 | "type": "github" 104 | }, 105 | "original": { 106 | "owner": "nix-systems", 107 | "repo": "default", 108 | "type": "github" 109 | } 110 | }, 111 | "systems_2": { 112 | "locked": { 113 | "lastModified": 1681028828, 114 | "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 115 | "owner": "nix-systems", 116 | "repo": "default", 117 | "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 118 | "type": "github" 119 | }, 120 | "original": { 121 | "owner": "nix-systems", 122 | "repo": "default", 123 | "type": "github" 124 | } 125 | } 126 | }, 127 | "root": "root", 128 | "version": 7 129 | } 130 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "Prototype tooling for deploying PostgreSQL"; 3 | 4 | inputs = { 5 | nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 6 | flake-utils.url = "github:numtide/flake-utils"; 7 | nix2container.url = "github:nlewo/nix2container"; 8 | }; 9 | 10 | nixConfig = { 11 | extra-substituters = [ 12 | "https://nix-postgres-artifacts.s3.amazonaws.com" 13 | ]; 14 | 15 | extra-trusted-public-keys = [ 16 | "nix-cache.supabase.com-1:ZfEc7Qb7SN+qOTJGMtCz54rnVQ1W2ZI2ROCSSD6YQYc=" 17 | ]; 18 | }; 19 | 20 | outputs = { self, nixpkgs, flake-utils, nix2container }: 21 | let 22 | gitRev = "vcs=${self.shortRev or "dirty"}+${builtins.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101")}"; 23 | 24 | ourSystems = with flake-utils.lib; [ 25 | system.x86_64-linux 26 | system.aarch64-linux 27 | ]; 28 | in 29 | flake-utils.lib.eachSystem ourSystems (system: 30 | let 31 | pgsqlDefaultPort = "5435"; 32 | pgsqlSuperuser = "postgres"; 33 | nix2img = nix2container.packages.${system}.nix2container; 34 | 35 | # The 'oriole_pkgs' variable holds all the upstream packages in nixpkgs, which 36 | # we can use to build our own images; it is the common name to refer to 37 | # a copy of nixpkgs which contains all its packages. 38 | # it also serves as a base for importing the orioldb/postgres overlay to 39 | #build the orioledb postgres patched version of postgresql16 40 | oriole_pkgs = import nixpkgs { 41 | inherit system; 42 | overlays = [ 43 | # NOTE (aseipp): add any needed overlays here. in theory we could 44 | # pull them from the overlays/ directory automatically, but we don't 45 | # want to have an arbitrary order, since it might matter. being 46 | # explicit is better. 47 | (import ./overlays/cargo-pgrx.nix) 48 | (import ./overlays/gdal-small.nix) 49 | (import ./overlays/psql_16-oriole.nix) 50 | 51 | ]; 52 | }; 53 | #This variable works the same as 'oriole_pkgs' but builds using the upstream 54 | #nixpkgs builds of postgresql 15 and 16 + the overlays listed below 55 | pkgs = import nixpkgs { 56 | inherit system; 57 | overlays = [ 58 | # NOTE (aseipp): add any needed overlays here. in theory we could 59 | # pull them from the overlays/ directory automatically, but we don't 60 | # want to have an arbitrary order, since it might matter. being 61 | # explicit is better. 62 | (import ./overlays/cargo-pgrx.nix) 63 | (import ./overlays/gdal-small.nix) 64 | 65 | ]; 66 | }; 67 | 68 | 69 | # FIXME (aseipp): pg_prove is yet another perl program that needs 70 | # LOCALE_ARCHIVE set in non-NixOS environments. upstream this. once that's done, we 71 | # can remove this wrapper. 72 | pg_prove = pkgs.runCommand "pg_prove" 73 | { 74 | nativeBuildInputs = [ pkgs.makeWrapper ]; 75 | } '' 76 | mkdir -p $out/bin 77 | for x in pg_prove pg_tapgen; do 78 | makeWrapper "${pkgs.perlPackages.TAPParserSourceHandlerpgTAP}/bin/$x" "$out/bin/$x" \ 79 | --set LOCALE_ARCHIVE "${pkgs.glibcLocales}/lib/locale/locale-archive" 80 | done 81 | ''; 82 | 83 | 84 | # Our list of PostgreSQL extensions which come from upstream Nixpkgs. 85 | # These are maintained upstream and can easily be used here just by 86 | # listing their name. Anytime the version of nixpkgs is upgraded, these 87 | # may also bring in new versions of the extensions. 88 | psqlExtensions = [ 89 | "postgis" 90 | "pgrouting" 91 | "pgtap" 92 | "pg_cron" 93 | "pgaudit" 94 | "pgjwt" 95 | "plpgsql_check" 96 | "pg_safeupdate" 97 | "wal2json" 98 | /* pljava */ 99 | "rum" 100 | "pg_repack" 101 | "pgroonga" 102 | "timescaledb" 103 | ]; 104 | 105 | #FIXME for now, timescaledb is not included in the orioledb version of supabase extensions, as there is an issue 106 | # with building timescaledb with the orioledb patched version of postgresql 107 | orioledbPsqlExtensions = [ 108 | "postgis" 109 | "pgrouting" 110 | "pgtap" 111 | "pg_cron" 112 | "pgaudit" 113 | "pgjwt" 114 | "plpgsql_check" 115 | "pg_safeupdate" 116 | "wal2json" 117 | /* pljava */ 118 | "rum" 119 | "pg_repack" 120 | "pgroonga" 121 | /*"timescaledb"*/ 122 | ]; 123 | 124 | # Custom extensions that exist in our repository. These aren't upstream 125 | # either because nobody has done the work, maintaining them here is 126 | # easier and more expedient, or because they may not be suitable, or are 127 | # too niche/one-off. 128 | # 129 | # Ideally, most of these should have copies upstream for third party 130 | # use, but even if they did, keeping our own copies means that we can 131 | # rollout new versions of these critical things easier without having to 132 | # go through the upstream release engineering process. 133 | ourExtensions = [ 134 | # see comment in ./ext/citus.nix 135 | # for why citus is deactivated 136 | #./ext/citus.nix 137 | ./ext/pgsql-http.nix 138 | ./ext/pg_plan_filter.nix 139 | ./ext/pg_net.nix 140 | ./ext/pg_hashids.nix 141 | ./ext/pgsodium.nix 142 | ./ext/pg_graphql.nix 143 | ./ext/pg_stat_monitor.nix 144 | ./ext/pg_jsonschema.nix 145 | ./ext/pgvector.nix 146 | ./ext/vault.nix 147 | ./ext/hypopg.nix 148 | ./ext/pg_tle.nix 149 | ./ext/wrappers/default.nix 150 | ./ext/supautils.nix 151 | ./ext/plv8.nix 152 | ]; 153 | 154 | #Where we import and build the orioledb extension, we add on our custom extensions 155 | # plus the orioledb option 156 | orioledbExtension = ourExtensions ++ [./ext/orioledb.nix ]; 157 | 158 | #this var is a convenience setting to import the orioledb patched version of postgresql 159 | postgresql_orioledb_16 = oriole_pkgs.postgresql_orioledb_16; 160 | 161 | # Create a 'receipt' file for a given postgresql package. This is a way 162 | # of adding a bit of metadata to the package, which can be used by other 163 | # tools to inspect what the contents of the install are: the PSQL 164 | # version, the installed extensions, et cetera. 165 | # 166 | # This takes three arguments: 167 | # - pgbin: the postgresql package we are building on top of 168 | # - upstreamExts: the list of extensions from upstream nixpkgs. This is 169 | # not a list of packages, but an attrset containing extension names 170 | # mapped to versions. 171 | # - ourExts: the list of extensions from upstream nixpkgs. This is not 172 | # a list of packages, but an attrset containing extension names 173 | # mapped to versions. 174 | # 175 | # The output is a package containing the receipt.json file, which can be 176 | # merged with the PostgreSQL installation using 'symlinkJoin'. 177 | makeReceipt = pgbin: upstreamExts: ourExts: pkgs.writeTextFile { 178 | name = "receipt"; 179 | destination = "/receipt.json"; 180 | text = builtins.toJSON { 181 | revision = gitRev; 182 | psql-version = pgbin.version; 183 | nixpkgs = { 184 | revision = nixpkgs.rev; 185 | extensions = upstreamExts; 186 | }; 187 | extensions = ourExts; 188 | 189 | # NOTE (aseipp): this field can be used to do cache busting (e.g. 190 | # force a rebuild of the psql packages) but also to helpfully inform 191 | # tools what version of the schema is being used, for forwards and 192 | # backwards compatibility 193 | receipt-version = "1"; 194 | }; 195 | }; 196 | 197 | makeOurOrioleDbPostgresPkgs = version: patchedPostgres: 198 | let postgresql = patchedPostgres; 199 | in map (path: pkgs.callPackage path { inherit postgresql; }) orioledbExtension; 200 | 201 | makeOurPostgresPkgs = version: 202 | let postgresql = pkgs."postgresql_${version}"; 203 | in map (path: pkgs.callPackage path { inherit postgresql; }) ourExtensions; 204 | 205 | # Create an attrset that contains all the extensions included in a server for the orioledb version of postgresql + extension. 206 | makeOurOrioleDbPostgresPkgsSet = version: patchedPostgres: 207 | (builtins.listToAttrs (map 208 | (drv: 209 | { name = drv.pname; value = drv; } 210 | ) 211 | (makeOurOrioleDbPostgresPkgs version patchedPostgres))) 212 | // { recurseForDerivations = true; }; 213 | 214 | # Create an attrset that contains all the extensions included in a server. 215 | makeOurPostgresPkgsSet = version: 216 | (builtins.listToAttrs (map 217 | (drv: 218 | { name = drv.pname; value = drv; } 219 | ) 220 | (makeOurPostgresPkgs version))) 221 | // { recurseForDerivations = true; }; 222 | 223 | 224 | # Create a binary distribution of PostgreSQL, given a version. 225 | # 226 | # NOTE: The version here does NOT refer to the exact PostgreSQL version; 227 | # it refers to the *major number only*, which is used to select the 228 | # correct version of the package from nixpkgs. This is because we want 229 | # to be able to do so in an open ended way. As an example, the version 230 | # "15" passed in will use the nixpkgs package "postgresql_15" as the 231 | # basis for building extensions, etc. 232 | makePostgresBin = version: 233 | let 234 | postgresql = pkgs."postgresql_${version}"; 235 | upstreamExts = map 236 | (ext: { 237 | name = postgresql.pkgs."${ext}".pname; 238 | version = postgresql.pkgs."${ext}".version; 239 | }) 240 | psqlExtensions; 241 | ourExts = map (ext: { name = ext.pname; version = ext.version; }) (makeOurPostgresPkgs version); 242 | 243 | pgbin = postgresql.withPackages (ps: 244 | (map (ext: ps."${ext}") psqlExtensions) ++ (makeOurPostgresPkgs version) 245 | ); 246 | in 247 | pkgs.symlinkJoin { 248 | inherit (pgbin) name version; 249 | paths = [ pgbin (makeReceipt pgbin upstreamExts ourExts) ]; 250 | }; 251 | 252 | makeOrioleDbPostgresBin = version: patchedPostgres: 253 | let 254 | postgresql = patchedPostgres; 255 | upstreamExts = map 256 | (ext: { 257 | name = postgresql.pkgs."${ext}".pname; 258 | version = postgresql.pkgs."${ext}".version; 259 | }) 260 | orioledbPsqlExtensions; 261 | ourExts = map (ext: { name = ext.pname; version = ext.version; }) (makeOurOrioleDbPostgresPkgs version postgresql); 262 | 263 | pgbin = postgresql.withPackages (ps: 264 | (map (ext: ps."${ext}") orioledbPsqlExtensions) ++ (makeOurOrioleDbPostgresPkgs version postgresql) 265 | ); 266 | in 267 | pkgs.symlinkJoin { 268 | inherit (pgbin) name version; 269 | paths = [ pgbin (makeReceipt pgbin upstreamExts ourExts) ]; 270 | }; 271 | 272 | # Make a Docker Image from a given PostgreSQL version and binary package. 273 | # updated to use https://github.com/nlewo/nix2container (samrose) 274 | makePostgresDocker = version: binPackage: 275 | let 276 | initScript = pkgs.runCommand "docker-init.sh" { } '' 277 | mkdir -p $out/bin 278 | substitute ${./docker/init.sh.in} $out/bin/init.sh \ 279 | --subst-var-by 'PGSQL_DEFAULT_PORT' '${pgsqlDefaultPort}' 280 | 281 | chmod +x $out/bin/init.sh 282 | ''; 283 | 284 | postgresqlConfig = pkgs.runCommand "postgresql.conf" { } '' 285 | mkdir -p $out/etc/ 286 | substitute ${./tests/postgresql.conf.in} $out/etc/postgresql.conf \ 287 | --subst-var-by 'PGSQL_DEFAULT_PORT' '${pgsqlDefaultPort}' \ 288 | --subst-var-by PGSODIUM_GETKEY_SCRIPT "${./tests/util/pgsodium_getkey.sh}" 289 | ''; 290 | 291 | l = pkgs.lib // builtins; 292 | 293 | user = "postgres"; 294 | group = "postgres"; 295 | uid = "1001"; 296 | gid = "1001"; 297 | 298 | mkUser = pkgs.runCommand "mkUser" { } '' 299 | mkdir -p $out/etc/pam.d 300 | 301 | echo "${user}:x:${uid}:${gid}::" > $out/etc/passwd 302 | echo "${user}:!x:::::::" > $out/etc/shadow 303 | 304 | echo "${group}:x:${gid}:" > $out/etc/group 305 | echo "${group}:x::" > $out/etc/gshadow 306 | 307 | cat > $out/etc/pam.d/other <logfile 2>&1 & 503 | sleep 2 504 | 505 | createdb -h localhost testing 506 | 507 | psql -h localhost -d testing -Xaf ${./tests/prime.sql} 508 | pg_prove -h localhost -d testing ${sqlTests}/*.sql 509 | 510 | pkill postgres 511 | mv logfile $out 512 | echo ${pgpkg} 513 | ''; 514 | 515 | in 516 | rec { 517 | # The list of all packages that can be built with 'nix build'. The list 518 | # of names that can be used can be shown with 'nix flake show' 519 | packages = flake-utils.lib.flattenTree basePackages // { 520 | # Any extra packages we might want to include in our package 521 | # set can go here. 522 | inherit (pkgs) 523 | # NOTE: comes from our cargo-pgrx.nix overlay 524 | cargo-pgrx_0_11_2; 525 | 526 | }; 527 | 528 | # The list of exported 'checks' that are run with every run of 'nix 529 | # flake check'. This is run in the CI system, as well. 530 | checks = { 531 | psql_15 = makeCheckHarness basePackages.psql_15.bin; 532 | psql_16 = makeCheckHarness basePackages.psql_16.bin; 533 | psql_orioledb_16 = makeCheckHarness basePackages.psql_orioledb_16.bin; 534 | }; 535 | 536 | # Apps is a list of names of things that can be executed with 'nix run'; 537 | # these are distinct from the things that can be built with 'nix build', 538 | # so they need to be listed here too. 539 | apps = 540 | let 541 | mkApp = attrName: binName: { 542 | type = "app"; 543 | program = "${basePackages."${attrName}"}/bin/${binName}"; 544 | }; 545 | in 546 | { 547 | start-server = mkApp "start-server" "start-postgres-server"; 548 | start-client = mkApp "start-client" "start-postgres-client"; 549 | start-replica = mkApp "start-replica" "start-postgres-replica"; 550 | migration-test = mkApp "migrate-tool" "migrate-postgres"; 551 | }; 552 | 553 | # 'devShells.default' lists the set of packages that are included in the 554 | # ambient $PATH environment when you run 'nix develop'. This is useful 555 | # for development and puts many convenient devtools instantly within 556 | # reach. 557 | devShells.default = pkgs.mkShell { 558 | packages = with pkgs; [ 559 | coreutils 560 | just 561 | nix-update 562 | pg_prove 563 | shellcheck 564 | 565 | basePackages.start-server 566 | basePackages.start-client 567 | basePackages.start-replica 568 | basePackages.migrate-tool 569 | ]; 570 | shellHook = '' 571 | export HISTFILE=.history 572 | ''; 573 | }; 574 | } 575 | ); 576 | } 577 | -------------------------------------------------------------------------------- /justfile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S just --justfile 2 | # ^ A shebang isn't required, but allows a justfile to be executed 3 | # like a script, with `./justfile test`, for example. 4 | 5 | default: 6 | @{{ just_executable() }} --choose 7 | 8 | alias b := build-all 9 | alias c := check 10 | 11 | build-all: 12 | nix build .#psql_15/bin .#psql_15/docker 13 | nix build .#psql_16/bin .#psql_16/docker 14 | nix build .#psql_orioledb_16/bin .#psql_orioledb_16/docker 15 | 16 | check: 17 | nix flake check -L 18 | -------------------------------------------------------------------------------- /overlays/cargo-pgrx.nix: -------------------------------------------------------------------------------- 1 | final: prev: { 2 | cargo-pgrx_0_11_2 = prev.cargo-pgrx.overrideAttrs (oldAttrs: rec { 3 | pname = "cargo-pgrx"; 4 | version = "0.11.2"; 5 | 6 | src = prev.fetchCrate { 7 | inherit version pname; 8 | hash = "sha256-8NlpMDFaltTIA8G4JioYm8LaPJ2RGKH5o6sd6lBHmmM="; 9 | }; 10 | 11 | # NOTE (aseipp): normally, we would just use 'cargoHash' here, but 12 | # due to a fantastic interaction of APIs, we can't do that so 13 | # easily, and have to use this incantation instead, which is 14 | # basically the exact same thing but with 4 extra lines. see: 15 | # 16 | # https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/5 17 | cargoDeps = oldAttrs.cargoDeps.overrideAttrs (prev.lib.const { 18 | name = "${pname}-vendor.tar.gz"; 19 | inherit src; 20 | outputHash = "sha256-qU2r67qI+aWsWr3vMWHb2FItHzwSaqXDnTvRe0rf+JY="; 21 | }); 22 | }); 23 | 24 | buildPgrxExtension_0_11_2 = prev.buildPgrxExtension.override { 25 | cargo-pgrx = final.cargo-pgrx_0_11_2; 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /overlays/gdal-small.nix: -------------------------------------------------------------------------------- 1 | final: prev: { 2 | # override the version of gdal used with postgis with the small version. 3 | # significantly reduces overall closure size 4 | gdal = prev.gdalMinimal.override { 5 | /* other features can be enabled, reference: 6 | https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/gdal/default.nix 7 | */ 8 | 9 | # useHDF = true; 10 | # useArrow = true; 11 | # useLibHEIF = true; 12 | # ... 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /overlays/psql_16-oriole.nix: -------------------------------------------------------------------------------- 1 | final: prev: { 2 | postgresql_16 = prev.postgresql_16.overrideAttrs (old: { 3 | pname = "postgresql_16"; 4 | version = "16_23"; 5 | src = prev.fetchurl { 6 | url = "https://github.com/orioledb/postgres/archive/refs/tags/patches16_23.tar.gz"; 7 | sha256 = "sha256-xWmcqn3DYyBG0FsBNqPWTFzUidSJZgoPWI6Rt0N9oJ4="; 8 | }; 9 | buildInputs = old.buildInputs ++ [ 10 | prev.bison 11 | prev.docbook5 12 | prev.docbook_xsl 13 | prev.docbook_xsl_ns 14 | prev.docbook_xml_dtd_45 15 | prev.flex 16 | prev.libxslt 17 | prev.perl 18 | ]; 19 | }); 20 | postgresql_orioledb_16 = final.postgresql_16; 21 | } 22 | -------------------------------------------------------------------------------- /tests/migrations/data.sql: -------------------------------------------------------------------------------- 1 | create table account( 2 | id int primary key, 3 | is_verified bool, 4 | name text, 5 | phone text 6 | ); 7 | 8 | insert into public.account(id, is_verified, name, phone) 9 | values 10 | (1, true, 'foo', '1111111111'), 11 | (2, true, 'bar', null), 12 | (3, false, 'baz', '33333333333'); 13 | 14 | select id as test_new_key_id from pgsodium.create_key(name:='test_new_key') \gset 15 | 16 | select vault.create_secret ( 17 | 's3kr3t_k3y', 'a_name', 'this is the foo secret key') test_secret_id \gset 18 | 19 | select vault.create_secret ( 20 | 's3kr3t_k3y_2', 'another_name', 'this is another foo key', 21 | (select id from pgsodium.key where name = 'test_new_key')) test_secret_id_2 \gset 22 | -------------------------------------------------------------------------------- /tests/postgresql.conf.in: -------------------------------------------------------------------------------- 1 | # ----------------------------- 2 | # PostgreSQL configuration file 3 | # ----------------------------- 4 | # 5 | # This file consists of lines of the form: 6 | # 7 | # name = value 8 | # 9 | # (The "=" is optional.) Whitespace may be used. Comments are introduced with 10 | # "#" anywhere on a line. The complete list of parameter names and allowed 11 | # values can be found in the PostgreSQL documentation. 12 | # 13 | # The commented-out settings shown in this file represent the default values. 14 | # Re-commenting a setting is NOT sufficient to revert it to the default value; 15 | # you need to reload the server. 16 | # 17 | # This file is read on server startup and when the server receives a SIGHUP 18 | # signal. If you edit the file on a running system, you have to SIGHUP the 19 | # server for the changes to take effect, run "pg_ctl reload", or execute 20 | # "SELECT pg_reload_conf()". Some parameters, which are marked below, 21 | # require a server shutdown and restart to take effect. 22 | # 23 | # Any parameter can also be given as a command-line option to the server, e.g., 24 | # "postgres -c log_connections=on". Some parameters can be changed at run time 25 | # with the "SET" SQL command. 26 | # 27 | # Memory units: B = bytes Time units: us = microseconds 28 | # kB = kilobytes ms = milliseconds 29 | # MB = megabytes s = seconds 30 | # GB = gigabytes min = minutes 31 | # TB = terabytes h = hours 32 | # d = days 33 | 34 | 35 | #------------------------------------------------------------------------------ 36 | # FILE LOCATIONS 37 | #------------------------------------------------------------------------------ 38 | 39 | # The default values of these variables are driven from the -D command-line 40 | # option or PGDATA environment variable, represented here as ConfigDir. 41 | 42 | #data_directory = 'ConfigDir' # use data in another directory 43 | # (change requires restart) 44 | #hba_file = 'ConfigDir/pg_hba.conf' # host-based authentication file 45 | # (change requires restart) 46 | #ident_file = 'ConfigDir/pg_ident.conf' # ident configuration file 47 | # (change requires restart) 48 | 49 | # If external_pid_file is not explicitly set, no extra PID file is written. 50 | #external_pid_file = '' # write an extra PID file 51 | # (change requires restart) 52 | 53 | 54 | #------------------------------------------------------------------------------ 55 | # CONNECTIONS AND AUTHENTICATION 56 | #------------------------------------------------------------------------------ 57 | 58 | # - Connection Settings - 59 | 60 | listen_addresses = '*' # what IP address(es) to listen on; 61 | #port = @PGSQL_DEFAULT_PORT@ # (change requires restart) 62 | max_connections = 100 # (change requires restart) 63 | #superuser_reserved_connections = 3 # (change requires restart) 64 | unix_socket_directories = '/tmp' # comma-separated list of directories 65 | # (change requires restart) 66 | #unix_socket_group = '' # (change requires restart) 67 | #unix_socket_permissions = 0777 # begin with 0 to use octal notation 68 | # (change requires restart) 69 | #bonjour = off # advertise server via Bonjour 70 | # (change requires restart) 71 | #bonjour_name = '' # defaults to the computer name 72 | # (change requires restart) 73 | 74 | # - TCP settings - 75 | # see "man tcp" for details 76 | 77 | #tcp_keepalives_idle = 0 # TCP_KEEPIDLE, in seconds; 78 | # 0 selects the system default 79 | #tcp_keepalives_interval = 0 # TCP_KEEPINTVL, in seconds; 80 | # 0 selects the system default 81 | #tcp_keepalives_count = 0 # TCP_KEEPCNT; 82 | # 0 selects the system default 83 | #tcp_user_timeout = 0 # TCP_USER_TIMEOUT, in milliseconds; 84 | # 0 selects the system default 85 | 86 | #client_connection_check_interval = 0 # time between checks for client 87 | # disconnection while running queries; 88 | # 0 for never 89 | 90 | # - Authentication - 91 | 92 | #authentication_timeout = 1min # 1s-600s 93 | #password_encryption = scram-sha-256 # scram-sha-256 or md5 94 | #db_user_namespace = off 95 | 96 | # GSSAPI using Kerberos 97 | #krb_server_keyfile = 'FILE:${sysconfdir}/krb5.keytab' 98 | #krb_caseins_users = off 99 | 100 | # - SSL - 101 | 102 | #ssl = off 103 | #ssl_ca_file = '' 104 | #ssl_cert_file = 'server.crt' 105 | #ssl_crl_file = '' 106 | #ssl_crl_dir = '' 107 | #ssl_key_file = 'server.key' 108 | #ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers 109 | #ssl_prefer_server_ciphers = on 110 | #ssl_ecdh_curve = 'prime256v1' 111 | #ssl_min_protocol_version = 'TLSv1.2' 112 | #ssl_max_protocol_version = '' 113 | #ssl_dh_params_file = '' 114 | #ssl_passphrase_command = '' 115 | #ssl_passphrase_command_supports_reload = off 116 | 117 | 118 | #------------------------------------------------------------------------------ 119 | # RESOURCE USAGE (except WAL) 120 | #------------------------------------------------------------------------------ 121 | 122 | # - Memory - 123 | 124 | shared_buffers = 128MB # min 128kB 125 | # (change requires restart) 126 | #huge_pages = try # on, off, or try 127 | # (change requires restart) 128 | #huge_page_size = 0 # zero for system default 129 | # (change requires restart) 130 | #temp_buffers = 8MB # min 800kB 131 | #max_prepared_transactions = 0 # zero disables the feature 132 | # (change requires restart) 133 | # Caution: it is not advisable to set max_prepared_transactions nonzero unless 134 | # you actively intend to use prepared transactions. 135 | #work_mem = 4MB # min 64kB 136 | #hash_mem_multiplier = 1.0 # 1-1000.0 multiplier on hash table work_mem 137 | #maintenance_work_mem = 64MB # min 1MB 138 | #autovacuum_work_mem = -1 # min 1MB, or -1 to use maintenance_work_mem 139 | #logical_decoding_work_mem = 64MB # min 64kB 140 | #max_stack_depth = 2MB # min 100kB 141 | #shared_memory_type = mmap # the default is the first option 142 | # supported by the operating system: 143 | # mmap 144 | # sysv 145 | # windows 146 | # (change requires restart) 147 | dynamic_shared_memory_type = posix # the default is the first option 148 | # supported by the operating system: 149 | # posix 150 | # sysv 151 | # windows 152 | # mmap 153 | # (change requires restart) 154 | #min_dynamic_shared_memory = 0MB # (change requires restart) 155 | 156 | # - Disk - 157 | 158 | #temp_file_limit = -1 # limits per-process temp file space 159 | # in kilobytes, or -1 for no limit 160 | 161 | # - Kernel Resources - 162 | 163 | #max_files_per_process = 1000 # min 64 164 | # (change requires restart) 165 | 166 | # - Cost-Based Vacuum Delay - 167 | 168 | #vacuum_cost_delay = 0 # 0-100 milliseconds (0 disables) 169 | #vacuum_cost_page_hit = 1 # 0-10000 credits 170 | #vacuum_cost_page_miss = 2 # 0-10000 credits 171 | #vacuum_cost_page_dirty = 20 # 0-10000 credits 172 | #vacuum_cost_limit = 200 # 1-10000 credits 173 | 174 | # - Background Writer - 175 | 176 | #bgwriter_delay = 200ms # 10-10000ms between rounds 177 | #bgwriter_lru_maxpages = 100 # max buffers written/round, 0 disables 178 | #bgwriter_lru_multiplier = 2.0 # 0-10.0 multiplier on buffers scanned/round 179 | #bgwriter_flush_after = 512kB # measured in pages, 0 disables 180 | 181 | # - Asynchronous Behavior - 182 | 183 | #backend_flush_after = 0 # measured in pages, 0 disables 184 | #effective_io_concurrency = 1 # 1-1000; 0 disables prefetching 185 | #maintenance_io_concurrency = 10 # 1-1000; 0 disables prefetching 186 | #max_worker_processes = 8 # (change requires restart) 187 | #max_parallel_workers_per_gather = 2 # taken from max_parallel_workers 188 | #max_parallel_maintenance_workers = 2 # taken from max_parallel_workers 189 | #max_parallel_workers = 8 # maximum number of max_worker_processes that 190 | # can be used in parallel operations 191 | #parallel_leader_participation = on 192 | #old_snapshot_threshold = -1 # 1min-60d; -1 disables; 0 is immediate 193 | # (change requires restart) 194 | 195 | 196 | #------------------------------------------------------------------------------ 197 | # WRITE-AHEAD LOG 198 | #------------------------------------------------------------------------------ 199 | 200 | # - Settings - 201 | 202 | wal_level = logical # minimal, replica, or logical 203 | # (change requires restart) 204 | #fsync = on # flush data to disk for crash safety 205 | # (turning this off can cause 206 | # unrecoverable data corruption) 207 | #synchronous_commit = on # synchronization level; 208 | # off, local, remote_write, remote_apply, or on 209 | #wal_sync_method = fsync # the default is the first option 210 | # supported by the operating system: 211 | # open_datasync 212 | # fdatasync (default on Linux and FreeBSD) 213 | # fsync 214 | # fsync_writethrough 215 | # open_sync 216 | #full_page_writes = on # recover from partial page writes 217 | wal_log_hints = on # also do full page writes of non-critical updates 218 | # (change requires restart) 219 | #wal_compression = off # enable compression of full-page writes 220 | #wal_init_zero = on # zero-fill new WAL files 221 | #wal_recycle = on # recycle WAL files 222 | #wal_buffers = -1 # min 32kB, -1 sets based on shared_buffers 223 | # (change requires restart) 224 | #wal_writer_delay = 200ms # 1-10000 milliseconds 225 | #wal_writer_flush_after = 1MB # measured in pages, 0 disables 226 | #wal_skip_threshold = 2MB 227 | 228 | #commit_delay = 0 # range 0-100000, in microseconds 229 | #commit_siblings = 5 # range 1-1000 230 | 231 | # - Checkpoints - 232 | 233 | #checkpoint_timeout = 5min # range 30s-1d 234 | #checkpoint_completion_target = 0.9 # checkpoint target duration, 0.0 - 1.0 235 | #checkpoint_flush_after = 256kB # measured in pages, 0 disables 236 | #checkpoint_warning = 30s # 0 disables 237 | max_wal_size = 1GB 238 | min_wal_size = 80MB 239 | 240 | # - Archiving - 241 | 242 | #archive_mode = off # enables archiving; off, on, or always 243 | # (change requires restart) 244 | #archive_command = '' # command to use to archive a logfile segment 245 | # placeholders: %p = path of file to archive 246 | # %f = file name only 247 | # e.g. 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f' 248 | #archive_timeout = 0 # force a logfile segment switch after this 249 | # number of seconds; 0 disables 250 | 251 | # - Archive Recovery - 252 | 253 | # These are only used in recovery mode. 254 | 255 | #restore_command = '' # command to use to restore an archived logfile segment 256 | # placeholders: %p = path of file to restore 257 | # %f = file name only 258 | # e.g. 'cp /mnt/server/archivedir/%f %p' 259 | #archive_cleanup_command = '' # command to execute at every restartpoint 260 | #recovery_end_command = '' # command to execute at completion of recovery 261 | 262 | # - Recovery Target - 263 | 264 | # Set these only when performing a targeted recovery. 265 | 266 | #recovery_target = '' # 'immediate' to end recovery as soon as a 267 | # consistent state is reached 268 | # (change requires restart) 269 | #recovery_target_name = '' # the named restore point to which recovery will proceed 270 | # (change requires restart) 271 | #recovery_target_time = '' # the time stamp up to which recovery will proceed 272 | # (change requires restart) 273 | #recovery_target_xid = '' # the transaction ID up to which recovery will proceed 274 | # (change requires restart) 275 | #recovery_target_lsn = '' # the WAL LSN up to which recovery will proceed 276 | # (change requires restart) 277 | #recovery_target_inclusive = on # Specifies whether to stop: 278 | # just after the specified recovery target (on) 279 | # just before the recovery target (off) 280 | # (change requires restart) 281 | #recovery_target_timeline = 'latest' # 'current', 'latest', or timeline ID 282 | # (change requires restart) 283 | #recovery_target_action = 'pause' # 'pause', 'promote', 'shutdown' 284 | # (change requires restart) 285 | 286 | 287 | #------------------------------------------------------------------------------ 288 | # REPLICATION 289 | #------------------------------------------------------------------------------ 290 | 291 | # - Sending Servers - 292 | 293 | # Set these on the primary and on any standby that will send replication data. 294 | 295 | #max_wal_senders = 10 # max number of walsender processes 296 | # (change requires restart) 297 | #max_replication_slots = 10 # max number of replication slots 298 | # (change requires restart) 299 | #wal_keep_size = 0 # in megabytes; 0 disables 300 | #max_slot_wal_keep_size = -1 # in megabytes; -1 disables 301 | #wal_sender_timeout = 60s # in milliseconds; 0 disables 302 | #track_commit_timestamp = off # collect timestamp of transaction commit 303 | # (change requires restart) 304 | 305 | # - Primary Server - 306 | 307 | # These settings are ignored on a standby server. 308 | 309 | #synchronous_standby_names = '' # standby servers that provide sync rep 310 | # method to choose sync standbys, number of sync standbys, 311 | # and comma-separated list of application_name 312 | # from standby(s); '*' = all 313 | #vacuum_defer_cleanup_age = 0 # number of xacts by which cleanup is delayed 314 | 315 | # - Standby Servers - 316 | 317 | # These settings are ignored on a primary server. 318 | 319 | #primary_conninfo = '' # connection string to sending server 320 | #primary_slot_name = '' # replication slot on sending server 321 | #promote_trigger_file = '' # file name whose presence ends recovery 322 | #hot_standby = on # "off" disallows queries during recovery 323 | # (change requires restart) 324 | #max_standby_archive_delay = 30s # max delay before canceling queries 325 | # when reading WAL from archive; 326 | # -1 allows indefinite delay 327 | #max_standby_streaming_delay = 30s # max delay before canceling queries 328 | # when reading streaming WAL; 329 | # -1 allows indefinite delay 330 | #wal_receiver_create_temp_slot = off # create temp slot if primary_slot_name 331 | # is not set 332 | #wal_receiver_status_interval = 10s # send replies at least this often 333 | # 0 disables 334 | #hot_standby_feedback = off # send info from standby to prevent 335 | # query conflicts 336 | #wal_receiver_timeout = 60s # time that receiver waits for 337 | # communication from primary 338 | # in milliseconds; 0 disables 339 | #wal_retrieve_retry_interval = 5s # time to wait before retrying to 340 | # retrieve WAL after a failed attempt 341 | #recovery_min_apply_delay = 0 # minimum delay for applying changes during recovery 342 | 343 | # - Subscribers - 344 | 345 | # These settings are ignored on a publisher. 346 | 347 | #max_logical_replication_workers = 4 # taken from max_worker_processes 348 | # (change requires restart) 349 | #max_sync_workers_per_subscription = 2 # taken from max_logical_replication_workers 350 | 351 | 352 | #------------------------------------------------------------------------------ 353 | # QUERY TUNING 354 | #------------------------------------------------------------------------------ 355 | 356 | # - Planner Method Configuration - 357 | 358 | #enable_async_append = on 359 | #enable_bitmapscan = on 360 | #enable_gathermerge = on 361 | #enable_hashagg = on 362 | #enable_hashjoin = on 363 | #enable_incremental_sort = on 364 | #enable_indexscan = on 365 | #enable_indexonlyscan = on 366 | #enable_material = on 367 | #enable_memoize = on 368 | #enable_mergejoin = on 369 | #enable_nestloop = on 370 | #enable_parallel_append = on 371 | #enable_parallel_hash = on 372 | #enable_partition_pruning = on 373 | #enable_partitionwise_join = off 374 | #enable_partitionwise_aggregate = off 375 | #enable_seqscan = on 376 | #enable_sort = on 377 | #enable_tidscan = on 378 | 379 | # - Planner Cost Constants - 380 | 381 | #seq_page_cost = 1.0 # measured on an arbitrary scale 382 | #random_page_cost = 4.0 # same scale as above 383 | #cpu_tuple_cost = 0.01 # same scale as above 384 | #cpu_index_tuple_cost = 0.005 # same scale as above 385 | #cpu_operator_cost = 0.0025 # same scale as above 386 | #parallel_setup_cost = 1000.0 # same scale as above 387 | #parallel_tuple_cost = 0.1 # same scale as above 388 | #min_parallel_table_scan_size = 8MB 389 | #min_parallel_index_scan_size = 512kB 390 | #effective_cache_size = 4GB 391 | 392 | #jit_above_cost = 100000 # perform JIT compilation if available 393 | # and query more expensive than this; 394 | # -1 disables 395 | #jit_inline_above_cost = 500000 # inline small functions if query is 396 | # more expensive than this; -1 disables 397 | #jit_optimize_above_cost = 500000 # use expensive JIT optimizations if 398 | # query is more expensive than this; 399 | # -1 disables 400 | 401 | # - Genetic Query Optimizer - 402 | 403 | #geqo = on 404 | #geqo_threshold = 12 405 | #geqo_effort = 5 # range 1-10 406 | #geqo_pool_size = 0 # selects default based on effort 407 | #geqo_generations = 0 # selects default based on effort 408 | #geqo_selection_bias = 2.0 # range 1.5-2.0 409 | #geqo_seed = 0.0 # range 0.0-1.0 410 | 411 | # - Other Planner Options - 412 | 413 | #default_statistics_target = 100 # range 1-10000 414 | #constraint_exclusion = partition # on, off, or partition 415 | #cursor_tuple_fraction = 0.1 # range 0.0-1.0 416 | #from_collapse_limit = 8 417 | #jit = on # allow JIT compilation 418 | #join_collapse_limit = 8 # 1 disables collapsing of explicit 419 | # JOIN clauses 420 | #plan_cache_mode = auto # auto, force_generic_plan or 421 | # force_custom_plan 422 | 423 | 424 | #------------------------------------------------------------------------------ 425 | # REPORTING AND LOGGING 426 | #------------------------------------------------------------------------------ 427 | 428 | # - Where to Log - 429 | 430 | #log_destination = 'stderr' # Valid values are combinations of 431 | # stderr, csvlog, syslog, and eventlog, 432 | # depending on platform. csvlog 433 | # requires logging_collector to be on. 434 | 435 | # This is used when logging to stderr: 436 | #logging_collector = off # Enable capturing of stderr and csvlog 437 | # into log files. Required to be on for 438 | # csvlogs. 439 | # (change requires restart) 440 | 441 | # These are only used if logging_collector is on: 442 | #log_directory = 'log' # directory where log files are written, 443 | # can be absolute or relative to PGDATA 444 | #log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # log file name pattern, 445 | # can include strftime() escapes 446 | #log_file_mode = 0600 # creation mode for log files, 447 | # begin with 0 to use octal notation 448 | #log_rotation_age = 1d # Automatic rotation of logfiles will 449 | # happen after that time. 0 disables. 450 | #log_rotation_size = 10MB # Automatic rotation of logfiles will 451 | # happen after that much log output. 452 | # 0 disables. 453 | #log_truncate_on_rotation = off # If on, an existing log file with the 454 | # same name as the new log file will be 455 | # truncated rather than appended to. 456 | # But such truncation only occurs on 457 | # time-driven rotation, not on restarts 458 | # or size-driven rotation. Default is 459 | # off, meaning append to existing files 460 | # in all cases. 461 | 462 | # These are relevant when logging to syslog: 463 | #syslog_facility = 'LOCAL0' 464 | #syslog_ident = 'postgres' 465 | #syslog_sequence_numbers = on 466 | #syslog_split_messages = on 467 | 468 | # This is only relevant when logging to eventlog (Windows): 469 | # (change requires restart) 470 | #event_source = 'PostgreSQL' 471 | 472 | # - When to Log - 473 | 474 | #log_min_messages = warning # values in order of decreasing detail: 475 | # debug5 476 | # debug4 477 | # debug3 478 | # debug2 479 | # debug1 480 | # info 481 | # notice 482 | # warning 483 | # error 484 | # log 485 | # fatal 486 | # panic 487 | 488 | #log_min_error_statement = error # values in order of decreasing detail: 489 | # debug5 490 | # debug4 491 | # debug3 492 | # debug2 493 | # debug1 494 | # info 495 | # notice 496 | # warning 497 | # error 498 | # log 499 | # fatal 500 | # panic (effectively off) 501 | 502 | #log_min_duration_statement = -1 # -1 is disabled, 0 logs all statements 503 | # and their durations, > 0 logs only 504 | # statements running at least this number 505 | # of milliseconds 506 | 507 | #log_min_duration_sample = -1 # -1 is disabled, 0 logs a sample of statements 508 | # and their durations, > 0 logs only a sample of 509 | # statements running at least this number 510 | # of milliseconds; 511 | # sample fraction is determined by log_statement_sample_rate 512 | 513 | #log_statement_sample_rate = 1.0 # fraction of logged statements exceeding 514 | # log_min_duration_sample to be logged; 515 | # 1.0 logs all such statements, 0.0 never logs 516 | 517 | 518 | #log_transaction_sample_rate = 0.0 # fraction of transactions whose statements 519 | # are logged regardless of their duration; 1.0 logs all 520 | # statements from all transactions, 0.0 never logs 521 | 522 | # - What to Log - 523 | 524 | #debug_print_parse = off 525 | #debug_print_rewritten = off 526 | #debug_print_plan = off 527 | #debug_pretty_print = on 528 | #log_autovacuum_min_duration = -1 # log autovacuum activity; 529 | # -1 disables, 0 logs all actions and 530 | # their durations, > 0 logs only 531 | # actions running at least this number 532 | # of milliseconds. 533 | #log_checkpoints = off 534 | #log_connections = off 535 | #log_disconnections = off 536 | #log_duration = off 537 | #log_error_verbosity = default # terse, default, or verbose messages 538 | #log_hostname = off 539 | #log_line_prefix = '%m [%p] ' # special values: 540 | # %a = application name 541 | # %u = user name 542 | # %d = database name 543 | # %r = remote host and port 544 | # %h = remote host 545 | # %b = backend type 546 | # %p = process ID 547 | # %P = process ID of parallel group leader 548 | # %t = timestamp without milliseconds 549 | # %m = timestamp with milliseconds 550 | # %n = timestamp with milliseconds (as a Unix epoch) 551 | # %Q = query ID (0 if none or not computed) 552 | # %i = command tag 553 | # %e = SQL state 554 | # %c = session ID 555 | # %l = session line number 556 | # %s = session start timestamp 557 | # %v = virtual transaction ID 558 | # %x = transaction ID (0 if none) 559 | # %q = stop here in non-session 560 | # processes 561 | # %% = '%' 562 | # e.g. '<%u%%%d> ' 563 | #log_lock_waits = off # log lock waits >= deadlock_timeout 564 | #log_recovery_conflict_waits = off # log standby recovery conflict waits 565 | # >= deadlock_timeout 566 | #log_parameter_max_length = -1 # when logging statements, limit logged 567 | # bind-parameter values to N bytes; 568 | # -1 means print in full, 0 disables 569 | #log_parameter_max_length_on_error = 0 # when logging an error, limit logged 570 | # bind-parameter values to N bytes; 571 | # -1 means print in full, 0 disables 572 | #log_statement = 'none' # none, ddl, mod, all 573 | #log_replication_commands = off 574 | #log_temp_files = -1 # log temporary files equal or larger 575 | # than the specified size in kilobytes; 576 | # -1 disables, 0 logs all temp files 577 | log_timezone = 'America/Chicago' 578 | 579 | 580 | #------------------------------------------------------------------------------ 581 | # PROCESS TITLE 582 | #------------------------------------------------------------------------------ 583 | 584 | #cluster_name = '' # added to process titles if nonempty 585 | # (change requires restart) 586 | #update_process_title = on 587 | 588 | 589 | #------------------------------------------------------------------------------ 590 | # STATISTICS 591 | #------------------------------------------------------------------------------ 592 | 593 | # - Query and Index Statistics Collector - 594 | 595 | #track_activities = on 596 | #track_activity_query_size = 1024 # (change requires restart) 597 | #track_counts = on 598 | #track_io_timing = off 599 | #track_wal_io_timing = off 600 | #track_functions = none # none, pl, all 601 | #stats_temp_directory = 'pg_stat_tmp' 602 | 603 | 604 | # - Monitoring - 605 | 606 | #compute_query_id = auto 607 | #log_statement_stats = off 608 | #log_parser_stats = off 609 | #log_planner_stats = off 610 | #log_executor_stats = off 611 | 612 | 613 | #------------------------------------------------------------------------------ 614 | # AUTOVACUUM 615 | #------------------------------------------------------------------------------ 616 | 617 | #autovacuum = on # Enable autovacuum subprocess? 'on' 618 | # requires track_counts to also be on. 619 | #autovacuum_max_workers = 3 # max number of autovacuum subprocesses 620 | # (change requires restart) 621 | #autovacuum_naptime = 1min # time between autovacuum runs 622 | #autovacuum_vacuum_threshold = 50 # min number of row updates before 623 | # vacuum 624 | #autovacuum_vacuum_insert_threshold = 1000 # min number of row inserts 625 | # before vacuum; -1 disables insert 626 | # vacuums 627 | #autovacuum_analyze_threshold = 50 # min number of row updates before 628 | # analyze 629 | #autovacuum_vacuum_scale_factor = 0.2 # fraction of table size before vacuum 630 | #autovacuum_vacuum_insert_scale_factor = 0.2 # fraction of inserts over table 631 | # size before insert vacuum 632 | #autovacuum_analyze_scale_factor = 0.1 # fraction of table size before analyze 633 | #autovacuum_freeze_max_age = 200000000 # maximum XID age before forced vacuum 634 | # (change requires restart) 635 | #autovacuum_multixact_freeze_max_age = 400000000 # maximum multixact age 636 | # before forced vacuum 637 | # (change requires restart) 638 | #autovacuum_vacuum_cost_delay = 2ms # default vacuum cost delay for 639 | # autovacuum, in milliseconds; 640 | # -1 means use vacuum_cost_delay 641 | #autovacuum_vacuum_cost_limit = -1 # default vacuum cost limit for 642 | # autovacuum, -1 means use 643 | # vacuum_cost_limit 644 | 645 | 646 | #------------------------------------------------------------------------------ 647 | # CLIENT CONNECTION DEFAULTS 648 | #------------------------------------------------------------------------------ 649 | 650 | # - Statement Behavior - 651 | 652 | #client_min_messages = notice # values in order of decreasing detail: 653 | # debug5 654 | # debug4 655 | # debug3 656 | # debug2 657 | # debug1 658 | # log 659 | # notice 660 | # warning 661 | # error 662 | #search_path = '"$user", public' # schema names 663 | #row_security = on 664 | #default_table_access_method = 'heap' 665 | #default_tablespace = '' # a tablespace name, '' uses the default 666 | #default_toast_compression = 'pglz' # 'pglz' or 'lz4' 667 | #temp_tablespaces = '' # a list of tablespace names, '' uses 668 | # only default tablespace 669 | #check_function_bodies = on 670 | #default_transaction_isolation = 'read committed' 671 | #default_transaction_read_only = off 672 | #default_transaction_deferrable = off 673 | #session_replication_role = 'origin' 674 | #statement_timeout = 0 # in milliseconds, 0 is disabled 675 | #lock_timeout = 0 # in milliseconds, 0 is disabled 676 | #idle_in_transaction_session_timeout = 0 # in milliseconds, 0 is disabled 677 | #idle_session_timeout = 0 # in milliseconds, 0 is disabled 678 | #vacuum_freeze_table_age = 150000000 679 | #vacuum_freeze_min_age = 50000000 680 | #vacuum_failsafe_age = 1600000000 681 | #vacuum_multixact_freeze_table_age = 150000000 682 | #vacuum_multixact_freeze_min_age = 5000000 683 | #vacuum_multixact_failsafe_age = 1600000000 684 | #bytea_output = 'hex' # hex, escape 685 | #xmlbinary = 'base64' 686 | #xmloption = 'content' 687 | #gin_pending_list_limit = 4MB 688 | 689 | # - Locale and Formatting - 690 | 691 | datestyle = 'iso, mdy' 692 | #intervalstyle = 'postgres' 693 | timezone = 'America/Chicago' 694 | #timezone_abbreviations = 'Default' # Select the set of available time zone 695 | # abbreviations. Currently, there are 696 | # Default 697 | # Australia (historical usage) 698 | # India 699 | # You can create your own file in 700 | # share/timezonesets/. 701 | #extra_float_digits = 1 # min -15, max 3; any value >0 actually 702 | # selects precise output mode 703 | #client_encoding = sql_ascii # actually, defaults to database 704 | # encoding 705 | 706 | # These settings are initialized by initdb, but they can be changed. 707 | lc_messages = 'C' # locale for system error message 708 | # strings 709 | lc_monetary = 'C' # locale for monetary formatting 710 | lc_numeric = 'C' # locale for number formatting 711 | lc_time = 'C' # locale for time formatting 712 | 713 | # default configuration for text search 714 | default_text_search_config = 'pg_catalog.english' 715 | 716 | # - Shared Library Preloading - 717 | 718 | #local_preload_libraries = '' 719 | #session_preload_libraries = '' 720 | #FIXME if we re-activate citus we'll need to add it back in here 721 | #shared_preload_libraries = 'citus,auto_explain,pgsodium' 722 | shared_preload_libraries = 'auto_explain,pgsodium' 723 | #jit_provider = 'llvmjit' # JIT library to use 724 | 725 | # - Other Defaults - 726 | 727 | #dynamic_library_path = '$libdir' 728 | #gin_fuzzy_search_limit = 0 729 | 730 | 731 | #------------------------------------------------------------------------------ 732 | # LOCK MANAGEMENT 733 | #------------------------------------------------------------------------------ 734 | 735 | #deadlock_timeout = 1s 736 | #max_locks_per_transaction = 64 # min 10 737 | # (change requires restart) 738 | #max_pred_locks_per_transaction = 64 # min 10 739 | # (change requires restart) 740 | #max_pred_locks_per_relation = -2 # negative values mean 741 | # (max_pred_locks_per_transaction 742 | # / -max_pred_locks_per_relation) - 1 743 | #max_pred_locks_per_page = 2 # min 0 744 | 745 | 746 | #------------------------------------------------------------------------------ 747 | # VERSION AND PLATFORM COMPATIBILITY 748 | #------------------------------------------------------------------------------ 749 | 750 | # - Previous PostgreSQL Versions - 751 | 752 | #array_nulls = on 753 | #backslash_quote = safe_encoding # on, off, or safe_encoding 754 | #escape_string_warning = on 755 | #lo_compat_privileges = off 756 | #quote_all_identifiers = off 757 | #standard_conforming_strings = on 758 | #synchronize_seqscans = on 759 | 760 | # - Other Platforms and Clients - 761 | 762 | #transform_null_equals = off 763 | 764 | 765 | #------------------------------------------------------------------------------ 766 | # ERROR HANDLING 767 | #------------------------------------------------------------------------------ 768 | 769 | #exit_on_error = off # terminate session on any error? 770 | #restart_after_crash = on # reinitialize after backend crash? 771 | #data_sync_retry = off # retry or panic on failure to fsync 772 | # data? 773 | # (change requires restart) 774 | #recovery_init_sync_method = fsync # fsync, syncfs (Linux 5.8+) 775 | 776 | 777 | #------------------------------------------------------------------------------ 778 | # CONFIG FILE INCLUDES 779 | #------------------------------------------------------------------------------ 780 | 781 | # These options allow settings to be loaded from files other than the 782 | # default postgresql.conf. Note that these are directives, not variable 783 | # assignments, so they can usefully be given more than once. 784 | 785 | #include_dir = '...' # include files ending in '.conf' from 786 | # a directory, e.g., 'conf.d' 787 | #include_if_exists = '...' # include file only if it exists 788 | #include = '...' # include file 789 | 790 | 791 | #------------------------------------------------------------------------------ 792 | # CUSTOMIZED OPTIONS 793 | #------------------------------------------------------------------------------ 794 | 795 | # Add settings for extensions here 796 | 797 | pgsodium.getkey_script = '@PGSODIUM_GETKEY_SCRIPT@' 798 | -------------------------------------------------------------------------------- /tests/prime.sql: -------------------------------------------------------------------------------- 1 | CREATE EXTENSION IF NOT EXISTS pgtap; 2 | 3 | CREATE EXTENSION IF NOT EXISTS postgis; 4 | CREATE EXTENSION IF NOT EXISTS pgrouting; 5 | CREATE EXTENSION IF NOT EXISTS pgcrypto; 6 | CREATE EXTENSION IF NOT EXISTS pgsodium; 7 | CREATE EXTENSION IF NOT EXISTS supabase_vault; 8 | 9 | CREATE EXTENSION IF NOT EXISTS pgjwt; 10 | CREATE EXTENSION IF NOT EXISTS plpgsql_check; 11 | CREATE EXTENSION IF NOT EXISTS plv8; 12 | CREATE EXTENSION IF NOT EXISTS rum; 13 | CREATE EXTENSION IF NOT EXISTS vector; 14 | CREATE EXTENSION IF NOT EXISTS pg_repack; 15 | CREATE EXTENSION IF NOT EXISTS pgroonga; 16 | 17 | CREATE EXTENSION IF NOT EXISTS wrappers; 18 | CREATE EXTENSION IF NOT EXISTS http; 19 | CREATE EXTENSION IF NOT EXISTS pg_graphql; 20 | CREATE EXTENSION IF NOT EXISTS pg_jsonschema; 21 | 22 | -- deactivate citus 23 | -- CREATE EXTENSION IF NOT EXISTS citus; 24 | -------------------------------------------------------------------------------- /tests/smoke/0000-hello-world.sql: -------------------------------------------------------------------------------- 1 | -- Start transaction and plan the tests. 2 | BEGIN; 3 | SELECT plan(1); 4 | 5 | -- Run the tests. 6 | SELECT pass( 'My test passed, w00t!' ); 7 | 8 | -- Finish the tests and clean up. 9 | SELECT * FROM finish(); 10 | ROLLBACK; 11 | -------------------------------------------------------------------------------- /tests/smoke/0001-pg_graphql.sql: -------------------------------------------------------------------------------- 1 | -- Start transaction and plan the tests. 2 | begin; 3 | select plan(1); 4 | 5 | create extension if not exists pg_graphql; 6 | 7 | create table account( 8 | id int primary key, 9 | is_verified bool, 10 | name text, 11 | phone text 12 | ); 13 | 14 | insert into public.account(id, is_verified, name, phone) 15 | values 16 | (1, true, 'foo', '1111111111'), 17 | (2, true, 'bar', null), 18 | (3, false, 'baz', '33333333333'); 19 | 20 | select is( 21 | graphql.resolve($$ 22 | { 23 | accountCollection { 24 | edges { 25 | node { 26 | id 27 | } 28 | } 29 | } 30 | } 31 | $$), 32 | '{ 33 | "data": { 34 | "accountCollection": { 35 | "edges": [ 36 | { 37 | "node": { 38 | "id": 1 39 | } 40 | }, 41 | { 42 | "node": { 43 | "id": 2 44 | } 45 | }, 46 | { 47 | "node": { 48 | "id": 3 49 | } 50 | } 51 | ] 52 | } 53 | } 54 | }'::jsonb 55 | ); 56 | 57 | 58 | select * from finish(); 59 | rollback; 60 | -------------------------------------------------------------------------------- /tests/smoke/0002-supautils.sql: -------------------------------------------------------------------------------- 1 | BEGIN; 2 | SELECT plan(2); 3 | 4 | -- the setting doesn't exist when supautils is not loaded 5 | SELECT throws_ok($$ 6 | select current_setting('supautils.privileged_extensions', false) 7 | $$); 8 | 9 | LOAD 'supautils'; 10 | 11 | -- now it does 12 | SELECT ok( 13 | current_setting('supautils.privileged_extensions', false) = '' 14 | ); 15 | 16 | SELECT * FROM finish(); 17 | ROLLBACK; 18 | -------------------------------------------------------------------------------- /tests/smoke/0003-pgsodium-vault.sql: -------------------------------------------------------------------------------- 1 | BEGIN; 2 | 3 | select plan(3); 4 | 5 | select id as test_new_key_id from pgsodium.create_key(name:='test_new_key') \gset 6 | 7 | select vault.create_secret ( 8 | 's3kr3t_k3y', 'a_name', 'this is the foo secret key') test_secret_id \gset 9 | 10 | select vault.create_secret ( 11 | 's3kr3t_k3y_2', 'another_name', 'this is another foo key', 12 | (select id from pgsodium.key where name = 'test_new_key')) test_secret_id_2 \gset 13 | 14 | SELECT results_eq( 15 | $$ 16 | SELECT decrypted_secret = 's3kr3t_k3y', description = 'this is the foo secret key' 17 | FROM vault.decrypted_secrets WHERE name = 'a_name'; 18 | $$, 19 | $$VALUES (true, true)$$, 20 | 'can select from masking view with custom key'); 21 | 22 | SELECT results_eq( 23 | $$ 24 | SELECT decrypted_secret = 's3kr3t_k3y_2', description = 'this is another foo key' 25 | FROM vault.decrypted_secrets WHERE key_id = (select id from pgsodium.key where name = 'test_new_key'); 26 | $$, 27 | $$VALUES (true, true)$$, 28 | 'can select from masking view'); 29 | 30 | SELECT lives_ok( 31 | format($test$ 32 | select vault.update_secret( 33 | %L::uuid, new_name:='a_new_name', 34 | new_secret:='new_s3kr3t_k3y', new_description:='this is the bar key') 35 | $test$, :'test_secret_id'), 36 | 'can update name, secret and description' 37 | ); 38 | 39 | SELECT * FROM finish(); 40 | ROLLBACK; 41 | -------------------------------------------------------------------------------- /tests/util/pgsodium_getkey.sh: -------------------------------------------------------------------------------- 1 | # NOTE (aseipp): just use some random key for testing, no need to query 2 | # /dev/urandom. also helps ferrit out other random flukes, perhaps? 3 | 4 | echo -n 8359dafbba5c05568799c1c24eb6c2fbff497654bc6aa5e9a791c666768875a1 5 | -------------------------------------------------------------------------------- /tools/README.md: -------------------------------------------------------------------------------- 1 | This directory just contains tools, but you can't run them directly. For the 2 | sake of robustness, you should use `nix run` on this repository to do so. 3 | -------------------------------------------------------------------------------- /tools/migrate-tool.sh.in: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | [ ! -z "$DEBUG" ] && set -x 4 | 5 | # first argument is the old version; a path 15 or 16 6 | if [[ $1 == /nix/store* ]]; then 7 | if [ ! -L "$1/receipt.json" ] || [ ! -e "$1/receipt.json" ]; then 8 | echo "ERROR: $1 does not look like a valid Postgres install" 9 | exit 1 10 | fi 11 | OLDVER="$1" 12 | elif [ "$1" == "15" ]; then 13 | PSQL15=@PSQL15_BINDIR@ 14 | OLDVER="$PSQL15" 15 | elif [ "$1" == "16" ]; then 16 | PSQL16=@PSQL16_BINDIR@ 17 | OLDVER="$PSQL16" 18 | else 19 | echo "Please provide a valid Postgres version (15 or 16), or a /nix/store path" 20 | exit 1 21 | fi 22 | 23 | # second argument is the new version; 15 or 16 24 | if [[ $2 == /nix/store* ]]; then 25 | if [ ! -L "$2/receipt.json" ] || [ ! -e "$2/receipt.json" ]; then 26 | echo "ERROR: $1 does not look like a valid Postgres install" 27 | exit 1 28 | fi 29 | NEWVER="$2" 30 | elif [ "$2" == "15" ]; then 31 | PSQL15=@PSQL15_BINDIR@ 32 | NEWVER="$PSQL15" 33 | elif [ "$2" == "16" ]; then 34 | PSQL16=@PSQL16_BINDIR@ 35 | NEWVER="$PSQL16" 36 | echo "NEWVER IS $NEWVER" 37 | else 38 | echo "Please provide a valid Postgres version (15 or 16), or a /nix/store path" 39 | exit 1 40 | fi 41 | 42 | # thid argument is the upgrade method: either pg_dumpall or pg_ugprade 43 | if [ "$3" != "pg_dumpall" ] && [ "$3" != "pg_upgrade" ]; then 44 | echo "Please provide a valid upgrade method (pg_dumpall or pg_upgrade)" 45 | exit 1 46 | fi 47 | UPGRADE_METHOD="$3" 48 | 49 | echo "Old server build: PSQL $1" 50 | echo "New server build: PSQL $2" 51 | echo "Upgrade method: $UPGRADE_METHOD" 52 | 53 | PORTNO="${2:-@PGSQL_DEFAULT_PORT@}" 54 | DATDIR=$(mktemp -d) 55 | NEWDAT=$(mktemp -d) 56 | mkdir -p "$DATDIR" "$NEWDAT" 57 | 58 | echo "NOTE: using temporary directory $DATDIR for PSQL $1 data, which will not be removed" 59 | echo "NOTE: you are free to re-use this data directory at will" 60 | echo 61 | 62 | $OLDVER/bin/initdb -D "$DATDIR" --locale=C 63 | $NEWVER/bin/initdb -D "$NEWDAT" --locale=C 64 | 65 | # NOTE (aseipp): we need to patch postgresql.conf to have the right pgsodium_getkey script 66 | PSQL_CONF_FILE=@PSQL_CONF_FILE@ 67 | PGSODIUM_GETKEY_SCRIPT=@PGSODIUM_GETKEY@ 68 | echo "NOTE: patching postgresql.conf files" 69 | for x in "$DATDIR" "$NEWDAT"; do 70 | sed \ 71 | "s#@PGSODIUM_GETKEY_SCRIPT@#$PGSODIUM_GETKEY_SCRIPT#g" \ 72 | $PSQL_CONF_FILE > "$x/postgresql.conf" 73 | done 74 | 75 | echo "NOTE: Starting first server (v${1}) to load data into the system" 76 | $OLDVER/bin/pg_ctl start -D "$DATDIR" 77 | 78 | PRIMING_SCRIPT=@PRIMING_SCRIPT@ 79 | MIGRATION_DATA=@MIGRATION_DATA@ 80 | 81 | $OLDVER/bin/psql -h localhost -d postgres -Xf "$PRIMING_SCRIPT" 82 | $OLDVER/bin/psql -h localhost -d postgres -Xf "$MIGRATION_DATA" 83 | 84 | if [ "$UPGRADE_METHOD" == "pg_upgrade" ]; then 85 | echo "NOTE: Stopping old server (v${1}) to prepare for migration" 86 | $OLDVER/bin/pg_ctl stop -D "$DATDIR" 87 | 88 | echo "NOTE: Migrating old data $DATDIR to $NEWDAT using pg_upgrade" 89 | 90 | export PGDATAOLD="$DATDIR" 91 | export PGDATANEW="$NEWDAT" 92 | export PGBINOLD="$OLDVER/bin" 93 | export PGBINNEW="$NEWVER/bin" 94 | 95 | if ! $NEWVER/bin/pg_upgrade --check; then 96 | echo "ERROR: pg_upgrade check failed" 97 | exit 1 98 | fi 99 | 100 | echo "NOTE: pg_upgrade check passed, proceeding with migration" 101 | $NEWVER/bin/pg_upgrade 102 | rm -f delete_old_cluster.sh # we don't need this 103 | exit 0 104 | fi 105 | 106 | if [ "$UPGRADE_METHOD" == "pg_dumpall" ]; then 107 | SQLDAT="$DATDIR/dump.sql" 108 | echo "NOTE: Exporting data via pg_dumpall ($SQLDAT)" 109 | $NEWVER/bin/pg_dumpall -h localhost > "$SQLDAT" 110 | 111 | echo "NOTE: Stopping old server (v${1}) to prepare for migration" 112 | $OLDVER/bin/pg_ctl stop -D "$DATDIR" 113 | 114 | echo "NOTE: Starting second server (v${2}) to load data into the system" 115 | $NEWVER/bin/pg_ctl start -D "$NEWDAT" 116 | 117 | echo "NOTE: Loading data into new server (v${2}) via 'cat | psql'" 118 | cat "$SQLDAT" | $NEWVER/bin/psql -h localhost -d postgres 119 | 120 | printf "\n\n\n\n" 121 | echo "NOTE: Done, check logs. Stopping the server; new database is located at $NEWDAT" 122 | $NEWVER/bin/pg_ctl stop -D "$NEWDAT" 123 | fi 124 | -------------------------------------------------------------------------------- /tools/run-client.sh.in: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # shellcheck shell=bash 3 | 4 | [ ! -z "$DEBUG" ] && set -x 5 | 6 | # first argument should be '15' or '16' for the version 7 | if [ "$1" == "15" ]; then 8 | echo "Starting client for PSQL 15" 9 | PSQL15=@PSQL15_BINDIR@ 10 | BINDIR="$PSQL15" 11 | elif [ "$1" == "16" ]; then 12 | echo "Starting client for PSQL 16" 13 | PSQL16=@PSQL16_BINDIR@ 14 | BINDIR="$PSQL16" 15 | elif [ "$1" == "orioledb-16" ]; then 16 | echo "Starting client for PSQL ORIOLEDB 16" 17 | PSQLORIOLEDB16=@PSQLORIOLEDB16_BINDIR@ 18 | BINDIR="$PSQLORIOLEDB16" 19 | else 20 | echo "Please provide a valid Postgres version (15, 16, or orioledb-16)" 21 | exit 1 22 | fi 23 | 24 | export PATH=$BINDIR/bin:$PATH 25 | 26 | PORTNO="${2:-@PGSQL_DEFAULT_PORT@}" 27 | PGSQL_SUPERUSER=@PGSQL_SUPERUSER@ 28 | 29 | exec psql -U "$PGSQL_SUPERUSER" -p "$PORTNO" -h localhost postgres 30 | -------------------------------------------------------------------------------- /tools/run-replica.sh.in: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # shellcheck shell=bash 3 | 4 | [ ! -z "$DEBUG" ] && set -x 5 | 6 | # first argument should be '15' or '16' for the version 7 | if [ "$1" == "15" ]; then 8 | echo "Starting server for PSQL 15" 9 | PSQL15=@PSQL15_BINDIR@ 10 | BINDIR="$PSQL15" 11 | elif [ "$1" == "16" ]; then 12 | echo "Starting server for PSQL 16" 13 | PSQL16=@PSQL16_BINDIR@ 14 | BINDIR="$PSQL16" 15 | elif [ "$1" == "orioledb-16" ]; then 16 | echo "Starting server for PSQL ORIOLEDB 16" 17 | PSQLORIOLEDB16=@PSQLORIOLEDB16_BINDIR@ 18 | BINDIR="$PSQLORIOLEDB16" 19 | else 20 | echo "Please provide a valid Postgres version (15, 16 or orioledb-16)" 21 | exit 1 22 | fi 23 | 24 | export PATH=$BINDIR/bin:$PATH 25 | 26 | PGSQL_SUPERUSER=@PGSQL_SUPERUSER@ 27 | MASTER_PORTNO="$2" 28 | REPLICA_PORTNO="$3" 29 | REPLICA_SLOT="replica_$RANDOM" 30 | DATDIR=$(mktemp -d) 31 | mkdir -p "$DATDIR" 32 | 33 | echo "NOTE: runing pg_basebackup for server on port $MASTER_PORTNO" 34 | echo "NOTE: using replica slot $REPLICA_SLOT" 35 | 36 | pg_basebackup -p "$MASTER_PORTNO" -h localhost -U "${PGSQL_SUPERUSER}" -X stream -C -S "$REPLICA_SLOT" -v -R -D "$DATDIR" 37 | 38 | echo "NOTE: using port $REPLICA_PORTNO for replica" 39 | echo "NOTE: using temporary directory $DATDIR for data, which will not be removed" 40 | echo "NOTE: you are free to re-use this data directory at will" 41 | echo 42 | 43 | exec postgres -p "$REPLICA_PORTNO" -D "$DATDIR" -k /tmp 44 | -------------------------------------------------------------------------------- /tools/run-server.sh.in: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # shellcheck shell=bash 3 | 4 | [ ! -z "$DEBUG" ] && set -x 5 | 6 | # first argument should be '15' or '16' for the version 7 | if [ "$1" == "15" ]; then 8 | echo "Starting server for PSQL 15" 9 | PSQL15=@PSQL15_BINDIR@ 10 | BINDIR="$PSQL15" 11 | elif [ "$1" == "16" ]; then 12 | echo "Starting server for PSQL 16" 13 | PSQL16=@PSQL16_BINDIR@ 14 | BINDIR="$PSQL16" 15 | elif [ "$1" == "orioledb-16" ]; then 16 | echo "Starting server for PSQL ORIOLEDB 16" 17 | PSQLORIOLEDB16=@PSQLORIOLEDB16_BINDIR@ 18 | BINDIR="$PSQLORIOLEDB16" 19 | else 20 | echo "Please provide a valid Postgres version (15, 16 or orioledb-16)" 21 | exit 1 22 | fi 23 | 24 | export PATH=$BINDIR/bin:$PATH 25 | 26 | PGSQL_SUPERUSER=@PGSQL_SUPERUSER@ 27 | PSQL_CONF_FILE=@PSQL_CONF_FILE@ 28 | PGSODIUM_GETKEY_SCRIPT=@PGSODIUM_GETKEY@ 29 | PORTNO="${2:-@PGSQL_DEFAULT_PORT@}" 30 | DATDIR=$(mktemp -d) 31 | mkdir -p "$DATDIR" 32 | 33 | echo "NOTE: using port $PORTNO for server" 34 | echo "NOTE: using temporary directory $DATDIR for data, which will not be removed" 35 | echo "NOTE: you are free to re-use this data directory at will" 36 | echo 37 | 38 | initdb -U "$PGSQL_SUPERUSER" -D "$DATDIR" --locale=C 39 | 40 | echo "NOTE: patching postgresql.conf files" 41 | sed \ 42 | "s#@PGSODIUM_GETKEY_SCRIPT@#$PGSODIUM_GETKEY_SCRIPT#g" \ 43 | $PSQL_CONF_FILE > "$DATDIR/postgresql.conf" 44 | 45 | exec postgres -p "$PORTNO" -D "$DATDIR" -k /tmp 46 | --------------------------------------------------------------------------------