1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

はじめに

ansible で OracleDB のRU適用をしたので、PostgreSQL でも同等のことをやってみます:elephant:

必要なファイルの準備

inventory.ini は OracleDB の方とほぼ同じなので割愛します。
確認したい方は「はじめに」に記載のリンク先をご確認ください。

playbook は下記の通りです。
起動 (停止) は serviceモジュールを使いたかったんですが、docker desktop上で試している都合上使用しても起動 (停止) できないので、shellモジュールを使いました。
serviceモジュールを使える環境では serviceモジュールを使いましょう。

また、DNFを使うにあたりbecome: yesしていますが、事前に postgresユーザを sudoers に追加しています。セキュリティ要件次第では別の方法を検討する必要があります。

mvup.yaml
- hosts: ansible_target
  gather_facts: false

  tasks:
    - name: stop pos
      shell: /usr/pgsql-16/bin/pg_ctl stop

    - name: vup pos
      dnf: name=postgresql16-server state=latest
      become: yes

    - name: start pos
      shell: /usr/pgsql-16/bin/pg_ctl -D /var/lib/pgsql/16/data/ -l logfile start

ディレクトリ構成も割愛します。
今回使用しているモジュールはすべて builtin なので。

いざ実行!

…の前に状態確認です。

確認
postgres=# select version();
                                                 version
----------------------------------------------------------------------------
------------------------------
 PostgreSQL 16.5 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 11.5.0 202407
19 (Red Hat 11.5.0-2), 64-bit
(1 row)

16.5で間違いないことを確認して実行!※

playbook実行
[postgres@73486a139b1a ~]$ ansible-playbook -i inventory.ini --connection=local mvup.yaml

PLAY [ansible_target] **********************************************************

TASK [stop pos] ****************************************************************
changed: [localhost]

TASK [vup pos] *****************************************************************
changed: [localhost]

TASK [start pos] ***************************************************************
changed: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

[postgres@73486a139b1a ~]$

無事完了したので、改めて状態確認です。

確認
postgres=# select version();
                                                 version
----------------------------------------------------------------------------
------------------------------
 PostgreSQL 16.9 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 11.5.0 202407
19 (Red Hat 11.5.0-5), 64-bit
(1 row)

最新版 (16.9) になっていることを確認できました!

※特定のマイナーバージョンをインストールする方法は下記を参考にさせていただきました:bow:

なお、マイナーバージョンによっては追加作業が必要になるケースがあるので、事前にリリースノートを確認しておきましょう。

下記の記載が該当箇所です。

However, if you have any self-referential foreign key constraints on partitioned tables, it may be necessary to recreate those constraints to ensure that they are being enforced correctly. See the second changelog entry below.

OracleDB のときは unzip したRUをどこかに置いておく必要がありましたが、これに相当する作業がないのは楽で良いですね。
builtinモジュールで済むのも良いです。(追加作業は community.postgresqlモジュールでできるかも?)

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?