Friday, 6 September 2019

MEMORY_TARGET (SGA_TARGET) or HugePages – which to choose?


MEMORY_TARGET (SGA_TARGET) or HugePages – which to choose?
Oracle 10g introduced the SGA_TARGET and SGA_MAX_SIZE parameter which dynamically resized many SGA components on demand. With 11g Oracle developed this feature further to include the PGA as well – the feature is now called “Automatic Memory Management” (AMM) which is enabled by setting the parameter MEMORY_TARGET.
Automatic Memory Management makes use of the SHMFS – a pseudo file system just like /proc. Every file created in the SHMFS is created in memory.
Unfortunately using MEMORY_TARGET or MEMORY_MAX_SIZE together with Huge Pages is not supported. You have to choose either Automatic Memory Management or HugePages. In this post i´d like to discuss AMM and Huge Pages.
Automatic Memory Management (AMM)
AMM – what it is
Automatic Memory Management was introduced with Oracle 11g Release 1 and automated sizing and re-sizing of SGA and PGA. With AMM activated there are two parameters of interest:
·       MEMORY_TARGET
·       MEMORY_MAX_TARGET
MEMORY_TARGET specifies the oracle system-wide usable amount of memory while MEMORY_MAX_TARGET specifies the upper bound of which the DBA can se MEMORY_TARGET to. If MEMORY_MAX_TARGET is not specified it defaults to MEMORY_TARGET.
For AMM to work there is one important requirement: Your system needs to support memory mapped files (on Linux typically mounted on /dev/shm).
According to the documentation the following platforms support AMM:
·       Linux
·       Solaris
·       Windows
·       HP-UX
·       AIX
More information on AMM can be found hereherehere and here.
Advantages
·       SGA and PGA automatically adjusted
·       dynamically resizeable
·       Not swappable
Disadvantages
·       Only available on a limited number of plattforms
Bug for Feature?
·       Does not work together with HugePages – so it is either AMM or HugePages
Before deciding lets see what HugePage are:
HugePages
HugePages – what are they?
Here is one description:
Hugepages is a mechanism that allows the Linux kernel to utilise the multiple page size capabilities of modern hardware architectures. Linux uses pages as the basic unit of memory, where physical memory is partitioned and accessed using the basic page unit. The default page size is 4096 Bytes in the x86 [and x86_64 as well; note by Ronny Egner] architecture. Hugepages allows large amounts of memory to be utilized with a reduced overhead. Linux uses “Transaction Lookaside Buffers” (TLB) in the CPU architecture. These buffers contain mappings of virtual memory to actual physical memory addresses. So utilising a huge amount of physical memory with the default page size consumes the TLB and adds processing overhead. The Linux kernel is able to set aside a portion of physical memory to be able be addressed using a larger page size. Since the page size is higher, there will be less overhead managing the pages with the TLB.
(Source: http://unixfoo.blogspot.com/2007/10/hugepages.html)
Advantages
·       Huge Pages are not swappable; thus keeping your SGA locked in memory
·       Overall memory performance is increased: Since there are less pages to scan the memory performance is increased
·       kswapd needs far less resources: kswapd regularly scans the page table for infrequent accessed pages which are a candidate for paging to disk. If the page table is large kswapd will use a lot of resources in therm of CPU. With Huge Pages enabled the page table is much smaller and Huge Pages are not subject to swap so kswapd will use less resources.
·       Improves TLB hit ratio due to less entries thus increasing memory performance further. The TLB is a small cache on cpu which stores virtual to physical memory mappings
Disadvantages
·       Should be allocated at startup (allocating huge pages at runtime is possible but will fail probably due to memory fragmentation; so it is advisable to allocate them at startup)
·       dynamically allocating hugepages is buggy
Linux memory management with and without Huge Pages
The following two figures try to illustrate how memory access with and without huge pages work. As you can see every process in a virtual memory operating system has it´s own process page table which points to a system page table.For oracle processes running on linux it is not uncommon to use the same physical memory regions due to accessing the SGA or the block cache. This is illustrated in the figures below for the pages 2 and 3; they are access by both processes.
Without huge pages memory is divided in chunks (called: “pages”) of 4 KB on Intel x86 and Intel x86_64 (the actual size depends on the hardware platform). Operating system offering virtual memory (as most modern operating system do, for instance linux, solaris, hp-ux, aix and even windows) present each process a continuous addressable memory (“virtual memory”) which consists of memory pages which reside in memory or even on disk (“swap”). See here for more information.
The following file taken from the wikipedia article mentioned above illustrates the concept of virtual memory:
VirtualMem01
From the process’ view it looks like it is solely running on the operating system. But it is not. In fact there are a lot of other processes running.
As mentioned above memory is presented to processes in chunks of 4 kb – a so called “page”. The operating system manages a list of pages – the “page table” – for each process and for the operating system as well which maps the virtual memory to physical memory.
The page table can be seen as “memory for managing memory”.Each page table entry (PTE) takes:
·       4 bytes of memory per page (4 kb) per process on 32-bit intel and
·       8 byte of memory per page (4 kb) per process on 64-bit intel
For more information see my post and the answer on the Linux Kernel Mailing List (LKML).
So for a process to touch every page on a 64-bit system with 16 GB memory there are required:
·       for the memory referenced by the process: 4.2 million PTE  (~ 16 GB) with 8 byte each = 32 MB
·       PLUS for the system page table: 4.2 million PTE (~ 16 GB) with 8 byte each = 32 MB
·       equals to 64 MB for the whole page table as counted in /proc/meminfo [PageTables]
On systems running oracle databases with a huge buffer cache and highly active processes (= sessions) it is not uncommon for the processes to reference the whole SGA and parts of the PGA after a while. Taken the example above assuming a buffer cache of 16 GB this adds up to 32 MB per process for the page table. 100 processes will consume 3.2 GB! Thats a lot of memory which is not available and solely used to manage memory.
The size of the page table can be querien on linux as follows:
cat /proc/meminfo | grep PageT
PageTables:      25096 kB
This command show the size of the Page Table (sum of system and all process page tables). This amount of memory is unusable for all processes and solely for managing the memory. On system with a lot of memory and a huge sga/pga and many dedicated server connections the page table can be several GByte in size!
The solution for this memory wastage is to implement huge pages. Huge pages increase the memory chunks from 4 kb to 2 MB so a page table entry still takes 8 bytes in 64-bit intel but references 2 mb – thats more efficenty by a factor of 512!
So taken our example from above with a buffer cache of 16 GB (16384 MB) referenced completely by a process the page table for the process will be:
·       16384 GB referenced / 2 MB per page = 8192 PTE with each 8 byte needed = 65536 Byte or 65 KB
I guess the advantage is obvious: 32 MB with no huge pages vs. 65 KB with huge pages!
Is my system already using huge pages?
You can check this by doing:
cat /proc/meminfo | grep Huge
There are three possibilities:
No huge pages configured at all
cat /proc/meminfo | grep Huge
HugePages_Total:  0
HugePages_Free:   0
HugePages_Rsvd:   0
Hugepagesize:     2048 kB
Huge pages configured but not used
cat /proc/meminfo | grep Huge
HugePages_Total:  3000
HugePages_Free:   3000
HugePages_Rsvd:   0
Hugepagesize:     2048 kB
Huge pages configured and used
[root@rac1 ~]# cat /proc/meminfo | grep Huge
HugePages_Total:  3000
HugePages_Free:   2601
HugePages_Rsvd:   2290
Hugepagesize:     2048 kB
How to configure huge pages?
1. edit /etc/sysctl.conf and add the following line:
vm.nr_hugepages = <number>
Note: This parameter specifies the number of huge pages. To get the total size you have to multiply “nr_hugepages” by “cat /proc/meminfo | grep Hugepagesize”. For 64-bit Linux on x86_64 the size of one Huge Page is 2 MB. So for a total amount of 2 GB or roughly 2000 MB you need 1000 Pages.
2. edit /etc/security/limits.conf and add the following lines:
<oracle user>    soft    memlock    unlimited
<oracle user>    hard    memlock    unlimited
3. Reboot the server and check
Some real world examples
The following are two database systems not using Huge Pages. Lets see how much memory is spend just for managing the memory:
System A
The following is an example of a Linux based database server running two database instances with approx. 8 GB SGA in total. At the time of sampling there are 444 dedicated server sessions connected.
MemTotal:     16387608 kB
MemFree:        105176 kB
Buffers:         21032 kB
Cached:        9575340 kB
SwapCached:       1036 kB
Active:       11977268 kB
Inactive:      2378928 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:     16387608 kB
LowFree:        105176 kB
SwapTotal:     8393952 kB
SwapFree:      8247912 kB
Dirty:            9584 kB
Writeback:           0 kB
AnonPages:     4754720 kB
Mapped:        7130088 kB
Slab:           256088 kB
CommitLimit:  16587756 kB
Committed_AS: 22134904 kB
PageTables:    1591860 kB
VmallocTotal: 34359738367 kB
VmallocUsed:      9680 kB
VmallocChunk: 34359728499 kB
HugePages_Total:     0
HugePages_Free:      0
HugePages_Rsvd:      0
Hugepagesize:     2048 kB
As you notice approx. 10% of all available memory is used for the Page Tables.
System B
System B is a Linux based system with 128 GB memory running one single database instance with 34 GB SGA and approx 400 sessions:
MemTotal:     132102884 kB
MemFree:        596308 kB
Buffers:        472620 kB
Cached:       111858096 kB
SwapCached:     138652 kB
Active:       65182984 kB
Inactive:     53195396 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:     132102884 kB
LowFree:        596308 kB
SwapTotal:     8393952 kB
SwapFree:      8112828 kB
Dirty:             568 kB
Writeback:           0 kB
AnonPages:     5901940 kB
Mapped:       33971664 kB
Slab:           915092 kB
CommitLimit:  74445392 kB
Committed_AS: 48640652 kB
PageTables:   12023792 kB
VmallocTotal: 34359738367 kB
VmallocUsed:    279912 kB
VmallocChunk: 34359456747 kB
HugePages_Total:     0
HugePages_Free:      0
HugePages_Rsvd:      0
Hugepagesize:     2048 kB
In this example Page Tables allocate 12 GB of memory. Thats a lot of memory.
Some laboratory examples
Test case no. 1
The first test case is quite simple. I started 100 dedicated database connections with a delay of 1 second between each database connection. Each session will log on and sleep for 200 seconds and log off. In the operating system i will monitor the page table size with increasing and decreasing database sessions.
foo.sql script
exec dbms_lock.sleep(200);
exit
doit.sql script
doit.sql
for i in {1..100}
do
echo $i
sqlplus system/manager@ora11p @foo.sql &
sleep 1
done
Results without Huge Pages
The following output were observed without huge pages:
while true; do cat /proc/meminfo | grep PageTable && sleep 3; done
PageTables:      58836 kB
PageTables:      60792 kB
PageTables:      62808 kB
PageTables:      64808 kB
PageTables:      66560 kB
PageTables:      68780 kB
PageTables:      70084 kB
PageTables:      72044 kB
PageTables:      72296 kB
PageTables:      74184 kB
PageTables:      76804 kB
PageTables:      79000 kB
PageTables:      80928 kB
PageTables:      82932 kB
PageTables:      84652 kB
PageTables:      86576 kB
PageTables:      88936 kB
PageTables:      90896 kB
PageTables:      94120 kB
PageTables:      96424 kB
PageTables:      98212 kB
PageTables:     100304 kB
PageTables:     101868 kB
PageTables:     103960 kB
PageTables:     105996 kB
PageTables:     108108 kB
PageTables:     109992 kB
PageTables:     111404 kB
PageTables:     113584 kB
PageTables:     114860 kB
PageTables:     116856 kB
PageTables:     118276 kB
PageTables:     120256 kB
PageTables:     120316 kB
PageTables:     120240 kB
PageTables:     120616 kB
PageTables:     120316 kB
PageTables:     121456 kB
PageTables:     121480 kB
PageTables:     121484 kB
PageTables:     121480 kB
PageTables:     121408 kB
PageTables:     121404 kB
PageTables:     121484 kB
PageTables:     121632 kB
PageTables:     121484 kB
PageTables:     121480 kB
PageTables:     120316 kB
PageTables:     120320 kB
PageTables:     120316 kB
PageTables:     120320 kB
PageTables:     121460 kB
PageTables:     121652 kB         <==== PEAK AROUND HERE
PageTables:     121500 kB
PageTables:     121540 kB
PageTables:     120096 kB
PageTables:     118136 kB
PageTables:     116188 kB
PageTables:     114192 kB
PageTables:     112236 kB
PageTables:     110240 kB
PageTables:     106556 kB
PageTables:     103792 kB
PageTables:     101820 kB
PageTables:      97916 kB
PageTables:      95900 kB
PageTables:      95120 kB
PageTables:      93104 kB
PageTables:      91848 kB
PageTables:      89852 kB
PageTables:      87860 kB
PageTables:      85896 kB
PageTables:      83868 kB
PageTables:      81940 kB
PageTables:      79944 kB
[...]
Results with Huge Pages
while true; do cat /proc/meminfo | grep PageTable && sleep 3; done
PageTables:      27112 kB
PageTables:      27236 kB
PageTables:      27280 kB
PageTables:      27320 kB
PageTables:      27344 kB
PageTables:      27368 kB
PageTables:      27396 kB
PageTables:      27416 kB
PageTables:      31028 kB
PageTables:      31412 kB
PageTables:      37668 kB
PageTables:      37912 kB
PageTables:      39964 kB
PageTables:      39756 kB
PageTables:      39740 kB
PageTables:      41312 kB
PageTables:      41436 kB
PageTables:      41508 kB
PageTables:      42192 kB
PageTables:      42196 kB
PageTables:      42528 kB
PageTables:      43036 kB
PageTables:      43232 kB
PageTables:      45616 kB
PageTables:      44852 kB
PageTables:      44540 kB
PageTables:      44552 kB
PageTables:      44728 kB
PageTables:      44748 kB
PageTables:      44764 kB
PageTables:      45936 kB
PageTables:      46992 kB
PageTables:      48128 kB
PageTables:      49264 kB
PageTables:      50312 kB
PageTables:      51056 kB
PageTables:      52244 kB
PageTables:      53496 kB
PageTables:      54256 kB
PageTables:      55296 kB
PageTables:      56440 kB
PageTables:      57712 kB
PageTables:      58240 kB
PageTables:      58824 kB
PageTables:      59612 kB
PageTables:      60656 kB
PageTables:      62468 kB
PageTables:      63592 kB
PageTables:      64700 kB
PageTables:      65820 kB
PageTables:      66916 kB
PageTables:      68344 kB
PageTables:      69144 kB
PageTables:      70260 kB
PageTables:      71044 kB
PageTables:      72172 kB
PageTables:      73224 kB
PageTables:      73684 kB
PageTables:      74736 kB
PageTables:      75828 kB
PageTables:      76952 kB
PageTables:      78068 kB
PageTables:      79180 kB
PageTables:      78604 kB
PageTables:      79384 kB
PageTables:      79384 kB
PageTables:      80064 kB
PageTables:      80092 kB
PageTables:      80096 kB
PageTables:      80096 kB
PageTables:      80096 kB
PageTables:      80084 kB
PageTables:      80096 kB
PageTables:      80092 kB
PageTables:      80096 kB        <=== PEAK AROUND HERE
PageTables:      80096 kB
PageTables:      79408 kB
PageTables:      79400 kB
PageTables:      79400 kB
PageTables:      79396 kB
PageTables:      79392 kB
PageTables:      79392 kB
PageTables:      79392 kB
PageTables:      79392 kB
PageTables:      79392 kB
PageTables:      79396 kB
PageTables:      79396 kB
PageTables:      70260 kB
[...]
Observations
·       without huge pages page table size peaked at approx. 120 MB
·       with huge page page table size peaked at approx. 80 MB
In this simple test case using huge pages used only 66% of memory.
Because of the choosen test case memory saving is not that big because we did not referenced that much memory from the SGA in our processes. Tests would be much clearer with larger parts (e.g. buffer cache) of the SGA referenced.
Conclusion
HugePages offers some important advantages over AMM, for instance:
·       minimizing cpu-cycles used for scanning memory pages which are candidates for swapping thus freeing cpu-cycles for your database,
·       minimizing memory spend for managing memory references
The latter point is the most important one. Especially systems with large memory amounts dedicated to SGA and PGA and many database sessions (> 100) will benefit from using Huge Pages. The more memory dedicated to SGA and PGA and the more sessions connected with the database the larger the memory savings from using Huge Pages will be.
From my point of view even if AMM simplifies memory management by including both PGA and SGA the memory (and cpu) savings from using Huge Pages are more important than just simlifying memory management.
So if you have an SGA larger than 16 GB and more than 100 sessions using Huge Pages is definetly worth trying. On system with only a few sessions using Huge Pages will give some benefit as well but only by reduding cpu-cycles needed for scanning the memory pages.



Hugepage setting itself: Nvm.nr_hugepages is the total number of hugepages to be allocated on the system. 
 The number of hugepages required can be determined by finding the maximum amount of SGA memory expected to be used by the system (the SGA_MAX_SIZE value normally, or the sum of them on a server with multiple instances) and dividing it by the size of the hugepages, 2048k, or 2M on Linux. To account for Oracle process overhead, add five more hugepages. So, if we want to allow 180G of hugepages, we would use this equation: (180*1024*1024/2048)+5.  
This gives us 92165 hugepages for 180G. Note: I took a shortcut in this calculation, by using memory in MEG rather than the full page size. 
To calculate the number in the way I initial described, the equation would be: (180*1024*1024*1024)/(2048*1024).

/etc/security/limits.conf

oracle soft memlock 230000000
oracle hard memlock 230000000

/etc/sysctl.conf

vm.nr_hugepages =  92165
kernel.shmmax  = 93273528320+1g = 94347270144
kernel.shmall  = 

USE_LARGE_PAGES=only
SGA_TARGET=80G
SGA_MAX_SIZE=80G
MEMORY_MAX_TARGET=0
MEMORY_TARGET=0

verify huge page
cat /proc/meminfo | grep Huge


awk '/Hugepagesize:/{p=$2} / 0 /{next} / kB$/{v[sprintf("%9d GB %-s",int($2/1024/1024),$0)]=$2;next} {h[$0]=$2} /HugePages_Total/{hpt=$2} /HugePages_Free/{hpf=$2} {h["HugePages Used (Total-Free)"]=hpt-hpf} END{for(k in v) print sprintf("%-60s %10d",k,v[k]/p); for (k in h) print sprintf("%9d GB %-s",p*h[k]/1024/1024,k)}' /proc/meminfo|sort -nr|grep --color=auto -iE "^|( HugePage)[^:]*"








Thursday, 5 September 2019

export backup script


# $Header: EXP_TAB_cmprss.sh 
# *====================================================================================+
# |  Author - DBACLASS ADMIN TEAM
# |                                                       |
# +====================================================================================+
# |
# | FILENAME
# |     EXP_table_bkp_cmprss_dbaclass.sh
# |
# | DESCRIPTION
# |     Daily Export backup script of a list of table
# | PLATFORM
# |     Linux/Solaris

# +===========================================================================+
#!/bin/bash
echo Set Oracle Database Env
export ORACLE_SID=$1
export ORACLE_HOME=/u01/app/oracle/product/12.2.0/dbhome_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
export PATH=$ORACLE_HOME/bin:$PATH:/usr/local/bin
export TIMESTAMP=`date +%a%d%b%Y`
export dir1=/u02/backup/export

echo =======
echo Export command
echo =======
echo $ORACLE_HOME
$ORACLE_HOME/bin/expdp \'/ as sysdba\' directory=dir1 dumpfile=expdp_pdb1_${TIMESTAMP}_%U.dmp logfile=expdp_log_${TIMESTAMP}.log full=y
PARALLEL=6  COMPRESSION=ALL

echo SEND MAIL TO STAKE HOLDERS
echo =======
mailx -s "$ORACLE_SID $TIMESTAMP Export backup logfile" shymon.ravi@nttdata.com < $EXP_DIR/expdp_log_${TIMESTAMP}.log
echo Export completed at $TIMESTAMP
exit



chmod 755 EXP_TAB_cmprss.sh

00 15  * * * /u02/backup/export/export.sh  PHFMDB

listener.ora

ADMIN_RESTRICTIONS_LISTENER = on

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = sdefr2pldb02.moviantogroup.com)(PORT = 1523))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1523))
    )
  )

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
       (ORACLE_HOME = /oraclebase/app/oracle/product/18.0.0/dbhome_1)
      (SID_NAME = PRIPRDSBY)
      (ORACLE_HOME = /oraclebase/app/oracle/product/18.0.0/dbhome_1)
      (SID_NAME = PRIPRD)
    )
  )





