搜尋此網誌

星期三, 9月 15, 2010

在dos下,如何使用無窮迴圈來作一個監控程式

在dos下,如何使用無窮迴圈來作一個監控程式

對一個dba來說,在dos 下想使用跟unix相同的工具來監控系統,會是一個很大的困擾。

今天在客戶端,為了進行tnsping的監控,user使用了tnsping {tnsname} 20

這是一個偵測資料庫是否可以連接的指令

不過,在dos下必須一直手動執行,才能繼續監控。

這對我來說是一個很不舒服的感覺。

因此我在網路上找到以下的指令:


for /l %%i in (1 1 50000) do (ping 168.95.1.1 -n 1)


其中的ping 為你想執行的系統指令,1 1 5000,代表,每由1開始,間隔1次執行,共執行至50000時停止。

不過真的執行下去,就馬上一直執行。這個結果還不能滿足我的需求,我還要他中間有暫停時間,暫停完後才再度執行指令。
---20100926補充:dos下有timeout指令,可以代替sleep來使用
可以改寫為:


for /l %i in (1 1 50000) do (
ping 168.95.1.1 -n 1 >>d:\test.log
timeout 2
)


---
然而dos下沒有sleep的指令,因此我把想法轉移到perl上面

對一個oracle dba來說,perl是你最好的朋友,只需要環境變數上,加上小小的路徑,你就可以瞬間提升功力。

這段perl的語法如下:


$num = 1;
while($num++){

print "$num\n";
system("ping 168.95.1.1 -n 1");
    sleep(2);
}

注意,這是一個無窮迴圈,若要限制次數,請修改num值,並將++改為--即可。

星期五, 9月 10, 2010

利用Wget 來抓整個網站

wget 是一個相當好的下載軟體,不過由於是命令模式介面,相較一般程式比較不易讓人接受。

基本的使用方法: wget url: 
例如:wget http://linuxreviews.org/
有關wget 使用手冊還是要靠各位自行去研讀。在網路漫遊的工具上,建議看看這二個手冊 wget (manual page) + less (manual page)。
wget 之所以強大,是在於你能對下載的網站,不斷的深入挖掘,這代表著你能挖光所有的頁面與所有的圖片。
例如: wget -r http://linuxreviews.org/

不過有的網站並不讓你下載全部的內容。這此網站是利用檢查你的流覽器( IE, FireFox,...) 版本。若他發現你不是用網頁流覽器來下載的話,會出現以下的錯誤訊息:
Sorry, but the download manager you are using to view this site is not supported. We do not support use of such download managers as flashget, go!zilla, or getright
--我們不支援下載管理器,如flashget, getright等--

Wget 可以非常方便的利用 -U 參數來對應這些網站. 使用 -U My-browser 來回應適當的版本資訊:




  wget  -r -p -U Mozilla http://www.stupidsite.com/restricedplace.html


其它重要的選項還有: --limit-rate= and --wait=. 你可以加入 --wait=20 來指定每個下載間的暫停時間(20秒), 這可以防止你被列入黑名單中而無法下載。加入 --limit-rate 預設值為 bytes, 加上 K 則為 KB/s. 
例如:
wget --wait=20 --limit-rate=20K -r -p -U Mozilla http://www.stupidsite.com/restricedplace.html
假如你只是簡單的這麼執行 wget http://foo.bar 指令, 網站管理者或許會覺得很沮喪。 而且如果你有限制下載的速度與下載的間隔時間,管理者更將不會查覺。

使用 --no-parent
--no-parent 是一個很方便的選項,這會讓wget 不會下載指定目錄外的其它檔案。

星期日, 8月 01, 2010

8/2 SQL 進階課程的建置檔

drop user Aha;
drop user Andy;
drop user Ann;
drop user Brian;
drop user Charles;
drop user Cloud;
drop user Clover;
drop user Danniel;
drop user Dennis;
drop user Dylan;
drop user Edgar;
drop user Edward;
drop user Eric;
drop user Frank;
drop user Howard;
drop user James;
drop user Jay;
drop user Jimmy;
drop user John;
drop user Joseph;
drop user Ken;
drop user kidd;
drop user Leon;
drop user Niles;
drop user Rainmo;
drop user Ray;
drop user Richie;
drop user Steven;
drop user Vincent;
drop user Walter;
drop user Xiandong;
drop user Yh;
drop user Yihhann;
drop user Apple;
drop user Banana;
drop user Cobby;
drop user Emily;
drop user Franky;
drop user Gimmy;
drop user Hocky;
drop user Ivy;
drop user Jacky;
drop user Kenny;
drop user Lemon;


