{"id":1505,"date":"2021-08-11T15:38:32","date_gmt":"2021-08-11T10:08:32","guid":{"rendered":"http:\/\/www.webhostingchennai.co.in\/blog\/?p=1505"},"modified":"2021-09-27T17:24:32","modified_gmt":"2021-09-27T11:54:32","slug":"how-to-install-postgresql","status":"publish","type":"post","link":"https:\/\/chennaiwebhosting.in\/blog\/how-to-install-postgresql\/","title":{"rendered":"How To Install PostgreSQL 11 \/ 10 on CentOS 7"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_80 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/chennaiwebhosting.in\/blog\/how-to-install-postgresql\/#How_To_Install_PostgreSQL_11_10_on_CentOS_7\" >How To Install PostgreSQL 11 \/ 10 on CentOS 7<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/chennaiwebhosting.in\/blog\/how-to-install-postgresql\/#Prerequisites\" >Prerequisites<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/chennaiwebhosting.in\/blog\/how-to-install-postgresql\/#Setup_PostgreSQL_repository\" >Setup PostgreSQL repository<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/chennaiwebhosting.in\/blog\/how-to-install-postgresql\/#Install_PostgreSQL_11_10_on_CentOS_7\" >Install PostgreSQL 11 \/ 10 on CentOS 7<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/chennaiwebhosting.in\/blog\/how-to-install-postgresql\/#Initialize_PostgreSQL_Server\" >Initialize PostgreSQL Server<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/chennaiwebhosting.in\/blog\/how-to-install-postgresql\/#Controlling_PostgreSQL_Service\" >Controlling PostgreSQL Service<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/chennaiwebhosting.in\/blog\/how-to-install-postgresql\/#Configuring_PostgreSQL_Server\" >Configuring PostgreSQL Server<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/chennaiwebhosting.in\/blog\/how-to-install-postgresql\/#Access_PostgreSQL_server\" >Access PostgreSQL server<\/a><\/li><\/ul><\/nav><\/div>\n<h4><span class=\"ez-toc-section\" id=\"How_To_Install_PostgreSQL_11_10_on_CentOS_7\"><\/span><span style=\"text-decoration: underline;\">How To Install PostgreSQL 11 \/ 10 on CentOS 7<\/span><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p><a href=\"https:\/\/www.postgresql.org\/\" rel=\"nofollow noopener\" target=\"_blank\">PostgreSQL<\/a> is an object-relational database management system (ORDBMS) available for many platforms including Linux, FreeBSD, Solaris, Microsoft Windows, and Mac OS X. It is an open source DBMS system with an emphasis on extensibility and standards compliance.It can handle workloads ranging from small single-machine applications to large Internet-facing applications with many concurrent users.<\/p>\n<figure id=\"attachment_1510\" aria-describedby=\"caption-attachment-1510\" style=\"width: 640px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1510 size-full\" src=\"http:\/\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2019\/04\/PostgreSQL-Basic-Architecure.png\" alt=\"How To Install PostgreSQL\" width=\"640\" height=\"375\" \/><figcaption id=\"caption-attachment-1510\" class=\"wp-caption-text\">PostgreSQL Basic Architecure<\/figcaption><\/figure>\n<h4 class=\"fittexted_for_content_h4\"><span class=\"ez-toc-section\" id=\"Prerequisites\"><\/span>Prerequisites<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ol>\n<li>Server with root login (CentOS 7)<\/li>\n<\/ol>\n<h4><span class=\"ez-toc-section\" id=\"Setup_PostgreSQL_repository\"><\/span><span style=\"text-decoration: underline;\">Setup PostgreSQL repository<\/span><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>PostgreSQL publishes rpm packages for all Linux platforms, their packages are fresher than those available in the OS repositories already exists on the server.<\/p>\n<p>Now, we need to add the repository by installing PostgreSQL repo rpm.<\/p>\n<p><span style=\"text-decoration: underline;\">PostgreSQL 11<\/span><\/p>\n<pre>yum install -y https:\/\/download.postgresql.org\/pub\/repos\/yum\/11\/redhat\/rhel-7-x86_64\/pgdg-centos11-11-2.noarch.rpm<\/pre>\n<p><span style=\"text-decoration: underline;\">PostgreSQL 10<\/span><\/p>\n<pre>yum install -y https:\/\/download.postgresql.org\/pub\/repos\/yum\/10\/redhat\/rhel-7-x86_64\/pgdg-centos10-10-2.noarch.rpm\r\n\r\n<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"Install_PostgreSQL_11_10_on_CentOS_7\"><\/span><span style=\"text-decoration: underline;\">Install PostgreSQL 11 \/ 10 on CentOS 7<\/span><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Install PostgreSQL 11 \/ 10 using, yum command.<\/p>\n<p><span style=\"text-decoration: underline;\">PostgreSQL 11<\/span><\/p>\n<pre>yum install -y postgresql11-server postgresql11<\/pre>\n<p><span style=\"text-decoration: underline;\">PostgreSQL 10<\/span><\/p>\n<pre>yum install -y postgresql10-server postgresql10<\/pre>\n<p>&nbsp;<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Initialize_PostgreSQL_Server\"><\/span><span style=\"text-decoration: underline;\">Initialize PostgreSQL Server<\/span><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>After completing the installation of PostgreSQL, need to initialize if we are using it for the first time.<\/p>\n<p><span style=\"text-decoration: underline;\">PostgreSQL 11<\/span><\/p>\n<pre>\/usr\/pgsql-11\/bin\/postgresql-11-setup initdb<\/pre>\n<p><span style=\"text-decoration: underline;\">PostgreSQL 10<\/span><\/p>\n<pre>\/usr\/pgsql-10\/bin\/postgresql-10-setup initdb<\/pre>\n<p>PostgreSQL&#8217;s data is found at \/var\/lib\/pgsql\/&lt;version&gt;\/data\/ directory in default.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Controlling_PostgreSQL_Service\"><\/span><span style=\"text-decoration: underline;\">Controlling PostgreSQL Service<\/span><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>To start PostgreSQL service<\/p>\n<p><span style=\"text-decoration: underline;\">PostgreSQL 11<\/span><\/p>\n<pre>systemctl start postgresql-11<\/pre>\n<p><span style=\"text-decoration: underline;\">PostgreSQL 10<\/span><\/p>\n<pre>systemctl start postgresql-10\r\n\r\n<\/pre>\n<p>To enable PostgreSQL on system startup<\/p>\n<p><span style=\"text-decoration: underline;\">PostgreSQL 11<\/span><\/p>\n<pre>systemctl enable postgresql-11<\/pre>\n<p><span style=\"text-decoration: underline;\">PostgreSQL 10<\/span><\/p>\n<pre>systemctl enable postgresql-10<\/pre>\n<p>To check the status of PostgreSQL service<\/p>\n<p><span style=\"text-decoration: underline;\">PostgreSQL 11<\/span><\/p>\n<pre>systemctl status postgresql-11<\/pre>\n<p><span style=\"text-decoration: underline;\">PostgreSQL 10<\/span><\/p>\n<pre>systemctl status postgresql-10\r\n\r\n<\/pre>\n<p><strong>Sample output(PostgreSQL 11)<\/strong><\/p>\n<pre>[root@webhostingchennai ~]# systemctl status postgresql-11\r\n&lt;span style=&quot;color: #00ff00;&quot;&gt;\u25cf&lt;\/span&gt; postgresql-11.service - PostgreSQL 11 database server\r\n   Loaded: loaded (\/usr\/lib\/systemd\/system\/postgresql-11.service; enabled; vendor preset: disabled)\r\n   Active: &lt;span style=&quot;color: #00ff00;&quot;&gt;active (running)&lt;\/span&gt; since Fri 2019-04-12 13:06:40 EEST; 2 days ago\r\n     Docs: https:\/\/www.postgresql.org\/docs\/11\/static\/\r\n  Process: 23726 ExecStartPre=\/usr\/pgsql-11\/bin\/postgresql-11-check-db-dir ${PGDATA} (code=exited, status=0\/SUCCESS)\r\n Main PID: 23731 (postmaster)\r\n   CGroup: \/system.slice\/postgresql-11.service\r\n           \u251c\u250023731 \/usr\/pgsql-11\/bin\/postmaster -D \/var\/lib\/pgsql\/11\/data\/\r\n           \u251c\u250023733 postgres: logger\r\n           \u251c\u250023735 postgres: checkpointer\r\n           \u251c\u250023736 postgres: background writer\r\n           \u251c\u250023737 postgres: walwriter\r\n           \u251c\u250023738 postgres: autovacuum launcher\r\n           \u251c\u250023739 postgres: stats collector\r\n           \u2514\u250023740 postgres: logical replication launcher\r\n\r\nApr 15 13:41:01 server.webhostingchennai.co.in systemd[1]: Starting PostgreSQL 11 database server...\r\nApr 15 13:41:01 server.webhostingchennai.co.in postmaster[1408]: 2019-02-15 13:41:01.202 EST [1408] LOG:  listening on...432\r\nApr 15 13:41:01 server.webhostingchennai.co.in postmaster[1408]: 2019-02-15 13:41:01.202 EST [1408] LOG:  listening on...432\r\nApr 15 13:41:01 server.webhostingchennai.co.in postmaster[1408]: 2019-02-15 13:41:01.207 EST [1408] LOG:  listening on...32&quot;\r\nApr 15 13:41:01 server.webhostingchennai.co.in postmaster[1408]: 2019-02-15 13:41:01.213 EST [1408] LOG:  listening on...32&quot;\r\nApr 15 13:41:01 server.webhostingchennai.co.in postmaster[1408]: 2019-02-15 13:41:01.226 EST [1408] LOG:  redirecting ...ess\r\nApr 15 13:41:01 server.webhostingchennai.co.in postmaster[1408]: 2019-02-15 13:41:01.226 EST [1408] HINT:  Future log ...g&quot;.\r\nApr 15 13:41:01 server.webhostingchennai.co.in systemd[1]: Started PostgreSQL 11 database server.\r\n[root@webhostingchennai ~]#\r\n<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"Configuring_PostgreSQL_Server\"><\/span><span style=\"text-decoration: underline;\">Configuring PostgreSQL Server<\/span><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>In default, PostgreSQL listens on localhost that means you can access the database from the server only and won\u2019t be able to connect to the database remotely (outside network).<\/p>\n<p>To enable the database service access for external network, edit the configuration file.<\/p>\n<p><span style=\"text-decoration: underline;\">PostgreSQL 11<\/span><\/p>\n<pre>nano \/var\/lib\/pgsql\/11\/data\/postgresql.conf<\/pre>\n<p><span style=\"text-decoration: underline;\">PostgreSQL 10<\/span><\/p>\n<pre>nano \/var\/lib\/pgsql\/10\/data\/postgresql.conf<\/pre>\n<p>Set the <strong>listen_addresses<\/strong> to <strong>*<\/strong>.<\/p>\n<pre>listen_addresses = &#039;*&#039;<\/pre>\n<p>Restart PostgreSQL service.<\/p>\n<p><span style=\"text-decoration: underline;\">PostgreSQL 11<\/span><\/p>\n<pre>systemctl restart postgresql-11<\/pre>\n<p><span style=\"text-decoration: underline;\">PostgreSQL 10<\/span><\/p>\n<pre>systemctl restart postgresql-10<\/pre>\n<p>Confirm the PostgreSQL listening on port 5432 using netstat command.<\/p>\n<pre>[root@webhostingchennai ~]# netstat -aon | grep 5432\r\ntcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      off (0.00\/0\/0)\r\ntcp6       0      0 :::5432                 :::*                    LISTEN      off (0.00\/0\/0)\r\nunix  2      [ ACC ]     STREAM     LISTENING     348965   \/var\/run\/postgresql\/.s.PGSQL.5432\r\nunix  2      [ ACC ]     STREAM     LISTENING     348967   \/tmp\/.s.PGSQL.5432\r\n[root@webhostingchennai ~]#<\/pre>\n<p>Else you need to open port 5432 in your server by using the below commands.<\/p>\n<pre>firewall-cmd --zone=public --permanent --add-port=5432\/tcp\r\nfirewall-cmd --reload<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"Access_PostgreSQL_server\"><\/span><span style=\"text-decoration: underline;\">Access PostgreSQL server<\/span><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>To create a database, log in as postgres (Linux user). Login from the root user or reset the password of postgres user for login.<\/p>\n<pre>su -l postgres<\/pre>\n<p>Access the database using the psql command. It is an interactive front-end terminal for PostgreSQL database.<\/p>\n<pre>$ psql<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre>-bash-4.2$ psql\r\npsql (11.2)\r\nType &quot;help&quot; for help.<\/pre>\n<pre>postgres=#<\/pre>\n<p>Set password for postgres (Database administrator) user.<\/p>\n<pre>postgres=# \\password<\/pre>\n<p>Now, we have successfully installed the PostgreSQL 11 \/ 10 on CentOS 7.<\/p>\n<p><a href=\"https:\/\/www.webhostingchennai.co.in\/blog\/pgadmin-4-installation-steps\/\" rel=\"nofollow noopener\" target=\"_blank\">To install pgAdmin 4 on centOS 7 : Click here<\/a><\/p>\n<p>Kindly share your valuable comments to improve us.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How To Install PostgreSQL 11 \/ 10 on CentOS 7 PostgreSQL is an object-relational database management system (ORDBMS) available for many platforms including Linux, FreeBSD, Solaris, Microsoft Windows, and Mac OS X. It is an open source DBMS system with an emphasis on extensibility and standards compliance.It can handle workloads ranging from small single-machine applications [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1562,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[57,13,5],"tags":[58,59,60,61],"class_list":["post-1505","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos-redhat","category-centos-7-rhel-7","category-database","tag-pgsql-installation","tag-postgre-installation-on-centos-7","tag-postgresql-installation","tag-steps-to-install-postgresql"],"_links":{"self":[{"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/1505","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/comments?post=1505"}],"version-history":[{"count":1,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/1505\/revisions"}],"predecessor-version":[{"id":1534,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/1505\/revisions\/1534"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/media\/1562"}],"wp:attachment":[{"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/media?parent=1505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/categories?post=1505"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/tags?post=1505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}