管理時區

主控台和 API 中的時區欄位可讓您啟動時區不是 UTC (預設值) 的資料庫系統資源。

建立資料庫系統時所指定的時區會套用至主機和 Oracle Grid Infrastructure (如果系統有 Grid Infrastructure),並控制資料庫日誌檔的時區。資料庫本身的時區不受影響。不過,資料庫的時區只會影響 timestamp 資料類型。您可以手動變更資料庫時區,但 Oracle 建議您將它保持為 UTC (預設值),以避免資料轉換,並改善資料在資料庫間傳輸時的效能。此組態對分散式資料庫、複製以及匯出與匯入作業特別重要。

雖然建議使用 UTC 時區,但是您的資料庫從屬端和應用程式主機具有通用時區,可以簡化資料庫管理員的管理和疑難排解。

備註:時區主要用於顯示或處理使用者輸入。變更時區不會變更系統時鐘的時間。

時區選項

無論您使用主控台或 API,您可選取的時區選項都會以指定的區域格式表示,例如 America/Los_Angeles 。主控台允許您選取 UTC、瀏覽器中偵測到的時區 (如果您的瀏覽器支援時區偵測) 或其他時區。

若要指定替代時區 ( 選取其他時區選項),您必須先在地區或國家欄位中選取一個值,以縮小要從時區欄位中選取的時區清單。在 America/Los_Angeles 範例中, America 是時間區域,而 Los_Angeles 是時區。您在這兩個欄位中看到的選項,與 Java.util.TimeZone 類別和 Linux 作業系統上支援的時區大致相關。如果您沒有看到要尋找的時區,請嘗試在地區與國家欄位中選取「雜項」。

提示:如果您使用 API 且想要查看支援的時區清單,可以查看主控台中的時區選項。當您選取資料庫系統資源配置後顯示進階選項時,建立資料庫系統頁面便會顯示這些選項。

檢視目前時區

執行下列步驟以檢視時區資訊。

  1. 以 Grid 使用者身分登入主機。

    範例:

    [opc@rc ~]$ sudo su - grid
  2. 請使用下列命令來檢視時區。

    timedatectl

    範例:

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

    請注意,系統目前使用 UTC 時區。

  3. 登入資料庫。

    範例:

    [grid@rc ~]$ sqlplus / as sysdba
    
    SQL*Plus: Release 21.0.0.0.0 - Production on Thu Mar 16 08:00:33 2023
    Version 21.9.0.0.0
    
    Copyright (c) 1982, 2022, Oracle.  All rights reserved.
    
    Connected to:
    Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 -Production
    Version 21.9.0.0.0
  4. 您可以使用下列命令來檢視目前的資料庫時間。

    sysdate

    範例:

    SQL> select to_char(sysdate,'DD-MON-YYYY HH24:MI:SS') from dual;
    
    TO_CHAR(SYSDATE,'DD-
    --------------------
    16-MAR-2023 08:00:40
  5. 結束。

變更資料庫系統的時區

請執行下列步驟來設定資料庫系統的時區。

  1. 以 root 使用者身分登入主機。

    範例:

    [opc@rc ~]$ sudo su -
  2. 使用下列指令識別要設定的正確時區 (TZ) 值。例如,如果您要識別美國東部時區 (EST/EDT) 的正確 TZ 值,可以使用 tzselect 命令並選擇「美洲 / 美國 / 東部」。

    tzselect

    範例:

    [root@rc ~]# 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.
    #? 2
    Please select a country.
     1) Anguilla              19) Dominican Republic    37) Peru
     2) Antigua & Barbuda     20) Ecuador               38) Puerto Rico
     3) Argentina             21) El Salvador           39) St Barthelemy
     4) Aruba                 22) French Guiana         40) St Kitts & Nevis
     5) Bahamas               23) Greenland             41) St Lucia
     6) Barbados              24) Grenada               42) St Maarten (Dutch)
     7) Belize                25) Guadeloupe            43) St Martin (French)
     8) Bolivia               26) Guatemala             44) St Pierre & Miquelon
     9) Brazil                27) Guyana                45) St Vincent
    10) Canada                28) Haiti                 46) Suriname
    11) Caribbean NL          29) Honduras              47) Trinidad & Tobago
    12) Cayman Islands        30) Jamaica               48) Turks & Caicos Is
    13) Chile                 31) Martinique            49) United States
    14) Colombia              32) Mexico                50) Uruguay
    15) Costa Rica            33) Montserrat            51) Venezuela
    16) Cuba                  34) Nicaragua             52) Virgin Islands (UK)
    17) Curaçao               35) Panama                53) Virgin Islands (US)
    18) Dominica              36) Paraguay
    #? 49
    Please select one of the following time zone regions.
     1) Eastern (most areas)              16) Central - ND (Morton rural)
     2) Eastern - MI (most areas)         17) Central - ND (Mercer)
     3) Eastern - KY (Louisville area)    18) Mountain (most areas)
     4) Eastern - KY (Wayne)              19) Mountain - ID (south); OR (east)
     5) Eastern - IN (most areas)         20) MST - Arizona (except Navajo)
     6) Eastern - IN (Da, Du, K, Mn)      21) Pacific
     7) Eastern - IN (Pulaski)            22) Alaska (most areas)
     8) Eastern - IN (Crawford)           23) Alaska - Juneau area
     9) Eastern - IN (Pike)               24) Alaska - Sitka area
    10) Eastern - IN (Switzerland)        25) Alaska - Annette Island
    11) Central (most areas)              26) Alaska - Yakutat
    12) Central - IN (Perry)              27) Alaska (west)
    13) Central - IN (Starke)             28) Aleutian Islands
    14) Central - MI (Wisconsin border)   29) Hawaii
    15) Central - ND (Oliver)
    #? 1
    The following information has been given:
            United States
            Eastern (most areas)
    Therefore TZ='America/New_York' will be used.
        Local time is now:    Thu Mar 16 04:01:39 EDT 2023.
    Universal Time is now:    Thu Mar 16 08:01:39 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='America/New_York'; 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:
            America/New_York
    [root@rc ~]#

    在 tzselect 命令中,我們已將 EDT 時區的 TZ 值識別為 America/New_York。

  3. 請更新下列指令以設定新的時區。

    timedatectl set-timezone <new_time_zone>

    範例:

    [root@rc ~]# timedatectl set-timezone America/New_York
  4. 使用下列命令驗證時區是否已更新。

    timedatectl

    範例:

    [root@rc ~]# timedatectl
             Local time: Thu 2023-03-16 04:02:15 EDT
         Universal time: Thu 2023-03-16 08:02:15 UTC
               RTC time: Thu 2023-03-16 08:02:10
              Time zone: America/New_York (EDT, -0400)
            NTP enabled: yes
       NTP synchronized: no
        RTC in local TZ: no
             DST active: yes
        Last DST change: DST began at
                         Sun 2023-03-12 01:59:59 EST
                         Sun 2023-03-12 03:00:00 EDT
        Next DST change: DST ends (the clock jumps one hour backwards) at
                         Sun 2023-11-05 01:59:59 EDT
                         Sun 2023-11-05 01:00:00 EST

    請注意,系統現在處於 America/New_York (EDT) 時區。

  5. 結束。

