{"id":2692,"date":"2020-12-17T10:50:42","date_gmt":"2020-12-17T10:50:42","guid":{"rendered":"https:\/\/linuxways.net\/?p=2692"},"modified":"2020-12-17T10:50:44","modified_gmt":"2020-12-17T10:50:44","slug":"how-to-install-postgresql-on-debian-10","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/debian\/how-to-install-postgresql-on-debian-10\/","title":{"rendered":"How to Install PostgreSQL on Debian 10"},"content":{"rendered":"<h2>Introduction:<\/h2>\n<p>PostgreSQL is a very famous free and open-source relational database management system (DBMS) that was developed in 1996 and is still very extensively used. It is written in C programming language. The main reason behind using this relational DBMS is its support for all the three major operating systems i.e. Linux, macOS, and Windows along with some other minor operating systems. In today\u2019s article, our focus will be on the method of installing PostgreSQL on Debian 10.<\/p>\n<h2>Method of Installing PostgreSQL on Debian 10:<\/h2>\n<p>For installing PostgreSQL on your Debian 10 system, you have to perform all the steps that we have listed below:<\/p>\n<h3>Step # 1: Update your Debian 10 System:<\/h3>\n<p>Since we are going to install a new database management system (DBMS) on our Debian 10 system that is why we have to update our system\u2019s cache first with the help of the following command:<\/p>\n<pre><strong>sudo apt update<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"359\" height=\"26\" class=\"wp-image-2693\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-314.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-314.png 359w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-314-300x22.png 300w\" sizes=\"auto, (max-width: 359px) 100vw, 359px\" \/><\/strong><\/p>\n<p>Once our Debian 10 system will finish the update, it will display the number of packages to be upgraded as shown in the image below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"672\" height=\"193\" class=\"wp-image-2694\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-315.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-315.png 672w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-315-300x86.png 300w\" sizes=\"auto, (max-width: 672px) 100vw, 672px\" \/><\/p>\n<h3>Step # 2: Install PostgreSQL on your Debian 10 System:<\/h3>\n<p>After updating our Debian 10 system, we are good to go with the installation of PostgreSQL on it. It can be installed by running the following command:<\/p>\n<pre><strong>sudo apt install postgresql postgresql-contrib<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"25\" class=\"wp-image-2695\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-316.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-316.png 640w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-316-300x12.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/strong><\/p>\n<p>The PostgreSQL DBMS will take a few minutes to install on Debian 10 along with all of its required packages and dependencies. Once it is installed, your terminal will allow you to proceed further as shown in the image below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"723\" height=\"402\" class=\"wp-image-2696\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-317.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-317.png 723w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-317-300x167.png 300w\" sizes=\"auto, (max-width: 723px) 100vw, 723px\" \/><\/p>\n<h3>Step # 3: Check the Version of the Installed PostgreSQL on your Debian 10 System:<\/h3>\n<p>After installing PostgreSQL on Debian 10, you can check out its version by executing the following command:<\/p>\n<pre><strong>psql --version<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"351\" height=\"27\" class=\"wp-image-2697\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-318.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-318.png 351w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-318-300x23.png 300w\" sizes=\"auto, (max-width: 351px) 100vw, 351px\" \/><\/strong><\/p>\n<p>The version of PostgreSQL installed on our Debian 10 system is shown in the image below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"421\" height=\"67\" class=\"wp-image-2698\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-319.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-319.png 421w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-319-300x48.png 300w\" sizes=\"auto, (max-width: 421px) 100vw, 421px\" \/><\/p>\n<h3>Step # 4: Start the PostgreSQL Service on Debian 10:<\/h3>\n<p>In some Linux distributions, the PostgreSQL service starts automatically, however, you can always start it manually by issuing the following command in your Debian 10 system:<\/p>\n<pre><strong>sudo systemctl start postgresql<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"504\" height=\"26\" class=\"wp-image-2699\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-320.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-320.png 504w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-320-300x15.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-320-501x26.png 501w\" sizes=\"auto, (max-width: 504px) 100vw, 504px\" \/><\/strong><\/p>\n<p>If the PostgreSQL service is started without any potential issues, then you will not face any error messages as shown in the image below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"515\" height=\"49\" class=\"wp-image-2700\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-321.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-321.png 515w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-321-300x29.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-321-501x49.png 501w\" sizes=\"auto, (max-width: 515px) 100vw, 515px\" \/><\/p>\n<h3>Step # 5: Check the Status of the PostgreSQL Service on Debian 10:<\/h3>\n<p>After starting the PostgreSQL service on your Debian 10 system, you can check its status by running the following command:<\/p>\n<pre><strong>sudo systemctl status postgresql<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"513\" height=\"31\" class=\"wp-image-2701\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-322.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-322.png 513w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-322-300x18.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-322-501x31.png 501w\" sizes=\"auto, (max-width: 513px) 100vw, 513px\" \/><\/strong><\/p>\n<p>The status of the PostgreSQL service on our Debian 10 system is shown in the image below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"723\" height=\"200\" class=\"wp-image-2702\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-323.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-323.png 723w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-323-300x83.png 300w\" sizes=\"auto, (max-width: 723px) 100vw, 723px\" \/><\/p>\n<h3>Step # 6: Check whether PostgreSQL is Accepting New Connections or not:<\/h3>\n<p>Additionally, you can also check whether your PostgreSQL DBMS is accepting new connections or not. This can be done by running the following command:<\/p>\n<pre><strong>pg_isready<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"318\" height=\"23\" class=\"wp-image-2703\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-324.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-324.png 318w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-324-300x22.png 300w\" sizes=\"auto, (max-width: 318px) 100vw, 318px\" \/><\/strong><\/p>\n<p>If your PostgreSQL service will be ready, then it will display the \u201caccepting connections\u201d status as shown in the image below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"446\" height=\"66\" class=\"wp-image-2704\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-325.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-325.png 446w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-325-300x44.png 300w\" sizes=\"auto, (max-width: 446px) 100vw, 446px\" \/><\/p>\n<h3>Step # 7: Switch to the Default User Account of PostgreSQL in Debian 10:<\/h3>\n<p>Now the next step is to access the PostgreSQL shell for which we have to switch to its default user account. When you install the PostgreSQL DBMS, a user account named \u201cpostgres\u201d is created by default. We can switch to that account by running the following command:<\/p>\n<pre><strong>sudo su \u2013 postgres<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"385\" height=\"28\" class=\"wp-image-2705\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-326.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-326.png 385w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-326-300x22.png 300w\" sizes=\"auto, (max-width: 385px) 100vw, 385px\" \/><\/strong><\/p>\n<p>When you will run this command, you will notice that the root user will switch to the default PostgreSQL user on the terminal as shown in the image below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"399\" height=\"46\" class=\"wp-image-2706\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-327.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-327.png 399w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-327-300x35.png 300w\" sizes=\"auto, (max-width: 399px) 100vw, 399px\" \/><\/p>\n<h3>Step # 8: Enter the PostgreSQL Shell in Debian 10:<\/h3>\n<p>Once you have switched to the default PostgreSQL user account in Debian 10, you can easily enter its shell by issuing the following command in the terminal:<\/p>\n<pre><strong>psql<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"265\" height=\"25\" class=\"wp-image-2707\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-328.png\" \/><\/strong><\/p>\n<p>The PostgreSQL shell is shown in the image below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"575\" height=\"164\" class=\"wp-image-2708\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-329.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-329.png 575w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-329-300x86.png 300w\" sizes=\"auto, (max-width: 575px) 100vw, 575px\" \/><\/p>\n<h2>Method of Removing PostgreSQL from Debian 10:<\/h2>\n<p>After getting your work done with the PostgreSQL DBMS in Debian 10, if you ever wish to remove this DBMS along with all of its configuration files, then you can execute the following command:<\/p>\n<pre><strong>sudo apt-get --purge remove postgresql\\*<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"586\" height=\"27\" class=\"wp-image-2709\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-330.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-330.png 586w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-330-300x14.png 300w\" sizes=\"auto, (max-width: 586px) 100vw, 586px\" \/><\/strong><\/p>\n<p>Once the PostgreSQL DBMS is removed from your Debian 10 system, it will display these messages on your terminal:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"724\" height=\"433\" class=\"wp-image-2710\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-331.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-331.png 724w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-331-300x179.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-331-501x300.png 501w\" sizes=\"auto, (max-width: 724px) 100vw, 724px\" \/><\/p>\n<p>Now when the PostgreSQL DBMS is removed successfully from your Debian 10 system, then you would no longer need those packages and dependencies that were installed automatically with this DBMS. For getting rid of all such packages and dependencies, you can run the following command in the terminal:<\/p>\n<pre><strong>sudo apt-get autoremove<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"436\" height=\"25\" class=\"wp-image-2711\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-332.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-332.png 436w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-332-300x17.png 300w\" sizes=\"auto, (max-width: 436px) 100vw, 436px\" \/><\/strong><\/p>\n<p>Once this command has removed all the unused and irrelevant packages and dependencies from your Debian 10 system, you will be displayed with the output shown in the image below on your terminal:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"690\" height=\"267\" class=\"wp-image-2712\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-333.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-333.png 690w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-333-300x116.png 300w\" sizes=\"auto, (max-width: 690px) 100vw, 690px\" \/><\/p>\n<h2>Conclusion:<\/h2>\n<p>In this article, we provided you with a brief introduction to the PostgreSQL DBMS. Then we explained to you step by step how you can install this extremely useful DBMS on your Debian 10 system. Finally, we also shared with you the method with which you can remove the PostgreSQL DBMS from your Debian 10 system.<\/p>","protected":false},"excerpt":{"rendered":"<p>Introduction: PostgreSQL is a very famous free and open-source relational database management system (DBMS) that was developed in 1996 and is still very extensively used. It is written&hellip;<\/p>","protected":false},"author":3,"featured_media":2713,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[17,43],"class_list":["post-2692","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-debian","tag-debian-10","tag-postgresql"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/2692","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=2692"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/2692\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/2713"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=2692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=2692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=2692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}