Issue
I want to use a specific PostgreSQL client version that is not the one available by default in the stack that my app uses.
Resolution
The Heroku community-supported buildpack heroku-buildpack-apt
adds support for installing packages from apt
during build time. You can use this buildpack to install specific PostgreSQL client packages. As a use case example, this approach can be used to install specific PostgreSQL client versions of pg_dump
and pg_restore
to match the version of your database.
To set this up for your application:
-
Add the buildpack to your app:
heroku buildpacks:add --index 1 heroku-community/apt
-
Create a file named
Aptfile
in the root directory of your app. Add the appropriate package names for the version you need. For example, to install the PostgreSQL 15 client, theAptfile
file needs to include:postgresql-client-15
-
Commit and deploy your changes. You can then use the installed packages, located under
/app/.apt/usr/lib/postgresql
:~ $ ls /app/.apt/usr/lib/postgresql 15 ~ $ /app/.apt/usr/lib/postgresql/15/bin/pg_dump --version pg_dump (PostgreSQL) 15.12 (Ubuntu 15.12-1.pgdg22.04+1)