create user Aha identified by Aha123 quota 100m on users;
create user Andy identified by Andy123 quota 100m on users;
create user Ann identified by Ann123 quota 100m on users;
create user Brian identified by Brian123 quota 100m on users;
create user Charles identified by Charles123 quota 100m on users;
create user Cloud identified by Cloud123 quota 100m on users;
create user Clover identified by Clover123 quota 100m on users;
create user Danniel identified by Danniel123 quota 100m on users;
create user Dennis identified by Dennis123 quota 100m on users;
create user Dylan identified by Dylan123 quota 100m on users;
create user Edgar identified by Edgar123 quota 100m on users;
create user Edward identified by Edward123 quota 100m on users;
create user Eric identified by Eric123 quota 100m on users;
create user Frank identified by Frank123 quota 100m on users;
create user Howard identified by Howard123 quota 100m on users;
create user James identified by James123 quota 100m on users;
create user Jay identified by Jay123 quota 100m on users;
create user Jimmy identified by Jimmy123 quota 100m on users;
create user John identified by John123 quota 100m on users;
create user Joseph identified by Joseph123 quota 100m on users;
create user Ken identified by Ken123 quota 100m on users;
create user kidd identified by kidd123 quota 100m on users;
create user Leon identified by Leon123 quota 100m on users;
create user Niles identified by Niles123 quota 100m on users;
create user Rainmo identified by Rainmo123 quota 100m on users;
create user Ray identified by Ray123 quota 100m on users;
create user Richie identified by Richie123 quota 100m on users;
create user Steven identified by Steven123 quota 100m on users;
create user Vincent identified by Vincent123 quota 100m on users;
create user Walter identified by Walter123 quota 100m on users;
create user Xiandong identified by Xiandong123 quota 100m on users;
create user Yh identified by Yh123 quota 100m on users;
create user Yihhann identified by Yihhann123 quota 100m on users;
create user Apple identified by Apple123 quota 100m on users;
create user Banana identified by Banana123 quota 100m on users;
create user Cobby identified by Cobby123 quota 100m on users;
create user Emily identified by Emily123 quota 100m on users;
create user Franky identified by Franky123 quota 100m on users;
create user Gimmy identified by Gimmy123 quota 100m on users;
create user Hocky identified by Hocky123 quota 100m on users;
create user Ivy identified by Ivy123 quota 100m on users;
create user Jacky identified by Jacky123 quota 100m on users;
create user Kenny identified by Kenny123 quota 100m on users;
create user Lemon identified by Lemon123 quota 100m on users;


create role rl_index;
grant connect,resource to rl_index;

create public synonym COUNTRIES for hr.COUNTRIES;
create public synonym  DEPARTMENTS for hr.DEPARTMENTS;
create public synonym EMPLOYEES for hr.EMPLOYEES;
create public synonym JOBS for hr.JOBS;
create public synonym  JOB_HISTORY for hr.JOB_HISTORY;
create public synonym LOCATIONS for hr.LOCATIONS;
create public synonym REGIONS for hr.REGIONS;


grant select on hr.COUNTRIES to rl_index;
grant select on hr.DEPARTMENTS to rl_index;
grant select on hr.EMPLOYEES to rl_index;
grant select on hr.JOBS to rl_index;
grant select on hr.JOB_HISTORY to rl_index;
grant select on hr.LOCATIONS to rl_index;
grant select on hr.REGIONS to rl_index;

grant rl_index to Aha ;
grant rl_index to Andy ;
grant rl_index to Ann ;
grant rl_index to Brian ;
grant rl_index to Charles ;
grant rl_index to Cloud ;
grant rl_index to Clover ;
grant rl_index to Danniel ;
grant rl_index to Dennis ;
grant rl_index to Dylan ;
grant rl_index to Edgar ;
grant rl_index to Edward ;
grant rl_index to Eric ;
grant rl_index to Frank ;
grant rl_index to Howard ;
grant rl_index to James ;
grant rl_index to Jay ;
grant rl_index to Jimmy ;
grant rl_index to John ;
grant rl_index to Joseph ;
grant rl_index to Ken ;
grant rl_index to kidd ;
grant rl_index to Leon ;
grant rl_index to Niles ;
grant rl_index to Rainmo ;
grant rl_index to Ray ;
grant rl_index to Richie ;
grant rl_index to Steven ;
grant rl_index to Vincent ;
grant rl_index to Walter ;
grant rl_index to Xiandong ;
grant rl_index to Yh ;
grant rl_index to Yihhann ;
grant rl_index to Apple ;
grant rl_index to Banana ;
grant rl_index to Cobby ;
grant rl_index to Emily ;
grant rl_index to Franky ;
grant rl_index to Gimmy ;
grant rl_index to Hocky ;
grant rl_index to Ivy ;
grant rl_index to Jacky ;
grant rl_index to Kenny ;
grant rl_index to Lemon ;

alter user scott identified by systex7720 account unlock;


create public synonym emp for scott.emp;
create public synonym dept for scott.dept;
create public synonym bonus for scott.dept;
create public synonym SALGRADE for scott.SALGRADE;

grant select on scott.emp to rl_index;
grant select on scott.dept to rl_index;
grant select on scott.dept to rl_index;
grant select on scott.SALGRADE to rl_index;

8/2 SQL 進階課程的練習檔

1、開啟isqlplus

2、登入自已的帳號

3、開始 autotrace
set autot on;

4、全表格掃描
select * from employees;

5、修改List 長度

6、掃描-1
全表格掃描

select * from employees;
Rowid 掃描

select * from employees where rowid='AAAAAAAAAAAAAAA';

7、索引掃描

create table big1 as select * from dba_objects;

create index big1_idx on big1(object_id);

8、收集apple 帳號下,big1 table & index 統計值

execute dbms_stats.gather_table_stats('apple','big1',cascade=>true);

select object_name from big1 where object_id=1000;

9、快速索引掃描

select count(object_id) from big1 ;

10、強迫使用index

Select object_id,object_name from big1 where object_id > 1000;

select /*+INDEX(big1 big1_idx)*/ object_id,object_name from big1 where object_id > 1000;

10、建立IOT Table

create table IOT_Big2(
OWNER   VARCHAR2(30),
OBJECT_NAME   VARCHAR2(128),
SUBOBJECT_NAME   VARCHAR2(30),
OBJECT_ID   NUMBER,
DATA_OBJECT_ID   NUMBER,
OBJECT_TYPE   VARCHAR2(19),
CREATED   DATE,
LAST_DDL_TIME   DATE,
TIMESTAMP   VARCHAR2(19),
STATUS   VARCHAR2(7),
TEMPORARY   VARCHAR2(1),
GENERATED   VARCHAR2(1),
SECONDARY   VARCHAR2(1),
constraint pk_object_id primary key(object_id))
organization index tablespace users;

複制資料
insert into iot_big2 select * from big1;

收集資料& 看差異
execute dbms_stats.gather_table_stats('apple','iot_big2',cascade=>true);

select * from user_tables;


建立額外的index在iot table 上

create index big2_idx1 on iot_big2(object_name);

11、index unusable

alter table big1 move;

. rebuild index

alter index big1_idx rebuild online;

12、尋找欄位基數

select column_name,num_distinct from user_tab_cols where table_name='BIG1';

13、clustering_factor 示範

create table t1 as select * from dba_objects order by object_name;

create table t2 as select * from t1 order by object_id;

create index t1_id_idx on t1(object_id);
create index t2_id_idx on t2(object_id);

execute dbms_stats.gather_table_stats('apple','t1');

execute dbms_stats.gather_table_stats('apple','t2');


select table_name,num_rows,blocks from user_tables where table_name in ('T1','T2');


select index_name,clustering_factor,blevel,leaf_blocks from dba_indexes where index_name in ('t1_id_idx','t2_id_idx');


Select object_id,object_name from t1 where object_id between 2000 and 3500;

Select object_id,object_name from t2 where object_id between 2000 and 3500;

14、複合index示範

create table big2 as select * from dba_objects;


create index big2_idx1 on big2(object_id);

execute dbms_stats.gather_table_stats('apple','big2');

set autot on
select object_name from big2 where object_id=1000;

create index big2_idx2 on big2(object_name);

drop index big2_idx1;
drop index big2_idx2;