ADR_BASE_LISTENER = /oraclebase/dump/
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER=ON              # line added by Agent
VALID_NODE_CHECKING_REGISTRATION_LISTENER=ON

WORKLOAD MANAGEMENT IN 11g R2 RAC : LOAD BALANCING


will discuss about various types of load balancing techniques that can be configured in 11g R2 RAC for workload management.
In RAC we have multiple instances of a database running on multiple servers.
Workload management involves :
   – Failover : If connection to an instance fails, client should automatically connect to another instance
   – Load balancing : Workload should spread across various instances to obtain maximum performance/throughput
Failover can be
  – Connect Time Connection Failover (CTCF) while making initial connection ()
  - Run time connection failover (RTCF) after connection has been established or (transparent application failover (TAF)
     FAILOVER_METHOD = NONE, BASIC, PRECONNECT
     FAILOVER TYPE   = SESSION, SELECT
Load balancing can be :
  – Connect time load balancing (CTLB)
    . On client side
    . On server side
  –  Run time load balancing (RTLB)
TO configure failover/load balancing, tnsnames.ora should contain multiple listener addresses to connect to multiple instances e.g.
Multiple Listener addresses within a description: i.e. User is trying to connect to a service which is supported by multiple instances.
RAC=
(DESCRIPTION=
   (ADDRESS_LIST=
     (ADDRESS= (PROTOCOL=TCP) (HOST=node1-vip) (PORT=1521))
     (ADDRESS= (PROTOCOL=TCP) (HOST=node2-vip) (PORT=1521))
     (ADDRESS= (PROTOCOL=TCP) (HOST=node3-vip) (PORT=1521))
     (ADDRESS= (PROTOCOL=TCP) (HOST=node4-vip) (PORT=1521))
                      )
    (CONNECT_DATA= (SERVICE_NAME= RAC))
       )
In case SCAN is used, SCAN name is used in the address which resolves to 3 SCAN listeners.
e.g.
RAC=
(DESCRIPTION=
   (ADDRESS_LIST=
     (ADDRESS= (PROTOCOL=TCP) (HOST=cluster01-scan) (PORT=1521))
                      )
    (CONNECT_DATA= (SERVICE_NAME= RAC))
       )
In this post, I will discuss in detail about Load Balancing. To know more about failover , please click here.
LOAD BALANCING 
————–
Load balancing in RAC implies distributing the workload over multiple instances accessing the same physical database. Two kinds load balancing can be configured
  – Connect time load balancing (CTLB)
    . On client side
    . On server side
  – On server side – Run time load balancing (RTLB)
Connect time load balancing (CTLB) : This enables user to connect to one of the instances supporting the service. The connection stays with the same instance until the user disconnects orthe session is killed. It can be configured on the client side and/or server side.
Connect time load balancing on client side: When a user session attempts to connect to the database, Oracle Net chooses an address specified in tnsnames.ora to connect to in a random order rather than sequential order. This has the effect of clients connecting through addresses which are picked up at random and no one address is overloaded. Its configuration is quite simple. You just need to set the parameter LOAD_BALANCE=ON in the client connection definition in tnsnames.ora. For example :
RAC=
(DESCRIPTION=
  (ADDRESS_LIST=
                       (LOAD_BALANCE=ON)
    (ADDRESS= (PROTOCOL=TCP) (HOST=node1-vip) (PORT=1521))
                       (ADDRESS= (PROTOCOL=TCP) (HOST=node2-vip) (PORT=1521))
    (ADDRESS= (PROTOCOL=TCP) (HOST=node3-vip) (PORT=1521))
    (ADDRESS= (PROTOCOL=TCP) (HOST=node4-vip) (PORT=1521))
                      )
   (CONNECT_DATA= (SERVICE_NAME= RAC)
       )
LOAD_BALANCE parameter is set to ON by default. When this parameter is set to ON, Oracle Net Services progresses through the list of listener addresses in a random sequence, balancing the load on several listeners. When it is set to OFF, the addresses are tried out sequentially until one succeeds.
When using SCAN in the connection definition, Oracle database randomly connects to one of the available SCAN listeners in a round robin fashion and balances the connections on the three scan listeners. Here is a sample tnsnames.ora for a RAC database using SCAN.
RAC=
(DESCRIPTION=
    (LOAD_BALANCE=ON)
    (ADDRESS= (PROTOCOL=TCP) (HOST=SCAN-HOSTNAME) (PORT=1521))
                  )
   (CONNECT_DATA= (SERVICE_NAME= RAC)
       )
Limitation of connect time load balancing : The connection stays with the same instance for the life of a session. If connection lasts a long time, it might be possible that load of current instance increases and some other less loaded instance might be preferable. In that case we would like the connection to switch the other more appropriate instance. This can be achieved by using Run time Load Balancing (RTLB).
Connect time load balancing on server side: After a listener receives the connection request, it can forward the request to another instance based on the connect time load balancing goal (CLB_GOAL)specified for the service. CLB_GOAL can be :
LONG(Default) - used for application connections that are connected for a long period such as third party connection pools and SQL*Forms applications. In this case,
   . the listener will load balance on number of sessions
   . Run time load balancing goal will not be used in this case
SHORT - used for application connections that are short in duration. This should be used with connection pools integrated with the load balancing advisory. In this case, listener uses Load Balancing Advisory (LBA) to make the connection based on CPU utilization on the node.
Limitation of Connect time load balancing on client side : The listener has no idea if the session has been assigned to an endpoint whose corresponding database server is already overloaded. Hence, timeouts can occur if the node is heavily loaded and unable to respond quickly.Hence, to overcome this problem, server side connect time load balancing needs to be configured. It is useful to spread initial connection load among all listeners inthe cluster. Client may then be redirected based on server side load balancing.
Run Time (Server side) load Balancing (RTLB): In this case, the listener routes incoming client connections according to policies and based on the current service level provided by the database instances. The listener determines the connection distribution depending upon profile statistics that  are dynamically updated by PMON. The higher the load on the node, the more frequently PMON updates the load profile.Thus connections may be switched depending upon changes in cluster configuration, application wrokload  overworked nodes or hangs.
   The core of server side laod balancing id Dynamic service registration so that a services are registered with all the listeners. Since PMON on each node sends load profile to all the listeners with which the service is registered,  all the  listeners come to know about load profile of all the instances and hence the connection is forwarded to the most appropriate listener depending upon the goal of the run time load balancing.
  Run time load balancing is achieved using connection pools. Work requests are automatically balanced across the pool of connections.The connection allocation is based on the current performance level provided by the database instances as indicated by the LBA FAN events. This provides load balancing at the transaction level instead of load balancing at the time of initial connection. 
With server-side load balancing, the listener directs a connection request to the best instance currently providing the service by using the load balancing advisory.
Load Balancing Advisory
- is an advisory for balancing work across RAC instances
- Monitors workload activity for a service across all instances in the cluster
- Analyzes the service level for each instance based on defined metric goal
    Metric: service time (GOAL_SERVICE_TIME)
    Metric: throughput (GOAL_THROUGHPUT)
- Publishes FAN events recommending amount of work to be sent to each instance and data quality  flag
- Default is Off.
-  Directs work to where services are executing well and resources are available
- Adjusts distribution for different power nodes, different priority and shape workloads, changing demand
- Stops sending work to slow, hung, failed nodes early
How to configure server side load balancing:
1. set parameters LOCAL_LISTENER and REMOTE_LISTENER
2. set CLB_GOAL = SHORT for the service
3. set RTLB_GOAL for the service
1. set parameters LOCAL_LISTENER and REMOTE_LISTENER
LOCAL_LISTENER parameter should be set to name of the listener defined in the same node
REMOTE_LISTENER should be set to names of the listeners running on other nodes
For example in a 3 node setup
Host01 running instance orcl1
Host02 running instance orcl2
Host03 running instance orcl3
For host01,
local_listener  – (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP) HOST=host01-vip)(PORT=1521))))
remote_listener  – (DESCRIPTION=(ADDRESS_LIST=
                                 (ADDRESS=(PROTOCOL=TCP) HOST=host02-vip)(PORT=1521)
                                 (ADDRESS=(PROTOCOL=TCP) HOST=host03-vip)(PORT=1521))))
For host02,
local_listener  – (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP) HOST=host02-vip)(PORT=1521))))
remote_listener  – (DESCRIPTION=(ADDRESS_LIST=
                                 (ADDRESS=(PROTOCOL=TCP) HOST=host01-vip)(PORT=1521)
                                 (ADDRESS=(PROTOCOL=TCP) HOST=host03-vip)(PORT=1521))))
For host03,
local_listener  – (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP) HOST=host03-vip)(PORT=1521))))
remote_listener  – (DESCRIPTION=(ADDRESS_LIST=
                                 (ADDRESS=(PROTOCOL=TCP) HOST=host02-vip)(PORT=1521)
                                 (ADDRESS=(PROTOCOL=TCP) HOST=host01-vip)(PORT=1521))))
When we start the three instances the corresponding PMON processes get dynamically registered with all the listeners and start feeding listeners with load profile information. Now all the listeners come to know about load profile of all the instances and hence the connection is forwarded to the listener of the least loaded node.
When SCAN is used, remote_listener parameter should be set to SCAN name on all the nodes i.e.
remote_listener – myrac-cluster-scan:1521
So that PMON process of each instance registers the database services with the default listener on the local node and with each SCAN listener, which is specified by the REMOTE_LISTENER database parameter.
2. set CLB_GOAL = SHORT for the service
   EXECUTE DBMS_SERVICE.MODIFY_SERVICE
   (service_name => ‘sjob’ -
   , clb_goal => DBMS_SERVICE.CLB_GOAL_SHORT);
