Skip to content

Instantly share code, notes, and snippets.

@cmdr-rohit-bang
Created March 8, 2025 05:08
Show Gist options
  • Save cmdr-rohit-bang/b3e9b2e41d5b2d3f2b058a3ee4ca3528 to your computer and use it in GitHub Desktop.
Save cmdr-rohit-bang/b3e9b2e41d5b2d3f2b058a3ee4ca3528 to your computer and use it in GitHub Desktop.

Step 1: Check the Installed Versions

First, verify which PostgreSQL versions are installed:

brew list | grep postgresql

Then, check the location of pg_restore:

which pg_restore

And confirm the version it is using:

pg_restore --version

If it's still showing PostgreSQL 14, it means your system is not using the newly installed PostgreSQL version.


Step 2: Check Homebrew PostgreSQL Installation

Find out the installed PostgreSQL versions via:

brew info postgresql

If you recently upgraded, you might have a newer version installed but not linked.

Run:

brew link postgresql

If you see an error about conflicting files, force the link:

brew link --overwrite postgresql

Then, restart your terminal and check pg_restore --version again.


Step 3: Use the Correct pg_restore Binary

Homebrew installs newer PostgreSQL versions under /opt/homebrew/bin (for Apple Silicon) or /usr/local/bin (for Intel Macs).
List the available versions:

ls /opt/homebrew/Cellar/postgresql/

(or for Intel Macs)

ls /usr/local/Cellar/postgresql/

If a newer version (e.g., 16.x) is installed, but pg_restore is still using an older one, run:

/opt/homebrew/Cellar/postgresql/16.2/bin/pg_restore --version

(or)

/usr/local/Cellar/postgresql/16.2/bin/pg_restore --version

If this shows the correct version, update your PATH:

echo 'export PATH="/opt/homebrew/Cellar/postgresql/16.2/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

Or for Intel Macs:

echo 'export PATH="/usr/local/Cellar/postgresql/16.2/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

Now, check pg_restore --version again.


Step 4: Manually Install PostgreSQL 16

If Homebrew isn’t working as expected, manually install PostgreSQL 16:

brew install postgresql@16
brew link postgresql@16 --force

Then check:

pg_restore --version

Step 5: Restart Services

If you've installed PostgreSQL 16 but it's not active, restart the service:

brew services restart postgresql

Then, verify again:

pg_restore --version

Final Check

Once pg_restore shows PostgreSQL 16.x, try running your restore command again.

Let me know if you need more help! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment