DEV Community

Geoff B.
Geoff B.

Posted on • Originally published at geoffroybaumier.hashnode.dev

Upgrading postgreSQL with Homebrew

After upgrading a few programs including postgres when starting a new project, I ran into an issue. I already had some postgres databases from older projects and I couldn't start postgres (and create my new database).

To install postgres with brew I used:

$ brew install postgres
Enter fullscreen mode Exit fullscreen mode

To see if postgres is running I can type:

$ brew services 
Name       Status  User Plist
postgresql stopped 
Enter fullscreen mode Exit fullscreen mode

Then the funny thing was when I tried to start the service:

$ brew services start postgres
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)
Enter fullscreen mode Exit fullscreen mode

Great! So it's running! But no..

$ brew services
Name       Status  User             Plist
postgresql error   geoffroy_baumier /Users/geoffroy_baumier/Library/LaunchAgents/homebrew.mxcl.postgresql.plist               
Enter fullscreen mode Exit fullscreen mode

To see what is the issue, let's look at the logs:

$ tail /usr/local/var/log/postgres.log
2021-01-26 21:12:47.678 CET [8757] FATAL:  database files are incompatible with server
2021-01-26 21:12:47.678 CET [8757] DETAIL:  The data directory was initialized by PostgreSQL version 12, which is not compatible with this version 13.1.
Enter fullscreen mode Exit fullscreen mode

And there was the issue.

All I had to do to fix this was to run this command:

$ brew postgresql-upgrade-database
Enter fullscreen mode Exit fullscreen mode

Then let's start it postgres:

$ brew services start postgres
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)

$ brew services
Name          Status  User             Plist
postgresql    started geoffroy_baumier /Users/geoffroy_baumier/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
postgresql@12 stopped      
Enter fullscreen mode Exit fullscreen mode

No I can see that I have two postgres services with the two different versions. I can create my new updated database. Also the good thing is that I didn't lose any data from previous project and I can run the service with version 12 if I ever need it.

Top comments (0)