create index big2_idx3 on big2(object_id,object_name);

select object_name from big2 where object_id=1000;

15、反轉index

清查目前的index
select index_name ,table_name, index_type from user_indexes;

drop index big2_idx3;

建立反轉index

create index big2_id_idx4 on big2(object_id) reverse;

基於函數索引

create index big1_name_idx on big1(object_name);
execute dbms_stats.gather_table_stats('apple','big1');


select object_id,object_name,object_type from big1 where object_name='TAB$';
select object_id,object_name,object_type from big1 where upper(object_name)='TAB$';
select object_id,object_name,object_type from big1 where object_name=upper('tab$');

drop index big1_name_idx;
drop index big1_name_idx2;
create index big1_name_idx2 on big1(upper(object_name));


16、bad sql

null & not null

select * from dept where deptno =10;
select * from dept where deptno is not null;


select ename from emp where empno != 0;

星期四, 7月 22, 2010

Oracle Trace Event

Oracle Trace Event

10000 control file debug event, name 'control_file'
10001 control file crash event1
10002 control file crash event2
10003 control file crash event3
10004 control file crash event4
10005 trace latch operations for debugging
10006 testing - block recovery forced
10007 log switch debug crash after new log select, thread %s
10008 log switch debug crash after new log header write, thread %s
10009 log switch debug crash after old log header write, thread %s
10010 Begin Transaction
10011 End Transaction
10012 Abort Transaction
10013 Instance Recovery
10014 Roll Back to Save Point
10015 Undo Segment Recovery
10016 Undo Segment extend
10017 Undo Segment Wrap
10018 Data Segment Create
10019 Data Segment Recovery
10020 partial link restored to linked list (KSG)
10021 latch cleanup for state objects (KSS)
10022 trace ktsgsp
10023 Create Save Undo Segment
10024 Write to Save Undo
10025 Extend Save Undo Segment
10026 Apply Save Undo
10027 latch cleanup for enqueue locks (KSQ)
10028 latch cleanup for enqueue resources (KSQ)
10029 session logon (KSU)
10030 session logoff (KSU)
10031 row source debug event (R*)
10032 sort end (SOR*)
10035 parse SQL statement (OPIPRS)
10036 create remote row source (QKANET)
10037 allocate remote row source (QKARWS)
10038 dump row source tree (QBADRV)
10039 type checking (OPITCA)
10040 dirty cache list
10041 dump undo records skipped
10042 trap error during undo application
10044 free list undo operations
10045 "free list update operations - ktsrsp, ktsunl"
10046 enable SQL statement timing
10047 trace switching of sessions
10048 Undo segment shrink
10049 protect library cache memory heaps
10050 sniper trace
10051 trace OPI calls
10052 don't clean up obj$
10053 CBO Enable optimizer trace
10054 trace UNDO handling in MLS
10055 trace UNDO handing
10056 dump analyze stats (kdg)
10057 suppress file names in error messages
10058 use table scan cost in tab$.spare1
10060 CBO Enable predicate dump
10061 disable SMON from cleaning temp segment
10062 disable usage of OS Roles in osds
10063 disable usage of DBA and OPER privileges in osds
10064 "thread enable debug crash level %s, thread %s"
10065 limit library cache dump information for state object dump
10066 simulate failure to verify file
10067 force redo log checksum errors - block number
10068 force redo log checksum errors - file number
10069 Trusted Oracle test event
10070 force datafile checksum errors - block number
10071 force datafile checksum errors - file number
10072 protect latch recovery memory
10073 have PMON dump info before latch cleanup
10074 default trace function mask for kst
10075 CBO Disable outer-join to regular join conversion
10076 CBO Enable cartesian product join costing
10077 CBO Disable view-merging optimization for outer-joins
10078 CBO Disable constant predicate elimination optimization
10080 dump a block on a segment list which cannot be exchanged
10081 segment High Water Mark has been advanced
10082 free list head block is the same as the last block
10083 a brand new block has been requested from space management
10084 free list becomes empty
10085 free lists have been merged
10086 CBO Enable error if kko and qka disagree on oby sort
10087 disable repair of media corrupt data blocks
10088 CBO Disable new NOT IN optimization
10089 CBO Disable index sorting
10090 invoke other events before crash recovery
10091 CBO Disable constant predicate merging
10092 CBO Disable hash join
10093 CBO Enable force hash joins
10094 before resizing a data file
10095 dump debugger commands to trace file
10096 after the cross instance call when resizing a data file
10097 after generating redo when resizing a data file
10098 after the OS has increased the size of a data file
10099 after updating the file header with the new file size
10100 after the OS has decreased the size of a data file
10101 atomic redo write recovery
10102 switch off anti-joins
10103 CBO Disable hash join swapping
10104 dump hash join statistics to trace file
10105 CBO Enable constant pred trans and MPs w WHERE-clause
10106 CBO Disable evaluating correlation pred last for NOT IN
10107 CBO Always use bitmap index
10108 CBO Don't use bitmap index
10109 CBO Disable move of negated predicates
10110 CBO Try index rowid range scans
10111 Bitmap index creation switch
10112 Bitmap index creation switch
10113 Bitmap index creation switch
10114 Bitmap index creation switch
10115 CBO Bitmap optimization use maximal expression
10116 CBO Bitmap optimization switch
10117 CBO Disable new parallel cost model
10118 CBO Enable hash join costing
10119 QKA Disable GBY sort elimination
10120 CBO Disable index fast full scan
10121 CBO Don't sort bitmap chains
10122 CBO disable count(col) => count(*) transformation
10123 QKA Disable Bitmap And-EQuals
10145 test auditing network errors
10146 enable Oracle TRACE collection
10200 block cleanout
10201 consistent read undo application
10202 consistent read block header
10203 consistent read buffer status
10204 signal recursive extend
10205 row cache debugging
10206 transaction table consistent read
10207 consistent read transactions' status report
10208 consistent read loop check
10209 enable simulated error on control file
10210 check data block integrity
10211 check index block integrity
10212 check cluster integrity
10213 crash after control file write
10214 simulate write errors on control file
10215 simulate read errors on control file
10216 dump control file header
10217 debug sequence numbers
10218 dump uba of applied undo
10219 monitor multi-pass row locking
10220 show updates to the transaction table
10221 show changes done with undo
10222 row cache
10223 transaction layer - turn on verification codes
10226 trace CR applications of undo for data operations
10227 verify (multi-piece) row structure
10228 trace application of redo by kcocbk
10230 check redo generation by copying before applying
10231 skip corrupted blocks on _table_scans_
10232 dump corrupted blocks symbolically when kcbgotten
10233 skip corrupted blocks on index operations
10234 trigger event after calling kcrapc to do redo N times
10235 check memory manager internal structures
10236 library cache manager
10237 simulate ^C (for testing purposes)
10238 instantiation manager
10239 multi-instance library cache manager
10240 dump dba's of blocks that we wait for
10241 dump SQL generated for remote execution (OPIX)
10243 simulated error for test %s of K2GTAB latch cleanup
10244 make tranids in error msgs print as 0.0.0 (for testing)
10245 simulate lock conflict error for testing PMON
10246 print trace of PMON actions to trace file
10247 Turn on scgcmn tracing. (VMS ONLY)
10248 turn on tracing for dispatchers
10249 turn on tracing for multi-stated servers
10250 Trace all allocate and free calls to the topmost SGA heap
10251 check consistency of transaction table and undo block
10252 simulate write error to data file header
10253 simulate write error to redo log
10254 trace cross-instance calls
10256 turn off multi-threaded server load balancing
10257 trace multi-threaded server load balancing
10258 force shared servers to be chosen round-robin
10259 get error message text from remote using explicit call
10260 Trace calls to SMPRSET (VMS ONLY)
10261 Limit the size of the PGA heap
10262 Don't check for memory leaks
10263 Don't free empty PGA heap extents
10264 Collect statistics on context area usage (x$ksmcx)
10265 Keep random system generated output out of error messages
10266 Trace OSD stack usage
10267 Inhibit KSEDMP for testing
10268 Don't do forward coalesce when deleting extents
10269 Don't do coalesces of free space in SMON
10270 Debug shared cursors
10271 distributed transaction after COLLECT
10272 distributed transaction before PREPARE
10273 distributed transaction after PREPARE
10274 distributed transaction before COMMIT
10275 distributed transaction after COMMIT
10276 distributed transaction before FORGET
10277 Cursor sharing (or not) related event (used for testing)
10281 maximum time to wait for process creation
10282 Inhibit signalling of other backgrounds when one dies
10286 Simulate control file open error
10287 Simulate archiver error
10288 Do not check block type in ktrget
10289 Do block dumps to trace file in hex rather than fromatted
10290 kdnchk - checkvalid event - not for general purpose use.
10291 die in dtsdrv to test controlfile undo"
10292 dump uet entries on a 1561 from dtsdrv"
10293 dump debugging information when doing block recovery"
10294 enable PERSISTENT DLM operations on non-compliant systems"
10300 disable undo compatibility check at database open
10301 Enable LCK timeout table consistency check"
10320 Enable data layer (kdtgrs) tracing of space management calls"
10352 report direct path statistics
10353 number of slots
10354 turn on direct read path for parallel query
10355 turn on direct read path for scans
10356 turn on hint usage for direct read
10357 turn on debug information for direct path
10374 parallel query server interrupt (validate lock value)
10375 turn on checks for statistics rollups
10376 turn on table queue statistics
10377 turn off load balancing
10379 direct read for rowid range scans (unimplemented)
10380 kxfp latch cleanup testing event
10381 kxfp latch cleanup testing event
10382 parallel query server interrupt (reset)
10383 auto parallelization testing event
10384 parallel dataflow scheduler tracing
10385 parallel table scan range sampling method
10386 parallel SQL hash and range statistics
10387 parallel query server interrupt (normal)
10388 parallel query server interrupt (failure)
10389 parallel query server interrupt (cleanup)
10390 Trace parallel query slave execution
10391 trace rowid range partitioning
10392 parallel query debugging bits
10393 print parallel query statistics
10394 allow parallelization of small tables
10395 adjust sample size for range table queues
10396 circumvent range table queues for queries
10397 suppress verbose parallel coordinator error reporting
10398 enable timeouts in parallel query threads
10399 use different internal maximum buffer size
10400 turn on system state dumps for shutdown debugging
10500 turn on traces for SMON
10510 turn off SMON check to offline pending offline rollbacksegment
10511 turn off SMON check to cleanup undo dictionary
10512 turn off SMON check to shrink rollback segments
10513 Disable SMON transaction cleanup
10600 check cursor frame. allocation
10602 cause an access violation (for testing purposes)
10603 cause an error to occur during truncate (for testing purposes)
10604 trace parallel create index
10605 enable parallel create index by default
10606 trace parallel create index
10607 trace index rowid partition scan
10608 trace create bitmap index
10610 trace create index pseudo optimizer
10666 Do not get database enqueue name
10667 Cause sppst to check for valid process ids
10690 Set shadow process core file dump type (Unix only)
10691 Set background process core file type (Unix only)
10700 Alter access violation exception handler
10701 Dump direct loader index keys
10702 Enable histogram data generation
10703 Simulate process death during enqueue get
10704 Print out information about what enqueues are being obtained
10706 Print out information about instance lock manipulation
10707 Simulate process death for instance registration
10708 Print out Tracing information for skxf multi instance comms
10709 enable parallel instances in create index by default
10710 trace bitmap index access
10711 trace bitmap index merge
10712 trace bitmap index or
10713 trace bitmap index and
10714 trace bitmap index minus
10715 trace bitmap index conversion to rowids
10800 disable Smart Disk scan
10801 enable Smart Disk trace
10802 reserved for Smart Disk
10803 write timing statistics on OPS recovery scan
10804 reserved for ksxb
10805 reserved for row source sort
10900 extent manager fault insertion event #%s
10924 import storage parse error ignore event
10925 trace name context forever
10926 trace name context forever
10927 trace name context forever
10928 trace name context forever
10999 do not get database enqueue name

星期日, 7月 18, 2010

Oracle Database 備份與還原設計

這是今年我作的案子。

目標是台灣的資料庫要將備份的檔案傳送至大陸。

然而因為License昂貴,因此要建立一VM,以方便其備份測試。

以下就是其架構圖

星期六, 7月 10, 2010

rman 中 expired 與 obsolete的不同

An obsolete backup differs from an expired backup. An obsolete backup is no longer needed according to the user's retention policy. An expired backup is a backup that the CROSSCHECK command fails to find on the specified media device.


一個過時的備份不同於過期的備份。一個過時的備份不再需要根據用戶的保留政策。一個過期的備份是一個備份的交叉檢驗命令無法找到指定的媒體設備.


所以如果備份檔案沒有消失不見,那麼用expired 來刪除檔案是無法刪除舊的不用檔案。


結論


1. 若你利用系統指令來刪除檔案,那麼就需要利用Crosscheck來檢查檔案後,用delete expired backup;來清除rman中的記錄。


2. 若你希望利用rman指令來刪除過期的備份記錄,請先設定


CONFIGURE RETENTION POLICY TO REDUNDANCY 2;


or


CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;


再備份完成後,再進行刪除動作


delete noprompt obsolete;

星期三, 7月 07, 2010

如何限制Client端連線到Oracle的方法

歐瑞客--尋找「自慢」絕活




如何限制Client端連線到Oracle的方法

在Oracle資料庫上限制Client連線的方法,當然有可以從網路層上限制IP,例如防火牆等方式。
應用層,例如:WebLogic設定連線資料庫的IP。 

在Oracle資料庫,可以透過不同的方式來解決這些問題。 

以下介紹兩個方式來實現這樣的功能: 

1、 修改SQLNET.ora文件來限制訪問資料庫的IP。 
2、 使用觸發器實現。 

以下範例就是使用sqlnet.ora的功能限制。 
適用版本:oracle 9i以上版本 
在9i提供了幾個參數: 
A. TCP.EXCLUDED_NODES 
   設定禁止訪問資料庫的IP地址列表。 
B. TCP.INVITED_NODES 
   設定允許訪問資料庫的IP地址列表,當這個參數和TCP.EXCLUDED_NODES設定的地址相同的時候
   將覆蓋TCP.EXCLUDED_NODES設定。 
C. TCP.VALIDNODE_CHECKING 
   檢測上述參數的設定。 

例如: 
tcp.validnode_checking=yes
#允許訪問的ip
tcp.invited_nodes =(ip1,ip2,……)
#不允許訪問的ip
tcp.excluded_nodes=(ip1,ip2,……)

