0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

pgbouncer 1.25.0(PGDGビルド)で systemd notify が原因で起動タイムアウトする

Posted at

概要

pgbouncer-1.24.1-42PGDG.rhel8から
pgbouncer-1.25.0-42PGDG.rhel8にアップデートしたところ、
pgbouncerが起動直後に落ちる(タイムアウトする)事象が発生しました。

事象の詳細

pgbouncerを1.25.0にdnfでupdateした後、pgbouncerに接続できなくなりました。
そこで手動でsystemctl start pgbouncerを実行しました。

$ sudo systemctl start pgbouncer

しかし応答が返ってきませんでした。
コマンドを打った直後、プロセスを確認すると以下のようになっていました。

$ ps ax | grep pgb
1267048 pts/0    S+     0:00 systemctl start pgbouncer.service
1267050 ?        Ss     0:02 /usr/bin/pgbouncer /etc/pgbouncer/pgbouncer.ini

pgbouncer自体は起動しているため、この時点ではpsqlで接続も可能でした。
しかし、しばらくするとsystemd側でタイムアウトして強制停止されました。

ログ抜粋

# systemctl status pgbouncer.service
Nov 12 06:46:12 sakura systemd[1]: pgbouncer.service: start operation timed out. Terminating.
Nov 12 06:46:16 sakura systemd[1]: pgbouncer.service: Failed with result 'timeout'.

systemctl start pgbouncerをCtrl+Cで停止してステータスを再確認すると次のWARNINGが出力されました。

Nov 12 06:49:16 sakura pgbouncer[1267050]:
WARNING apparently running under systemd with notify socket, but systemd support was not built

原因

この警告が示す通り、pgbouncer 1.25.0(PGDGビルド)がsystemdのnotify機能なしでビルドされているのに、ユニットファイル側がType=notifyのままになっているため、systemdがREADY=1通知を待ち続け、結果的に 起動タイムアウトしています。
pgbouncer自体は動作しており、systemd側が「起動完了通知が来ない」と誤認している状態です。

対処方法

ユニットファイルを上書きしてType=simpleに変更しました。
具体的には以下のとおりです。

$ sudo systemctl edit pgbouncer

エディタが開いたら、以下を記述します。

[Service]
# notify をやめて simple に変更
Type=simple

設定を反映して再起動します。

$ sudo systemctl daemon-reload
$ sudo systemctl restart pgbouncer
$ sudo systemctl status pgbouncer

これで、pgbouncerは正常に起動し、タイムアウトせず動作しました。

原因の裏付け(ビルド依存関係の比較)

pgbouncer-1.25.0-42PGDG.rhel8libsystemdが含まれているかどうかで、systemd対応の有無を確認できます。

1.25.0(PGDGビルド)

$ rpm -q --requires pgbouncer | grep -i systemd || echo "=> RPM依存にlibsystemdなし"
=> RPM依存にlibsystemdなし

1.24.1(PGDGビルド)

$ rpm -q --requires pgbouncer | grep -i systemd
libsystemd.so.0()(64bit)
libsystemd.so.0(LIBSYSTEMD_209)(64bit)
systemd
systemd-sysv

→ 1.24.1ではlibsystemdにリンクしているが、1.25.0では外されている。

参考: systemd のタイムアウト仕様

補足: pgbouncerの公式ビルドオプション

Type=notifyにさせるビルドオプション(--with-systemd)の説明は以下のとおり。

To enable systemd integration, use the configure option --with-systemd.
This allows using Type=notify (or Type=notify-reload if you are using systemd 253 or later) as well as socket activation.
See etc/pgbouncer.service and etc/pgbouncer.socket for examples.

まとめ

項目 状況
pgbouncer 1.24.1 systemd notify 対応(libsystemd あり)
pgbouncer 1.25.0 systemd notify 非対応(libsystemd なし)
原因 Type=notify のまま systemd が READY 通知を待ち続ける
対処法 systemd ユニットの [Service]Type=simple を設定

環境情報

  • OS: AlmaLinux 8
  • pgbouncer: 1.25.0-42PGDG.rhel8
  • systemd: 252
  • PostgreSQL: 17 (PGDG)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?