postgresql の移行

2023-09-14 に正式リリースされた PostgreSQL 16 が `apt upgrade` で降ってきた

The following NEW packages will be installed:
  postgresql-16 postgresql-client-16

ので、Mastodon ソロサーバーの丼くまを移行させることにした。

環境

$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.3 LTS"
$ uname -a
Linux kumarin 5.15.0-84-generic #93-Ubuntu SMP Tue Sep 5 17:16:10 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

インストールされている postgres-16 の確認

postgresql-15 が稼働している状態で postgresql-16 が新たにインストールされると、16 はポート tcp/5433 で listen をはじめる。

$ netstat -an | grep -w LISTEN
tcp    0    0 127.0.0.1:5433    0.0.0.0:*    LISTEN    # postgresql-15
tcp    0    0 127.0.0.1:5432    0.0.0.0:*    LISTEN    # postgresql-16
$ sudo su - postgres
$ psql --port 5433

postgres=# select * From version();
PostgreSQL 16.0 (Ubuntu 16.0-1.pgdg22.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 64-bit

もくじ

下準備

postgresql-16 に mastodon ユーザを作成しておく。

$ sudo su - postgres
postgres:~$ createuser --port 5433 --createdb mastodon
postgres:~$ exit

postgresql-16 サービスをとめて、自動起動を無効化しておく。

$ systemctl stop postgresql@16-main.service
$ systemctl disable postgresql@16-main.service

postgresql-16 のポートを 5433 から 5432 に変更。

$ vim /etc/postgresql/16/main/postgresql.conf
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------

# - Connection Settings -
port = 5432

移行の実施

Mastodon のサービスをとめる。

$ sudo systemctl stop mastodon-web mastodon-sidekiq mastodon-streaming

既存データベースを待避する。

$ sudo -u mastodon -i
$ pg_dump -Fc mastodon_production -f ~/donbak/pg_backup.dump
$ exit

postgresql-15 サービスをとめて、自動起動を無効化。

$ systemctl stop postgresql@15-main.service
$ systemctl disable postgresql@15-main.service

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS