Skip to content

Instantly share code, notes, and snippets.

@egatjens
Last active March 2, 2020 17:19
Show Gist options
  • Save egatjens/c42a4dc82e016dadd7bac970bd990bda to your computer and use it in GitHub Desktop.
Save egatjens/c42a4dc82e016dadd7bac970bd990bda to your computer and use it in GitHub Desktop.
Homebrew Postgresql

Homebrew, use multiple database versions

Install versions

brew install postgresql@9.5
brew install postgresql@10

Commands

brew services start postgresql@9.5
brew services stop postgresql@9.5
brew services restart postgresql@9.5

brew services start postgresql@10
brew services stop postgresql@10
brew services restart postgresql@10

pg_ctl -D /usr/local/var/postgres status

Switch versions

Stop and unlink current:

brew services stop postgresql@9.5

brew unlink postgresql@9.5

Link new version:

brew link postgresql@10 --force

Start:

brew services start postgresql@10

Check config data

PostgreSQL has specific command to get config details: pg_config

The output should show the route to the right version: /usr/local/Cellar/postgresql@10/...

InitDB

# Before: Make sure PG_VERSION is the correct one
cat /usr/local/var/postgres/PG_VERSION 

initdb /usr/local/var/postgres

PostgreSQL file and database locations

config file: /usr/local/var/postgres/postgresql.conf

client authentication config: /usr/local/var/postgres/pg_hba.conf

config folder: /usr/local/var/postgres

bin folder: /usr/local/Cellar/postgresql/11.2/bin

database location: /usr/local/var/postgres

ref: https://igorkhromov.com/2019/04/10/install-postrgesql-om-macos-with-brew

Troubleshoting

FATAL: role "postgres" does not exist

unset PGUSER
createuser -s postgres

# then, create your user and database
createuser my_user --createdb
createdb my_db -U my_user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment