Let’s demonstrates how to install PostgreSQL on an Ubuntu 18.04
VM /Dedicated Server with Ubuntu 18.04 installed.
Step 1 — Installing PostgreSQL
Ubuntu’s default repositories contain Postgres packages, so you can install these using the
apt packaging system.
$ sudo apt update $ sudo apt install postgresql postgresql-contrib
Step 2 — Using PostgreSQL Roles and Databases
Upon installation, Postgres is set up to use ident authentication, meaning that it associates Postgres roles with a matching Unix/Linux system account. If a role exists within Postgres, a Unix/Linux username with the same name is able to sign in as that role.
The installation procedure created a user account called postgres that is associated with the default Postgres role. In order to use Postgres, you can log into that account.
Switching Over to the postgres Account
Switch over to the postgres account on your server by typing:
You can now access a Postgres prompt immediately by typing:
$ sudo -i -u postgres
This will log you into the PostgreSQL prompt.
Exit out of the PostgreSQL prompt by typing:
Step 3 — Creating a New Role
If you are logged in as the postgres account, you can create a new user by typing:
The script will prompt you with some choices and, based on your responses, execute the correct Postgres commands to create a user to your specifications.
Enter name of role to add: CyberSal Shall the new role be a superuser? (y/n) y
Step 4 — Creating a New Database
If you are logged in as the postgres account, you would type something like: