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)
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
Have you initialize the PostgreSQL DB using,
sudo postgresql-setup initdb
If not then you need to first initialize the DB.
Secondly, you need to login Postgresql using
sudo -u postgres psql
After login you need to create the user and database and grant the permission.
Also, you need to just change only one configuration line from /var/lib/pgsql/data/pg_hba.conf
local all all peer to local all all md5
After that you need to restart the postgresql service.
@AkshayT thanks for replying. Yes, I did initialize the database. And did the necessary configuration on the pg_hba.conf file and restarted the service.
Dear @mmumshad @Inderpreet @kodekloud-support3
I am eagerly waiting for your reply. Would you please check my PostgreSQL Task?
kind regards.
You did typo at all. Database name is kodekloud_db1 not kodeKloud_db1
Thanks @Tej-Singh-Rana for replying. Is that the case and does it really mater? Is name of a database case sensitive? I donât know that can be, but it will be very pity if I miss it because of it.
i am getting below error while connecting to postgresql.
psql -d kodekloud_db1 -U kodekloud_top -W
Password for user kodekloud_top:
psql: FATAL: Peer authentication failed for user âkodekloud_topâ
You have to make a changes in pg_hba.conf file of postgresql. In local connection column, change peer to md5. Donât change in replication connection.
I have done changes in pg_hba.conf file and changed peer to md5 in local connection.
after that getting below error.
Please post your pg_hba.conf file here.
Or have u run this command while creating the user.
create user kodekloud_gem with encrypted password âksH85Ujhubâ
Please check or else you reset the password again and run above command.
I have used below commands for creation of user and database.
sudo -u postgres psql
CREATE USER kodekloud_roy WITH ENCRYPTED PASSWORD âGyQkFRVNr3â;
CREATE DATABASE kodekloud_db4;
GRANT ALL PRIVILEGES ON DATABASE kodekloud_db3 TO kodekloud_roy;
Output of pg_hba.conf
cat /var/lib/pgsql/12/data/pg_hba.conf |grep md5
METHOD can be âtrustâ, ârejectâ, âmd5â, âpasswordâ, âscram-sha-256â,
Note that âpasswordâ sends passwords in clear text; âmd5â or
local all all md5
but getting error attached in screenshot.
Any idea what wrong i am doing in this task ?
In Addition to previous⌠that is very good.
finish with âpg_ctl reload;â to apply changes
@Inderpreet @Tej-Singh-Rana @devops503 @fazalmahmood @juancgarciaco @swaroopcs88
Getting below error, please guys help me out to complete the task!
Steps Followed:
yum install postgresql-server postgresql-contrib
postgresql-setup initdb
systemctl enable postgresql && systemctl start postgresql
systemctl status postgresql
echo -n âBruCStnMT5â | md5sum
184b4fb9d4689f4acc81eaafe9d9cf2ad
su - postgres
sudo -u postgres psql postgres
psql
psql=# CREATE USER kodekloud_tim WITH ENCRYPTED PASSWORD â184b4fb9d4689f4acc81eaafe9d9cf2adâ;
psql=# CREATE DATABASE kodekloud_db8 OWNER kodekloud_tim;
psql=# GRANT ALL PRIVILEGES ON DATABASE kodekloud_db8 TO kodekloud_tim;
vi /var/lib/pgsql/data/pg_hba.conf
local all all md5
host kodekloud_db8 kodekloud_tim 127.0.0.1/32 md5
host kodekloud_db8 kodekloud_tim ::1/128 md5
vi /var/lib/pgsql/data/postgresql.conf
listen_addresses= â*â
systemctl restart postgresql.service
systemctl status postgresql.service
#Authentication
psql -U kodekloud_tim -d kodekloud_db8 -h 127.0.0.1 -W
Please check and let me know what else change can be done to complete the task!
removed md5 encryption and worked!
CREATE USER kodekloud_aim WITH ENCRYPTED PASSWORD âTmPcZjtRQxâ;
this worked for me
Thanks @nenadmiladin for your post on the task, helped me to complete the task!