Completely removes PostgreSQL binaries, services, configs, and data from your operating system.
Uninstalling PostgreSQL means deleting the server binaries, stopping and disabling related services, purging configuration files, and wiping the data directory. Use your OS package manager for a clean, conflict-free removal.
Common reasons include reclaiming disk space, upgrading to a fresh major version, removing conflicting installations, or switching to a containerized setup. A clean uninstall avoids leftover libraries that can break future installs.
Stop the service first, purge all packages, and remove data and users.
sudo systemctl stop postgresql
sudo apt-get --purge remove postgresql\*
sudo apt-get autoremove --purge -y
sudo rm -rf /var/lib/postgresql/ /etc/postgresql/ /etc/postgresql-common/ /var/log/postgresql/
sudo deluser postgres
Use dnf or yum depending on the version.
sudo systemctl stop postgresql
sudo dnf remove postgresql* # yum remove postgresql* on older systems
sudo rm -rf /var/lib/pgsql/ /var/log/pgsql/ /etc/postgresql/
sudo userdel postgres -r
Homebrew keeps data outside Cellar; delete both.
brew services stop postgresql
brew uninstall --zap postgresql
rm -rf /usr/local/var/postgres
Use the Control Panel or Winget, then delete remaining folders.
winget uninstall PostgreSQL
After removal, delete C:\Program Files\PostgreSQL
and the data directory if you chose a custom path.
Run psql --version
. A “command not found” or empty result means binaries are gone. Also run systemctl status postgresql
(Linux) or check Services (Windows) to confirm no running service remains.
• Backup any required databases first with pg_dumpall
.
• Stop the PostgreSQL service before removing packages.
• Use the package manager’s purge/zap flag to erase configs.
• Remove the postgres
system user only when no other clusters exist.
1. Forgetting to delete the data directory leaves gigabytes on disk.
2. Skipping the service stop step can lock files or cause errors.
No, package removal keeps data unless you manually delete the data directory. Back up first, then remove the directory if you truly want everything gone.
Yes. Skip the data-directory deletion step, install the new version, then use pg_upgrade
to migrate data.
Only remove the postgres system user after confirming no PostgreSQL clusters remain. Other software rarely relies on that account.