Skip to content

Instantly share code, notes, and snippets.

@krishnadey30
Created March 26, 2020 12:16
Show Gist options
  • Save krishnadey30/6b0bb42de4d269ce0abe8965bbcf9d03 to your computer and use it in GitHub Desktop.
Save krishnadey30/6b0bb42de4d269ce0abe8965bbcf9d03 to your computer and use it in GitHub Desktop.
This gist is for installing PostgreSQL and creating a new Role

How To Install and Use PostgreSQL on Ubuntu

Step 1 — Installing PostgreSQL

sudo apt update
sudo apt install postgresql postgresql-contrib

Step 2 — Using PostgreSQL Roles and Databases

Switching Over to the postgres Account
sudo -i -u postgres

You can now access a Postgres prompt immediately by typing:

psql
or
sudo -u postgres psql

Step 3 — Creating a New Role

sudo -u postgres createuser --interactive

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: krishna
Shall the new role be a superuser? (y/n) y

Step 4 — Creating a New Database

sudo -u postgres createdb

Step 5 — Change default PostgreSQL passwords

\password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment