2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Oracle Base Database Service(BaseDB) のタイムゾーンを変更してみてみた

Last updated at Posted at 2023-08-03

データベース・タイムゾーンは手動で変更できますが、データベース間でデータを転送するときにデータ変換を回避し、パフォーマンスを向上させるために、UTC (デフォルト)のままにすることをお薦めします。この構成は、特に、分散データベース、レプリケーションおよびインポートの操作で重要です。
UTCのタイム・ゾーンを使用することをお薦めしますが、データベース・クライアントとアプリケーション・ホストに共通のタイム・ゾーンを設定すると、データベース管理者の管理およびトラブルシューティングを簡素化できます。
ということで、UTC から Asia/Tokyo (JST) へ変更してみてみます。

■ 現在のタイム・ゾーンの表示

⚫︎ OS タイム・ゾーン確認

1) gridユーザー・ログオン
gridユーザーとしてホストにログオンします。

[opc@basedb ~]$ sudo su - grid
[grid@basedb ~]$ id -a
	uid=102(grid) gid=1001(oinstall) groups=1001(oinstall),1002(dbaoper),1004(asmadmin),1005(asmoper),1006(asmdba)

2) タイム・ゾーン確認
次のコマンドを使用して、タイム・ゾーンを表示します。

[grid@basedb ~]$ timedatectl
      Local time: Thu 2023-08-03 05:29:39 UTC
  Universal time: Thu 2023-08-03 05:29:39 UTC
        RTC time: Thu 2023-08-03 05:29:39
       Time zone: UTC (UTC, +0000)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

⚫︎ Databasae タイム・ゾーン確認

1) Databae ログイン
データベースにログオンします。

[grid@basedb ~]$ sqlplus / as sysdba

	SQL*Plus: Release 19.0.0.0.0 - Production on Thu Aug 3 16:48:28 2023
	Version 19.19.0.0.0

	Copyright (c) 1982, 2022, Oracle.  All rights reserved.


	Connected to:
	Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
	Version 19.19.0.0.0

2) データベース時間確認
次のコマンドを使用して、現在のデータベース時間を表示できます。

SQL> select to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') as data from dual;

	DATA
	-------------------
	2023-08-03 05:30:48

■ OS タイム・ゾーンの変更

1) rootユーザー・ログオン
rootユーザーとしてホストにログオンします。

[opc@basedb ~]$ sudo su -

2) タイム・ゾーン(TZ)値確認
次のコマンドを使用して、設定する正しいタイム・ゾーン(TZ)値を特定します。

[root@basedb ~]# tzselect
Please identify a location so that time zone rules can be set correctly.
	Please select a continent or ocean.
	 1) Africa
	 2) Americas
	 3) Antarctica
	 4) Arctic Ocean
	 5) Asia
	 6) Atlantic Ocean
	 7) Australia
	 8) Europe
	 9) Indian Ocean
	1)  Pacific Ocean
	2)  none - I want to specify the time zone using the Posix TZ format.
	#? 5
	
	Please select a country.
	 1) Afghanistan		  18) Israel		    35) Palestine
	 2) Armenia		  19) Japan		    36) Philippines
	 3) Azerbaijan		  20) Jordan		    37) Qatar
	 4) Bahrain		  21) Kazakhstan	    38) Russia
	 5) Bangladesh		  22) Korea (North)	    39) Saudi Arabia
	 6) Bhutan		  23) Korea (South)	    40) Singapore
	 7) Brunei		  24) Kuwait		    41) Sri Lanka
	 8) Cambodia		  25) Kyrgyzstan	    42) Syria
	 9) China		  26) Laos		    43) Taiwan
	10) Cyprus		  27) Lebanon		    44) Tajikistan
	11) East Timor		  28) Macau		    45) Thailand
	12) Georgia		  29) Malaysia		    46) Turkmenistan
	13) Hong Kong		  30) Mongolia		    47) United Arab Emirates
	14) India		  31) Myanmar (Burma)	    48) Uzbekistan
	15) Indonesia		  32) Nepal		    49) Vietnam
	16) Iran		  33) Oman		    50) Yemen
	17) Iraq		  34) Pakistan
	#? 19
	
	The following information has been given:
	
		Japan
	
	Therefore TZ='Asia/Tokyo' will be used.
	Local time is now:	Thu Aug  3 14:32:04 JST 2023.
	Universal Time is now:	Thu Aug  3 05:32:04 UTC 2023.
	Is the above information OK?
	1) Yes
	2) No
	#?
	
	You can make this change permanent for yourself by appending the line
		TZ='Asia/Tokyo'; export TZ
	to the file '.profile' in your home directory; then log out and log in again.
	
	Here is that TZ value again, this time on standard output so that you
	can use the /usr/bin/tzselect command in shell scripts:
	Asia/Tokyo