透過這樣的設定就可以根據自己的需要更改, 

需要注意的問題: 
1、 需要設定參數為YES,這樣才能啟動。 
2、 建議設定允許訪問的IP,因為IP地址有可能被隨意修改,這樣比較安全。 
3、 TCP當參數TCP.INVITED_NODES和TCP.EXCLUDED_NODES設定的地址相同的時候將覆蓋TCP.EXCLUDED_NODES設定。 
4、 需要重啟監聽器才能生效。 
5、 這個方式只是適合TCP協定。 
6、 這個配置適用9i以上版本。在9i之前的版本使用文件protocol.ora。 
7、 在服務器上直接連接資料庫不受影響。 
8、 這種限制方式是透過監聽器來限制的。 
 
使用觸發器
很多時候我們需要寫一個logon trigger來進行帳號登入的控管。
在 Three-tier 架構下,大部分的程式可能都是由一個固定的帳號,
授與適當的權限經由AP Server連接到後端的Oracle資料庫來進行一般操作,
這個帳號的權限可能很大,而你並不希望programer利用這個帳號進入資料庫做一些測試動作,
因為這樣就達不到有效權限控管的要求。可是這個AP專用的帳號及密碼可能是半公開的,
你如何防止這樣的情況發生呢? 寫一個logon trigger 也許是不錯的主意。 

CREATE OR REPLACE TRIGGER LOGON_DB_TRIGGER 
AFTER LOGON ON DATABASE 
DECLARE 
IP VARCHAR2(30); 
UNAME VARCHAR2(30); 
BEGIN 
SELECT SYS_CONTEXT ('USERENV','IP_ADDRESS'),USERNAME INTO IP,UNAME FROM V$SESSION 
WHERE AUDSID=USERENV('SESSIONID');
IF IP != '10.70.36.120' AND 
UNAME = 'STEVEN' THEN 
RAISE_APPLICATION_ERROR(-20001,'Access Deny'); 
END IF; 
END LOGON_DB_TRIGGER; 

寫好這個Trigger,只要使用者帳號為STEVEN,且來源IP不是10.70.36.120都會被拒絕連線掉喔!!
這樣是不是多了些安全管控呢?特別注意一點,如果欲受限制的帳號權限為DBA or SYSDBA者,
將不受此Trigger管制。 

刪除觸發器
DROP TRIGGER LOGON_DB_TRIGGER;