Mettre à jour Postgresql sur debian Stretch

Stretch

Nous allons voir comment mettre à jour votre base de données postgresql après l’update de Jessie à Stretch.
La version de jessie était 9.4. La version pour Stretch est 9.6.

Les commandes suivantes sont exécutées en root. Vous pouvez bien sûr utiliser sudo.

Lister les clusters postgresql installés sur votre machine:

# pg_lsclusters

Si votre installation de postgresql date de Jessie vous aurez un truc comme cela.

[pastacode lang=”bash” manual=”Ver%20Cluster%20Port%20Status%20Owner%20Data%20directory%20Log%20file%0A9.4%20main%20%20%20%205432%20online%20postgres%20%2Fvar%2Flib%2Fpostgresql%2F9.4%2Fmain%20%2Fvar%2Flog%2Fpostgresql%2Fpostgresql-9.4-main.log%0A9.6%20main%20%20%20%205433%20online%20postgres%20%2Fvar%2Flib%2Fpostgresql%2F9.6%2Fmain%20%2Fvar%2Flog%2Fpostgresql%2Fpostgresql-9.6-main.log” message=”” highlight=”” provider=”manual”/]

 

Si vous n’avez pas fait la mise à jour de votre cluster après la mise à jour de wheezy vers jessie. Vous devriez voir un truc dans ce style la.

[pastacode lang=”bash” manual=”Ver%20Cluster%20Port%20Status%20Owner%20Data%20directory%20Log%20file%0A9.1%20main%20%20%20%205432%20online%20postgres%20%2Fvar%2Flib%2Fpostgresql%2F9.1%2Fmain%20%2Fvar%2Flog%2Fpostgresql%2Fpostgresql-9.1-main.log%0A9.4%20main%20%20%20%205433%20online%20postgres%20%2Fvar%2Flib%2Fpostgresql%2F9.4%2Fmain%20%2Fvar%2Flog%2Fpostgresql%2Fpostgresql-9.4-main.log%0A9.6%20main%20%20%20%205434%20online%20postgres%20%2Fvar%2Flib%2Fpostgresql%2F9.6%2Fmain%20%2Fvar%2Flog%2Fpostgresql%2Fpostgresql-9.6-main.log” message=”” highlight=”” provider=”manual”/]

Le port par défaut de postgresql est le 5432.  Le cluster ayant 5432 comme port est votre cluster courant.

Normalement Debian installe la nouvelle version de postgresql à la mise à jour de version et il crée un nouveau cluster dans la foulée.
Si ce n’est pas le cas, vous pouvez l’installer par cette ligne:

# apt-get install postgresql-9.6

Supprimer le cluster postgresql 9.6 créé

Installer une nouvelle version de postgresql sur debian crée un cluster principal (main) qui empêche la commande pg_upgradecluster de fonctionner.

Il faut donc supprimer cette instance dans le but d’obtenir une base de données propre.
Faite très attention, ne vous tromper pas dans la commande.
Ne supprimer surtout pas votre vieille base de données. C’est elle qui contient toutes vos données. 🙂

Nous détruisons la nouvelle; la vide.

# pg_dropcluster --stop 9.6 main

Mettre à jour la vieille base vers le nouveau format

La syntaxe est la suivante:

# pg_upgradecluster -v NouvelleVersion AncienneVersion main

La fonction va créer un nouvelle base main dans le format NouvelleVersion.
Pour ensuite, copier les données de AncienneVersion vers NouvelleVersion.
Cela prendra un peu de temps.