3) タイム・ゾーン設定
次のコマンドを更新して、新しいタイム・ゾーンを設定します。

[root@basedb ~]# timedatectl set-timezone Asia/Tokyo

4) タイム・ゾーン設定確認
次のコマンドを使用して、タイム・ゾーンが更新されたかどうかを確認します。

[root@basedb ~]# timedatectl
      Local time: Thu 2023-08-03 14:35:16 JST
  Universal time: Thu 2023-08-03 05:35:16 UTC
        RTC time: Thu 2023-08-03 05:35:17
       Time zone: Asia/Tokyo (JST, +0900)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

■ Grid Infrastructureを使用するDBシステムでのホストのタイム・ゾーンの変更

⚫︎ Grid Infrastructureタイム・ゾーン変更

1) gridユーザー・ログオン
gridユーザーとしてホストにログオンします。

[root@basedb ~]# sudo su - grid
	Last login: Thu Aug  3 14:29:19 JST 2023 on pts/0
[grid@basedb ~]$ id
	uid=102(grid) gid=1001(oinstall) groups=1001(oinstall),1002(dbaoper),1004(asmadmin),1005(asmoper),1006(asmdba)

2) タイム・ゾーン(TZ)値確認
次のコマンドを使用して、設定する正しいタイム・ゾーン(TZ)値を特定します。

[grid@basedb ~]$ tzselect
Please identify a location so that time zone rules can be set correctly.
	Please select a continent or ocean.
	 1) Africa
	 2) Americas
	 3) Antarctica
	 4) Arctic Ocean
	 5) Asia
	 6) Atlantic Ocean
	 7) Australia
	 8) Europe
	 9) Indian Ocean
	10) Pacific Ocean
	11) none - I want to specify the time zone using the Posix TZ format.
	#? 5
	Please select a country.
	 1) Afghanistan		  18) Israel		    35) Palestine
	 2) Armenia		  19) Japan		    36) Philippines
	 3) Azerbaijan		  20) Jordan		    37) Qatar
	 4) Bahrain		  21) Kazakhstan	    38) Russia
	 5) Bangladesh		  22) Korea (North)	    39) Saudi Arabia
	 6) Bhutan		  23) Korea (South)	    40) Singapore
	 7) Brunei		  24) Kuwait		    41) Sri Lanka
	 8) Cambodia		  25) Kyrgyzstan	    42) Syria
	 9) China		  26) Laos		    43) Taiwan
	10) Cyprus		  27) Lebanon		    44) Tajikistan
	11) East Timor		  28) Macau		    45) Thailand
	12) Georgia		  29) Malaysia		    46) Turkmenistan
	13) Hong Kong		  30) Mongolia		    47) United Arab Emirates
	14) India		  31) Myanmar (Burma)	    48) Uzbekistan
	15) Indonesia		  32) Nepal		    49) Vietnam
	16) Iran		  33) Oman		    50) Yemen
	17) Iraq		  34) Pakistan
	#? 19
	
	The following information has been given:
	
		Japan
	
	Therefore TZ='Asia/Tokyo' will be used.
	Local time is now:	Thu Aug  3 14:36:24 JST 2023.
	Universal Time is now:	Thu Aug  3 05:36:24 UTC 2023.
	Is the above information OK?
	1) Yes
	2) No
	#? 1
	
	You can make this change permanent for yourself by appending the line
		TZ='Asia/Tokyo'; export TZ
	to the file '.profile' in your home directory; then log out and log in again.
	
	Here is that TZ value again, this time on standard output so that you
	can use the /bin/tzselect command in shell scripts:
	Asia/Tokyo

