CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 12:57:03 GMT
server: Fly/6f91d33b9d (2025-10-08)
content-type: text/html; charset=utf-8
content-encoding: gzip
via: 2 fly.io, 2 fly.io
fly-request-id: 01K79NH6ACWBKJRY478TQXDBCA-bom
Installing different PostgreSQL server versions in GitHub Actions | Simon Willison’s TILs
Installing different PostgreSQL server versions in GitHub Actions
The GitHub Actions ubuntu-latest
default runner currently includes an installation of PostgreSQL 13. The server is not running by default but you can interact with it like this:
$ /usr/lib/postgresql/13/bin/postgres --version
postgres (PostgreSQL) 13.3 (Ubuntu 13.3-1.pgdg20.04+1)
You can install alternative PostgreSQL versions by following the PostgreSQL Ubuntu instructions - like this:
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install postgresql-12
This works with postgresql-10
and postgresql-11
as well as postgresql-12
.
I wanted to use a GitHub Actions matrix to run my tests against all four versions of PostgreSQL. Here's my complete workflow - the relevant sections are below:
name: Test
on: [push]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
postgresql-version: [10, 11, 12, 13]
steps:
- name: Install PostgreSQL
env:
POSTGRESQL_VERSION: ${{ matrix.postgresql-version }}
run: |
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install "postgresql-$POSTGRESQL_VERSION"
- name: Run tests
env:
POSTGRESQL_VERSION: ${{ matrix.postgresql-version }}
run: |
export POSTGRESQL_PATH="/usr/lib/postgresql/$POSTGRESQL_VERSION/bin/postgres"
export INITDB_PATH="/usr/lib/postgresql/$POSTGRESQL_VERSION/bin/initdb"
pytest
I modified my tests to call the postgres
and initdb
binaries specified by the POSTGRESQL_PATH
and INITDB_PATH
environment variables.
Related
- github-actions Running tests against PostgreSQL in a service container - 2021-02-23
- github-actions Talking to a PostgreSQL service container from inside a Docker container - 2020-09-18
- github-actions Running tests against multiple versions of a Python dependency in GitHub Actions - 2023-09-15
- heroku Programatically accessing Heroku PostgreSQL from GitHub Actions - 2020-08-18
- github-actions Testing against Python 3.11 preview using GitHub Actions - 2022-02-02
- github-actions Deploying a live Datasette demo when the tests pass - 2022-03-27
- postgresql Upgrade Postgres.app on macOS - 2024-06-15
- datasette Writing Playwright tests for a Datasette Plugin - 2024-01-08
- heroku Using heroku pg:pull to restore a backup to a macOS laptop - 2020-07-10
- github-actions actions/setup-python caching for setup.py projects - 2022-11-28
Created 2021-07-05T17:43:13-07:00 · Edit