Install and Configure PostgreSQL

@dipjyoty Please check now.

@Inderpreet it’s reflecting now. Thank you so much :slight_smile:

Same issue faced … Hope someone could assist and fix.

https://kodekloud.com/community/t/install-configure-postgresql-task/2470/5?u=kleansoul

Hi @kleansoul, in the screenshot you are using the -W switch to connect to the DB, which forces psql to prompt for a password before connecting to a database. Did you enable md5 authentication for the user by changing the configuration in file /var/lib/pgsql/12/data/pg_hba.conf ?

Hi,

Whats wrong with my task resolution

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

yum install postgresql-server postgresql-contrib
postgresql-setup initdb
systemctl enable postgresql && systemctl start postgresql

b. Create a database user kodekloud_aim and set its password to GyQkFRVNr3.

echo -n 'GyQkFRVNr3' | md5sum
20c59d9fe9be7db32e683554222f227c

su - postgres
psql
psql=# CREATE USER kodekloud_aim WITH ENCRYPTED PASSWORD 'md520c59d9fe9be7db32e683554222f227c';
psql=# CREATE DATABASE kodekloud_db9 OWNER kodekloud_aim;

c. Create a database kodekloud_db9 and grant full permissions to
user kodekloud_aim on this database.

psql=# GRANT ALL PRIVILEGES ON DATABASE kodekloud_db9 TO kodekloud_aim;

d. Make appropriate settings to allow all local clients to
connect to the kodekloud_db9 database through kodekloud_db9
user using md5 encrypted password for authentication.

edit pg_hba.conf to use md5 and change all to kodekloud_db9
edit postgresql.conf to permit listen = localhost

systemctl restart postgresql.service
systemctl status postgresql.service

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

try to connect psql using root does not work
    psql -U root -h localhost -d kodekloud_db9 -W 
Failed 

Connect using kodekloud_aim 
    psql -U kodekloud_aim -d kodekloud_db9 -h 127.0.0.1 -W

Works OK

@kleansoul did you also test it with -h localhost ?

Yes, and it worked with that too.

Thats why I was surprised why the task got failed.

@kleansoul
what is your email ID?

Hi @Inderpreet,

The task has also been marked failed for me though I was able to authenticate with password using the kodekloud_roy user to database kodekloud_db8 as described in the task. The error is saying the user or the database does not exist, please check.

[email protected]

Please check. Thank you!

@Inderpreet

Did you got time to check?

Hi @Inderpreet

Havnt received any reply from you yet on that task ??

Have you checked and marked it correctly please.

@kleansoul Sorry for delayed response. There were some missing config changes in your hba conf. Did you enable the local all connections ? As mentioned in last point of question you could test by login into Linux root user or sudo user and then by accessing the DB using credentials you created.

@Inderpreet Thanks for your response. Though this has now been almost more than a week old task but you can check my screenshots on the below link and see that the I tested the login and it worked fine also. I suspect some other platform related issue as that week there were lot of ongoing issues with labs (if you remember, for which it was reported too several times on slack).

https://kodekloud.com/community/t/install-configure-postgresql-task/2470/5?u=kleansoul

pg_hba.conf

@kleansoul

As per your screenshot when you tested the access you were logged in to kodekloud_roy user itself which worked, however as asked in the question it must work for all local clients so you could tested while switching to root or sudo user. Also the reply given on this thread is the correct way to configure as per requirements
https://kodekloud.com/community/t/install-configure-postgresql-task/2470/5

  1. The password doesn’t need to be hashed in order to finish the task successfully.
    So like this:
    CREATE USER kodekloud_aim WITH ENCRYPTED PASSWORD ‘TmPcZjtRQx’;
  2. /var/lib/pgsql/data/pg_hba.conf needs just to edited like this:
    “local” is for Unix domain socket connections only
    local all all md5
  3. Just test the connection with the root user and the Task password:
    [root@stdb01 ~]# psql -U kodekloud_aim -d kodekloud_db2
    Password for user kodekloud_aim:
    psql (9.2.24)
    Type “help” for help.

kodekloud_db2=>

And the Task should be successful.

hi @dipjyoty
what do task 4 and 5 check?

1 Like

@swaroopcs88 please check your inbox.

@Inderpreet I got this task assigned to Install and Configure PostgreSQL
I performed all steps correctly. After updating vi /var/lib/pgsql/data/pg_hba.conf file when I try to restart postgresql service its failing. Unable to start service. Getting below error message.

Could not bind IPv6 socket: Cannot assign requested address

Could you please help here why the service is not coming up?

Hi @jadhav.darshan2015

Seems like some other process is using the required port. You could try to identify that with netstat, like: sudo netstat -natp | grep 5432