How to remove an old version of postgresql from OSX with multiple versions installed
Here is a short tutorial on how to remove older versions of PostgreSQL database from OSX when you have multiple versions installed.
If you follow one of the popular answers on StackOverFlow you may accidentally delete an important file for your other newer versions of PostgreSQL running on your Mac. These instructions assume you installed the database with the EnterpriseDB installer.
Here are the steps you need to follow:
- First, make a backup of the database if you need any data or schema. Use the graphical PgAdmin or commandline to do this.
- Open a terminal window
- Change to the super user by typing sudo su in that terminal window, enter your password
- Change directory to
Where X.Y is the older version you want to remove, example 9.5
- run the script in that directory
This should remove all of the main files but may not remove data files.
- Multiple versions of PostgreSQL on the same machine will share the file
Make sure not to delete it. Edit it and remove the section for the older version you want to remove from your machine.
- Next remove the directory version specific directory and any files under it
example rm -rf /Library/PostgreSQL/9.5
8. Finally, you need to update the home directory of the postgres user to point to the new directory of the new version of the database /Library/PostgreSQL/9.6
Open up a terminal window and run
open “/System/Library/CoreServices/Applications/Directory Utility.app”
click the “Directory Editor” icon at the top of the app.
click on the lock to authenticate yourself. enter your main user and password. The lock icon will turn to unlock if you did it correctly.
next make sure the drop down “Viewing” has the value Users selected. Locate the PostgreSQL entry in the list on the left by scrolling down and next select it. Now choose the NFSHomeDirectory on the right side panel. Change the 9.5 value to 9.6 in the string below. Then click the Save button. Now quit out of the application.
That is it, if you completed those steps, you will have removed the older version of the database.