How can I install a specific PostgreSQL client version on my dynos?

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:

  1. Add the buildpack to your app:

    heroku buildpacks:add --index 1 heroku-community/apt
    
  2. 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, the Aptfile file needs to include:

    postgresql-client-15
    
  3. 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)
    

Ask on Stack Overflow

Engage with a community of passionate experts to get the answers you need

Ask on Stack Overflow

Heroku Support

Create a support ticket and our support experts will get back to you

Contact Heroku Support