12
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?

OCI Database with PostgreSQLのフェイルオーバ時の挙動確認

Posted at

この記事は OCIjp Advent Calendar 2024の 4日目の記事です。

はじめに

OCIで昨年リリースされた OCI Database with PostgreSQL はPostgreSQL互換の DBaaS となります。
代表的な特徴としては、フルマネージドであることや OCIデータベース最適化ストレージ を持つことで性能や拡張性・運用性に優れた DBaaS となっています。

特徴など細かい点は次の資料を参照下さい。

OCI Database with PostgreSQLの高可用性

OCI Database with PostgreSQLでは Database Optimized Storage(以下、DbOS) という OCI の Regional Block Storage 上で動作するストレージを基盤として動作します。DbOS 自体は全ての AD1/FD2 にレプリケートされるため、すべてのコンピュートは同じデータを参照することが可能となり、コンピュートもしくは AD/FD 単位での障害が発生しても別のレプリカが昇格することで迅速にサービス回復を行うことが可能です。

image.png
(出典:Database Optimized StorageによるOCI独自の分離ストレージ・アーキテクチャ

フェイルオーバ時の挙動確認

マルチノード(プライマリ+リードレプリカ)の PostgreSQL をデプロイし、クライアントからプライマリノードに対してSQLを実行し、プライマリノードを再起動3させることでリードレプリカをプライマリに昇格させます。
その際にクライアントからのSQL実行がどのようになるか、確認してみます。

① OCI Database with PostgreSQLのデプロイ

OCIコンソール上でPostgreSQLを作成します。流れは次のような形です。

  • OCIコンソール→ データベース → PostgreSQL

詳細な手順は次のblogなどを参照ください。

ノード数は 「」以上で設定してください(後で追加も可能です)。
image.png

2ノードのデータベースをデプロイすると次のようにタイプが「プライマリ」と「レプリカ」の2つのノードが表示されます。

image.png

② プライマリへSQL実行

デプロイしたデータベースのプライマリエンドポイント(10.0.2.6)に対して、1秒毎にデータインサートを行います。毎秒 id がインクリメントされ、current_datetime が dt 列に挿入します。

データインサート
                version                 |   pg_postmaster_start_time
----------------------------------------+-------------------------------
 PostgreSQL 14.11 OCI Optimized, 64-bit | 2024-11-23 02:32:18.484738+00
(1 row)

 id |             dt
----+----------------------------
  2 | 2024-11-23 02:34:31.209775
(1 row)

Sat Nov 23 02:34:31 GMT 2024
                version                 |   pg_postmaster_start_time
----------------------------------------+-------------------------------
 PostgreSQL 14.11 OCI Optimized, 64-bit | 2024-11-23 02:32:18.484738+00
(1 row)

 id |             dt
----+----------------------------
  3 | 2024-11-23 02:34:32.243124
(1 row)

Sat Nov 23 02:34:32 GMT 2024
                version                 |   pg_postmaster_start_time
----------------------------------------+-------------------------------
 PostgreSQL 14.11 OCI Optimized, 64-bit | 2024-11-23 02:32:18.484738+00
(1 row)

 id |             dt
----+----------------------------
  4 | 2024-11-23 02:34:33.277039
(1 row)

Sat Nov 23 02:34:33 GMT 2024

 :
 :

イメージとしては次図のような状態です。

image.png

③ フェイルオーバ実行

プライマリノードのケバブメニュー(縦3点リーダ)をクリックし、再起動を選択します。

image.png

停止タイプを「標準」か「ノード再起動」を選択することができます。「標準」は PostgreSQL プロセスの再起動になり、数秒での実行が可能です。
今回はノード再起動を選択します。

image.png

再起動を実施すると、コンソール上でステータスが「UPDATING」になります。

image.png

④ フェイルオーバ発生

ステータスが「UPDATING」となって数秒後には次のようにノードのタイプの「プライマリ」と「レプリカ」が切り替わり、フェイルオーバが発生していることが確認できます。

image.png

イメージとしては次図になります。

image.png

また、フェイルオーバによって id 52 のインサートが失敗し、フェイルオーバ完了後にインサートが実行されていることが確認できます。
エラーが発生している時間帯は大体15秒弱ですね。

フェイルオーバ
                version                 |   pg_postmaster_start_time
----------------------------------------+-------------------------------
 PostgreSQL 14.11 OCI Optimized, 64-bit | 2024-11-23 02:32:18.484738+00
(1 row)

 id |             dt
----+----------------------------
 51 | 2024-11-23 02:35:21.900767
(1 row)

Sat Nov 23 02:35:21 GMT 2024
                version                 |   pg_postmaster_start_time
----------------------------------------+-------------------------------
 PostgreSQL 14.11 OCI Optimized, 64-bit | 2024-11-23 02:32:18.484738+00
(1 row)

SSL SYSCALL error: EOF detected
connection to server was lost
Sat Nov 23 02:35:22 GMT 2024
psql: could not connect to server: Connection refused
        Is the server running on host "10.0.2.6" and accepting
        TCP/IP connections on port 5432?
Sat Nov 23 02:35:23 GMT 2024
psql: could not connect to server: Connection refused
        Is the server running on host "10.0.2.6" and accepting
        TCP/IP connections on port 5432?
Sat Nov 23 02:35:24 GMT 2024
psql: could not connect to server: Connection refused
        Is the server running on host "10.0.2.6" and accepting
        TCP/IP connections on port 5432?
Sat Nov 23 02:35:25 GMT 2024
psql: could not connect to server: Connection refused
        Is the server running on host "10.0.2.6" and accepting
        TCP/IP connections on port 5432?
Sat Nov 23 02:35:26 GMT 2024
psql: could not connect to server: Connection refused
        Is the server running on host "10.0.2.6" and accepting
        TCP/IP connections on port 5432?
Sat Nov 23 02:35:28 GMT 2024
psql: could not connect to server: Connection refused
        Is the server running on host "10.0.2.6" and accepting
        TCP/IP connections on port 5432?
Sat Nov 23 02:35:29 GMT 2024
psql: could not connect to server: Connection refused
        Is the server running on host "10.0.2.6" and accepting
        TCP/IP connections on port 5432?
Sat Nov 23 02:35:30 GMT 2024
psql: could not connect to server: Connection refused
        Is the server running on host "10.0.2.6" and accepting
        TCP/IP connections on port 5432?
Sat Nov 23 02:35:31 GMT 2024
psql: could not connect to server: Connection refused
        Is the server running on host "10.0.2.6" and accepting
        TCP/IP connections on port 5432?
Sat Nov 23 02:35:32 GMT 2024
psql: could not connect to server: Connection refused
        Is the server running on host "10.0.2.6" and accepting
        TCP/IP connections on port 5432?
Sat Nov 23 02:35:33 GMT 2024
psql: could not connect to server: Connection refused
        Is the server running on host "10.0.2.6" and accepting
        TCP/IP connections on port 5432?
Sat Nov 23 02:35:34 GMT 2024
                version                 |   pg_postmaster_start_time
----------------------------------------+-------------------------------
 PostgreSQL 14.11 OCI Optimized, 64-bit | 2024-11-23 02:35:32.676362+00
(1 row)

 id |             dt
----+----------------------------
 52 | 2024-11-23 02:35:35.124922
(1 row)

Sat Nov 23 02:35:35 GMT 2024
                version                 |   pg_postmaster_start_time
----------------------------------------+-------------------------------
 PostgreSQL 14.11 OCI Optimized, 64-bit | 2024-11-23 02:35:32.676362+00
(1 row)

 id |             dt
----+----------------------------
 53 | 2024-11-23 02:35:36.164655
(1 row)

Sat Nov 23 02:35:36 GMT 2024

まとめ

資料上は約2分程度の RTO となっているので、それに比べるとだいぶ速いフェイルオーバ時間になりますね。
Tokyoリージョンは同一の AD 内部でのフェイルオーバとなるので別 AD のフェイルオーバに比べたら速い、という事はあるかもしれません。

  1. Availability Domain: OCIのデータセンター単位の区切り、AWS における AZ

  2. Fault Domain: OCIのデータセンター内における 電源などが別になっている区切り、VMを別の FD に配置することで電源障害などで同時に影響を受けることを防ぐ

  3. コンソールからの手動フェイルオーバは実施ができないが、OCICLIからフェイルオーバを実施することは可能(出典:Runs a failover operation)。

12
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
12
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?