Install Configure PostgreSQL Task

hello

so I went through the task of Postgres installation and configuration.
I installed the version 12 of Postgres,
but eventually I the failed mark, though I finished it as per requirement as screenshots below :

here’s the user and the Database created as demanded :

here’s the permissions granted to the user :

here’s the config edited and reloaded
image

here’s the user connection tested :
image

can you please check and let me know what’s wrong ??
thanks!

@Inderpreet
can you please take a look here.
thanks in advance!

@siraj_krm

This is marked as Success for you, sorry for this inconvenience.

@Inderpreet
much appreciation!

and what configuration you have set in pg_hba.conf ?

pg_hba.conf

host	kodekloud_db8	kodekloud_roy	127.0.0.1/32	md5
host	kodekloud_db8	kodekloud_roy	::1/128		md5

I dont think there is any issue in the conf file otherwise as per the screenshot , i wouldnt have been able to connect.

one more option is there before this. like :----
local all all peer
changed it into
local all all md5

1 Like

create and setup user password upon creation
createuser kodekloud_roy -–pwprompt

this configuration is also correct for pg_hba.conf
local kodekloud_db9 kodekloud_roy md5

@player001 @kleansoul @siraj_krm
hi all,
what could be the default password for this file?


I have not set any password after installing postgres.
please advise.

In Linux by default, a user named postgres is created once PostgreSQL is installed. Default password for this is empty.

You can change the user’s password with the following command:
sudo passwd postgres

First come out from that bash shell to default user then do changes. You don’t need password for that even need though you knew the default user password like tony, steve etc. To make changes in database then login again by sudo su postgres whatever you did.

hi Tej
I was able to reset the password, after that,while I was trying to update the conf file.
I am getting this message. any suggestions.


this is the password I set for postgres - Password@123
also, executing this command, I am seeing this result, is this correct, because one of the user has attached the results with roles. In my case it was coming empty.

@Inderpreet @vijin.palazhi
please check and advise.

@siraj_krm @devops503 @kleansoul
sorry, copying all, one of you please check and advise.
thanks

I dont think you need to do a sudo to modify pg_hba.conf with the postgres user, postgres is not a OS admin, just the DB admin, bu default it should have permissions for this file
su - postgres
vi var/lib/pgsql/data/pg_hba.conf

that’s why i am saying postgres is not a sudo user and don’t have permission to change the files.
Do one thing if you are updating database then change user into postgres. If you have to change configuration file of the system then switch into DB server sudo user.
That’s the good steps i guess.
postgres -----> CRUD database(CREATE, REPLACE, UPDATE, DELETE)
sudo user -----> configuration files of system(database)

hi Tej, @siraj_krm @kleansoul
I edited hg_pba.conf file as per below.


what does task 4 and 5 check?

task 4 :-- In the configuration file of psql. Configure it according to task that allow all local clients or can say that local user to connect to the kodekloud_db4 database with database user kodekloud_cap user with md5 password as already there password column.
pg_hba.conf file has section of “local” where is encryption set to peer but we need to change into md5.
Don’t change other section peer to md5 otherwise task will be failed. Only to local.
task 5 :-- Try with sudo user or root user to login with that credentials(database user and database password).
I don’t know exactly but something like
$root ># psql -u kodekloud_cap -d kodekloud_db4 -p
u stands for user.
p stands for password
d stands for database
not sure but search it on internet to confirm.

Your /var/lib/pgsql/12/data/pg_hba.conf not looks like actual file of psql. Have you changed something?

hi Tej,

thanks for the information. I was able to complete the task!

thank you!
Swaroop

@mmumshad @Inderpreet @kodekloud-support3
Would you please check my “Install and Configure PostgresSQL” task. I thought I did it correctly and clicked “Finish” I however got status failed. And I don’t know why. I attached you some screenshots.




This is the reason shown on the failed status
"PostgreSQL is not configured correctly, either user ‘kodekloud_pop’ and database ‘kodekloud_db1’ does not exist or user ‘kodekloud_pop’ does not has appropriate permissions on database ‘kodekloud_db1’ on DB Server"

Kind regards
LuHa