OR
   srvctl modify service
      -s orcl_serv database -d orcl
      -j SHORT   // connection load balancing goal {long|short}
3. set RTLB_GOAL for the service
A request for a connection is serviced by selecting a connection based on the service goal as determined by the Load Balancing Advisory. The service goal determines whether the connection provides best service quality, that is, how efficiently a single transaction completes, or best throughput, that is, how efficiently an entire job or long-running query completes.
For RTLB, we can define service level goal which will be used only if CLB_GOAL= SHORT
There are 3 options available
NONE – Default setting, you are not taking advantage of this feature
THROUGHPUT – Work requests are directed based on throughput.  THROUGHPUT should be used when the work in a service completes at homogenous rates.  An example is a trading system where work requests are similar lengths. Attempts to direct work requests according to throughput. The load balancing advisory analyzes the service level for each instance based on the service time and is based on the rate that work is completed in the service plus available bandwidth to the service. For example for the use of THROUGHPUT is for workloads such as batch processes,trading system work requests have similar lengths and  next job starts when the last job completes:
EXECUTE DBMS_SERVICE.MODIFY_SERVICE
 (service_name => ‘sjob’ -
  , goal => DBMS_SERVICE.GOAL_THROUGHPUT );
OR
srvctl modify  service
      -s orcl_serv database -d orcl
      -B throughput      // runtime connection load balancing goal { service_time|throughput | none}
SERVICE_TIME – Work requests are directed based on response time. SERVICE_TIME should be used when the work in a service completes at various rates.  In this case, Load balancing advisory data is based on elapsed time for work done in the service plus available bandwidth to the service. An example for the use of SERVICE_TIME is for workloads such as internet shopping where the rate of demand changes and work requests are of differing various lengths.:
EXECUTE DBMS_SERVICE.MODIFY_SERVICE
(service_name => ‘OE’ -
, goal => DBMS_SERVICE.GOAL_SERVICE_TIME -
);
OR
srvctl modify  service
      -s orcl_serv database -d orcl
      -B service_time      // runtime connection load balancing goal { service_time|throughput | none}
 You can see the goal settings for a service in the data dictionary and in the DBA_SERVICES, V$SERVICES, and V$ACTIVE_SERVICES views.
SUMMARY:
Workload management involves :
   – Failover : If connection to an instance fails, client should automatically connect to another instance
   – Load balancing : Workload should spread across various instances to obtain maximum performance/throughput
Load balancing can be :
  – Connect time load balancing (CTLB)
    . On client side
    . On server side
  –  Run time load balancing (RTLB)
TO configure failover/load balancing, tnsnames.ora should contain multiple listener addresses to connect to multiple instances
Connect time load balancing (CTLB) : This enables user to connect to one of the instances supporting the service. The connection stays with the same instance until the user disconnects orthe session is killed. It can be configured on the client side and/or server side.
Connect time load balancing on client side: When a user session attempts to connect to the database, Oracle Net chooses an address specified in tnsnames.ora to connect to in a random order rather than sequential order. This has the effect of clients connecting through addresses which are picked up at random and no one address is overloaded. Its configuration is quite simple. You just need to set the parameter LOAD_BALANCE=ON in the client connection definition in tnsnames.ora.
Limitation of Connect time load balancing (CTLB) on client side : The listener has no idea if the session has been assigned to an endpoint whose corresponding database server is already overloaded.
Connect time load balancing (CTLB) on server side: After a listener receives the connection request, it can forward the request to another instance based on the connect time load balancing goal (CLB_GOAL)specified for the service. CLB_GOAL can be : LONG or SHORT
LONG(Default) – In this case,
   . the listener will load balance on number of sessions
   . Run time load balancing goal will not be used in this case
