Primary:           ylesia-scan:1521/HUTTPRD
Dataguard:         rodia-scan:1521/HUTTDRP
Cascade 1:         kamino:1521/HUTTCA1
Far sync:          mandalore:1521/HUTTFAR
Remote dataguard:  taris:1521/HUTTREM

alias HUTTPRD='rlwrap sqlplus sys/"Secret00!"@ylesia-scan:1521/HUTTPRD as sysdba'
alias HUTTPRD1='rlwrap sqlplus sys/"Secret00!"@ylesia-db01-vip:1521/HUTTPRD as sysdba'
alias HUTTPRD2='rlwrap sqlplus sys/"Secret00!"@ylesia-db02-vip:1521/HUTTPRD as sysdba'
alias HUTTDRP='rlwrap sqlplus sys/"Secret00!"@rodia-scan:1521/HUTTDRP as sysdba'
alias HUTTCA1='rlwrap sqlplus sys/"Secret00!"@kamino:1521/HUTTCA1 as sysdba'
alias HUTTFAR='rlwrap sqlplus sys/"Secret00!"@mandalore:1521/HUTTFAR as sysdba'
alias HUTTREM='rlwrap sqlplus sys/"Secret00!"@taris:1521/HUTTREM as sysdba'


run
{
  allocate auxiliary channel aux01 device type disk;
  allocate auxiliary channel aux02 device type disk;
  allocate auxiliary channel aux03 device type disk;
  allocate auxiliary channel aux04 device type disk;
  duplicate database 'HUTT' for standby backup location '/mnt/yavin4/tmp/_oracle_/orabackup/_keep_/RAC/21/backupset/';
}


run
{
  allocate channel pri01 device type disk;
  allocate channel pri02 device type disk;
  allocate channel pri03 device type disk;
  allocate channel pri04 device type disk;
  recover database from service 'ylesia-scan:1521/HUTTPRD' using compressed backupset section size 1G;
}

alter database create standby controlfile as '/mnt/yavin4/tmp/00000/HUTTPRD1.stdby';
alter database create far sync instance controlfile as '/mnt/yavin4/tmp/00000/HUTTPRD1.far';

dgmgrl
DGMGRL> connect sys/"Secret00!"@ylesia-scan:1521/HUTTPRD
DGMGRL> add database HUTTCA1 as connect identifier is kamino:1521/HUTTCA1;
DGMGRL> add database HUTTREM as connect identifier is taris:1521/HUTTREM
DGMGRL> add far_sync HUTTFAR as connect identifier is mandalore:1521/HUTTFAR;

DGMGRL> show database 'huttprd' redoroutes;
DGMGRL> show database 'huttdrp' redoroutes;

# routes config ###########################################################################

# without FAR SYNC: main dataguard relies redo to cascade
DGMGRL> edit database huttprd set property redoroutes = '(local:huttdrp)(huttdrp:huttca1)';
DGMGRL> edit database huttdrp set property redoroutes = '(huttprd:huttca1)(local:huttprd)';

# FAR SYNC built but not activated: main dataguard relies redo to cascade and remote dataguard
DGMGRL> edit database huttprd set property redoroutes = '(local:huttdrp)(huttdrp:huttca1)';
DGMGRL> edit database huttdrp set property redoroutes = '(huttprd:huttca1,huttrem)(local:huttprd)';

# FAR SYNC activated: main dataguard relies redo to cascade and FAR SYNC relies redo to remote dataguard
DGMGRL> edit database huttprd set property redoroutes = '(local:huttdrp,huttfar SYNC)(huttdrp:huttca1 ASYNC)';
DGMGRL> edit database huttdrp set property redoroutes = '(huttprd:huttca1 ASYNC)(local:huttprd,huttfar SYNC)';
DGMGRL> edit far_sync huttfar set property redoroutes = '(huttprd:huttrem ASYNC)(huttdrp:huttrem ASYNC)';

# #########################################################################################


