在上一篇博客中,我在oracle 数据库一体机(打了最新的19.14补丁)中使用oracle 21c安装了2个数据库。现在,让我们继续演示如何在这两台服务器之间配置date guard。
一种可供选择的方式是在比如非oda环境中那样手动创建date guard。我展示的第二种方式,通过使用odacli命令配置date guard。
oracle文档中描述了所有步骤
第一步是创建备份配置。/u01/backup可以设置为nfs共享,也可以不是。在本文示例中,它只是我在每个服务器中创建的一个本地目录。
[root@mdidbi42 u01]# odacli create-backupconfig -n nfsbkup -w 10 -d nfs -c /u01/backup/
{
"jobid" : "b051745b-702a-48ff-92c2-3c80a16e73f2",
"status" : "created",
"message" : "backup config creation",
"reports" : [ ],
"createtimestamp" : "april 29, 2022 09:28:37 am cest",
"resourcelist" : [ {
"resourceid" : "8da9a983-6afa-45b9-bd66-a66d1420e048",
"resourcetype" : null,
"resourcenewtype" : "backupconfig",
"jobid" : "b051745b-702a-48ff-92c2-3c80a16e73f2",
"updatedtime" : null
} ],
"description" : "create backup config:nfsbkup",
"updatedtime" : "april 29, 2022 09:28:37 am cest"
}
[root@mdidbi42 u01]#
检查任务状态
[root@mdidbi42 u01]# odacli describe-job -i "b051745b-702a-48ff-92c2-3c80a16e73f2"
job details
----------------------------------------------------------------
id: b051745b-702a-48ff-92c2-3c80a16e73f2
description: create backup config:nfsbkup
status: success
created: april 29, 2022 9:28:37 am cest
message: backup config creation
task name start time end time status
---------------------------------------- ----------------------------------- ----------------------------------- ----------
backup config metadata persist april 29, 2022 9:28:37 am cest april 29, 2022 9:28:37 am cest success
[root@mdidbi42 u01]#
然后,我们需要将备份相关配置与数据库进行关联
[root@mdidbi42 orabackups]# odacli modify-database -in mdidb1 -bin nfsbkup
{
"jobid" : "1220f80f-098e-4a3f-98db-e83f00a260a4",
"status" : "created",
"message" : "modify database",
"reports" : [ ],
"createtimestamp" : "april 29, 2022 09:30:03 am cest",
"resourcelist" : [ {
"resourceid" : "f964b35e-7209-4d2d-9fca-5387c61c2148",
"resourcetype" : "db",
"resourcenewtype" : null,
"jobid" : "1220f80f-098e-4a3f-98db-e83f00a260a4",
"updatedtime" : "april 29, 2022 09:30:03 am cest"
} ],
"description" : "modify database : mdidb1",
"updatedtime" : "april 29, 2022 09:30:03 am cest"
}
[root@mdidbi42 orabackups]#
查看job详细信息
[root@mdidbi42 orabackups]# odacli describe-job -i "1220f80f-098e-4a3f-98db-e83f00a260a4"
job details
----------------------------------------------------------------
id: 1220f80f-098e-4a3f-98db-e83f00a260a4
description: modify database : mdidb1
status: success
created: april 29, 2022 9:30:03 am cest
message: modify database
task name start time end time status
---------------------------------------- ----------------------------------- ----------------------------------- ----------
validate omf parameter values april 29, 2022 9:30:09 am cest april 29, 2022 9:30:11 am cest success
update db with backupconfig attributes april 29, 2022 9:30:28 am cest april 29, 2022 9:30:31 am cest success
enable database autobackup april 29, 2022 9:30:31 am cest april 29, 2022 9:30:31 am cest success
enable archivelog autobackup april 29, 2022 9:30:31 am cest april 29, 2022 9:30:31 am cest success
configure control file auto backup format april 29, 2022 9:30:31 am cest april 29, 2022 9:30:35 am cest success
backup current control file april 29, 2022 9:30:35 am cest april 29, 2022 9:30:49 am cest success
update metadata for database:mdidb1 april 29, 2022 9:30:50 am cest april 29, 2022 9:30:50 am cest success
[root@mdidbi42 orabackups]#
现在,是时候对你的主库进行备份了。
[root@mdidbi42 orabackups]# odacli create-backup --backuptype regular-l0 -in mdidb1
{
"jobid" : "be3e4d32-12f7-4b6e-8fc2-0d1d3f7d982e",
"status" : "created",
"message" : null,
"reports" : [ ],
"createtimestamp" : "april 29, 2022 09:31:51 am cest",
"resourcelist" : [ ],
"description" : "create regular-l0 backup[tag:auto][db:mdidb1][nfs:/u01/backup/orabackups/dbs0fab9fed3/database/3671723533/mdidb1_42]",
"updatedtime" : "april 29, 2022 09:31:51 am cest"
}
[root@mdidbi42 orabackups]#
[root@mdidbi42 orabackups]# odacli describe-job -i "be3e4d32-12f7-4b6e-8fc2-0d1d3f7d982e"
job details
----------------------------------------------------------------
id: be3e4d32-12f7-4b6e-8fc2-0d1d3f7d982e
description: create regular-l0 backup[tag:auto][db:mdidb1][nfs:/u01/backup/orabackups/dbs0fab9fed3/database/3671723533/mdidb1_42]
status: success
created: april 29, 2022 9:31:51 am cest
message:
task name start time end time status
---------------------------------------- ----------------------------------- ----------------------------------- ----------
validate backup config april 29, 2022 9:31:55 am cest april 29, 2022 9:31:55 am cest success
nfs location existence validation april 29, 2022 9:31:55 am cest april 29, 2022 9:31:55 am cest success
backup validations april 29, 2022 9:31:55 am cest april 29, 2022 9:32:02 am cest success
recovery window validation april 29, 2022 9:32:02 am cest april 29, 2022 9:32:04 am cest success
archivelog deletion policy configuration april 29, 2022 9:32:04 am cest april 29, 2022 9:32:07 am cest success
database backup april 29, 2022 9:32:07 am cest april 29, 2022 9:33:32 am cest success
[root@mdidbi42 orabackups]#
当备份结束后,在json文件中保存备份相关报告。首先,查看备份的id
[root@mdidbi42 ~]# odacli list-backupreports | grep regular-l0
ce3b0eb9-3976-45f2-829e-c39cc5d21e43 e5fbd9e1-ccb6-4d3e-88cb-ece45007a549 3671906653 mdidb1 mdidb1_42 regular-l0 auto april 29, 2022 3:16:36 pm cest april 29, 2022 3:16:36 pm cest configured
[root@mdidbi42 ~]
然后,将其保存
[root@mdidbi42 ~]# odacli describe-backupreport -i ce3b0eb9-3976-45f2-829e-c39cc5d21e43 > backup_report_mdidb1.json
[root@mdidbi42 ~]#
下面是json文件的内容
[root@mdidbi42 ~]# cat backup_report_mdidb1.json
{
"id" : "ce3b0eb9-3976-45f2-829e-c39cc5d21e43",
"dbresid" : "e5fbd9e1-ccb6-4d3e-88cb-ece45007a549",
"tag" : "auto",
"dbid" : "3671906653",
"dbname" : "mdidb1",
"dbuniquename" : "mdidb1_42",
"backuptype" : "regular-l0",
"keepdays" : null,
"backuplocation" : "/u01/backup/orabackups/dbs0fab9fed3/database/3671906653/mdidb1_42/db",
"cfbackuphandle" : "/u01/backup/orabackups/dbs0fab9fed3/database/3671906653/mdidb1_42/db/c-3671906653-20220429-05",
"spfbackuphandle" : "/u01/backup/orabackups/dbs0fab9fed3/database/3671906653/mdidb1_42/db/c-3671906653-20220429-05",
"pitrtimestamp" : "april 29, 2022 15:17:33 pm cest",
"pitrscn" : "1842740",
"resetlogstimestamp" : "april 29, 2022 14:05:17 pm cest",
"resetlogsscn" : "1712336",
"orahomeversion" : "21.5.0.0.220118",
"sqlpatches" : null,
"backuplogloc" : "/u01/backup/orabackups/dbs0fab9fed3/database/3671906653/mdidb1_42/rmanlog/2022-04-29/rman_backup_auto_2022-04-29_15-16-40.0579.log",
"tdewalletloc" : null,
"dbconfigloc" : "/u01/backup/orabackups/dbs0fab9fed3/database/3671906653/mdidb1_42/dbconfig/2022-04-29/dbconfig_auto_2022-04-29_15-17-50.0845.tar.gz",
"name" : "backup_report_mdidb1",
"createtime" : "april 29, 2022 15:16:36 pm cest",
"state" : {
"status" : "configured"
},
"updatedtime" : "april 29, 2022 15:16:36 pm cest",
"backupreportlogdetail" : "/u01/backup/orabackups/dbs0fab9fed3/database/3671906653/mdidb1_42/rmandetaillogreport/2022-04-29/rman_list_backup_detail_auto_2022-04-29_15-17-44.0692.log",
"dbinfo" : {
"dbclass" : "oltp",
"dbtype" : "si",
"dbshape" : "odb2",
"dbedition" : "ee",
"dbstorage" : "asm",
"dbredundancy" : null,
"pdbname" : "pdb1",
"iscdb" : true
},
"dbdatasize" : "4202m",
"dbredosize" : "12306m",
"rmanbackuppieces" : "/u01/backup/orabackups/dbs0fab9fed3/database/3671906653/mdidb1_42/backuppieces/2022-04-29/backuppieces_auto_e5fbd9e1-ccb6-4d3e-88cb-ece45007a549_20220429151749.json",
"compressionalgo" : "basic",
"cpupool" : null,
"numberofcores" : null
}
[root@mdidbi42 ~]#
现在,将备份复制到备用数据库系统中的同一文件位置,同时将备份报告复制到备用系统,并将备份恢复到备用数据库。不要忘记将备份文件的访问权限授予oracle用户
[root@mdidbi42 backup]# pwd
/u01/backup
[root@mdidbi42 backup]# scp -r orabackups/ mdidbi43:$pwd
fips mode initialized
root@mdidbi43's password:
scp -r backup_report_mdidb1.json mdidbi43:$pwd
现在是在备用服务器上恢复备份的时候了。就我个人而言,我已经删除了在备用服务器上创建db系统时附带的现有数据库
[root@mdidbi43 ~]# odacli irestore-database -r backup_report_mdidb1.json -u mdidb2_43 -ro standby -dh b3da570b-acd1-41fa-8c8c-1c16fd66 abb3
enter sys user password:
retype sys user password:
{
"jobid" : "aa280ddf-f215-452a-833c-4912d68aa2e5",
"status" : "created",
"message" : null,
"reports" : [ ],
"createtimestamp" : "april 29, 2022 15:26:56",
"resourcelist" : [ ],
"description" : "database service recovery with db name: mdidb1",
"updatedtime" : "april 29, 2022 15:26:56"
}
[root@mdidbi43 ~]# odacli describe-job -i "aa280ddf-f215-452a-833c-4912d68aa2e5"
job details
----------------------------------------------------------------
id: aa280ddf-f215-452a-833c-4912d68aa2e5
description: database service recovery with db name: mdidb1
status: success
created: april 29, 2022 3:26:56 pm cest
message:
task name start time end time status
---------------------------------------- ----------------------------------- ----------------------------------- ----------
check if cluster ware is running april 29, 2022 3:26:58 pm cest april 29, 2022 3:26:58 pm cest success
creating dbstorage for dbrestore april 29, 2022 3:26:58 pm cest april 29, 2022 3:27:00 pm cest success
validating diskspace for data april 29, 2022 3:26:58 pm cest april 29, 2022 3:26:59 pm cest success
generating ssh key april 29, 2022 3:26:59 pm cest april 29, 2022 3:27:00 pm cest success
ssh key april 29, 2022 3:27:00 pm cest april 29, 2022 3:27:00 pm cest success
ssh key scan april 29, 2022 3:27:00 pm cest april 29, 2022 3:27:00 pm cest success
audit directory creation april 29, 2022 3:27:00 pm cest april 29, 2022 3:27:00 pm cest success
create pfile for auxiliary instance april 29, 2022 3:27:01 pm cest april 29, 2022 3:27:01 pm cest success
deleting fra april 29, 2022 3:27:01 pm cest april 29, 2022 3:27:02 pm cest success
rman duplicate april 29, 2022 3:27:02 pm cest april 29, 2022 3:29:10 pm cest success
creating pfile from spfile april 29, 2022 3:29:11 pm cest april 29, 2022 3:29:11 pm cest success
set pfile ownership april 29, 2022 3:29:11 pm cest april 29, 2022 3:29:11 pm cest success
customize db parameters april 29, 2022 3:29:11 pm cest april 29, 2022 3:29:12 pm cest success
shutdown and start database april 29, 2022 3:29:12 pm cest april 29, 2022 3:29:33 pm cest success
create spfile for restore db april 29, 2022 3:29:33 pm cest april 29, 2022 3:29:33 pm cest success
set pfile ownership april 29, 2022 3:29:33 pm cest april 29, 2022 3:29:33 pm cest success
shutdown and mount database april 29, 2022 3:29:33 pm cest april 29, 2022 3:29:51 pm cest success
register database taskflow april 29, 2022 3:29:55 pm cest april 29, 2022 3:31:33 pm cest success
create spfile in shared loc april 29, 2022 3:29:55 pm cest april 29, 2022 3:30:03 pm cest success
delete local spfile april 29, 2022 3:30:03 pm cest april 29, 2022 3:30:03 pm cest success
register db with clusterware april 29, 2022 3:30:03 pm cest april 29, 2022 3:30:31 pm cest success
set syspassword and create pwfile april 29, 2022 3:30:31 pm cest april 29, 2022 3:30:33 pm cest success
enable block change tracking april 29, 2022 3:30:33 pm cest april 29, 2022 3:30:37 pm cest success
creating pfile april 29, 2022 3:30:37 pm cest april 29, 2022 3:30:38 pm cest success
updating db env april 29, 2022 3:30:38 pm cest april 29, 2022 3:30:39 pm cest success
enable dbsizing template april 29, 2022 3:30:39 pm cest april 29, 2022 3:31:06 pm cest success
create tns entry april 29, 2022 3:31:06 pm cest april 29, 2022 3:31:07 pm cest success
running datapatch april 29, 2022 3:31:07 pm cest april 29, 2022 3:31:08 pm cest success
set cpu pool april 29, 2022 3:31:08 pm cest april 29, 2022 3:31:08 pm cest success
reset associated networks april 29, 2022 3:31:34 pm cest april 29, 2022 3:31:38 pm cest success
set log_archive_dest for database april 29, 2022 3:31:38 pm cest april 29, 2022 3:31:43 pm cest success
copy pwfile to shared storage april 29, 2022 3:31:43 pm cest april 29, 2022 3:31:49 pm cest success
[root@mdidbi43 ~]#
备份恢复到备用数据库后,我们可以连接到备用数据库,并可以看到它处于装载状态
[oracle@mdidbi43 ~]$ . oraenv
oracle_sid = [mdidb1] ?
the oracle base remains unchanged with value /u01/app/oracle
[oracle@mdidbi43 ~]$ sqlplus / as sysdba
sql*plus: release 21.0.0.0.0 - production on fri apr 29 10:01:23 2022
version 21.5.0.0.0
米乐app官网下载 copyright (c) 1982, 2021, oracle. all rights reserved.
connected to:
oracle database 21c enterprise edition release 21.0.0.0.0 - production
version 21.5.0.0.0
sql> select db_unique_name ,open_mode from v$database;
db_unique_name open_mode
------------------------------ --------------------
mdidb2_43 mounted
好了,现在我们可以通过从主服务器运行configure dataguard命令来配置data guard。
你会遇到一些问题需要解决。
[root@mdidbi42 ~]# odacli configure-dataguard
standby site address: mdidbi43
bui username for standby site. if multi-user access is disabled on standby site, enter 'oda-admin'; otherwise, enter the name of the use who has irestored the standby database (default: oda-admin):
bui password for standby site:
root@mdidbi43's password:
database name for data guard configuration: mdidb1
primary database sys password:
*******************************************************************************************
data guard default settings
primary site network for data guard configuration: public-network
standby site network for data guard configuration: public-network
primary database listener port: 1521
standby database listener port: 1521
transport type: async
protection mode: max_performance
data guard configuration name: mdidb1_42_mdidb2_43
active data guard: disabled
do you want to edit this data guard configuration? (y/n, default:n): y
*******************************************************************************************
primary site network for data guard configuration [public-network] (default: public-network):
standby site network for data guard configuration [public-network] (default: public-network):
primary database listener port (default: 1521):
standby database listener port (default: 1521):
transport type [async, fastsync, sync] (default: async):
protection mode [max_protection, max_performance, max_availability] (default: max_performance):
data guard configuration name (default: mdidb1_42_mdidb2_43):
primary database is missing certain archivelogs for data guard configuration. we need to restore those from backup.
enter rman backup encryption password:
do you want to provide another rman backup encryption password? [y/n] (default 'n'): n
enable active data guard? (y/n, default:n):
standby database's sys password will be set to primary database's after data guard configuration. ignore warning and proceed with data gard configuration? (y/n, default:n): y
*******************************************************************************************
configure data guard mdidb1_42_mdidb2_43 started
*******************************************************************************************
step 1: validate data guard configuration request (primary site)
description: validate dg config creation for db mdidb1
job id: eb1c048d-4a26-44f6-972d-d0923b43a30c
started april 29, 2022 15:36:13 pm cest
validate create data guard configuration request
finished april 29, 2022 15:36:17 pm cest
*******************************************************************************************
step 2: validate data guard configuration request (standby site)
description: validate dg config creation for db mdidb1
job id: 81d48002-8478-4c4b-a49c-89f7babe8764
started april 29, 2022 15:36:18 pm cest
validate create data guard configuration request
finished april 29, 2022 15:36:23 pm cest
*******************************************************************************************
step 3: restore missing archivelog (primary site)
description: create archivelog restore for db:mdidb1
job id: ca35287b-e306-4372-a1ad-84ed61185b55
started april 29, 2022 15:36:24 pm cest
restore archivelog validation
restore archivelog
finished april 29, 2022 15:36:43 pm cest
*******************************************************************************************
step 4: download password file from primary database (primary site)
description: download orapwd file from primary database
started april 29, 2022 15:36:43 pm cest
prepare orapwd file for primary database mdidb1
finished april 29, 2022 15:36:45 pm cest
*******************************************************************************************
step 5: upload password file to standby database (standby site)
description: upload orapwd file to standby database
started april 29, 2022 15:36:45 pm cest
write orapwd file to standby database mdidb1
finished april 29, 2022 15:36:58 pm cest
*******************************************************************************************
step 6: configure primary database (primary site)
description: dg config service for db mdidb1 - configureprimary
job id: 55c4622f-3190-4ac6-9344-9e551075bc21
started april 29, 2022 15:36:59 pm cest
configure host dns on primary env
configure data guard tns on primary env
enable data guard related db parameters for primary env
enable force logging and archivelog mode in primary env
enable flashback
configure network parameters for local listener on primary env
restart listener on primary env
create services for primary db
finished april 29, 2022 15:37:26 pm cest
*******************************************************************************************
step 7: configure standby database (standby site)
description: dg config service for db mdidb1 - configurestandby
job id: 642866cc-c2e3-49fd-99af-7017bcf23ae2
started april 29, 2022 15:37:27 pm cest
configure data guard tns on standby env
configure host dns on standby env
clear data guard related db parameters for standby env
enable data guard related db parameters for standby env
enable force logging and archivelog mode in standby env
populate standby database metadata
configure network parameters for local listener on standby env
reset db sizing and hidden parameters for oda best practice
restart listener on standby env
create services for standby db
finished april 29, 2022 15:38:39 pm cest
*******************************************************************************************
step 8: configure and enable data guard (primary site)
description: dg config service for db mdidb1 - configuredg
job id: e6882484-c946-4b4e-b51e-ddca8886449d
started april 29, 2022 15:38:40 pm cest
config and enable data guard
post check data guard configuration
finished april 29, 2022 15:40:22 pm cest
*******************************************************************************************
step 9: enable flashback (standby site)
description: dg config service for db mdidb1 - enableflashback
job id: e9e0d091-7bc2-4185-901d-7914168f32bb
started april 29, 2022 15:40:23 pm cest
enable flashback
finished april 29, 2022 15:40:36 pm cest
*******************************************************************************************
step 10: re-enable data guard (primary site)
description: dg config service for db mdidb1 - reenabledg
job id: d83d2779-f7fd-4d90-b5eb-58fda4792f15
started april 29, 2022 15:40:37 pm cest
re-enable data guard if inconsistent properties found
post check data guard configuration
finished april 29, 2022 15:40:39 pm cest
*******************************************************************************************
step 11: create data guard status (primary site)
description: dg status operation for db mdidb1 - newdgconfig
job id: cb590d03-3795-4dfe-b374-69212f8aecd8
started april 29, 2022 15:40:40 pm cest
create data guard status
finished april 29, 2022 15:40:42 pm cest
*******************************************************************************************
step 12: create data guard status (standby site)
description: dg status operation for db mdidb1 - newdgconfig
job id: ba68bda7-f705-4a6e-9e96-d37d042603f0
started april 29, 2022 15:40:43 pm cest
create data guard status
finished april 29, 2022 15:40:44 pm cest
*******************************************************************************************
configure data guard mdidb1_42_mdidb2_43 completed
*******************************************************************************************
[root@mdidbi42 ~]#
成功完成配置后,我们可以列出date guard的状态
[root@mdidbi42 ~]# odacli list-dataguardstatus
updated about 4 minute(s) ago
id name database name role protection mode apply lag transport lag apply rate status
---------------------------------------- -------------------------------- -------------------- ---------- ------------------ --------------- --------------- --------------- ----------
b297b32d-987e-407d-9422-6d3748481907 mdidb1_42_mdidb2_43 mdidb1 primary max_performance 18 seconds 0 seconds 19.00 kbyte/s configured
[root@mdidbi42 ~]#
[root@mdidbi42 ~]# odacli describe-dataguardstatus -i b297b32d-987e-407d-9422-6d3748481907
updated about 4 minute(s) ago
dataguard status details
----------------------------------------------------------------
id: b297b32d-987e-407d-9422-6d3748481907
name: mdidb1_42_mdidb2_43
database name: e5fbd9e1-ccb6-4d3e-88cb-ece45007a549
role: primary
protection mode: max_performance
apply lag: 0 seconds
transport lag: 0 seconds
apply rate: 1.00 kbyte/s
status: configured
updated time: april 29, 2022 3:45:05 pm cest
[root@mdidbi42 ~]#
我们还可以通过dgmgrl命令连接并验证(请注意:当前mdidb1_42是主库,mdidb2_43是备库)
dgmgrl> show configuration
configuration - mdidb1_42_mdidb2_43
protection mode: maxperformance
members:
mdidb1_42 - primary database
mdidb2_43 - physical standby database
fast-start failover: disabled
configuration status:
success (status updated 58 seconds ago)
dgmgrl>
在主库服务器上通过运行以下命令进行主备库切换操作
[root@mdidbi42 ~]# odacli switchover-dataguard -i b297b32d-987e-407d-9422-6d3748481907 -u mdidb2_43
password for target database:
{
"jobid" : "758d015e-c208-4313-b989-5ffb4fd9fa7c",
"status" : "created",
"message" : null,
"reports" : [ ],
"createtimestamp" : "april 29, 2022 15:59:47 pm cest",
"resourcelist" : [ ],
"description" : "dataguard operation for mdidb1_42_mdidb2_43 - switchoverdg",
"updatedtime" : "april 29, 2022 15:59:47 pm cest"
}
[root@mdidbi42 ~]#
[root@mdidbi42 ~]# odacli describe-job -i "758d015e-c208-4313-b989-5ffb4fd9fa7c"
job details
----------------------------------------------------------------
id: 758d015e-c208-4313-b989-5ffb4fd9fa7c
description: dataguard operation for mdidb1_42_mdidb2_43 - switchoverdg
status: success
created: april 29, 2022 3:59:47 pm cest
message:
task name start time end time status
---------------------------------------- ----------------------------------- ----------------------------------- ----------
precheck switchover dataguard april 29, 2022 3:59:47 pm cest april 29, 2022 3:59:58 pm cest success
switchover dataguard april 29, 2022 3:59:58 pm cest april 29, 2022 4:01:07 pm cest success
postcheck switchover dataguard april 29, 2022 4:01:07 pm cest april 29, 2022 4:01:08 pm cest success
check if dataguard config is updated april 29, 2022 4:01:09 pm cest april 29, 2022 4:01:19 pm cest success
[root@mdidbi42 ~]#
我们可以连接到dg broker时验证切换结果(请注意:当前mdidb1_43是主库,mdidb2_42是备库,主备已经成功切换)
dgmgrl> show configuration
configuration - mdidb1_42_mdidb2_43
protection mode: maxperformance
members:
mdidb2_43 - primary database
mdidb1_42 - physical standby database
fast-start failover: disabled
configuration status:
success (status updated 19 seconds ago)
dgmgrl>
要重新切换回mdidb1_42作为主库,只需在当前为主库的服务器(mdidb1_43)上运行switchover命令
[root@mdidbi43 ~]# odacli switchover-dataguard -i b297b32d-987e-407d-9422-6d3748481907 -u mdidb1_42
password for target database:
{
"jobid" : "17eef433-7e8e-4d4d-95e3-defe8724cb99",
"status" : "created",
"message" : null,
"reports" : [ ],
"createtimestamp" : "april 29, 2022 16:05:49 pm cest",
"resourcelist" : [ ],
"description" : "dataguard operation for mdidb1_42_mdidb2_43 - switchoverdg",
"updatedtime" : "april 29, 2022 16:05:49 pm cest"
}
[root@mdidbi43 ~]#
在切换回来后,主备库情况如下:
dgmgrl> show configuration
configuration - mdidb1_42_mdidb2_43
protection mode: maxperformance
members:
mdidb1_42 - primary database
mdidb2_43 - physical standby database
fast-start failover: disabled
configuration status:
success (status updated 70 seconds ago)
dgmgrl>
我们同样可以通过在备库服务器上运行以下命令进行故障转移:
[root@mdidbi42 ~]# odacli failover-dataguard -i 96e5c5cf-f710-4a14-a506-9024e4952ba4 -u mdidb2_43
password for target database:
dcs-10001:internal error encountered: invalid role for failoverdg:primary. execute this command on the standby site mdidbi43.dbi-lab.ch.
[root@mdidbi42 ~]#
检查任务状态
[root@mdidbi43 ~]# odacli describe-job -i "7c0dd208-1fca-4c03-99e1-7d896f79c1b5"
job details
----------------------------------------------------------------
id: 7c0dd208-1fca-4c03-99e1-7d896f79c1b5
description: dataguard operation for mdidb1_42_mdidb2_43 - failoverdg
status: success
created: april 29, 2022 4:11:09 pm cest
message:
task name start time end time status
---------------------------------------- ----------------------------------- ----------------------------------- ----------
precheck failover dataguard april 29, 2022 4:11:09 pm cest april 29, 2022 4:11:12 pm cest success
failover dataguard april 29, 2022 4:11:12 pm cest april 29, 2022 4:11:33 pm cest success
postcheck dataguard status april 29, 2022 4:11:33 pm cest april 29, 2022 4:11:37 pm cest success
check if dataguard config is updated april 29, 2022 4:11:37 pm cest april 29, 2022 4:11:47 pm cest success
[root@mdidbi43 ~]#
在mdidbi43所在服务器上检查data guard的状态
dgmgrl> show configuration
configuration - mdidb1_42_mdidb2_43
protection mode: maxperformance
members:
mdidb2_43 - primary database
mdidb1_42 - physical standby database (disabled)
ora-16661: the standby database needs to be reinstated
fast-start failover: disabled
configuration status:
success (status updated 59 seconds ago)
dgmgrl>
在之前的主库 mdidbi42服务器上查看状态
dgmgrl> show configuration
configuration - mdidb1_42_mdidb2_43
protection mode: maxperformance
members:
mdidb1_42 - primary database
mdidb2_43 - physical standby database
fast-start failover: disabled
configuration status:
disabled
dgm-17290: role change detected. this database may no longer be the primary database.
dgmgrl>
///译者备注:在mdidbi43上执行故障转移前,mdidbi42是主库,mdidbi43是备库,现在由于故障转移,将mdidbi42作为有问题的备库下线,并且将mdidbi43提升为主库。因此,在故障转移后,mdidbi42上看的信息,主库虽然还是写的是mdidb1_42,但是他的配置状态为disabled,并提示dgm-17290: role change detected. this database may no longer be the primary database.(检测到角色更改。此数据库可能不再是主数据库),而在mdidbi43,显示的为准确的信息,mdidb2_43 为主库,并提示mdidb2_42已经是备库了,且需要被恢复后才能使用。///
让我们恢复以前的主数据库mdidb1_42。因此,连接到mdidbi43运行以下命令
[root@mdidbi43 ~]# odacli reinstate-dataguard -i b297b32d-987e-407d-9422-6d3748481907 -u mdidb1_42
password for target database:
{
"jobid" : "cfe917c4-85f6-4469-b8e0-e6c6e602c54e",
"status" : "created",
"message" : null,
"reports" : [ ],
"createtimestamp" : "april 29, 2022 16:16:56 pm cest",
"resourcelist" : [ ],
"description" : "dataguard operation for mdidb1_42_mdidb2_43 - reinstatedg",
"updatedtime" : "april 29, 2022 16:16:56 pm cest"
}
[root@mdidbi43 ~]#
[root@mdidbi43 ~]# odacli describe-job -i "cfe917c4-85f6-4469-b8e0-e6c6e602c54e"
job details
----------------------------------------------------------------
id: cfe917c4-85f6-4469-b8e0-e6c6e602c54e
description: dataguard operation for mdidb1_42_mdidb2_43 - reinstatedg
status: success
created: april 29, 2022 4:16:56 pm cest
message:
task name start time end time status
---------------------------------------- ----------------------------------- ----------------------------------- ----------
precheck reinstate dataguard april 29, 2022 4:16:56 pm cest april 29, 2022 4:16:59 pm cest success
reinstate dataguard april 29, 2022 4:16:59 pm cest april 29, 2022 4:18:13 pm cest success
postcheck dataguard status april 29, 2022 4:18:13 pm cest april 29, 2022 4:18:17 pm cest success
check if dataguard config is updated april 29, 2022 4:18:17 pm cest april 29, 2022 4:18:27 pm cest success
[root@mdidbi43 ~]#
查看最新状态:
dgmgrl> show configuration
configuration - mdidb1_42_mdidb2_43
protection mode: maxperformance
members:
mdidb2_43 - primary database
mdidb1_42 - physical standby database
fast-start failover: disabled
configuration status:
success (status updated 19 seconds ago)
dgmgrl>
原文标题:configure data guard between 2 db systems with oracle 21c
原文作者:mouhamadou diaw
原文地址:https://www.dbi-services.com/blog/configure-data-guard-between-2-db-systems-with-oracle-21c/