100-Days-Of-DevOps-Challenge-KodeKloud

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:

PostgreSQL database server is already installed on the Nautilus database server.

Please do not try to restart PostgreSQL server service.

Steps

  1. Login into Database server

     ssh user@db_host
    
  2. Switch to postgres user and run following commands:

     sudo -i -u postgres
     psql -c "CREATE DATABASE kodekloud_db6;"
     psql -c "CREATE ROLE kodekloud_aim LOGIN PASSWORD 'your-password';"
     psql -c "GRANT ALL PRIVILEGES ON DATABASE kodekloud_db6 TO kodekloud_aim;"
     psql -c "ALTER DATABASE kodekloud_db6 OWNER TO kodekloud_aim;"
    

    This is based on terminal, you don’t have to login inside pgsql

    • It will create database
    • Create user and grant all privileges for the database
  3. Alternatively, login inside the postgres query and run the following commands:

     sudo psql -U postgres
    
     CREATE DATABASE kodekloud_db6;
     CREATE ROLE kodekloud_aim LOGIN PASSWORD 'your-password';
     GRANT ALL PRIVILEGES ON DATABASE kodekloud_db6 TO kodekloud_aim;
     ALTER DATABASE kodekloud_db6 OWNER TO kodekloud_aim;
    

Good to Know?

PostgreSQL Fundamentals

User and Role Management

Database Permissions

Best Practices