SHORT - used for application connections that are short in duration. This should be used with connection pools integrated with the load balancing advisory. In this case, listener uses Load Balancing Advisory (LBA) to make the connection based on CPU utilization on the node.
Limitation of connect time load balancing : The connection stays with the same instance for the life of a session. If connection lasts a long time, it might be possible that load of current instance increases and some other less loaded instance might be preferable.
Run Time (Server side) load Balancing (RTLB): In this case, the listener routes incoming client connections according to policies and based on the current service level provided by the database instances. With server-side load balancing, the listener directs a connection request to the best instance currently providing the service by using the load balancing advisory.
To configure server side load balancing:
1. set parameters LOCAL_LISTENER and REMOTE_LISTENER
2. set CLB_GOAL = SHORT for the service
3. set RTLB_GOAL for the service

create of physical standby through active database


source and target database should be same configuration



primary





SQL> select name, open_mode, database_role, INSTANCE_NAME from v$database,v$instance;



NAME      OPEN_MODE            DATABASE_ROLE    INSTANCE_NAME

--------- -------------------- ---------------- ----------------

Ram    READ WRITE           PRIMARY          Ram





SQL> select force_logging from v$database;



FORCE_LOGGING

---------------------------------------

NO







SQL> ALTER DATABASE FORCE LOGGING;



Database altered.



SQL> select force_logging from v$database;



FORCE_LOGGING

---------------------------------------

YES





[oracle@rac1 ~]$ cd $ORACLE_HOME/dbs

[oracle@rac1 dbs]$ rm hc_apac.dat

[oracle@rac1 dbs]$ ls -ltr

total 20

-rw-r--r-- 1 oracle oinstall 2851 May 15  2009 init.ora

-rw-r----- 1 oracle oinstall   24 Jan  6 22:46 lkW5005PR

-rw-r----- 1 oracle oinstall 1536 Jan  6 22:47 orapww5005pr

-rw-r----- 1 oracle oinstall   41 Jan  6 22:48 initw5005pr.ora

-rw-rw---- 1 oracle oinstall 1544 Jan  6 22:48 hc_w5005pr.dat

[oracle@rac1 dbs]$





configure standby redolog on primary



SQL> set lines 180

col MEMBER for a60

select b.thread#, a.group#, a.member, b.bytes FROM v$logfile a, v$log b WHERE a.group# = b.group#;SQL> SQL>



   THREAD#     GROUP# MEMBER                                                            BYTES

---------- ---------- ------------------------------------------------------------ ----------

         1          3 +DATA01/Ram/ONLINELOG/group_3.259.1018027407               209715200

         1          3 +FLASH01/Ram/ONLINELOG/group_3.1590.1018027409             209715200

         1          2 +DATA01/Ram/ONLINELOG/group_2.267.1018027407               209715200

         1          2 +FLASH01/Ram/ONLINELOG/group_2.1589.1018027409             209715200

         1          1 +DATA01/Ram/ONLINELOG/group_1.260.1018027407               209715200

         1          1 +FLASH01/Ram/ONLINELOG/group_1.1591.1018027409             209715200



6 rows selected.





ALTER DATABASE ADD standby logfile thread 1 group 4 ( '+DATA01','+FLASH01') SIZE 200m;



SQL> ALTER DATABASE ADD standby logfile thread 1 group 5 ('+DATA01','+FLASH01') size 200m;



Database altered.



SQL> ALTER DATABASE ADD standby logfile thread 1 group 6 ('+DATA01','+FLASH01') size 200m;



Database altered.



SQL>  ALTER DATABASE ADD standby logfile thread 1 group 7 ('+DATA01','+FLASH01') size 200m;



Database altered.





SQL> show parameter pfile;



NAME       TYPE         VALUE

---------- ----------- --------------------------------

spfile     string       +DATA/w5005pr/spfilew5005pr.ora



SQL> create pfile='/home/oracle/initw5005pr.ora.bkp' from spfile;



File created.



SQL> alter system set db_unique_name='Ram' scope=spfile;



System altered.



SQL> ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(Ram,RamSBY)' scope=both;



System altered.



SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_1='LOCATION=+FLASH01 VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=Ram' scope=both;



System altered.



SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=RamSBY LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=RamSBY' scope=both;



System altered.



SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_1=ENABLE scope=both;



System altered.



SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE scope=both;



System altered.



SQL> ALTER SYSTEM SET LOG_ARCHIVE_FORMAT='%t_%s_%r.arc' SCOPE=SPFILE;



System altered.



SQL> ALTER SYSTEM SET LOG_ARCHIVE_MAX_PROCESSES=30 scope=both;



System altered.



SQL> ALTER SYSTEM SET REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE SCOPE=SPFILE;



System altered.



SQL> ALTER SYSTEM SET fal_client=Ram scope=both;



System altered.



SQL> ALTER SYSTEM SET fal_server=RamSBY scope=both;



System altered.



SQL> ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO;



System altered.



SQL> create pfile='/oraclebase/app/oracle/product/18.0.0/dbhome_1/dbs/initRam' from spfile;



File created.



SQL>





Copy the password file from the primary $ORACLE_HOME/dbs and rename it to the standby database name.

The username is required to be SYS and the password needs to be the same on the Primary and Standby.

The best practice for this is to copy the passwordfile as suggested.

The password file name must match the instance name/SID used at the standby site, not the DB_NAME





copy the initora file to standylocation and change it accordingly.



prod pfile

Ram.__data_transfer_cache_size=0

Ram.__db_cache_size=22817013760

Ram.__inmemory_ext_roarea=0

Ram.__inmemory_ext_rwarea=0

Ram.__java_pool_size=268435456

Ram.__large_pool_size=335544320

Ram.__oracle_base='/oraclebase/app/oracle'#ORACLE_BASE set from environment

Ram.__pga_aggregate_target=3422552064

Ram.__sga_target=26910654464

Ram.__shared_io_pool_size=536870912

Ram.__shared_pool_size=2885681152

Ram.__streams_pool_size=0

*.audit_file_dest='/oraclebase/app/oracle/admin/Ram/adump'

*.audit_trail='db'

*.compatible='18.0.0'

