Datalbi  
Créé le 29/09/2018 par Laurent Bourcier

Installation de PostgreSQL 10 sous Debian

Sommaire
1. Introduction
2. Configuration du dépot pour PostgreSQL
3. Installation de PostgreSQL 10
4. Bilan du cluster créé par défaut
5. Suppression du cluster main

Introduction

Ce tutorial présente l'installation de PostgreSQL 10 sous Debian 9 (nom de code Stretch).

Les prérequis sont les suivants :


Configuration du dépot pour PostgreSQL

Les actions doivent être réalisées avec le compte root.

Editer le fichier /etc/apt/sources.list.d/postgresql.list et ajouter la ligne suivante :

deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main

Récupérer la signature du dépot :

# wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -

Mettre à jour le repository :

# apt-get update

Installation de PostgreSQL 10

Sous root, installer les 2 paquets suivants :

# apt-get install postgresql-10 postgresql-client-10

Bilan du cluster créé par défaut

On constate qu'un cluster est créé par défaut (cluster main).

Un cluster est un ensemble de bases de données.

# pg_lsclusters
Ver Cluster Port Status Owner    Data directory              Log file
10  main    5432 online postgres /var/lib/postgresql/10/main /var/log/postgresql/postgresql-10-main.log

# ps -fu postgres
UID        PID  PPID  C STIME TTY          TIME CMD
postgres  3091     1  0 23:10 ?        00:00:00 /usr/lib/postgresql/10/bin/postgres -D /var/lib/postgresql/10/main -c config_file=/etc/postgresql/10/main/postgresql.conf
postgres  3093  3091  0 23:10 ?        00:00:00 postgres: 10/main: checkpointer process
postgres  3094  3091  0 23:10 ?        00:00:00 postgres: 10/main: writer process
postgres  3095  3091  0 23:10 ?        00:00:00 postgres: 10/main: wal writer process
postgres  3096  3091  0 23:10 ?        00:00:00 postgres: 10/main: autovacuum launcher process
postgres  3097  3091  0 23:10 ?        00:00:00 postgres: 10/main: stats collector process
postgres  3098  3091  0 23:10 ?        00:00:00 postgres: 10/main: bgworker: logical replication launcher

Un service est également créé pour ce cluster.

Son nom est : postgresql@<version>-<cluster>.service

# systemctl status postgresql@10-main.service
? postgresql@10-main.service - PostgreSQL Cluster 10-main
   Loaded: loaded (/lib/systemd/system/postgresql@.service; disabled; vendor preset: enabled)
   Active: active (running) since Tue 2018-09-18 23:10:45 CEST; 2min 48s ago
 Main PID: 3091 (postgres)
   CGroup: /system.slice/system-postgresql.slice/postgresql@10-main.service
           +-3091 /usr/lib/postgresql/10/bin/postgres -D /var/lib/postgresql/10/main -c config_file=/etc/postgresql/10/main/postgresql.conf
           +-3093 postgres: 10/main: checkpointer process
           +-3094 postgres: 10/main: writer process
           +-3095 postgres: 10/main: wal writer process
           +-3096 postgres: 10/main: autovacuum launcher process
           +-3097 postgres: 10/main: stats collector process
           +-3098 postgres: 10/main: bgworker: logical replication launcher

Les fichiers de configuration de ce cluster sont ici :

$ cd /etc/postgresql/10/main
$ ls -l
total 52
drwxr-xr-x 2 postgres postgres  4096 sept. 18 23:10 conf.d
-rw-r--r-- 1 postgres postgres   315 sept. 18 23:10 environment
-rw-r--r-- 1 postgres postgres   143 sept. 18 23:10 pg_ctl.conf
-rw-r----- 1 postgres postgres  4686 sept. 18 23:10 pg_hba.conf
-rw-r----- 1 postgres postgres  1636 sept. 18 23:10 pg_ident.conf
-rw-r--r-- 1 postgres postgres 22950 sept. 18 23:10 postgresql.conf
-rw-r--r-- 1 postgres postgres   317 sept. 18 23:10 start.conf

Les parametres par défaut de ce cluster sont les suivants :

$ grep -v "^[[:blank:]]*#" postgresql.conf | grep -v "^$"
data_directory = '/var/lib/postgresql/10/main'          # use data in another directory
hba_file = '/etc/postgresql/10/main/pg_hba.conf'        # host-based authentication file
ident_file = '/etc/postgresql/10/main/pg_ident.conf'    # ident configuration file
external_pid_file = '/var/run/postgresql/10-main.pid'                   # write an extra PID file
port = 5432                             # (change requires restart)
max_connections = 100                   # (change requires restart)
unix_socket_directories = '/var/run/postgresql' # comma-separated list of directories
ssl = on
ssl_cert_file = '/etc/ssl/certs/ssl-cert-snakeoil.pem'
ssl_key_file = '/etc/ssl/private/ssl-cert-snakeoil.key'
shared_buffers = 128MB                  # min 128kB
dynamic_shared_memory_type = posix      # the default is the first option
log_line_prefix = '%m [%p] %q%u@%d '            # special values:
log_timezone = 'localtime'
cluster_name = '10/main'                        # added to process titles if nonempty
stats_temp_directory = '/var/run/postgresql/10-main.pg_stat_tmp'
datestyle = 'iso, dmy'
timezone = 'localtime'
lc_messages = 'fr_FR.UTF-8'                     # locale for system error message
lc_monetary = 'fr_FR.UTF-8'                     # locale for monetary formatting
lc_numeric = 'fr_FR.UTF-8'                      # locale for number formatting
lc_time = 'fr_FR.UTF-8'                         # locale for time formatting
default_text_search_config = 'pg_catalog.french'
include_dir = 'conf.d'                  # include files ending in '.conf' from

Suppression du cluster main

Il est souvent préférable de supprimer le cluster main créé par défaut.

Dans un premier temps nous supprimons le cluster avec le compte postgres

$ pg_dropcluster -stop 10 main

Nous devons ensuite recharcher les services sous root :

# systemctl daemon-reload