Database Installation in Linux
Installing postgre sql installation in redhat / Cent OS linux
Step 1 — Installing PostgreSQL
Postgres can be installed using default CentOS repositories. But as of the writing of this tutorial, the version that is available in the CentOS 7 Base repository is obsolete. Therefore, this tutorial will use the official Postgres repository.
Before you move on to setting up a new repository, exclude the search for postgresql
packages from the CentOS-Base repository. Otherwise, dependencies might resolve to the postgresql
supplied by the base repository.
Open the repository configuration file using your preferred text editor.
sudo nano /etc/yum.repos.d/CentOS-Base.repo
Find the [base]
and [updates]
sections, enter insert mode by pressing i
, and insert the exclude=postgresql*
line in both sections. As a result, your file will look like the following, with new lines highlighted:
Now, install a repository configuration package using the official PostgreSQL repository for CentOS
sudo yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
The PostgreSQL repository includes information for all available PostgreSQL releases. You can see all available packages and versions using the following command
yum list postgresql* it will show all the packages can be installed related to postgresql
To install the PostgreSQL server use the following command
Step 2 — Creating a New PostgreSQL Database Cluster
You have to create a new PostgreSQL database cluster before you can use your Postgres database. A database cluster is a collection of databases that are managed by a single server instance. Creating a database cluster consists of creating the directories in which the database data will be placed, generating the shared catalog tables, and creating the template1
and postgres
databases
The template1
database is needed to create a new database. Everything that is stored in it will be placed in a new database when it is created. A postgres
database is a default database designed for use by users, utilities, and third-party applications.
Create a new PostgreSQL database cluster with initdb
sudo /usr/pgsql-11/bin/postgresql-11-setup initdb
Enable and Start the Postgresql service
Step 3 — Using PostgreSQL Roles and Databases
Switching Over to the postgres Account
You will be prompted to the psql prompt
To Exit out of the Prompt and Return to your bash shell
Done :)