Skip to content

Instantly share code, notes, and snippets.

@anilahir
Created October 12, 2020 15:30
Show Gist options
  • Save anilahir/a7b3908392ff1e8ff507fd6d938cadc3 to your computer and use it in GitHub Desktop.
Save anilahir/a7b3908392ff1e8ff507fd6d938cadc3 to your computer and use it in GitHub Desktop.
PostgreSQL Installation & User Setup

Installation:

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install postgresql

Setup User:

$ sudo -u postgres psql
CREATE DATABASE <dbname>;
CREATE USER <username> WITH ENCRYPTED PASSWORD '<password>';
GRANT ALL PRIVILEGES ON DATABASE <dbname> TO <username>;

Create user:

sudo -u postgres createuser <username>

Create Database

sudo -u postgres createdb <dbname>

Give password to the user:

$ sudo -u postgres psql
psql=# ALTER USER <username> WITH ENCRYPTED PASSWORD '<password>';

Grant privileges on database:

psql=# GRANT ALL PRIVILEGES ON DATABASE <dbname> TO <username>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment