Skip to content

Instantly share code, notes, and snippets.

@AbdullahGhani1
Last active August 29, 2022 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save AbdullahGhani1/04b063de19f35bc9d15e3496ae582887 to your computer and use it in GitHub Desktop.
Save AbdullahGhani1/04b063de19f35bc9d15e3496ae582887 to your computer and use it in GitHub Desktop.
Install and Configure Postgresql

Install and Configure Postgresql

The Nautilus application development team has shared that they are planning to deploy one newly developed application on Nautilus infra in Stratos DC. The application uses PostgreSQL database, so as a pre-requisite we need to set up PostgreSQL database server as per requirements shared below:

a. Install and configure PostgreSQL database on Nautilus database server.

b. Create a database user kodekloud_rin and set its password to TmPcZjtRQx.

c. Create a database kodekloud_db10 and grant full permissions to user kodekloud_rin on this database.

d. Make appropriate settings to allow all local clients (local socket connections) to connect to the kodekloud_db10 database through kodekloud_rin user using md5 method (Please do not try to encrypt password with md5sum).

e. At the end its good to test the db connection using these new credentials from root user or server's sudo user.

Click on ✔ and Do Task Again

Solution:

NOTE:

Change"kodekloud_db10" to kodekloud_gem

and Pssword AS Per Task

Login to database server

ssh peter@stdb01

Then login as root

sudo su -

Then install postgresql

yum install postgresql-server postgresql-contrib -y
postgresql-setup initdb
systemctl enable postgresql 
sudo systemctl start postgresql
systemctl status postgresql

Enter into postgresql database AS

sudo -u postgres psql postgres
Create user, database, and grant permission
CREATE USER kodekloud_gem WITH PASSWORD 'LQfKeWWxWD';
CREATE DATABASE kodekloud_db10;
GRANT ALL PRIVILEGES ON DATABASE "kodekloud_db10" to kodekloud_gem;

\q to exit from postgresql

Then set the config for local

sudo vi /var/lib/pgsql/data/pg_hba.conf

Go to bottom of the config and edit

local all all md5
host all all 127.0.0.1/32 md5  

Change peer,ident with md5

Next open another config

sudo vi /var/lib/pgsql/data/postgresql.conf

Uncomment listen_address=localhost

Then restart

sudo systemctl restart postgresql
sudo systemctl status postgresql.service

Finally Check

psql -U kodekloud_aim -d kodekloud_db8 -h 127.0.0.1 -W  ## Change name according to question
#### for the test on mode postgres u have
## \conninfo 
## \l
## \dg+
## \q   # to quit
psql -U kodekloud_gem -d kodekloud_db10 -h localhost -W
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment