PostgreSQL on OpenBSD: 12 から 13 へのアップグレード – pg_dumpall 使用

はじめに

OpenBSD の 6.8 から 6.9 へのアップグレードに際しては、PostgreSQL サーバーも (12.6 から 13.2) へアップグレードする必要があります。OpenBSD の アップグレード・ガイド (英語) でそのように案内されています。
本記事では、以下の postgresql-server パッケージ公式の readme に沿って、実施した内容を記載します:

$ nvim -R /usr/local/share/doc/pkg-readme…


This content originally appeared on DEV Community and was authored by nabbisen

はじめに

OpenBSD6.8 から 6.9 へのアップグレードに際しては、PostgreSQL サーバーも (12.6 から 13.2) へアップグレードする必要があります。OpenBSD の アップグレード・ガイド (英語) でそのように案内されています
本記事では、以下の postgresql-server パッケージ公式の readme に沿って、実施した内容を記載します:

$ nvim -R /usr/local/share/doc/pkg-readmes/postgresql-server

本記事とは別の方法もありますpg_upgrade を使う方法です。追加のパッケージのインストールが必要ですが、マイグレーション速度の向上が期待できます。

チュートリアル

サーバーが動いていることを確認しましょう。

$ doas rcctl check postgresql
postgresql(ok)

pg_dumpall を実行します。

$ doas su _postgresql -c "cd /var/postgresql \
    && pg_dumpall -U postgres > /var/postgresql/full.sqldump.bkYYMMDD"
$ # pg superuser's password is required times of the number of tables

なおここでの "YYMMDD" は実際のバックアップ取得日にしてください。一例ですが Fish シェル でしたら date +"%y%m%d" でシステム日をセットできます。

サーバーを停止します。

$ doas rcctl stop postgresql
postgresql(ok)
$ # check the server is stopped
$ doas rcctl check postgresql
postgresql(failed)

サーバーのパッケージをアップグレードします。

$ doas pkg_add -ui postgresql-server
$ # updated

/var/postgresql/data をつくりかえます。

$ doas mv /var/postgresql/data /var/postgresql/data-12
$ doas su _postgresql -c "mkdir /var/postgresql/data"

initdb を実行します。

$ # `--locale` option here can be omitted
$ doas su _postgresql -c "cd /var/postgresql && \
    initdb -D /var/postgresql/data -U postgres -A scram-sha-256 -E UTF8 -W \
        --locale=xx_XX.UTF-8"
$ # pg superuser's password is required

必ずしもというわけではありませんが、必要に応じて、サーバーの設定を行います。

$ # in case of using tls/ssl connection
$ # - set `listen_addresses` and `ssl` option
$ doas nvim "/var/postgresql/data/postgresql.conf"
$ # - add `hostssl` authentication
$ doas nvim "/var/postgresql/data/pg_hba.conf"
$ # - create certificate if not exists
$ doas su _postgresql -c \
    "cp /var/postgresql/data-12/server.{crt,key} /var/postgresql/data/"

上記は こちらの記事 に基づいています。

新しくなったサーバーを起動します。

$ doas rcctl start postgresql
postgresql(ok)
$ # check the server is started and running
$ doas rcctl check postgresql
postgresql(ok)

データベースとテーブルやレコード等のオブジェクトをリストアします。

$ doas su _postgresql -c "cd /var/postgresql && \
    psql -U postgres < /var/postgresql/full.sqldump.bkYYMMDD"
$ # restored

完了です 🙂


This content originally appeared on DEV Community and was authored by nabbisen


Print Share Comment Cite Upload Translate Updates
APA

nabbisen | Sciencx (2023-05-06T01:14:05+00:00) PostgreSQL on OpenBSD: 12 から 13 へのアップグレード – pg_dumpall 使用. Retrieved from https://www.scien.cx/2023/05/06/postgresql-on-openbsd-12-%e3%81%8b%e3%82%89-13-%e3%81%b8%e3%81%ae%e3%82%a2%e3%83%83%e3%83%97%e3%82%b0%e3%83%ac%e3%83%bc%e3%83%89-pg_dumpall-%e4%bd%bf%e7%94%a8/

MLA
" » PostgreSQL on OpenBSD: 12 から 13 へのアップグレード – pg_dumpall 使用." nabbisen | Sciencx - Saturday May 6, 2023, https://www.scien.cx/2023/05/06/postgresql-on-openbsd-12-%e3%81%8b%e3%82%89-13-%e3%81%b8%e3%81%ae%e3%82%a2%e3%83%83%e3%83%97%e3%82%b0%e3%83%ac%e3%83%bc%e3%83%89-pg_dumpall-%e4%bd%bf%e7%94%a8/
HARVARD
nabbisen | Sciencx Saturday May 6, 2023 » PostgreSQL on OpenBSD: 12 から 13 へのアップグレード – pg_dumpall 使用., viewed ,<https://www.scien.cx/2023/05/06/postgresql-on-openbsd-12-%e3%81%8b%e3%82%89-13-%e3%81%b8%e3%81%ae%e3%82%a2%e3%83%83%e3%83%97%e3%82%b0%e3%83%ac%e3%83%bc%e3%83%89-pg_dumpall-%e4%bd%bf%e7%94%a8/>
VANCOUVER
nabbisen | Sciencx - » PostgreSQL on OpenBSD: 12 から 13 へのアップグレード – pg_dumpall 使用. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/05/06/postgresql-on-openbsd-12-%e3%81%8b%e3%82%89-13-%e3%81%b8%e3%81%ae%e3%82%a2%e3%83%83%e3%83%97%e3%82%b0%e3%83%ac%e3%83%bc%e3%83%89-pg_dumpall-%e4%bd%bf%e7%94%a8/
CHICAGO
" » PostgreSQL on OpenBSD: 12 から 13 へのアップグレード – pg_dumpall 使用." nabbisen | Sciencx - Accessed . https://www.scien.cx/2023/05/06/postgresql-on-openbsd-12-%e3%81%8b%e3%82%89-13-%e3%81%b8%e3%81%ae%e3%82%a2%e3%83%83%e3%83%97%e3%82%b0%e3%83%ac%e3%83%bc%e3%83%89-pg_dumpall-%e4%bd%bf%e7%94%a8/
IEEE
" » PostgreSQL on OpenBSD: 12 から 13 へのアップグレード – pg_dumpall 使用." nabbisen | Sciencx [Online]. Available: https://www.scien.cx/2023/05/06/postgresql-on-openbsd-12-%e3%81%8b%e3%82%89-13-%e3%81%b8%e3%81%ae%e3%82%a2%e3%83%83%e3%83%97%e3%82%b0%e3%83%ac%e3%83%bc%e3%83%89-pg_dumpall-%e4%bd%bf%e7%94%a8/. [Accessed: ]
rf:citation
» PostgreSQL on OpenBSD: 12 から 13 へのアップグレード – pg_dumpall 使用 | nabbisen | Sciencx | https://www.scien.cx/2023/05/06/postgresql-on-openbsd-12-%e3%81%8b%e3%82%89-13-%e3%81%b8%e3%81%ae%e3%82%a2%e3%83%83%e3%83%97%e3%82%b0%e3%83%ac%e3%83%bc%e3%83%89-pg_dumpall-%e4%bd%bf%e7%94%a8/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.