{"id":2984,"date":"2020-03-02T15:28:44","date_gmt":"2020-03-02T21:28:44","guid":{"rendered":"http:\/\/microsoftgeek.com\/?p=2984"},"modified":"2020-03-02T15:28:44","modified_gmt":"2020-03-02T21:28:44","slug":"how-to-completely-uninstall-postgresql","status":"publish","type":"post","link":"https:\/\/microsoftgeek.com\/?p=2984","title":{"rendered":"How To Completely Uninstall PostgreSQL"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"introduction\">Introduction<\/h2>\n\n\n\n<p>If you\u2019re using PostgreSQL, you may need to remove the package from your system at some point. It\u2019s important to know how to uninstall PostgreSQL properly to make sure all components of the package are completely removed and you don\u2019t encounter any errors. In this article, we\u2019ll explain how to uninstall PostgreSQL from Linux, macOS and Windows operating systems.<\/p>\n\n\n\n<p><strong><em>NOTE:<\/em><\/strong>&nbsp;Be sure to elevate the privileges for any of the commands in this article with&nbsp;<code>sudo<\/code>&nbsp;if the terminal returns a&nbsp;<code>Permission denied<\/code>&nbsp;error.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"uninstall+and+remove+postgresql+on+debian+linux\">Uninstall and remove PostgreSQL on Debian Linux<\/h2>\n\n\n\n<p>You can use the&nbsp;<code>apt-get<\/code>&nbsp;command to completely remove PostgreSQL on a Debian-based distribution of Linux such as Linux Mint or Ubuntu:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td>1<br>2<br>3<br><\/td><td>sudo&nbsp;apt-get&nbsp;&#8211;purge&nbsp;remove postgresql<br>sudo&nbsp;apt-get purge&nbsp;postgresql*<br>sudo&nbsp;apt-get&nbsp;&#8211;purge&nbsp;remove postgresql postgresql-doc postgresql-common<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"grep+for+all+postgresql+packages+in+debian+linux\">Grep for all PostgreSQL packages in Debian Linux<\/h3>\n\n\n\n<p>You can use the&nbsp;<code>dpkg<\/code>&nbsp;command for managing Debian packages, in conjunction with&nbsp;<code>grep<\/code>, to search for&nbsp;<em>all<\/em>&nbsp;the package names installed that contain the sub-string&nbsp;<code>postgres<\/code>. An example of this command is shown below:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td>1<br><\/td><td>dpkg&nbsp;-l&nbsp;|&nbsp;grep&nbsp;postgres<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Finally, make sure to use the APT-GET repository\u2019s&nbsp;<code>--purge remove<\/code>&nbsp;command, followed by the&nbsp;<code>postgres<\/code>&nbsp;package name. This command will remove the package and purge all the data associated with it:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td>1<br><\/td><td>sudo&nbsp;apt-get&nbsp;&#8211;purge&nbsp;remove&nbsp;{POSTGRESS-PACKAGE NAME}<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"remove+all+of+the+postgresql+data+and+directories\">Remove all of the PostgreSQL data and directories<\/h3>\n\n\n\n<p>Use the&nbsp;<code>rm<\/code>&nbsp;command with the&nbsp;<code>-rf<\/code>&nbsp;options to recursively remove all of the directories and data for the&nbsp;<code>postgresql<\/code>&nbsp;packages:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td>1<br>2<br>3<br><\/td><td>sudo&nbsp;rm&nbsp;-rf&nbsp;\/var\/lib\/postgresql\/<br>sudo&nbsp;rm&nbsp;-rf&nbsp;\/var\/log\/postgresql\/<br>sudo&nbsp;rm&nbsp;-rf&nbsp;\/etc\/postgresql\/<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.gyazo.com\/ee0f71928ba1c60e2e956dd34b959aa0.jpg\" alt=\"Screenshot of a Debian Ubuntu terminal uninstalling, removing, and purging postgresql\"\/><\/figure>\n\n\n\n<p>After you complete your&nbsp;<code>rm<\/code>&nbsp;commands, execute the&nbsp;<code>dpkg -l | grep postgres<\/code>&nbsp;command one more time to verify that all of the packages have been removed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"uninstall+and+remove+postgresql+packages+on+fedora+linux\">Uninstall and remove PostgreSQL packages on Fedora Linux<\/h2>\n\n\n\n<p>You can use the YUM repository\u2019s&nbsp;<code>yum<\/code>&nbsp;command to uninstall PostgreSQL on Fedora-based distributions of Linux such Red Hat or CentOS:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td>1<br><\/td><td>yum remove&nbsp;postgresql<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>To use a wildcard operator (<code>*<\/code>) to remove&nbsp;<em>all<\/em>&nbsp;packages with names beginning with&nbsp;<code>postgres<\/code>, use the following command:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td>1<br><\/td><td>yum remove&nbsp;postgres\\*<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Be sure to remove the&nbsp;<code>pgsql<\/code>&nbsp;directory as well:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td>1<br><\/td><td>rm&nbsp;\/var\/lib\/pgsql<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong><em>NOTE:<\/em><\/strong>&nbsp;Keep in mind that&nbsp;<code>sudo<\/code>&nbsp;is not enabled for RHEL users by default. Instead, use the&nbsp;<code>su<\/code>&nbsp;(switch user) command to enter as&nbsp;<code>root<\/code>&nbsp;and execute the above commands with elevated privileges if necessary.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"grep+for+the+postgresql+packages+in+fedora+using+%5C%27rpm%5C%27\">Grep for the PostgreSQL packages in Fedora using \u2018rpm\u2019<\/h3>\n\n\n\n<p>You can use the&nbsp;<code>rpm<\/code>&nbsp;command with the&nbsp;<code>-qa<\/code>&nbsp;options to grep for any packages that contain \u201cpostgres\u201d in their name:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td>1<br><\/td><td>rpm&nbsp;-qa&nbsp;|&nbsp;grep&nbsp;postgres<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>If you prefer, you can shorten the search to something like&nbsp;<code>post<\/code>&nbsp;as well:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td>1<br><\/td><td>rpm&nbsp;-qa&nbsp;|&nbsp;grep&nbsp;post<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.gyazo.com\/98c8f6f5aba3cd47a6f954c35c226e8b.jpg\" alt=\"Screenshot of Fedora Linux using grep to look for PostgreSQL packages\"\/><\/figure>\n\n\n\n<p>You can also use&nbsp;<code>grep<\/code>&nbsp;in conjunction with YUM\u2019s&nbsp;<code>list<\/code>&nbsp;command to return a list of all package instances of PostgreSQL:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td>1<br><\/td><td>yum list&nbsp;installed&nbsp;|&nbsp;grep&nbsp;postgres<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"uninstall+the+postgresql+package+using+yum+remove\">Uninstall the PostgreSQL package using YUM remove<\/h3>\n\n\n\n<p>Once you\u2019ve located the package, use YUM\u2019s&nbsp;<code>remove<\/code>&nbsp;command to uninstall PostgreSQL from your Linux system:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td>1<br><\/td><td>yum remove&nbsp;{POSTGRESS-PACKAGE NAME}<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Navigate to the assigned directory for the PostgreSQL data, and then use the&nbsp;<code>rm<\/code>&nbsp;command to delete all of your databases and tables.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"uninstall+and+remove+postgresql+from+windows\">Uninstall and remove PostgreSQL from Windows<\/h2>\n\n\n\n<p>If you\u2019re using Windows, type&nbsp;<code>uninstall<\/code>&nbsp;or&nbsp;<code>remove<\/code>&nbsp;into the search bar at the bottom left-hand side of the screen:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.gyazo.com\/0cc4e0f7ba90125b345cf594f2862635.jpg\" alt=\"Screenshot of Windows 10 removing the PostgreSQL application in settings\"\/><\/figure>\n\n\n\n<p>Then, follow the steps for the removal process, making sure to select the \u201cEntire Components option when prompted.<\/p>\n\n\n\n<p>You\u2019ll see a pop-up stating something like:&nbsp;<code>The data directory s(C:\\Program Files\\PostgreSQL\\11\\data) has not been removed<\/code>. Simply click \u201cOK\u201d to close the pop-up window, and&nbsp;<strong>do not<\/strong>&nbsp;select the option to restart your PC.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"delete+the+data+folder+for+postgresql+in+windows\">Delete the data folder for PostgreSQL in Windows<\/h3>\n\n\n\n<p>After you\u2019ve completed the removal process described in the previous section, open File Explorer for Windows and navigate to the&nbsp;<code>data<\/code>&nbsp;folder. Right-click the data folder and click the Delete button. Be sure to empty the recycle bin afterwards to ensure that any sensitive data has been properly deleted.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.gyazo.com\/91c039346c13fed943983bb4cdce0062.jpg\" alt=\"Screenshot of File Explorer in Windows 10 deleting the PostgreSQL 11 data folder\"\/><\/figure>\n\n\n\n<p>After all of the data has been deleted, you should restart Windows 10.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"uninstall+and+remove+postgresql+on+macos\">Uninstall and remove PostgreSQL on macOS<\/h2>\n\n\n\n<p>To uninstall PostgreSQL on macOS, open a new instance of Finder and navigate to the Applications directory. Look for the PostgreSQL folder and drag its contents to the Trash application folder in macOS.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.gyazo.com\/3a1c5da4e1c9c729285c132f6d1fa4e5.jpg\" alt=\"Screenshot of Finder in macOS placing PostgreSQL application in trash\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"remove+the+postgresql+data+in+a+terminal+in+macos\">Remove the PostgreSQL data in a terminal in macOS<\/h3>\n\n\n\n<p>After you\u2019ve removed the PostgreSQL folder, open the Utilities folder in a Finder window, and then open the Terminal application.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.gyazo.com\/c34c2d9e74651069489e23d44268b378.jpg\" alt=\"Screenshot of the Utilities folder and the Terminal application in macOS \"\/><\/figure>\n\n\n\n<p>Use the&nbsp;<code>cd<\/code>&nbsp;command to navigate to the&nbsp;<code>PostgreSQL<\/code>&nbsp;directory. You can do this by typing the directory path into the terminal prompt and pressing Return:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td>1<br><\/td><td>cd&nbsp;\/Library\/PostgreSQL\/11<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Then, use the&nbsp;<code>rm -rf<\/code>&nbsp;command to remove the directory and its contents:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td>1<br><\/td><td>sudo&nbsp;rm&nbsp;-rf<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Don\u2019t forget to empty the Trash application\u2019s contents when you are finished.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"uninstall+the+homebrew+installation+of+postgresql+on+macos\">Uninstall the Homebrew installation of PostgreSQL on macOS<\/h3>\n\n\n\n<p>You can use the&nbsp;<code>brew<\/code>&nbsp;command in a macOS terminal window to remove the Homebrew version of PostgreSQL. First, use the&nbsp;<code>list<\/code>&nbsp;command to return all of the applications installed using Homebrew:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td>1<br><\/td><td>brew list<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Then, use the following command to force the removal the Homebrew installation of&nbsp;<code>postgresql<\/code>:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td>1<br><\/td><td>brew uninstall&nbsp;&#8211;force&nbsp;postgresql<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n\n<p>If you find yourself needing to uninstall PostgreSQL, it\u2019s important to do a careful and thorough job. Taking shortcuts when it comes to the removal process can leave sensitive data remaining on your machine. In this article, we explained how to uninstall and remove PostgreSQL from Windows, Linux and macOS. With the step-by-step instructions detailed in this tutorial, you\u2019ll be ready to remove PostgreSQL from any of your own machines.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction If you\u2019re using PostgreSQL, you may need to remove the package from your system at some point. It\u2019s important to know how to uninstall PostgreSQL properly to make sure all components of the package are completely removed and you don\u2019t encounter any errors. In this article, we\u2019ll explain how to uninstall PostgreSQL from Linux, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-2984","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/2984","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2984"}],"version-history":[{"count":1,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/2984\/revisions"}],"predecessor-version":[{"id":2985,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/2984\/revisions\/2985"}],"wp:attachment":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}