Create PostgreSQL Role and Database

Creating PostgreSQL Role and Database

The createuser command allows you to create new roles from the command line. Only superusers and roles with CREATEROLE privilege can create new roles.

In the following example, we’ll create a new role named kylo, a database named kylodb and grant privileges on the database to the role.

  1. Connect to the database:

sudo su - postgres
psql
  1. Create the USER by issuing the following command:

CREATE USER Kylo with password 'PASSWORD123';
  1. Create Database:

CREATE DATABASE kylodb; 
  1. Grant Permissions to the database

GRANT ALL PRIVILEGES ON DATABASE kylodb TO kylo;

Last updated