Home > Software engineering >  Unable to reinstall postgresql on mac
Unable to reinstall postgresql on mac

Time:12-15

I'm trying to reset postgreSQL but looks like it is stuck on Mac M1 with a password and every time that I uninstall and reinstall postgreSQL it is remembering the previously set password.

So when I run brew uninstall postgresql and then brew install postgresql it is not fixing the problem.

I tried to delete the /tmp/.s.PGSQL but it looks like that makes it worse because now can't find this file even on the reinstall.

So what is the proper way to completely remove postgreSQL from a Mac M1 and then reinstall it from 0.

CodePudding user response:

Disclaimer: Make sure you backup your db's in case you need them later because running these commands will delete all your local Postgres databases.

First you need to run:

$ brew uninstall postgres
$ rm -rf /usr/local/var/postgres
$ rm /usr/local/var/log/postgres.log
$ rm -f ~/.psqlrc ~/.psql_history

If you want to make sure there are no other Postgres-adjacent Homebrew formulae still installed you can eihter check via:

$ brew list --formula | grep -e postgres -e psql

or search your entire system for file name matches:

$ sudo find / -name "*postgres*" -o -name "*psql*"

Before reinstalling postgreSQL it might be a good time to reboot your machine. After the reboot run the following commands to get your fresh installation of postgreSQL:

Make sure your Homebrew is fully updated and give Homebrew a chance to diagnose any problems:

$ brew update
$ brew doctor

The diagnostic command $ brew doctor should exit cleanly with the simple message 'Your system is ready to brew.'

Now you can reinstall postgreSQL and see if it runs via:

$ brew install postgres
$ brew services start postgresql

Source: https://blog.testdouble.com/posts/2021-01-28-how-to-completely-uninstall-homebrew-postgres/

  • Related