3) ホスト名確認
次のコマンドを実行して、ホスト名を取得します。

[grid@basedb ~]$ hostname
	basedb

4) データベース名確認
次のコマンドを実行して、データベース名を取得します。

[grid@basedb ~]$ srvctl config database -v
CDB_d6w_nrt	/u01/app/oracle/product/19.0.0.0/dbhome_1	19.0.0.0.0

5) rootユーザー・ログオン
gridユーザーとしてログアウトし、rootユーザーとしてサインインします。

[grid@basedb ~]$ env | grep ORA
	ORACLE_SID=+ASM1
	ORACLE_HOME=/u01/app/19.0.0.0/grid
[grid@basedb ~]$ exit
	logout
[root@basedb ~]# id
	uid=0(root) gid=0(root) groups=0(root)

6) 設定ファイル・ディレクトリ移動
次のディレクトリに移動します。

[root@basedb ~]# cd $GRID_HOME/crs/install
[root@basedb ~]# cd /u01/app/19.0.0.0/grid/crs/install

7) s_crsconfig__env.txtファイル設定
次のファイルのTZの内容を編集します。編集後、ファイルを保存して閉じます。

コマンド
vi s_crsconfig_<hostname>_env.txt
[grid@basedb install]$ cp s_crsconfig_basedb_env.txt s_crsconfig_basedb_env.txt.bk
[grid@basedb install]$ ls -l | grep  s_crsconfig_basedb_env.txt
	-rwxr-xr-x 1 root oinstall       990 Jul 24 12:26 s_crsconfig_basedb_env.txt
	-rwxr-xr-x 1 grid oinstall       990 Aug  3 14:40 s_crsconfig_basedb_env.txt.bk

[grid@basedb install]$ vi s_crsconfig_basedb_env.txt
	-->TZ=Asia/Tokyo へ変更

8) s_crsconfig__env.txtファイル設定確認
cat s_crsconfig__env.txt ファイルのTZエントリが更新されているかどうかを確認します。

[grid@basedb install]$ cat s_crsconfig_basedb_env.txt
	#########################################################################
	#This file can be used to set values for the NLS_LANG and TZ environment
	#variables and to set resource limits for Oracle Clusterware and
	#Database processes.
	#1. The NLS_LANG environment variable determines the language and
	#   characterset used for messages. For example, a new value can be
	#   configured by setting NLS_LANG=JAPANESE_JAPAN.UTF8
	#2. The Time zone setting can be changed by setting the TZ entry to
	#   the appropriate time zone name. For example, TZ=America/New_York
	#3. Resource limits for stack size, open files and number of processes
	#   can be specified by modifying the appropriate entries.
	#
	#Do not modify this file except as documented above or under the
	#direction of Oracle Support Services.
	#########################################################################
	TZ=Asia/Tokyo
	NLS_LANG=AMERICAN_AMERICA.AL32UTF8
	CRS_LIMIT_STACK=2048
	CRS_LIMIT_OPENFILE=65536
	CRS_LIMIT_NPROC=65536
	TNS_ADMIN=

9) タイムゾーン変更
新しいタイムゾーンを設定します。

[grid@basedb install]$ timedatectl set-timezone Asia/Tokyo

⚫︎ Database タイムゾーン変更

1) データベース・レベルのTZ値確認

[grid@basedb bin]$ srvctl getenv database -d CDB_d6w_nrt
	CDB_d6w_nrt:
	TZ=UTC

2) データベースTZ値変更

次のコマンドを使用して、データベース・レベルのTZ値を目的のタイム・ゾーンに変更します。
srvctl setenv database -d -t "TZ="

[root@basedb ~]# /u01/app/19.0.0.0/grid/bin/srvctl setenv database -d CDB_d6w_nrt -t "TZ=Asia/Tokyo"

3) データベースTZ値変更確認
次のコマンドを使用して、設定されたTZ値を確認します。
srvctl getenv database -d