DGMGRL> edit database huttprd set property StandbyFileManagement='AUTO';
DGMGRL> edit database huttdrp set property StandbyFileManagement='AUTO';
DGMGRL> edit database huttca1 set property StandbyFileManagement='AUTO';
DGMGRL> edit database huttrem set property StandbyFileManagement='AUTO';
DGMGRL> edit far_sync huttfar set property StandbyFileManagement='AUTO';

# unless setting configuration protection to MaxAvailability, cascade standby redelog was not used and broker show warnings
# after setting to MaxAvailability, switching back to MaxPerformance does not affected the sitiation, cascade standby still use 
# standby redologs and broker status does not display warnings anymore

DGMGRL> edit configuration set protection mode as MaxAvailability;
DGMGRL> edit configuration set protection mode as MaxPerformance;


# not sure that help for 
#    ORA-16853: apply lag has exceeded specified threshold
#    ORA-16855: transport lag has exceeded specified threshold

DGMGRL> edit database huttprd set property TransportDisconnectedThreshold=0;
DGMGRL> edit database huttdrp set property TransportDisconnectedThreshold=0;
DGMGRL> edit database huttca1 set property TransportDisconnectedThreshold=0;

DGMGRL> edit database huttprd set property ApplyLagThreshold=0;
DGMGRL> edit database huttdrp set property ApplyLagThreshold=0;
DGMGRL> edit database huttca1 set property ApplyLagThreshold=0;

# othrwise, to reset:

DGMGRL> edit database huttprd reset property ApplyLagThreshold;
DGMGRL> edit database huttdrp reset property ApplyLagThreshold;
DGMGRL> edit database huttca1 reset property ApplyLagThreshold;

DGMGRL> edit database huttprd reset property TransportDisconnectedThreshold;
DGMGRL> edit database huttdrp reset property TransportDisconnectedThreshold;
DGMGRL> edit database huttca1 reset property TransportDisconnectedThreshold;


DGMGRL> enable database huttca1;
DGMGRL> edit database huttca1 set state='APPLY-OFF';
DGMGRL> edit database huttca1 set state='ONLINE';

-- create standby redologs
select 'ALTER DATABASE ADD STANDBY LOGFILE THREAD '||thread#||' size '||bytes||';' from v$log union all
select distinct 'ALTER DATABASE ADD STANDBY LOGFILE THREAD '||thread#||' size '||bytes||';' from v$log;

-- clear / drop standby redologs
select 'ALTER DATABASE CLEAR LOGFILE GROUP '||GROUP#||';' from v$standby_log;
select 'ALTER DATABASE DROP STANDBY LOGFILE GROUP '||GROUP#||';' from v$standby_log;


alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
set lines 200

-- on PRIMARY database
----------------------
select THREAD#, max(SEQUENCE#), max(FIRST_TIME),max(NEXT_TIME),max(COMPLETION_TIME) from gv$archived_log group by THREAD#;

-- on STANDBY database
----------------------
select THREAD#, max(SEQUENCE#), max(FIRST_TIME),max(NEXT_TIME),max(COMPLETION_TIME) from gv$archived_log
  where APPLIED='YES' group by THREAD#;


set lines 155 pages 9999
col thread# for 9999990
col sequence# for 999999990
col grp for 990
col fnm for a50 head "File Name"
col "Fisrt SCN Number" for 999999999999990
break on thread

select
	a.thread#
	,a.sequence#
	,a.group# grp     
	, a.bytes/1024/1024 Size_MB     
	,a.status     
	,a.archived     
	,a.first_change# "First SCN Number"     
	,to_char(FIRST_TIME,'YYYY-MM-DD HH24:MI:SS') "First SCN Time"   
	,to_char(LAST_TIME,'YYYY-MM-DD HH24:MI:SS') "Last SCN Time"
from
	gv$standby_log a  order by 1,2,3,4
 /



# https://www.dba-scripts.com/articles/dataguard-standby/data-guard-far-sync/


edit database huttdrp set property redoroutes = '(huttprd:huttca1)(huttprd:huttrem)(local:huttprd)';
enable database huttrem;




create pluggable database JABBA admin user admin identified by "Secret00!";