[pastacode lang=”bash” manual=”%23%20pg_upgradecluster%20-v%209.6%209.4%20main%0AStopping%20old%20cluster…%0ANotice%3A%20extra%20pg_ctl%2Fpostgres%20options%20given%2C%20bypassing%20systemctl%20for%20stop%20operation%0ADisabling%20connections%20to%20the%20old%20cluster%20during%20upgrade…%0ARestarting%20old%20cluster%20with%20restricted%20connections…%0ARedirecting%20start%20request%20to%20systemctl%0ACreating%20new%20cluster%209.6%2Fmain%20…%0Aconfig%20%2Fetc%2Fpostgresql%2F9.6%2Fmain%0Adata%20%2Fvar%2Flib%2Fpostgresql%2F9.6%2Fmain%0Alocale%20en_US.UTF-8%0Asocket%20%2Fvar%2Frun%2Fpostgresql%0Aport%205434%0ADisabling%20connections%20to%20the%20new%20cluster%20during%20upgrade…%0ARedirecting%20start%20request%20to%20systemctl%0ARoles%2C%20databases%2C%20schemas%2C%20ACLs…%0AFixing%20hardcoded%20library%20paths%20for%20stored%20procedures…%0AUpgrading%20database%20pbf…%0AAnalyzing%20database%20pbf…%0AFixing%20hardcoded%20library%20paths%20for%20stored%20procedures…%0AUpgrading%20database%20template1…%0AAnalyzing%20database%20template1…%0AFixing%20hardcoded%20library%20paths%20for%20stored%20procedures…%0AUpgrading%20database%20livres…%0AAnalyzing%20database%20livres…%0AFixing%20hardcoded%20library%20paths%20for%20stored%20procedures…%0AUpgrading%20database%20cmdline…%0AAnalyzing%20database%20cmdline…%0AFixing%20hardcoded%20library%20paths%20for%20stored%20procedures…%0AUpgrading%20database%20systemtest…%0AAnalyzing%20database%20systemtest…%0AFixing%20hardcoded%20library%20paths%20for%20stored%20procedures…%0AUpgrading%20database%20creatures…%0AAnalyzing%20database%20creatures…%0AFixing%20hardcoded%20library%20paths%20for%20stored%20procedures…%0AUpgrading%20database%20articles…%0AAnalyzing%20database%20articles…%0AFixing%20hardcoded%20library%20paths%20for%20stored%20procedures…%0AUpgrading%20database%20postgres…%0AAnalyzing%20database%20postgres…%0AFixing%20hardcoded%20library%20paths%20for%20stored%20procedures…%0AUpgrading%20database%20campagnes…%0AAnalyzing%20database%20campagnes…%0AFixing%20hardcoded%20library%20paths%20for%20stored%20procedures…%0AUpgrading%20database%20animations…%0AAnalyzing%20database%20animations…%0AFixing%20hardcoded%20library%20paths%20for%20stored%20procedures…%0AUpgrading%20database%20asso_member…%0AAnalyzing%20database%20asso_member…%0ARe-enabling%20connections%20to%20the%20old%20cluster…%0ARe-enabling%20connections%20to%20the%20new%20cluster…%0ACopying%20old%20configuration%20files…%0ACopying%20old%20start.conf…%0ACopying%20old%20pg_ctl.conf…%0ACopying%20old%20server.crt…%0ACopying%20old%20server.key…%0AStopping%20target%20cluster…%0ARedirecting%20stop%20request%20to%20systemctl%0AStopping%20old%20cluster…%0ARedirecting%20stop%20request%20to%20systemctl%0ADisabling%20automatic%20startup%20of%20old%20cluster…%0AConfiguring%20old%20cluster%20to%20use%20a%20different%20port%20(5434)…%0AStarting%20target%20cluster%20on%20the%20original%20port…%0ARedirecting%20start%20request%20to%20systemctl%0ASuccess.%20Please%20check%20that%20the%20upgraded%20cluster%20works.%20If%20it%20does%2C%0Ayou%20can%20remove%20the%20old%20cluster%20with%0A%0Apg_dropcluster%209.4%20main” message=”” highlight=”” provider=”manual”/]

Supprimer l’ancienne version

Si la copie s’est bien passée. Vous pouvez supprimer l’ancienne version. Elle est maintenant entièrement copié dans le cluster main 9.6.

# pg_dropcluster 9.4 main

Leave a Reply

Your email address will not be published. Required fields are marked *