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

はじめに

参画している案件でOracleDBのKeepAlive設定を行う機会があったのでまとめてみました。

KeepAliveとは

KeepAliveとはネットワーク接続が有効であるか確認するため定期的に行われる通信のことを指します。

接続先がハングや強制停止されエラーを戻さなかった場合でも、接続元からの定期的なチェックにより、エラーとして検知できるようになります。

また非アクティブ状態が一定時間続いた場合に強制切断する設定を入れている環境(例えばDBサーバとクライアントサーバの間にあるNW機器がアイドル状態の接続に対してタイムアウト設定を持っているときなど)での、意図しない切断の回避などにも有効です。

OracleDBのKeepAlive設定について

クライアントサーバ側

KeepAliveの設定はデフォルトではオフになっています。
設定する際は以下のようにtnsnames.oraに(ENABLE = BROKEN)を追加することで有効化できます。

tnanames.ora
ORCL =
  (DESCRIPTION =
    (ENABLE = BROKEN)
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

OSのデフォルト値

RHEL8.6の場合以下のコマンドを実行して確認することができます。

# sysctl -a | grep tcp_keepalive
net.ipv4.tcp_keepalive_intvl = 75
net.ipv4.tcp_keepalive_probes = 9
net.ipv4.tcp_keepalive_time = 7200
  • net.ipv4.tcp_keepalive_intvl
     KeepAlive 送信開始後、何ミリ秒間隔で次の KeepAlive を送信するか

  • net.ipv4.tcp_keepalive_probes
     TCP コネクション開始から KeepAlive の送信を開始するまでの時間 

  • net.ipv4.tcp_keepalive_time
     KeepAlive を送信し、何回応答が無かったら TCP コネクションを切断するか

KeepAliveのチェック間隔値変更方法

RHEL8.6の場合以下のようにsysctl.confを編集して変更します。
※デフォルト値が適用されている場合は追記が必要

# vi /etc/sysctl.conf

<!--以下の内容を記載 -->
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_probes = 5
net.ipv4.tcp_keepalive_time = 3600

# sysctl -p
#
# sysctl -a | grep tcp_keepalive
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_probes = 5
net.ipv4.tcp_keepalive_time = 3600

DBサーバ側

デフォルトでOSのKeepAliveが適用されています。
sqlnet.oraに SQLNET.EXPIRE_TIME が設定されている場合はそちらが優先されます。 SQLNET.EXPIRE_TIME に指定した数値(分単位)の間隔で、KeepAlive(プローブ・パケットの送信)を実行します。
チェック間隔を短くする場合、特にプロセス数が多い場合などはネットワークへの負荷が多少増加するため、注意する必要があります。
下の例では10分ごとにKeepAliveを実行します。

sqlnet.ora
SQLNET.EXPIRE_TIME=10

最後に

ご覧いただきありがとうございました。
この記事がどなたかのお役に立てれば幸いです。

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