*.control_files='+DATA01/Ram/CONTROLFILE/current.261.1018026219','+FLASH01/Ram/CONTROLFILE/current.256.1018026219'#Restore Controlfile

*.db_block_size=8192

*.db_create_file_dest='+DATA01'

*.db_create_online_log_dest_1='+DATA01'

*.db_create_online_log_dest_2='+FLASH01'

*.db_name='Ram'

*.db_recovery_file_dest_size=100006m

*.db_recovery_file_dest=''

*.db_unique_name='Ram'

*.diagnostic_dest='/oraclebase/app/oracle'

*.dispatchers='(PROTOCOL=TCP) (SERVICE=RamXDB)'

*.fal_client='Ram'

*.fal_server='RamSBY'

*.local_listener='LISTENER_Ram'

*.log_archive_config='DG_CONFIG=(Ram,RamSBY)'

*.log_archive_dest_1='LOCATION=+FLASH01 VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=Ram'

*.log_archive_dest_2='SERVICE=RamSBY LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=RamSBY'

*.log_archive_dest_state_1='ENABLE'

*.log_archive_dest_state_2='ENABLE'

*.log_archive_format='%t_%s_%r.arc'

*.log_archive_max_processes=30

*.nls_language='AMERICAN'

*.nls_territory='AMERICA'

*.open_cursors=300

*.pga_aggregate_target=3201m

*.processes=1280

*.remote_login_passwordfile='EXCLUSIVE'

*.sga_target=25602m

*.standby_file_management='AUTO'

*.star_transformation_enabled='TRUE'

*.undo_tablespace='UNDOTBS1'





standby pfile





RamSBY.__data_transfer_cache_size=0

RamSBY.__db_cache_size=22817013760

RamSBY.__inmemory_ext_roarea=0

RamSBY.__inmemory_ext_rwarea=0

RamSBY.__java_pool_size=268435456

RamSBY.__large_pool_size=335544320

RamSBY.__oracle_base='/oraclebase/app/oracle'#ORACLE_BASE set from environment

RamSBY.__pga_aggregate_target=3422552064

RamSBY.__sga_target=26910654464

RamSBY.__shared_io_pool_size=536870912

RamSBY.__shared_pool_size=2885681152

RamSBY.__streams_pool_size=0

*.audit_file_dest='/oraclebase/app/oracle/admin/RamSBY/adump'

*.audit_trail='db'

*.compatible='18.0.0'

*.control_files='+DATA01','+FLASH01'#Restore Controlfile

*.db_block_size=8192

*.db_create_file_dest='+DATA01'

*.db_create_online_log_dest_1='+DATA01'

*.db_create_online_log_dest_2='+FLASH01'

*.db_name='Ram'

*.db_recovery_file_dest_size=100006m

*.db_recovery_file_dest=''

*.db_unique_name='RamSBY'

*.diagnostic_dest='/oraclebase/app/oracle'

*.dispatchers='(PROTOCOL=TCP) (SERVICE=RamSBYXDB)'

*.fal_client='RamSBY'

*.fal_server='Ram'

*.local_listener='LISTENER_RamSBY'

*.log_archive_config='DG_CONFIG=(RamSBY,Ram)'

*.log_archive_dest_1='LOCATION=+FLASH01 VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=RamSBY'

*.log_archive_dest_2='SERVICE=Ram LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=Ram'

*.log_archive_dest_state_1='ENABLE'

*.log_archive_dest_state_2='DEFER'

*.log_archive_format='%t_%s_%r.arc'

*.log_archive_max_processes=30

*.nls_language='AMERICAN'

*.nls_territory='AMERICA'

*.open_cursors=300

*.pga_aggregate_target=3201m

*.processes=1280

*.remote_login_passwordfile='EXCLUSIVE'

*.sga_target=25602m

*.standby_file_management='AUTO'

*.star_transformation_enabled='TRUE'

*.undo_tablespace='UNDOTBS1'





***********************************************







mkdir -p /u01/app/oracle/admin/Ramsby/adump





startup nomount pfile='/oraclebase/app/oracle/product/18.0.0/dbhome_1/dbs/initRamSBY';









create spfile='+DATA01/RamSBY/spfileRamSBY.ora' from pfile='/oraclebase/app/oracle/product/18.0.0/dbhome_1/dbs/initRamSBY';









startup nomount force;



show parameter pfile



SELECT thread#, group#, sequence#, bytes, archived, status FROM v$standby_log order by thread#, group#;







--Example for two members

--alter database add standby logfile THREAD 1 group 5 ('D:\ORACLEXE\STANDBYREDO01A.log','D:\ORACLEXE\STANDBYREDO01B.log') SIZE 200M;


--Example for ASM
--alter database add standby logfile THREAD 1 group 7 ('+DATA(ONLINELOG)','+FRA(ONLINELOG)') SIZE 200M;



configure listener and tnsnames



srvctl modify scan_listener -p TCP:1523



srvctl modify listener -p TCP:1523



Verify connection ‘AS SYSDBA’ from Primary



Verify connection ‘AS SYSDBA’ from Standby



Run the duplicate from active database command from primary



rman target sys/ChangeMe2019@Ram auxiliary sys/ChangeMe2019@RamSBY

duplicate target database for standby from active database nofilenamecheck;

once completed


"alter database mount standby database;
database altered;"
alter database recover managed standby database disconnect from session;
alter system set log_archive_dest_state_2=defer;


on primary



select name, open_mode, database_role, INSTANCE_NAME from v$database,v$instance;


SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;

SQL> alter system switch logfile;



System altered.



SQL> alter system switch logfile;



System altered.



