{"id":2850,"date":"2020-12-22T18:58:10","date_gmt":"2020-12-22T18:58:10","guid":{"rendered":"https:\/\/linuxways.net\/?p=2850"},"modified":"2020-12-22T19:04:28","modified_gmt":"2020-12-22T19:04:28","slug":"how-to-install-postgresql-in-centos-8","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/centos\/how-to-install-postgresql-in-centos-8\/","title":{"rendered":"How to Install PostgreSQL in CentOS 8"},"content":{"rendered":"<p>PostgreSQL, which is popular with a name as Postgres, is an open-source and freely available relational database management system. This type of database server more emphasis on SQL compliance and extensibility. In this article, we will elaborate on the installation of PostgreSQL on CentOS 8 Linux distribution.<\/p>\n<h2><strong>Prerequisites<\/strong><\/h2>\n<p>You should be login as the root user or you must have privileges to run the \u2018sudo\u2019 command on your system.<\/p>\n<h2><strong>Installation of PostgreSQL databases on CentOS 8<\/strong><\/h2>\n<p>First, you will open the command line application \u2018Terminal\u2019 by clicking on the terminal icon from the left sidebar of your desktop. Type the below-mentioned command to log in on your terminal as the root user:<\/p>\n<pre>$ su<\/pre>\n<p>Enter the root account password.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"777\" height=\"127\" class=\"wp-image-2851\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-404.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-404.png 777w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-404-300x49.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-404-768x126.png 768w\" sizes=\"auto, (max-width: 777px) 100vw, 777px\" \/><\/p>\n<p>Now, you can run all the administrative commands for PostgreSQL installation.<\/p>\n<p>To complete the installation of PostgreSQL on CentOS 8, you will implement the following steps:<\/p>\n<h3><strong>Step 1: Update system cache<\/strong><\/h3>\n<p>It is a recommended and quite an easy step that you should update the repository cache of your system repository or packages by using the following command:<\/p>\n<pre># dnf makecache<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"735\" height=\"170\" class=\"wp-image-2852\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-405.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-405.png 735w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-405-300x69.png 300w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/p>\n<h3><strong>Step 2: Install PostgreSQL<\/strong><\/h3>\n<p>All package has been updated. Now, execute the below-given command to install the PostgreSQL server on your system:<\/p>\n<pre># dnf install postgresql postgresql-server<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"737\" height=\"500\" class=\"wp-image-2853\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-406.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-406.png 737w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-406-300x204.png 300w\" sizes=\"auto, (max-width: 737px) 100vw, 737px\" \/><\/p>\n<p>During the installation, you need to press \u2018y\u2019 and then hit the \u2018Enter\u2019 key to confirm the installation of PostgreSQL.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"735\" height=\"446\" class=\"wp-image-2854\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-407.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-407.png 735w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-407-300x182.png 300w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/p>\n<p>The complete status will display on the terminal that represents the installation of PostgreSQL has been completed.<\/p>\n<h3><strong>Step 3: Check installed version of PostgreSQL<\/strong><\/h3>\n<p>Once the installation of PostgreSQL is complete, to verify the working of PostgreSQL databases run the below-mentioned command:<\/p>\n<pre># postgres --version<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"732\" height=\"57\" class=\"wp-image-2855\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-408.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-408.png 732w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-408-300x23.png 300w\" sizes=\"auto, (max-width: 732px) 100vw, 732px\" \/><\/p>\n<p>As you can see in the above screenshot the Postgres 10.14 is installed on this system.<\/p>\n<h3><strong>Step 4: Initialize the PostgreSQL database<\/strong><\/h3>\n<p>To initialize the PostgreSQL database server directory, type the following command on the terminal:<\/p>\n<pre># postgresql-setup --initdb<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"733\" height=\"73\" class=\"wp-image-2856\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-409.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-409.png 733w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-409-300x30.png 300w\" sizes=\"auto, (max-width: 733px) 100vw, 733px\" \/><\/p>\n<h3><strong>Step 5: Enable and Start PostgreSQL services<\/strong><\/h3>\n<p>You can enable the services of PostgreSQL by running the following set of commands:<\/p>\n<pre># systemctl enable postgresql<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"730\" height=\"82\" class=\"wp-image-2857\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-410.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-410.png 730w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-410-300x34.png 300w\" sizes=\"auto, (max-width: 730px) 100vw, 730px\" \/><\/p>\n<p>To know the services running status, use the below-mentioned commands:<\/p>\n<pre># systemctl start postgresql<\/pre>\n<pre># systemctl status postgresql<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"735\" height=\"43\" class=\"wp-image-2858\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-411.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-411.png 735w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-411-300x18.png 300w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"732\" height=\"493\" class=\"wp-image-2859\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-412.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-412.png 732w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-412-300x202.png 300w\" sizes=\"auto, (max-width: 732px) 100vw, 732px\" \/><\/p>\n<h2><strong>Remove PostgreSQL server<\/strong><\/h2>\n<p>If you don\u2019t want to use the PostgreSQL database server on your system then, by using the following command you can remove it:<\/p>\n<pre># dnf remove postgresql postgresql-server<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"730\" height=\"498\" class=\"wp-image-2860\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-413.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-413.png 730w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-413-300x205.png 300w\" sizes=\"auto, (max-width: 730px) 100vw, 730px\" \/><\/p>\n<h2><strong>Creating a new PostgreSQL database<\/strong><\/h2>\n<p>Login as root on your PostgreSQL database server as follows:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"738\" height=\"202\" class=\"wp-image-2861\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-414.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-414.png 738w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-414-300x82.png 300w\" sizes=\"auto, (max-width: 738px) 100vw, 738px\" \/><\/p>\n<p>Now, we have created a new PostgreSQL database with the name \u2018samreenadb\u2019 by using the following command:<\/p>\n<pre>$ createdb samreenadb<\/pre>\n<p>Now, access the created database \u2018samreenadb\u2019 by using the following command:<\/p>\n<pre>$ psql samreenadb<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"729\" height=\"201\" class=\"wp-image-2862\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-415.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-415.png 729w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-415-300x83.png 300w\" sizes=\"auto, (max-width: 729px) 100vw, 729px\" \/><\/p>\n<p>To test the working of the above-mentioned database execute the following SQL query:<\/p>\n<pre>SELECT CURRENT_DATE;<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"734\" height=\"336\" class=\"wp-image-2863\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-416.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-416.png 734w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-416-300x137.png 300w\" sizes=\"auto, (max-width: 734px) 100vw, 734px\" \/><\/p>\n<p>As you can see in the above-displayed image, the query is working on this database.<\/p>\n<h2><strong>Create Tables in PostgreSQL Database<\/strong><\/h2>\n<p>Here, we can create tables and assigned privileges on this database by pasting the following code in your current database shell which you can also see in the below-displayed screenshot:<\/p>\n<pre>CREATE TABLE users (\n\nid INT NOT NULL,\n\nname VARCHAR(16) NOT NULL,\n\npin VARCHAR(4) NOT NULL\n\n);<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"735\" height=\"293\" class=\"wp-image-2864\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-417.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-417.png 735w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-417-300x120.png 300w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/p>\n<p>As you can see the table is created in the above screenshot with the name \u2018users\u2019.<\/p>\n<p>To list all tables or relations of your database run the below-given command:<\/p>\n<pre># \\d<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"730\" height=\"166\" class=\"wp-image-2865\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-418.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-418.png 730w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-418-300x68.png 300w\" sizes=\"auto, (max-width: 730px) 100vw, 730px\" \/><\/p>\n<p>To exit from the database type the following command:<\/p>\n<pre># \\q<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"691\" height=\"60\" class=\"wp-image-2866\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-419.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-419.png 691w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-419-300x26.png 300w\" sizes=\"auto, (max-width: 691px) 100vw, 691px\" \/><\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>So, we have demonstrated in this article how you install and remove the PostgreSQL server and create a database in PostgreSQL on CentOS 8. We have also shown how you can add tables in the database by using the SQL query. I hope this article would be helpful and knowledgeable for you.<\/p>","protected":false},"excerpt":{"rendered":"<p>PostgreSQL, which is popular with a name as Postgres, is an open-source and freely available relational database management system. This type of database server more emphasis on SQL&hellip;<\/p>","protected":false},"author":2,"featured_media":2872,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[93,43],"class_list":["post-2850","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","tag-centos-8","tag-postgresql"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/2850","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\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=2850"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/2850\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/2872"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=2850"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=2850"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=2850"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}