2017年10月30日 星期一

oracle LOGICAL_STANDBY_DB

與 physical standby db 的差異

http://www.dba-oracle.com/t_difference_logical_physical_standby_database.htm

In  Oracle Data Guard you, Oracle transfers data from the main database to a standby database, and in case of failures, Oracle will switch over to the standby database.  We have two ways to create a standby database, logical standby and physical standby:
Physical standby differs from logical standby:
  • Physical standby schema matches exactly the source database.
  • Archived redo logs and FTP'ed directly to the standby database which is always running in "recover" mode.  Upon arrival, the archived redo logs are applied directly to the standby database.
Logical standby is different from physical standby:
  • Logical standby database does not have to match the schema structure of the source database.
     
  • Logical standby uses LogMiner techniques to transform the archived redo logs into native DML statements (insert, update, delete).  This DML is transported and applied to the standby database.
     
  • Logical standby tables can be open for SQL queries (read only), and all other standby tables can be open for updates.
     
  • Logical standby database can have additional materialized views and indexes added for faster performance.
Installing Physical standbys offers these benefits:
  • An identical physical copy of the primary database
  • Disaster recovery and high availability
  • High Data protection
  • Reduction in primary database workload
  • Performance Faster
Installing Logical standbys offer:
  • Simultaneous use for reporting, summations and queries
  • Efficient use of standby hardware resources
  • Reduction in primary database workload
  • Some limitations on the use of certain datatypes

For more complete differences between logical and physical standby databases, see the book "Oracle Data Guard", by Bipul Kumar.


Create Logical Standby DB


需要用 PK 或 unique index 識別唯一值

在 DBA_LOGSTDBY_NOT_UNIQUE 可以查到無法識別出的表


2017年10月24日 星期二

Ubuntu 16.04 LTS Template 要調整的東西

1. 打開  ipv4 DHCP

sudo nano /etc/network/interfaces

auto enp0s25
iface enp0s25 inet dhcp


要改成固定IP的話

auto enp0s25
iface enp0s25 inet static
address 192.168.0.16
netmask 255.255.255.0
gateway 192.168.0.1
dns-nameservers 8.8.4.4 8.8.8.8


2. disable ivp6 

/etc/sysctl.conf
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

allow root login

  1. sudo nano /etc/ssh/sshd_config
    1. change
      PermitRootLogin prohibit-password
    to
    PermitRootLogin yes 
    
    or sudo sed -i 's/prohibit-password/yes/' /etc/ssh/sshd_config
    1. in order to PAM authentication add
      AllowUsers root
    or sudo echo "AllowUsers root" >> /etc/ssh/sshd_config
    1. sudo service ssh restart
works fine
in order you don't know your root password set new with privileged user
sudo passwd root





“Shockwave Flash has crashed” workaround for vSphere Web (Flash) Client

https://www.virtuallyghetto.com/2017/10/shockwave-flash-has-crashed-workaround-for-vsphere-web-flash-client.html


原因可能是:
After a bit of back/fourth and a few other folks chiming in, it looks like Google actually went and published a newer version of Flash (27.0.0.170) with latest Chrome (61.0.3163.100) update. This newer Flash version is not even available for download and the current version as listed on Adobe's website should be 27.0.0.159. This issue not only affects VMware products that uses Flash but any website that has Flash content and I had also noticed few others sharing frustrations on Twitter for other flash-based websites.

解法:
UPDATE5 (10/18/2017) - Adobe has just published a new beta build of Flash which includes both the security fix as well as the fix resolving the vSphere Web Client as well as other VMware-based products that rely on Flash (e.g. vCloud Director, etc). Depending on the platform, you may need to un-install the previous version of Flash and make sure you restart your browser. I just verified on my macOS system that I can now logon to a vSphere Web (Flex) Client without issues.
For Windows, the path is %LocalAppData%\Google\Chrome\User Data\PepperFlash
For macOS, the path is ~/Library/Application\ Support/Google/Chrome/PepperFlash


2017年10月20日 星期五

用 sed 在 xml 裡新增收件者

find * -name 'resource_*.xml' -exec grep -H -i "w33" {} \;|awk -F":" '{print "sed -i.bak -e \x27\\#w33#a\\\\x9\\x9<receiver user=\x22三五\x22 >w35@mail.XXX.XXX.tw</receiver>\x27 "$1 " "}'

* 印不出來的時候用 \x 代替

"  =  \x22
'   =  \x27
\t  =  \x9


* 在 sed 要換  delimiters 的時候前面要加一個 \

# do this (ugly)...
sed '/\/a\/b\/c\//{do something;}'
# ...or these (better)
sed '\#/a/b/c/#{do something;}'
sed '\_/a/b/c/_{do something;}'
sed '\%/a/b/c/%{do something;}'
# etc.