[root@basedb ~]# /u01/app/19.0.0.0/grid/bin/srvctl getenv database -d CDB_d6w_nrt
	CDB_d6w_nrt:
	TZ=Asia/Tokyo

⚫︎ Database再起動

1)CRS停止
すべてのコンピュート・ノードでCRSスタックを停止します。

[root@basedb ~]# /u01/app/19.0.0.0/grid/bin/crsctl stop cluster
	CRS-2673: Attempting to stop 'ora.crsd' on 'basedb'
	CRS-2790: Starting shutdown of Cluster Ready Services-managed resources on server 'basedb'
	CRS-2673: Attempting to stop 'ora.qosmserver' on 'basedb'
	CRS-2673: Attempting to stop 'ora.cdb_d6w_nrt.cdbdev.paas.oracle.com.svc' on 'basedb'
	CRS-2673: Attempting to stop 'ora.chad' on 'basedb'
	CRS-2673: Attempting to stop 'ora.cdb_d6w_nrt.cdb_idbdev.paas.oracle.com.svc' on 'basedb'
	CRS-2673: Attempting to stop 'ora.cdb_d6w_nrt.cdb_dwhdev.paas.oracle.com.svc' on 'basedb'
	CRS-2677: Stop of 'ora.cdb_d6w_nrt.cdbdev.paas.oracle.com.svc' on 'basedb' succeeded
	CRS-2677: Stop of 'ora.cdb_d6w_nrt.cdb_dwhdev.paas.oracle.com.svc' on 'basedb' succeeded
	CRS-2677: Stop of 'ora.cdb_d6w_nrt.cdb_idbdev.paas.oracle.com.svc' on 'basedb' succeeded
	CRS-2673: Attempting to stop 'ora.cdb_d6w_nrt.db' on 'basedb'
	CRS-2677: Stop of 'ora.chad' on 'basedb' succeeded
	CRS-2677: Stop of 'ora.qosmserver' on 'basedb' succeeded
	CRS-2677: Stop of 'ora.cdb_d6w_nrt.db' on 'basedb' succeeded
	CRS-2673: Attempting to stop 'ora.data.commonstore.acfs' on 'basedb'
	CRS-2677: Stop of 'ora.data.commonstore.acfs' on 'basedb' succeeded
	CRS-2673: Attempting to stop 'ora.DATA.COMMONSTORE.advm' on 'basedb'
	CRS-2677: Stop of 'ora.DATA.COMMONSTORE.advm' on 'basedb' succeeded
	CRS-2673: Attempting to stop 'ora.proxy_advm' on 'basedb'
	CRS-2677: Stop of 'ora.proxy_advm' on 'basedb' succeeded
	CRS-33673: Attempting to stop resource group 'ora.asmgroup' on server 'basedb'
	CRS-2673: Attempting to stop 'ora.RECO.dg' on 'basedb'
	CRS-2673: Attempting to stop 'ora.DATA.dg' on 'basedb'
	CRS-2673: Attempting to stop 'ora.LISTENER.lsnr' on 'basedb'
	CRS-2673: Attempting to stop 'ora.cvu' on 'basedb'
	CRS-2677: Stop of 'ora.RECO.dg' on 'basedb' succeeded
	CRS-2677: Stop of 'ora.DATA.dg' on 'basedb' succeeded
	CRS-2673: Attempting to stop 'ora.asm' on 'basedb'
	CRS-2677: Stop of 'ora.cvu' on 'basedb' succeeded
	CRS-2677: Stop of 'ora.LISTENER.lsnr' on 'basedb' succeeded
	CRS-2673: Attempting to stop 'ora.basedb.vip' on 'basedb'
	CRS-2677: Stop of 'ora.basedb.vip' on 'basedb' succeeded
	CRS-2677: Stop of 'ora.asm' on 'basedb' succeeded
	CRS-2673: Attempting to stop 'ora.ASMNET1LSNR_ASM.lsnr' on 'basedb'
	CRS-2677: Stop of 'ora.ASMNET1LSNR_ASM.lsnr' on 'basedb' succeeded
	CRS-2673: Attempting to stop 'ora.asmnet1.asmnetwork' on 'basedb'
	CRS-2677: Stop of 'ora.asmnet1.asmnetwork' on 'basedb' succeeded
	CRS-33677: Stop of resource group 'ora.asmgroup' on server 'basedb' succeeded.
	CRS-2673: Attempting to stop 'ora.ons' on 'basedb'
	CRS-2677: Stop of 'ora.ons' on 'basedb' succeeded
	CRS-2673: Attempting to stop 'ora.net1.network' on 'basedb'
	CRS-2677: Stop of 'ora.net1.network' on 'basedb' succeeded
	CRS-2792: Shutdown of Cluster Ready Services-managed resources on 'basedb' has completed
	CRS-2677: Stop of 'ora.crsd' on 'basedb' succeeded
	CRS-2673: Attempting to stop 'ora.storage' on 'basedb'
	CRS-2673: Attempting to stop 'ora.evmd' on 'basedb'
	CRS-2673: Attempting to stop 'ora.ctssd' on 'basedb'
	CRS-2677: Stop of 'ora.storage' on 'basedb' succeeded
	CRS-2673: Attempting to stop 'ora.asm' on 'basedb'
	CRS-2677: Stop of 'ora.ctssd' on 'basedb' succeeded
	CRS-2677: Stop of 'ora.evmd' on 'basedb' succeeded
	CRS-2677: Stop of 'ora.asm' on 'basedb' succeeded
	CRS-2673: Attempting to stop 'ora.cssd' on 'basedb'
	CRS-2677: Stop of 'ora.cssd' on 'basedb' succeeded

