Keywords: PostgreSQL Uninstall | Mac OSX | Homebrew | EnterpriseDB | System Cleanup
Abstract: This article provides a comprehensive guide to completely uninstall PostgreSQL 9.0.4 from Mac OSX Lion systems. It covers multiple installation methods including Homebrew, EnterpriseDB installer, and Postgres.app, with detailed step-by-step instructions for each approach. The guide includes command-line operations, residual file cleanup, and system configuration restoration to ensure a thorough removal process.
Introduction
PostgreSQL, as a powerful open-source relational database, can be installed on Mac OSX systems through various methods. However, when complete uninstallation is required, different installation approaches correspond to distinct removal procedures. Based on actual Q&A data and reference documentation, this article systematically organizes the complete solution for thoroughly uninstalling PostgreSQL 9.0.4 from Mac OSX Lion systems.
Installation Method Identification and Corresponding Uninstallation Approaches
Before beginning the uninstallation process, it's crucial to identify the installation method used for PostgreSQL. Common installation methods include Homebrew, EnterpriseDB installer, and Postgres.app. By examining the system directory structure, you can quickly identify the installation method: if the /usr/local/var/postgres directory exists, it's likely installed via Homebrew; if the /Library/PostgreSQL/ directory is found, it indicates use of the EnterpriseDB installer.
Uninstallation for Homebrew Installation
For PostgreSQL installed through Homebrew, the uninstallation process is relatively straightforward. First, ensure the PostgreSQL service is stopped by checking its status with: brew services list | grep postgresql. If the service is running, stop it using brew services stop postgresql. Then execute the core uninstall command: brew uninstall postgresql. This command removes the main PostgreSQL files managed by Homebrew but may leave behind some configuration files and cached data.
Residual File Cleanup
After completing the basic uninstallation, manual cleanup of residual files is necessary to ensure complete removal. Use the sudo find / -name "*postgres*" command to comprehensively search for all PostgreSQL-related files in the system. Based on the search results, focus on cleaning the following directories: /usr/local/var/postgres (data directory), /usr/local/Cellar/postgresql (if present), /Users/[username]/Library/Caches/Homebrew/postgresql-* (cache files), and various logs and configuration files.
Uninstallation Process for EnterpriseDB Installer
If PostgreSQL was installed using the EnterpriseDB official installer, the uninstallation process requires a dedicated uninstaller. First, locate the installation directory: /Library/PostgreSQL/9.0.4/, then execute sudo /Library/PostgreSQL/9.0.4/uninstall-postgresql.app/Contents/MacOS/installbuilder.sh. If a graphical interface is preferred, you can also use the open /Library/PostgreSQL/9.0.4/uninstall-postgresql.app command to launch the graphical uninstaller wizard.
System User and Configuration Cleanup
Regardless of the installation method used, PostgreSQL typically creates a dedicated user account in the system. In System Preferences' "Users & Groups" section, manually delete the user account named "postgres". Simultaneously, check and clean up related system configuration files, such as PostgreSQL-related settings in /etc/postgres-reg.ini and /etc/sysctl.conf.
Verifying Uninstallation Completeness
After completing all uninstallation steps, it's recommended to run the sudo find / -name "*postgres*" command again to verify if any residual files remain. Also check the system service list to ensure no PostgreSQL-related background processes are still running. Use the ps aux | grep postgres command to confirm all PostgreSQL processes have been terminated.
Common Issues and Solutions
During the uninstallation process, you may encounter permission issues, particularly when deleting system-level files requiring sudo privileges. If you encounter "file in use" errors, ensure all PostgreSQL-related processes have been stopped. For mixed installation scenarios using multiple methods, it's recommended to perform uninstallation operations in the order of Homebrew, EnterpriseDB, and Postgres.app.
Conclusion
Thoroughly uninstalling PostgreSQL requires selecting the appropriate uninstallation method based on the original installation approach, combined with system-level cleanup work. The complete uninstallation process provided in this article covers the entire procedure from service stopping, main program uninstallation to residual file cleanup, ensuring the system can completely return to its pre-PostgreSQL installation state, ready for reinstallation or other database deployments.