http://backreference.org/2010/02/20/using-different-delimiters-in-sed/

* grep  可以用  -H  印出檔名

* sed 要印 兩個 tab 的時候用  \\x9\x9 ,丟到 awk 裡面的話 前面各再加一個 \

* sed 真的要跑的時候加上 -i.bak -e 'SCRIPT' 就會真的改

* sed '/PATT/aNEW' 代表在 MATCH 到 PATT 這個 pattern 的後面一行加上 NEW



*sed 把換行符號拿掉

sed ':a;N;$!ba;s/\n/ /g' file
sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/ /g' file

https://stackoverflow.com/questions/1251999/how-can-i-replace-a-newline-n-using-sed


  1. Create a label via :a.
  2. Append the current and next line to the pattern space via N.
  3. If we are before the last line, branch to the created label $!ba ($! means not to do it on the last line as there should be one final newline).
  4. Finally the substitution replaces every newline with a space on the pattern space (which is the whole file).

2017年10月17日 星期二

CDS 7 版掛載 oracle db and recovery

--MAXDATAFILES

在  /act/act_scripts/oracleclone/Clone_generateCtrlFileScript.sh
裡面指定了 MAXDATAFILES=4000
每次更新完要手動改這個script 不然掛主資料庫的時候一定會死掉

掛載完之後,主要的SCRIPT是 AppMount.sh

要處理的部分:

SGA底下的參數要拿掉
在 no mount 下 re-create control file
recover



./Clone_generateCtrlFileScript.sh hisspx /act/mnt/Job_3769585_mountpoint_1508134264362/datafile /act/mnt/Job_3769585_mountpoint_1508134264362/



chown oracle10:dba /act/mnt/Job_3769585_mountpoint_1508134264362/hisspx

f7n3:/act/act_scripts/oracleclone> ./recoverRman.sh /act/mnt/Job_3769585_mountpoint_1508134264362/ hisspx




SQL> startup nomount pfile='/act/mnt/Job_3769585_mountpoint_1508134264362/inithisspx.ora';
ORA-01081: cannot start already-running ORACLE - shut it down first
SQL> @/act/act_scripts/oracleclone/Clone_createCtrlFile_hisspx_g.sql;

Control file created.

SQL>



SQL> alter database open read only;
alter database open read only
*
ERROR at line 1:
ORA-16008: indeterminate control file checkpoint

SQL> alter database open resetlogs;

Database altered.

SQL>



Step By Step

Application Manager 選擇要使用的 APP , 選擇 Restore , 選擇要掛的版本,選擇 mount

選擇 storage pool 擺在比較空的地方

選擇 mount point (不選的話會放在 /act/mnt/JobXXXXXX )

選擇要掛的 HOST  <-- 注意不要選錯

選 App Aware Mount

填 sid , username , ORACLE_HOME , TNS_ADMIN , DB MEM , SGA% ,

Redo / shared_pool / db_cache , db_recovery_fiel_dest_size 都填 100
( 不填值的話會抓 backup pfile 裡的值,碰到比較小的機器就會炸)

跑完以後

f7n3:/> sqlplus "/as sysdba"

SQL*Plus: Release 10.2.0.4.0 - Production on Tue Oct 17 15:33:40 2017

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.

Connected to an idle instance.

沒起來 看看原因

SQL> startup;
ORA-00821: Specified value of sga_target 4112M is too small, needs to be at least 31024M
SQL>

SGA不夠大...

到掛載點下找 pfile

*.db_keep_cache_size=32212254720
*.log_buffer=62914560
*.sort_area_size=1024000
*.shared_pool_size=100m
*.db_cache_size=100m
*.db_recovery_file_dest='/hisspx/flash_recovery_area/hisspx'
*.db_recovery_file_dest_size=100m

把這些抓掉

然後指定 pfile 重開看看

SQL> startup pfile=/hisspx/inithisspx.ora;
ORACLE instance started.

Total System Global Area 4311744512 bytes
Fixed Size                  2089576 bytes
Variable Size             805309848 bytes
Database Buffers         3489660928 bytes
Redo Buffers               14684160 bytes
ORA-00205: error in identifying control file, check alert log for more info

找不到 control file ...
翻一下 pfile 看看 control file 在哪裡...

*.control_files='/hisspx/admin/hisspx/control/control01.ctl','/hisspx/admin/hisspx/control/control02.ctl'

f7n3:/hisspx> ls -alh /hisspx/admin/hisspx/control/             
total 0
drwxr-xr-x  2 oracle10 dba 256 2017-10-17 15:30 .
drwxr-xr-x  6 oracle10 dba 256 2017-10-17 15:30 ..
f7n3:/hisspx>

空的 -_____-