2) CRS起動
すべてのコンピュート・ノードでCRSスタックを起動します。

[root@basedb ~]# /u01/app/19.0.0.0/grid/bin/crsctl start cluster
	CRS-2672: Attempting to start 'ora.cssdmonitor' on 'basedb'
	CRS-2672: Attempting to start 'ora.evmd' on 'basedb'
	CRS-2676: Start of 'ora.cssdmonitor' on 'basedb' succeeded
	CRS-2672: Attempting to start 'ora.cssd' on 'basedb'
	CRS-2672: Attempting to start 'ora.diskmon' on 'basedb'
	CRS-2676: Start of 'ora.diskmon' on 'basedb' succeeded
	CRS-2676: Start of 'ora.evmd' on 'basedb' succeeded
	CRS-2676: Start of 'ora.cssd' on 'basedb' succeeded
	CRS-2672: Attempting to start 'ora.ctssd' on 'basedb'
	CRS-2676: Start of 'ora.ctssd' on 'basedb' succeeded
	CRS-2672: Attempting to start 'ora.asm' on 'basedb'
	CRS-2676: Start of 'ora.asm' on 'basedb' succeeded
	CRS-2672: Attempting to start 'ora.storage' on 'basedb'
	CRS-2676: Start of 'ora.storage' on 'basedb' succeeded
	CRS-2672: Attempting to start 'ora.crsd' on 'basedb'
	CRS-2676: Start of 'ora.crsd' on 'basedb' succeeded

■ タイム・ゾーン更新確認

⚫︎ OS タイムゾーン確認

次のコマンドを使用して、タイム・ゾーンが更新されたかどうかを確認します。

[oracle@basedb ~]$ timedatectl
      Local time: Thu 2023-08-03 14:57:13 JST
  Universal time: Thu 2023-08-03 05:57:13 UTC
        RTC time: Thu 2023-08-03 05:57:14
       Time zone: Asia/Tokyo (JST, +0900)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a


[oracle@basedb trace]$ date
	Thu Aug  3 14:59:07 JST 2023

⚫︎ Grid Infrastructure タイムゾーン確認

[opc@basedb ~]$ sudo su - grid
[grid@basedb bin]$ srvctl getenv database -d CDB_d6w_nrt
	CDB_d6w_nrt:
	TZ=UTC

⚫︎ DB タイムゾーン確認

[opc@basedb ~]$ sudo su - oracle
[oracle@basedb ~]$ sqlplus / as sysdba
SQL> select to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') as data from dual;

	DATA
	-------------------
	2023-08-03 14:58:44

■ 参考

タイム・ゾーンの管理

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?