meta données pour cette page
  •  

Ceci est une ancienne révision du document !


Installation PostGreSQL 16

Environnement:
  • VM Rocky Linux 9
  • 8 GB RAM
  • FS:
    • Binaires: /u01 ⇒10GB
    • Datafiles: /u02 ⇒ 15GB
    • WAL: /u07 ⇒ 5GB
Préparation des FS
[root@postgre1 ~]# pvcreate /dev/xvdb
[root@postgre1 ~]# pvcreate /dev/xvdc
[root@postgre1 ~]# pvcreate /dev/xvde
 
[root@postgre1 ~]# vgcreate vg_u01 /dev/xvdb
[root@postgre1 ~]# vgcreate vg_u02 /dev/xvdc
[root@postgre1 ~]# vgcreate vg_u07 /dev/xvde
 
[root@postgre1 ~]# lvcreate -n lv_u01 -l 100%VG vg_u01
[root@postgre1 ~]# lvcreate -n lv_u02 -l 100%VG vg_u02
[root@postgre1 ~]# lvcreate -n lv_u07 -l 100%VG vg_u07
 
[root@postgre1 ~]# mkfs -t xfs /dev/vg_u01/lv_u01
[root@postgre1 ~]# mkfs -t xfs /dev/vg_u02/lv_u02
[root@postgre1 ~]# mkfs -t xfs /dev/vg_u07/lv_u07
 
[root@postgre1 ~]# mkdir /u01
[root@postgre1 ~]# mkdir /u02
[root@postgre1 ~]# mkdir /u07
 
[root@postgre1 ~]# vi /etc/fstab
 
## PostGreSQL FS ##
/dev/vg_u01/lv_u01     /u01                     xfs    defaults        0 0
/dev/vg_u02/lv_u02     /u02                     xfs    defaults        0 0
/dev/vg_u07/lv_u07     /u07                     xfs    defaults        0 0
 
[root@postgre1 ~]# mount -a
Installation:
  • ajout du repos
[root@postgre1 ~]# dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm     
Dernière vérification de l’expiration des métadonnées effectuée il y a 0:41:03 le lun. 05 janv. 2026 13:45:38.
pgdg-redhat-repo-latest.noarch.rpm                                                                                                                                            125 kB/s |  13 kB     00:00    
Dépendances résolues.
==============================================================================================================================================================================================================
 Paquet                                               Architecture                               Version                                               Dépôt                                            Taille
==============================================================================================================================================================================================================
Installation:
 pgdg-redhat-repo                                     noarch                                     42.0-63.rhel9PGDG                                     @commandline                                      13 k
 
Résumé de la transaction
==============================================================================================================================================================================================================
Installer  1 Paquet
 
Taille totale  : 13 k
Taille des paquets installés : 18 k
Téléchargement des paquets :
Test de la transaction
La vérification de la transaction a réussi.
Lancement de la transaction de test
Transaction de test réussie.
Exécution de la transaction
  Préparation           :                                                                                                                                                                                 1/1 
  Installation          : pgdg-redhat-repo-42.0-63.rhel9PGDG.noarch                                                                                                                                       1/1 
  Vérification de       : pgdg-redhat-repo-42.0-63.rhel9PGDG.noarch                                                                                                                                       1/1 
 
Installé:
  pgdg-redhat-repo-42.0-63.rhel9PGDG.noarch                                                                                                                                                                   
 
Terminé !
 
 
 
[root@postgre1 ~]# dnf update
Dernière vérification de l’expiration des métadonnées effectuée il y a 0:03:31 le lun. 05 janv. 2026 14:27:42.
Dépendances résolues.
Rien à faire.
Terminé !
 
 
[root@postgre1 ~]# dnf list postgresql16-server
Dernière vérification de l’expiration des métadonnées effectuée il y a 2:13:52 le lun. 05 janv. 2026 14:44:04.
Paquets installés
postgresql16-server.x86_64                                                                              16.11-1PGDG.rhel9                                                                              @pgdg16
  • installation du moteur
[root@postgre1 ~]# dnf install postgresql16-server
Dernière vérification de l’expiration des métadonnées effectuée il y a 2:12:03 le lun. 05 janv. 2026 14:44:04.
Dépendances résolues.
==============================================================================================================================================================================================================
 Paquet                                                  Architecture                               Version                                                  Dépôt                                      Taille
==============================================================================================================================================================================================================
Installation:
 postgresql16-server                                     x86_64                                     16.11-1PGDG.rhel9                                        pgdg16                                     6.8 M
Installation des dépendances:
 postgresql16                                            x86_64                                     16.11-1PGDG.rhel9                                        pgdg16                                     1.8 M
 postgresql16-libs                                       x86_64                                     16.11-1PGDG.rhel9                                        pgdg16                                     336 k
 
Résumé de la transaction
==============================================================================================================================================================================================================
Installer  3 Paquets
 