SQL> select max(sequence#) from v$archived_log where archived='YES';



MAX(SEQUENCE#)

--------------

            10



standyb





SQL> select name, open_mode, database_role, INSTANCE_NAME from v$database,v$instance;



NAME      OPEN_MODE            DATABASE_ROLE    INSTANCE_NAME

--------- -------------------- ---------------- ----------------

ddd   READ ONLY WITH APPLY PHYSICAL STANDBY standy



SQL> SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;



 SEQUENCE# FIRST_TIM NEXT_TIME

---------- --------- ---------

         6 07-JAN-16 07-JAN-16

         7 07-JAN-16 07-JAN-16

         8 07-JAN-16 07-JAN-16

         9 07-JAN-16 07-JAN-16

        10 07-JAN-16 07-JAN-16



SQL> select max(sequence#) from v$archived_log where applied='YES';



select process,status,sequence#,thread# from v$managed_standby;



SQL> ALTER SYSTEM SET log_archive_dest_state_2 = DEFER;



System altered.



SQL> ALTER SYSTEM SET log_archive_dest_state_2 =enable';

ALTER SYSTEM SET log_archive_dest_state_2 =enable'

                                                 *

ERROR at line 1:

ORA-01756: quoted string not properly terminated





SQL> ALTER SYSTEM SET log_archive_dest_state_2 = ENABLE;



System altered.







[oracle@rac2 ~]$ which srvctl

/u01/app/oracle/product/11.2.0/db_1/bin/srvctl

[oracle@rac2 ~]$ srvctl add database -d w5005prg -o /u01/app/oracle/product/11.2.0/db_1/ -r physical_standby -s 'READ ONLY'

[oracle@rac2 ~]$ srvctl start database -d w5005prg



[oracle@rac2 ~]$ /u01/app/11.2.0/grid/bin/crsctl stat res -t

--------------------------------------------------------------------------------

NAME           TARGET  STATE        SERVER                   STATE_DETAILS

--------------------------------------------------------------------------------

Local Resources

--------------------------------------------------------------------------------





applying retention policy for rman on both primary and standby



CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON ALL STANDBY;

or


CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON STANDBY;



On Primary Site :
Connect with sys and :
SQL>Alter system set  "_log_deletion_policy" = 'ALL' scope=both;

The Archivelogs will be deleted on stanby site when a "Backup Database occurs in Primary Site" !!! To be confirmed



SELECT DEST_ID,dest_name,status,type,srl,RECOVERY_MODE FROM V$ARCHIVE_DEST_STATUS;






Wednesday, 4 September 2019

dataguard log shipping problem

How to stop and start the Log shipping? With this procedure, we can simulate a disaster crash at the main site.
For our example, we use PRD and PRD-STBY to differentiate the two sites, and SAP is installed in Windows.
1 - Stop the log shipping at the PRD Site
C:\>sqlplus / as sysdba
*** Do Some validations Infos
SQL> select name,open_mode from v$database;
PRD       READ WRITE
SQL> select max(sequence#) from v$log_history;
         54275
SQL> alter system switch logfile;
SQL> select max(sequence#) from v$log_history;
         54276
SQL> select status, DEST_NAME, DESTINATION from v$archive_dest where status = 'VALID';
VALID      LOG_ARCHIVE_DEST_1    E:\oracle\PRD\saparch
VALID      LOG_ARCHIVE_DEST_2    prd_standby

SQL> show parameter LOG_ARCHIVE_DEST_2;
log_archive_dest_2     string      Service=prd_standby lgwr async
                                    VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
                                    db_unique_name=standby
SQL>

NOW DEACTIVATE THE LOG SHIPPING!!!!


SQL> alter system set log_archive_dest_state_2=defer scope=both;
System altered.

SQL> show parameter log_archive_dest_state_2
NAME                                 TYPE        VALUE
------------------------------------ ----------- -----
log_archive_dest_state_2             string      DEFER

SQL> select max(sequence#) from v$log_history;
         54276

SQL> alter system switch logfile;

SQL> select max(sequence#) from v$log_history;
         24277
You can check the Alert Log of the DR Side, you will see which last is applied and see Network Error
2 - Login to the PRD-STBY Site
C:\> NOTEPAD E:\oracle\PRD\saptrace\background\alert_PRD.log
RFS[2]: Archived Log: 'E:\ORACLE\PRD\SAPARCH\PRD_54276.1.834712720.DBF'
Primary database is in MAXIMUM PERFORMANCE mode
Sun Jun 19 12:33:32 2013
Media Recovery Log E:\ORACLE\PRD\SAPARCH\PRD_54268.1.834712720.DBF
Media Recovery Delayed for 240 minute(s) (thread 1 sequence 54269)
Sun Jun 19 12:51:27 2013
RFS[2]: Archived Log: 'E:\ORACLE\PRD\SAPARCH\PRD_54277.1.834712720.DBF'
RFS[2]: Possible network disconnect with primary database
3 -  RE-START LOG SHIPPING
3.1 – Validate the Status of Standby Database.

3.2 – Validate the last available redo-log
DIR E:\oracle\PRD\saparch\*dbf (You will see only the last shipped)

3.3 – Activate the Log Shipping (Real Production Site-PRD)

C:\>sqlplus / as sysdba
*** Do Some validations Infos
SQL> select name,open_mode from v$database;
NAME      OPEN_MODE
--------- ----------
PRD       READ WRITE

SQL> select max(sequence#) from v$log_history;
         54279

SQL> select status, DEST_NAME, DESTINATION from v$archive_dest where status = 'VALID';

STATUS     DEST_NAME             DESTINATION
---------  ----------            ----------------------------------
VALID      LOG_ARCHIVE_DEST_1    E:\oracle\PRD\saparch

SQL> show parameter LOG_ARCHIVE_DEST_2;

NAME                   TYPE        VALUE
---------------------- ----------- ---------------------------------------------
log_archive_dest_2     string      Service=prd_standby lgwr async
                                    VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
                                    db_unique_name=standby

SQL> show parameter log_archive_dest_state_2
NAME                                 TYPE        VALUE
------------------------------------ ----------- -----
log_archive_dest_state_2             string      DEFER

NOW ACTIVATE THE LOG SHIPPING!!!!


SQL> alter system set log_archive_dest_state_2=enable scope=both;

SQL> show parameter log_archive_dest_state_2
NAME                                 TYPE        VALUE
------------------------------------ ----------- -----
log_archive_dest_state_2             string      ENABLE


SQL> select max(sequence#) from v$log_history;
         54279

SQL> alter system switch logfile;

SQL> select max(sequence#) from v$log_history;
         54280

3.4 – Validate the shipping logs and appliance in theStandby Site (PRD-STBY)
DIR E:\oracle\PRD\saparch\*dbf

3.5 – Rebuild Synchronization without Delay (You are logged into the PRD-STBY Site)
C:\> SQLPLUS / AS SYSDBA
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE cancel;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;

3.6 – Validate the Status of Standby Database. (PRD_STBY)
 

3.7 – Rebuild Synchronization With 180mn Delay (3 hours for example)
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE cancel;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DELAY 180 DISCONNECT FROM SESSION;
EXIT
And you are done!

ora -600 internal error and database connectivity issue.


RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00554: initialization of internal recovery manager package failed
RMAN-04005: error from target database:
ORA-00600: internal error code, arguments: [ksm_mga_pseg_cbk_attach:map_null], [], [], [], [], [], [], [], [], [], [], []
ORA-27300: OS system dependent operation:open failed with status: 2
ORA-27301: OS failure message: No such file or directory
ORA-27302: failure occurred at: sskgm_mga_at
09-04-19 06:20:05 Alert file: /tmp/PXRPDB.rman_archivelog_backup.error_found.txt
09-04-19 06:20:05 Errors found

crsctl status res -t init

check the crsd log

/oraclebase/app/oracle/product/18.0.0/grid/log/omexd001/crsd


Featured post

Restircted session due to sync filed with ora-65177

Application is unable to connect the database due to restricted session. sql> show pdbs; SQL> show con_name CON_NAME -----------------...