How to Uninstall PostgreSQL (Windows/Mac/Linux)

How to Uninstall PostgreSQL (Windows/Mac/Linux)

PostgreSQL is a robust and Open Source relational database management system that has proven to be Scalable and Extensible.

You might want to uninstall PostgreSQL due to conflicts with other database software or when migrating to a different database system.

Uninstalling PostgreSQL can free up system resources and storage space, especially if it’s no longer needed for your project or application.

So let us go through how to uninstall PostgreSQL on Windows, Mac, and Linux.

Removing PostgreSQL on Windows

To uninstall PostgreSQL on Windows, you can follow these steps:[1][2]

  1. Stop the PostgreSQL service:
    • To open the Run dialog box, press Win + R.
    • Type services.msc and press Enter to open up the Windows services panel.
    • Locate the PostgreSQL service, right-click on it, and select “Stop.”
  2. Uninstall PostgreSQL using the Control Panel:
    • Open the Windows Settings dialog box by pressing Win + I.
    • Go to “Apps” or “Apps & features” depending on your Windows version.
    • Click on PostgreSQL, then click “Uninstall” or “Remove” and follow the uninstallation wizard.
  3. Delete the PostgreSQL data directory (if necessary):
    • The data directory is located in C:\Program Files\PostgreSQL\<version>\data by default.
    • Delete this directory to remove all data associated with the PostgreSQL installation. Make sure you have a backup if you need this data.
  4. Remove any remaining files or directories:
    • After uninstallation, check if any files or directories related to PostgreSQL remain. These might be in the installation directory or elsewhere where PostgreSQL files were.
  5. Remove PostgreSQL from the system’s PATH (optional):
    • Use the Windows search bar to find “Environment Variables” and select “Edit System Environment Variables.”
    • Click on “Environment Variables” in the System Properties window.
    • Under “System variables,” find the “Path” variable and select “Edit.”
    • Remove any paths that include references to the PostgreSQL installation directory.
  6. Restart your computer.

Removing PostgreSQL on Mac

To uninstall PostgreSQL from your Mac, you will need to follow these general steps:[3]

  1. Stop PostgreSQL Server: If PostgreSQL is running, stop it. You can do this using the following command in your terminal: sudo launchctl unload /Library/LaunchDaemons/org.postgresql.postgres.plist
  2. Remove PostgreSQL Files: After stopping the server, you can remove the PostgreSQL files. The exact locations may vary depending on your installation, but the default locations are:
    • Remove the PostgreSQL Application: sudo rm -rf /Library/PostgreSQL
    • Remove Data Directory: sudo rm -rf /Library/PostgreSQL/*version_number*/data
    • Remove Configuration Files: sudo rm -rf /etc/postgres-reg.ini
  3. Remove User Accounts: You may also want to remove the PostgreSQL user accounts. To do this, you can run the following command: sudo dscl . -delete /Users/postgres
  4. Remove PostgreSQL System User: If you have a system user for PostgreSQL, you can remove it by running the following command: sudo dscl . -delete /Users/_postgres
  5. Remove PostgreSQL Preferences and Cache Files: You may want to remove any preference and cache files related to PostgreSQL. The following commands do this:
    • sudo rm -rf ~/Library/Application\ Support/PostgreSQL
    • sudo rm -rf ~/Library/Caches/org.postgresql.PostgreSQL
  6. Remove any additional directories or files related to PostgreSQL that may have been created during the installation or use.

It’s a good idea to restart your machine after completing these steps.

Removing PostgreSQL on Linux

To uninstall PostgreSQL on a Linux system, you can follow these steps:[4]

  1. First, you need to stop the PostgreSQL service. Use the Systemctl command to do this. The service name might vary depending on your distribution, but common service names are postgresql or postgresql-<version>. Use the following command to stop the PostgreSQL service: sudo systemctl stop postgresql
  2. If you want to prevent PostgreSQL from starting on system boot, you can disable the service using the following command: sudo systemctl disable postgresql
  3. The command to uninstall PostgreSQL varies depending on your Linux distribution.
    • Ubuntu/Debian: sudo apt-get purge postgresql postgresql-contrib && sudo apt-get autoremove
    • CentOS/Fedora: sudo dnf remove postgresql postgresql-server postgresql-contrib
  4. Uninstalling PostgreSQL using the package manager doesn’t always remove configuration files and data. If you want to completely remove all PostgreSQL-related files, you can manually remove the PostgreSQL data directory and configuration files.
    • Data directory is typically in /var/lib/pgsql or /var/lib/postgresql. Use the following command to remove it: sudo rm -rf /var/lib/pgsql
    • Configuration files are usually in /etc/postgresql. You can remove the configuration files with: sudo rm -rf /etc/postgresql
  5. PostgreSQL creates a system user and group during installation. You can remove them if you’re sure they’re no longer needed. Replace <username> and <groupname> with the appropriate PostgreSQL user and group names (commonly postgres). sudo userdel <username> sudo groupdel <groupname>
  6. To remove any residual packages or dependencies that might not have been automatically removed, you can use the package manager’s cleanup command.
    • Ubuntu/Debian: sudo apt-get autoremove
    • CentOS/Fedora: sudo dnf autoremove

After performing the above steps, you can reboot your system to ensure any lingering processes or services are completely terminated.


  1. Uninstalling PostgreSQL. (n.d.). ↩︎
  2. Written by: Elijah Ugoh. (2023b, July 17). PostgreSQL download for free – 2024 Latest Version. WizCase. ↩︎
  3. Stavniychuk, D. (2023b, November 30). Here is the correct way to uninstall PostgreSQL on Mac. MacPaw. ↩︎
  4. How to completely uninstall PostgreSQL | ObjectRocket. (n.d.). ↩︎