變更使用 Grid Infrastructure 之資料庫系統上的主機時區

Oracle Grid Infrastructure 的時區決定資料庫日誌檔的時區。

請執行下列步驟,更新使用 Grid Infrastructure 進行儲存管理之資料庫系統主機的時區資訊。

備註:

  1. 以 grid 使用者身分登入主機。

    範例:

    [opc@rc ~]$ sudo su - grid
  2. 使用下列指令識別要設定的正確時區 (TZ) 值。例如,若要識別美國太平洋時區 (PST/PDT) 的正確 TZ 值,您可以使用 tzselect 命令並選擇 Americas/United States/Pacific。

    tzselect

    範例:

    [grid@rc ~]$ 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.
    #? 2
    Please select a country.
     1) Anguilla              19) Dominican Republic    37) Peru
     2) Antigua & Barbuda     20) Ecuador               38) Puerto Rico
     3) Argentina             21) El Salvador           39) St Barthelemy
     4) Aruba                 22) French Guiana         40) St Kitts & Nevis
     5) Bahamas               23) Greenland             41) St Lucia
     6) Barbados              24) Grenada               42) St Maarten (Dutch)
     7) Belize                25) Guadeloupe            43) St Martin (French)
     8) Bolivia               26) Guatemala             44) St Pierre & Miquelon
     9) Brazil                27) Guyana                45) St Vincent
    10) Canada                28) Haiti                 46) Suriname
    11) Caribbean NL          29) Honduras              47) Trinidad & Tobago
    12) Cayman Islands        30) Jamaica               48) Turks & Caicos Is
    13) Chile                 31) Martinique            49) United States
    14) Colombia              32) Mexico                50) Uruguay
    15) Costa Rica            33) Montserrat            51) Venezuela
    16) Cuba                  34) Nicaragua             52) Virgin Islands (UK)
    17) Curaçao               35) Panama                53) Virgin Islands (US)
    18) Dominica              36) Paraguay
    #? 49
    Please select one of the following time zone regions.
     1) Eastern (most areas)              16) Central - ND (Morton rural)
     2) Eastern - MI (most areas)         17) Central - ND (Mercer)
     3) Eastern - KY (Louisville area)    18) Mountain (most areas)
     4) Eastern - KY (Wayne)              19) Mountain - ID (south); OR (east)
     5) Eastern - IN (most areas)         20) MST - Arizona (except Navajo)
     6) Eastern - IN (Da, Du, K, Mn)      21) Pacific
     7) Eastern - IN (Pulaski)            22) Alaska (most areas)
     8) Eastern - IN (Crawford)           23) Alaska - Juneau area
     9) Eastern - IN (Pike)               24) Alaska - Sitka area
    10) Eastern - IN (Switzerland)        25) Alaska - Annette Island
    11) Central (most areas)              26) Alaska - Yakutat
    12) Central - IN (Perry)              27) Alaska (west)
    13) Central - IN (Starke)             28) Aleutian Islands
    14) Central - MI (Wisconsin border)   29) Hawaii
    15) Central - ND (Oliver)
    #? 21
    The following information has been given:
            United States
            Pacific
    Therefore TZ='America/Los_Angeles' will be used.
        Local time is now:    Thu Mar 16 01:08:57 PDT 2023.
    Universal Time is now:    Thu Mar 16 08:08:57 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='America/Los_Angeles'; 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:
            America/Los_Angeles
    [grid@rc ~]$

    在 tzselect 命令中,我們已將 PDT 時區的 TZ 值識別為 America/Los_Angeles。

  3. 執行下列命令以取得主機名稱。

    hostname

    範例:

    [grid@rc ~]$ hostname
    rc
  4. 執行下列命令以取得資料庫名稱。

    srvctl config database -v

    範例:

    [grid@rc ~]$ srvctl config database -v
    SMDB0316_iad1cx    /u01/app/oracle/product/21.0.0.0/dbhome_1    21.0.0.0.0
  5. 以 Grid 使用者身分登出,並以 root 使用者身分登入。

    範例:

    [grid@rc ~]$ exit
    logout
    [opc@rc ~]$ sudo su -
  6. 瀏覽至下列目錄。

    cd $GRID_HOME/crs/install

    範例:

    [root@rc ~]# cd /u01/app/21.0.0.0/grid/crs/install/
  7. 編輯下列檔案的 TZ 內容。在編輯檔案後儲存並關閉檔案。

    vim s_crsconfig_<hostname>_env.txt

    範例:

    [root@rc install]# vim s_crsconfig_rc_env.txt
  8. 驗證檔案中的 TZ 項目是否已更新。

    cat s_crsconfig_<hostname>_env.txt

    範例:

    [root@rc install]# cat s_crsconfig_rc_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=America/Los_Angeles
    NLS_LANG=AMERICAN_AMERICA.AL32UTF8
    CRS_LIMIT_STACK=2048
    CRS_LIMIT_OPENFILE=65536
    CRS_LIMIT_NPROC=65536
    TNS_ADMIN=
    [root@rc install]#
  9. 使用下列指令設定新時區。

    timedatectl set-timezone <new_time_zone>

    範例:

    [root@rc install]# timedatectl set-timezone America/Los_Angeles

    備註:

    • 應該在 RAC 叢集中的所有節點上執行步驟 1 到 9。
    • 步驟 10 至 15 可在 RAC 叢集中的任何節點上執行。
  10. 瀏覽至下列目錄。

    cd $GRID_HOME/bin

    範例:

    [root@rc install]# cd /u01/app/21.0.0.0/grid/bin/
  11. 使用下列命令,將資料庫層次的 TZ 值變更為想要的時區。

    srvctl setenv database -d <database_name> -t "TZ=<new_time_zone>"

    範例:

    [root@rc bin]# ./srvctl setenv database -d SMDB0316_iad1cx -t "TZ=America/Los_Angeles"
  12. 使用下列命令驗證 TZ 值集。

    srvctl getenv database -d <database_name>

    範例:

    [root@rc bin]# ./srvctl getenv database -d SMDB0316_iad1cx
    SMDB0316_iad1cx:
    TZ=America/Los_Angeles
  13. 停止所有運算節點上的 CRS 堆疊。

    crsctl stop cluster

    範例:

    [root@rc bin]# ./crsctl stop cluster
    CRS-2673: Attempting to stop 'ora.crsd' on 'rc'
    .
    .
    .
    CRS-2673: Attempting to stop 'ora.cssd' on 'rc'
    CRS-2677: Stop of 'ora.cssd' on 'rc' succeeded
    [root@rc bin]#
  14. 在所有運算節點上啟動 CRS 堆疊。

    crsctl start cluster

    範例:

    [root@rc bin]# ./crsctl start cluster
    CRS-2672: Attempting to start 'ora.cssdmonitor' on 'rc'
    .
    .
    .
    CRS-2672: Attempting to start 'ora.crsd' on 'rc'
    CRS-2676: Start of 'ora.crsd' on 'rc' succeeded
    [root@rcbin]#
  15. 使用下列命令驗證時區是否已更新。

    timedatectl

    範例:

    [root@rc bin]# timedatectl
             Local time: Thu 2023-03-16 01:19:15 PDT
         Universal time: Thu 2023-03-16 08:19:15 UTC
               RTC time: Thu 2023-03-16 08:19:10
              Time zone: America/Los_Angeles (PDT, -0700)
            NTP enabled: yes
       NTP synchronized: no
        RTC in local TZ: no
             DST active: yes
        Last DST change: DST began at
                         Sun 2023-03-12 01:59:59 PST
                         Sun 2023-03-12 03:00:00 PDT
        Next DST change: DST ends (the clock jumps one hour backwards) at
                         Sun 2023-11-05 01:59:59 PDT
                         Sun 2023-11-05 01:00:00 PST

    請注意,系統現在處於 America/Los_Angeles (PDT) 時區。