Make support/pg_bindir search for target PostgreSQL version

What does this merge request do and why?

Previously support/pg_bindir would return whatever version of PostgreSQL was available in the local path. For asdf users, this worked fine since .tool-versions specifies the target PostgreSQL version (14.9 currently). However, for users of Homebrew or other package managers, support/pg_bindir returns whatever is listed in PATH, which could be a stale version of PostgreSQL.

To fix this, we reuse the logic in the PostgreSQL upgrader, which looks for specific versions based on the package manager available (Homebrew, apt, rtx). We then use the target version as the current bin dir, and only fallback to whatever is in the PATH if the target version isn't available.

How to set up and validate locally

On macOS:

  1. Disable asdf by dropping it from the PATH.
  2. Attempt to run support/pg_bindir. This should return an error if no PostgreSQL version is available.
  3. Run brew install postgresql@13.
  4. Run support/pg_bindir. This should throw an error since PostgreSQL 14 is still not installed.
  5. Run brew install postgresql@14.
  6. This should print /opt/homebrew/Cellar/postgresql@14/14.9/bin.

Impacted categories

The following categories relate to this merge request:

Merge request checklist

  • This change is backward compatible. If not, please include steps to communicate to our users.
  • Tests added for new functionality. If not, please raise an issue to follow-up.
  • Documentation added/updated, if needed.
  • Announcement added, if change is notable.
  • gdk doctor test added, if needed.
  • Add the ~highlight label if this MR should be included in the CHANGELOG.md.
Edited by Stan Hu

Merge request reports

Loading