Skip to content

Instantly share code, notes, and snippets.

@dadajuice
Last active February 24, 2020 16:29
Show Gist options
  • Select an option

  • Save dadajuice/fb105a56a43ad933eaad4c8b89bf61d0 to your computer and use it in GitHub Desktop.

Select an option

Save dadajuice/fb105a56a43ad933eaad4c8b89bf61d0 to your computer and use it in GitHub Desktop.
Installation et configuration PostgreSQL

Base de données (PostgreSQL)

Installation

sudo apt-get install postgresql postgresql-contrib

Configuration des rôles

Depuis la console PostgreSQL sudo -u postgres psql, ajouter les rôles nécessaires.

postgres=# CREATE ROLE <USER> WITH SUPERUSER CREATEDB CREATEROLE LOGIN ENCRYPTED PASSWORD '<PASS>';
postgres=# CREATE ROLE <APP_USER> WITH LOGIN ENCRYPTED PASSWORD '<APP_PASS>';
postgres=# \q

Création des bases de données

createdb <DB_NAME>

Depuis la console PostgreSQL sudo -u postgres psql, Spécifier les privilèges des rôles applicatifs sur les bases de données créées.

postgres=# grant all privileges on database <DB_NAME> to <APP_USER>;
postgres=# \q

Mise à jour des informations d'authentification de PostGreSQL

sudo vi /etc/postgresql/11/main/pg_hba.conf
# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    all             <USER>          0.0.0.0/0               password
host    <DB_NAME>       <APP_USER>      localhost               password

Ouvrir PostGreSQL aux connexions distantes (pour prise de contrôle depuis DataGrip par exemple)

Attention, ne pas permettre pour un serveur de production.

sudo vi /etc/postgresql/11/main/postgresql.conf
listen_addresses = '*'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment