Oracle DG修改hostname

将dg01修改为dg001
将dg02修改为dg002
1.实验环境,dg01为Primary节点,dg02为Standby节点https://www.cndba.cn/hbhe0316/article/5042

[root@dg01 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.56.101 dg01
192.168.56.102 dg02
[root@dg01 ~]# su - oracle
Last login: Sat Nov  6 09:39:04 CST 2021 on pts/2
[oracle@dg01 ~]$ sqlplus -V

SQL*Plus: Release 19.0.0.0.0 - Production
Version 19.12.0.0.0

2.Primary节点和Standby节点停止数据库
主库:

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

备库:

https://www.cndba.cn/hbhe0316/article/5042
https://www.cndba.cn/hbhe0316/article/5042
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;

Database altered.

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

3.Primary节点和Standby节点停止监听
主库

https://www.cndba.cn/hbhe0316/article/5042
[oracle@dg01 ~]$ lsnrctl stop

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 06-NOV-2021 10:08:24

Copyright (c) 1991, 2021, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dg01)(PORT=1521)))
The command completed successfully

备库

[oracle@dg02 ~]$ lsnrctl stop

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 06-NOV-2021 10:08:50

Copyright (c) 1991, 2021, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dg02)(PORT=1521)))
The command completed successfully

4.修改主库和备库hostname
主库

[root@dg01 ~]# hostnamectl set-hostname dg001

备库

[root@dg02 ~]# hostnamectl set-hostname dg002

5.重新打开连接终端,并修改/etc/hosts文件
主库:

[root@dg001 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.56.111 dg001
192.168.56.112 dg002

备库:

https://www.cndba.cn/hbhe0316/article/5042
[root@dg002 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.56.111 dg001
192.168.56.112 dg002

6.修改tnsnams.ora文件
主库:

[oracle@dg001 ~]$ cd $ORACLE_HOME/network/admin
[oracle@dg001 admin]$ cat tnsnames.ora 
LISTENER_ORCL =
  (ADDRESS = (PROTOCOL = TCP)(HOST = dg001)(PORT = 1521))


ORCL_P =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = dg001)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl)
    )
  )

ORCL_S =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = dg002)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl)
    )
  )

备库:

[oracle@dg002 ~]$ cd $ORACLE_HOME/network/admin
[oracle@dg002 admin]$ cat tnsnames.ora 
ORCL_P =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = dg001)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl)
    )
  )

ORCL_S =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = dg002)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl)
    )
  )

7.修改listener.ora文件
主库:

https://www.cndba.cn/hbhe0316/article/5042
[oracle@dg001 admin]$ cat listener.ora 
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = orcl)
      (ORACLE_HOME = /u01/app/oracle/product/19.3.0/dbhome_1)
      (SID_NAME = orcl)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = dg001)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

ADR_BASE_LISTENER = /u01/app/oracle

备库:

[oracle@dg002 admin]$ cat listener.ora 
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = orcl)
      (ORACLE_HOME = /u01/app/oracle/product/19.3.0/dbhome_1)
      (SID_NAME = orcl)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = dg002)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

ADR_BASE_LISTENER = /u01/app/oracle

8.启动主库和备库监听
主库:

https://www.cndba.cn/hbhe0316/article/5042
[oracle@dg001 admin]$ lsnrctl start

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 06-NOV-2021 11:15:59

Copyright (c) 1991, 2021, Oracle.  All rights reserved.

Starting /u01/app/oracle/product/19.3.0/dbhome_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 19.0.0.0.0 - Production
System parameter file is /u01/app/oracle/product/19.3.0/dbhome_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/dg001/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=dg001)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dg001)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date                06-NOV-2021 11:15:59
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/19.3.0/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/dg001/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=dg001)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "orcl" has 1 instance(s).
  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully

备库:https://www.cndba.cn/hbhe0316/article/5042

[oracle@dg002 admin]$ lsnrctl start

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 06-NOV-2021 11:16:27

Copyright (c) 1991, 2021, Oracle.  All rights reserved.

Starting /u01/app/oracle/product/19.3.0/dbhome_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 19.0.0.0.0 - Production
System parameter file is /u01/app/oracle/product/19.3.0/dbhome_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/dg002/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=dg002)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dg002)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date                06-NOV-2021 11:16:27
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/19.3.0/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/dg002/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=dg002)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "orcl" has 1 instance(s).
  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully

9.启动主库和备库数据库
备库:

[oracle@dg002 admin]$ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Sat Nov 6 11:17:19 2021
Version 19.12.0.0.0

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

Connected to an idle instance.

SQL> startup nomount
ORACLE instance started.

Total System Global Area 2516581448 bytes
Fixed Size                  9141320 bytes
Variable Size             654311424 bytes
Database Buffers         1845493760 bytes
Redo Buffers                7634944 bytes
SQL> alter database mount standby database;

Database altered.

SQL> alter database open read only;

Database altered.

SQL> alter database recover managed standby database using current logfile disconnect from session;

Database altered.

主库:

[oracle@dg001 admin]$ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Sat Nov 6 11:18:13 2021
Version 19.12.0.0.0

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

Connected to an idle instance.

SQL> STARTUP
ORACLE instance started.

Total System Global Area 2516581448 bytes
Fixed Size                  9141320 bytes
Variable Size            1157627904 bytes
Database Buffers         1342177280 bytes
Redo Buffers                7634944 bytes
Database mounted.
Database opened.

10.验证主备库状态
主库:https://www.cndba.cn/hbhe0316/article/5042

https://www.cndba.cn/hbhe0316/article/5042
SQL> set linesize 200
SQL> set pagesize 200
SQL> col open_mod for a30
SQL> col protection_mode for a30
SQL> col database_role for a20
SQL> col switchover_status for a20
SQL> select open_mode,protection_mode,database_role,switchover_status from v$database;

OPEN_MODE                    PROTECTION_MODE                DATABASE_ROLE        SWITCHOVER_STATUS
------------------------------------------------------------ ------------------------------ ------------
READ WRITE                  MAXIMUM PERFORMANCE            PRIMARY              TO STANDBY

备库:

SQL> set linesize 200
SQL> set pagesize 200
SQL> col open_mod for a10
SQL> col protection_mode for a20
SQL> col database_role for a20
SQL> col switchover_status for a20
SQL> select open_mode,protection_mode,database_role,switchover_status from v$database;

OPEN_MODE                           PROTECTION_MODE      DATABASE_ROLE        SWITCHOVER_STATUS
------------------------------------------ -------------------- -------------------- ------
READ ONLY WITH APPLY                MAXIMUM PERFORMANCE  PHYSICAL STANDBY     NOT ALLOWED

版权声明:本文为博主原创文章,未经博主允许不得转载。

Linux,oracle

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值