Taille totale des téléchargements : 8.9 M
Taille des paquets installés : 40 M
Voulez-vous continuer ? [o/N] : o
Téléchargement des paquets :
(1/3): postgresql16-libs-16.11-1PGDG.rhel9.x86_64.rpm                                                                                                                         1.9 MB/s | 336 kB     00:00    
(2/3): postgresql16-16.11-1PGDG.rhel9.x86_64.rpm                                                                                                                              8.8 MB/s | 1.8 MB     00:00    
(3/3): postgresql16-server-16.11-1PGDG.rhel9.x86_64.rpm                                                                                                                        12 MB/s | 6.8 MB     00:00    
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                          16 MB/s | 8.9 MB     00:00     
PostgreSQL 16 for RHEL / Rocky Linux / AlmaLinux 9 - x86_64                                                                                                                   2.4 MB/s | 2.4 kB     00:00    
Import de la clef GPG 0x08B40D20 :
Utilisateur : « PostgreSQL RPM Repository <pgsql-pkg-yum@lists.postgresql.org> »
Empreinte : D4BF 08AE 67A0 B4C7 A1DB CCD2 40BC A2B4 08B4 0D20
Provenance : /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL
Voulez-vous continuer ? [o/N] : o
La clé a bien été importée
Test de la transaction
La vérification de la transaction a réussi.
Lancement de la transaction de test
Transaction de test réussie.
Exécution de la transaction
  Préparation           :                                                                                                                                                                                 1/1 
  Installation          : postgresql16-libs-16.11-1PGDG.rhel9.x86_64                                                                                                                                      1/3 
  Exécution du scriptlet: postgresql16-libs-16.11-1PGDG.rhel9.x86_64                                                                                                                                      1/3 
  Installation          : postgresql16-16.11-1PGDG.rhel9.x86_64                                                                                                                                           2/3 
  Exécution du scriptlet: postgresql16-16.11-1PGDG.rhel9.x86_64                                                                                                                                           2/3 
  Exécution du scriptlet: postgresql16-server-16.11-1PGDG.rhel9.x86_64                                                                                                                                    3/3 
  Installation          : postgresql16-server-16.11-1PGDG.rhel9.x86_64                                                                                                                                    3/3 
  Exécution du scriptlet: postgresql16-server-16.11-1PGDG.rhel9.x86_64                                                                                                                                    3/3 
  Vérification de       : postgresql16-16.11-1PGDG.rhel9.x86_64                                                                                                                                           1/3 
  Vérification de       : postgresql16-libs-16.11-1PGDG.rhel9.x86_64                                                                                                                                      2/3 
  Vérification de       : postgresql16-server-16.11-1PGDG.rhel9.x86_64                                                                                                                                    3/3 
 
Installé:
  postgresql16-16.11-1PGDG.rhel9.x86_64                           postgresql16-libs-16.11-1PGDG.rhel9.x86_64                           postgresql16-server-16.11-1PGDG.rhel9.x86_64                          
 
Terminé !
[root@postgre1 ~]# 
Initialisation du moteur dans un répertoire custom

Ce script permet de générer le dictionnaire et les vues système

[postgres@postgre1 ~]$ /usr/pgsql-16/bin/initdb -D /u01/pgsql/data
Démarrage automatique
[root@postgre1 ~]# vi /usr/lib/systemd/system/postgresql.service
 
 
[Unit]
Description=PostgreSQL database server
After=network.target
 
[Service]
Type=forking
 
User=postgres
Group=postgres
 
# Where to send early-startup messages from the server (before the logging
# options of postgresql.conf take effect)
# This is normally controlled by the global default set by systemd
# StandardOutput=syslog
 
# Disable OOM kill on the postmaster
OOMScoreAdjust=-1000
# ... but allow it still to be effective for child processes
# (note that these settings are ignored by Postgres releases before 9.5)
Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE=0
 
# Maximum number of seconds pg_ctl will wait for postgres to start.  Note that
# PGSTARTTIMEOUT should be less than TimeoutSec value.
Environment=PGSTARTTIMEOUT=270
 
Environment=PGDATA=/u01/pgsql/data/
 
 
ExecStart=/usr/pgsql-16/bin/pg_ctl start -D ${PGDATA} -s -w -t ${PGSTARTTIMEOUT}
ExecStop=/usr/pgsql-16/bin/pg_ctl stop -D ${PGDATA} -s -m fast
ExecReload=/usr/pgsql-16/bin/pg_ctl reload -D ${PGDATA} -s
 
# Give a reasonable amount of time for the server to start up/shut down.
# Ideally, the timeout for starting PostgreSQL server should be handled more
# nicely by pg_ctl in ExecStart, so keep its timeout smaller than this value.
TimeoutSec=300
 
[Install]
WantedBy=multi-user.target
 
 
 
[root@postgre1 ~]# systemctl daemon-reload 
[root@postgre1 ~]# systemctl enable postgresql
[root@postgre1 ~]# systemctl start postgresql