Setup for Ubuntu

Installation

When working with MEDUSA for ecommerse, you will need to use postgresql. Here will will look into how to install and confugure postgresql before installing MEDUSA bbackend, so that the MEDUSA installation goes smoothly.

For installing postgresql in ubuntu first add the postgresql repository

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

Retrieve and adds the PostgreSQL repository's GPG (GNU Privacy Guard) key to your system

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

Install Postgresql

sudo apt-get update
sudo apt-get -y install postgresql

Check installation using version command

psql -V

Access PostgreSQL

To access postgresql type "psql" but this will generate error

psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: role "username" does not exist

As the default configuration of Postgres is, a user called postgres is made on and the user postgres has full superadmin access to entire PostgreSQL instance running on your OS.

The DB console cn be accesed using the below command, by passing the username along with 'psql'

sudo -u postgres psql

Incase the above steps doesnot work Create as password for postgres user

sudo passwd postgres

Enter the new password and switch to this user acount, by using this newly created password

su postgres

Now you can use the command 'psql' to enter into DB consile. To list all the database and owners use the '\l' command on the DB console. Command '\q' is used to exit the terminal

Configure PosrgreSQL for Medusa

When installing MEDUSA backend, it asks for creating psotgresql DB. if the default user is not regitered with postgres DB then the process of DB creation will fail.

To prevent this we create a new user (medusa_adim) in postgresql DB with a known password and will provide these credentials while instaling MEDUSA backen. This will ensure that necesary DB is created and linked to MEDUSA.

In the DB console type

CREATE USER youruser WITH ENCRYPTED PASSWORD 'yourpass';

Now provide the newly created user with Database creation rights

ALTER USER youruser WITH CREATEDB;

This should be enough for MEDUSA installation to go through one you provide youruser and yourpass

Other Actions in PostgreSQL

All the commands are self explanator

CREATE DATABASE yourdbname;
ALTER USER username WITH CREATEDB;
AGRANT ALL PRIVILEGES ON DATABASE yourdbname TO youruser;
DROP USER youruser;
DROP DATABASE yourdbname WITH (FORCE);

Last updated