因為要抓 control file 就挫塞了 所以現在應該是在 no mount 模式

在  /act/act_scripts/oracleclone  底下有一個  Clone_generateCtrlFileScript.sh 
是用來長 control file 用的.

參考了一下 OracleAppMount.sh  這隻的使用方式應該是

./Clone_generateCtrlFileScript.sh $nsid $backupdir $ORACLE_BASE"/oradata"

nsid 是新的 db 的 SID ,  第二個參數應該是備份目錄的掛載點 , 
第三個參數好像是用來長 redo 用的 , redo會長在  $BASEDIR/$SID/redo*.log
--> oracle owner 要對 redo 所在的位置有讀寫權 不然 redo 會 create fail .

所以 
f7n3:/act/act_scripts/oracleclone> ./Clone_generateCtrlFileScript.sh hisspx /hisspx /hisspx/oradata

----
修正一下 第二個參數是用來找備份的 datafile 用的 ,要告訴它 datafile 所在的位置

f7n3:/act/act_scripts/oracleclone> ./Clone_generateCtrlFileScript.sh hisspx /hisspx/datafile /hisspx/oradata
----
跑完之後會長出一個 Clone_createCtrlFile_hisspx_g.sql
內容就是 recreate control  file

CREATE CONTROLFILE SET DATABASE hisspx RESETLOGS ......之類的

回到 sqlplus 下,因為現在是在 no mount mode ,所以可以直接

SQL> @Clone_createCtrlFile_hisspx_g.sql

Control file created.

SQL> 

來開開看

SQL> startup pfile=/hisspx/inithisspx.ora;
ORA-01081: cannot start already-running ORACLE - shut it down first
SQL>

SQL> alter database open read only;
alter database open read only
*
ERROR at line 1:
ORA-16008: indeterminate control file checkpoint

SQL>

好像需要 recovrey 的樣子
再回到 /act/act_scripts/oracleclone  有一隻 recoverRman.sh 看起來是用來 recover 用的

需要兩個參數 備份掛載點 跟 新的DB的SID

./recoverRman.sh /hisspx hisspx

log 檔會寫在   dbrecover.txt  裡,可以 tail 看現在的進度

f7n3:/act/act_scripts/oracleclone> id
uid=206(oracle10) gid=205(dba) groups=202(spadmin)
f7n3:/act/act_scripts/oracleclone> export ORACLE_SID=hisspx
f7n3:/act/act_scripts/oracleclone> ./recoverRman.sh /hisspx hisspx
******* recovering database *********** 
run { catalog start with '/hisspx/archivelog' noprompt; recover database; }
RMAN> 2> 3> 4> 5> RMAN> f7n3:/act/act_scripts/oracleclone>

channel ORA_DISK_1: restore complete, elapsed time: 00:00:16
archive log filename=/hisspx/admin/hisspx/archivelog/1_811335_766335352.dbf thread=1 sequence=811335
archive log filename=/hisspx/admin/hisspx/archivelog/1_811336_766335352.dbf thread=1 sequence=811336
archive log filename=/hisspx/admin/hisspx/archivelog/1_811337_766335352.dbf thread=1 sequence=811337
archive log filename=/hisspx/admin/hisspx/archivelog/1_811338_766335352.dbf thread=1 sequence=811338
unable to find archive log
archive log thread=1 sequence=811339
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 10/17/2017 16:22:33
RMAN-06054: media recovery requesting unknown log: thread 1 seq 811339 lowscn 177120294171

RMAN> 

Recovery Manager complete.

跑到後來還是會有錯 不過也沒有後面的 archive log 可以用了。 直接 reset 吧

--BTW, 這時候應已經是 mount mode 了

SQL> alter database open resetlogs;  

Database altered.

SQL>alter system register;



TODO: 應該可以找一下 script 把炸的地方改掉
然後每隻 agent 都要去改一下....


補

在 nid_hisspx.log 發現 open_cursors 不足造成 change dbid fail

ORA-01000: maximum open cursors exceeded

由於desktop 在 7.0.3 沒有指定這個參數的功能

原廠建議手動加 alter system set open_cursors=1000 scope=both;

在 OracleAppMountComFunc.sh 有個 change_dbid 的 function

看起來是在用 nid 做 change dbid 的動作 先加在那邊看看

** 其實這個參數好像有寫在 pfile 裡,應該也可以在一開始用 sed 做 pfile 的時候就抓掉。

** 看起來是在每個檔案 change dbid 的時候炸的 如果每個檔案同時需要開 一個 cursor 那應該要改到跟 MAXFILES 一樣大...




2017/10/20 測試,好像可以開起來,不過 recover 就跑了快一個小時...
大約整趟跑完要 90min左右 ,  paging 會吃到快25%