Here is the correct way to uninstall PostgreSQL on Mac

If you’ve installed PostgreSQL on your Mac for a project and no longer need it, it’s a good idea to uninstall it. That will help free up space on your Mac and prevent the possibility of conflicts with other files and software that could cause problems. In this article, we’ll explain the options for uninstalling PostgreSQL.

What is PostgreSQL?

Dating all the way back to 1982, PostgreSQL is a system for managing relational databases that is focused on allowing users to extend their capabilities and SQL compliance. It was the default database for macOS Server, but it also runs on Windows, Linux, FreeBSD, and OpenBSD. It’s free and open source. It can handle workloads on individual machines, web services, and data warehouses as well as support multiple concurrent users. It can also be used with services like AWS (Amazon Web Services).

Why uninstall PostgreSQL?

The main reason for uninstalling it, as with any tool you no longer use, is to prevent problems further down the line. If you’re not using software, it’s unlikely that you will keep it updated. And out-of-date software is a common cause of conflicts and can even leave your Mac vulnerable to malware attacks.

Now, let’s find out how to remove PostgreSQL from Mac. There are two options for uninstalling. One easy, one not so easy. Let’s tackle the easy method first; then, we’ll show you the not-so-easy way.

How to uninstall PostgreSQL the easy way

This method uses a tool that’s designed to uninstall apps and drivers and can also reset them to the state they were in when you first installed them if they run into trouble. The tool is CleanMyMac X, and as well as uninstalling and resetting apps, it has a bunch of other modules that can clear the clutter from your Mac and keep it running smoothly. You can download it for free here.

  1. Open CleanMyMac X.
  2. Go to Uninstaller from the left sidebar.
  3. Search for PostgreSQL and select the box next to it.
  4. Click Uninstall.

That’s it. That’s all you need to do to completely uninstall PostgreSQL with CleanMyMac X.

How to uninstall PostgreSQL manually

You’ll need to use the Terminal for this, but if you’ve used PostgreSQL, using the Terminal shouldn’t be an issue.

First, though, you need to shut down the server if it’s running on your Mac: click the elephant icon in the toolbar and choose “Shutdown server.”

Next, there are a couple of options for Terminal commands, depending on how you installed PostgreSQL. Try them in the order below. Only use the second one if the first is unsuccessful.

  1. Go to Applications > Utilities and open Terminal.
  2. Type the following command: open /Library/PostgreSQL/9.2/
  3. Press Return and type in your admin password when prompted.
  4. Follow the instructions on the screen.

If that doesn’t work, use this command:

  • Type this command and then hit Return: sudo /Library/PostgreSQL/9.1/
  • Type in your admin password when prompted.
  • Follow the instructions on the screen.

It’s possible that even though the Terminal commands above uninstall PostgreSQL, they will leave files on your startup disk. To get rid of those, you will need to run a couple more commands in Terminal:

  1. Type sudo rm /etc/postgres-reg.ini
  2. Press Return.
  3. Type sudo rm -rf /Library/PostgreSQL
  4. Press Return.

Finally, you will need to remove the PostgreSQL user account from your Mac:

  1. Click the Apple menu and choose System Settings.
  2. Choose Users & Groups.
  3. Select the PostgreSQL user.
  4. Click the i icon and choose Delete Account. Note that you cannot do it for the account you are logged in to. 
  5. Quit System Settings.

PostgreSQL should now be completely uninstalled.

PostgreSQL is a relational database management tool that may have been installed on your Mac by you or a previous user. If you don’t use it anymore, follow the steps above to uninstall and remove all of its files from your Mac.

Frequently asked questions

How to check if PostgreSQL is running?

You can use the following command: ps aux | grep postgres

If it is running, you’ll see some postgre processes. Or you can open Activity Monitor from Applications > Utilities and search postgre processes there.

How to find PostgreSQL version?

There is a command that can help you find PostgreSQL version: psql -–version

Or you can expand the Servers tree, left-click PostgreSQL > Properties via pgAdmin and look for the needed information there.

How to backup PostgreSQL database?

You will first have to log in to the PostgreSQL server and run a superuser. Use this command: 

su – postgres

Next, use pg_dump to backup one database at a time: 
pg_dump -U username -h hostname -p portnumber -F databasename > filename.sql

Laptop with CleanMyMac
CleanMyMac X

Your Mac. As good as new.