搜尋此網誌

星期日, 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;

星期四, 3月 11, 2010





如何使用Google Mail - GMAIL

Gmail是GOOGLE 所提供的免費服務之一,目前(3/11/2009)每個信箱的容量有7432MB。Gmail有幾項特色:(此文資料是擷取自Gmail說明)


封存取代刪除

您不必刪除郵件,一樣可以妥當整理收件匣,而且隨時可以運用搜尋功能或在 [所有郵件] 中尋找封存郵件。

即時通訊及視訊通訊

您可以直接在 Gmail 中與聯絡人進行即時通訊,甚至透過內建的視訊通訊功能面對面暢談。

標籤取代資料夾

標籤除了具備資料夾的各項功能,還有一個額外優點:您可以為一封電子郵件加上多個標籤。


與其它Google 工具結合
Google 聯絡人,Google Talk, Goolgle Docs, Google Buzz, Google News等。

新增功能陸續增加中
Google Labs 研發各種Google 好用的工具集。


一、Gmail 設定

請在登入Gmail後,右上方點選設定

?一般:
Ⅰ、語言:設定你預設顯示的語言
Ⅱ、瀏覽器連線:設定自動為安全且加密的連線。
Ⅲ、簽名:如果你希望在每封信後,有你的相關聯絡方式與公司職稱, 可以在此填寫。
Ⅳ、休假回覆:當你在休息時,為了避免有人認為你怎麼都不回信,可以設定自動回覆通知,讓其它人能知道你正在休假。
Ⅴ、外寄郵件編碼:
每一次傳送郵件時,Gmail 會依您撰寫郵件的語言自動選取適當的編碼。不過,收件人有可能無法正確檢視您傳送的郵件。如果您聯絡的人無法檢視您傳送給他們的郵件,建議使用 「UTF-8」(Unicode) 來傳送所有郵件。UTF-8 是許多電子郵件用戶端程式可以接受的標準編碼。
Ⅵ、進階附件功能:
進階附件功能
 - 當您附加檔案至郵件時,以功能會顯示進度列,並讓您能同時附加多個檔案。必須安裝 Flash 才能使用。 
基本附件功能
 - 一次附加一個檔案,並且不顯示進度列。
?帳戶和匯入:
Ⅰ、匯入郵件與聯絡人:如果您要從其他電子郵件供應商的服務轉換到 Gmail,您只要匯入舊電子郵件帳戶的通訊錄和郵件,就可以輕鬆轉移內容,省去許多麻煩手續。

Ⅱ、以這個地址寄送郵件:Gmail 的自訂寄件者功能可讓您設定寄件地址,以其他的電子郵件地址傳送郵件,以便運用 Gmail 介面輕鬆管理多個帳戶。如要查看詳細設定方式,請在下方點選適用的選項。

Ⅲ、以pop3檢查郵件:Gmail 的 Mail Fetcher 最多可以從五個其他電子郵件帳戶下載郵件,將您所有的電子郵件集中至 Gmail。

Ⅳ、增加更多儲存容量:
?標籤:Gmail 並不使用資料夾。 為了協助您更有效地組織郵件,Gmail 改用標籤 。


標籤
資料夾
一個會話群組可以有一個以上的標籤
一封郵件只能放在一個資料夾內
會話群組可以同時存放在幾個不同位置 ([收件匣]、[所有郵 件]、[寄件備份] 等),便於日後找到
您必須記得歸檔郵件的位置,才能找到它
您可以依標籤搜尋會話群組
您有時候無法進行特定資料夾的搜尋
標籤使用方式

列印 
標籤除了具備資料夾的各項功能,還有一個額外優點:您可以為同一個會話群組 加上多個標籤。為郵件加上標籤之後,透過搜尋或按一下 Gmail 網頁左側的標籤名稱,即可查看所有標示該標籤的郵件。
建立、編輯和刪除既有標籤的方法很簡單,請按照以下步驟操作:
如何建立標籤:

按一下 [標籤] 下拉式選單 (已啟用鍵盤快速鍵時,按下 l 鍵也可開啟這個選單),或是依序按一下 [設定] 和 [標籤]。
選取 [建立新的]。
輸入新標籤的名稱,然後按一下 [確定]。
系統會將您選取的所有郵件自動歸類在新標籤底下。如果想讓收件匣看起來井然有序,建議您封存 已加上標籤的會話群組,系統即會將其移出收件匣。當您日後需要查閱這些郵件時,只要按一下 [所有郵件] 或 Gmail 網頁左側的標籤名稱,仍然可以找到這些郵件。想為郵件套用標籤時,請勾選郵件旁邊的核取方塊,然後從 [標籤] 下拉式選單中選取所需的標籤名稱。您也可以在閱讀單一郵件時,按一下該下拉式選單 (或按鍵盤快速鍵 L 鍵開啟此選單),然後選取所需標籤。此外,把郵件拖曳至標籤名稱上,也可將郵件移至標籤底下。
如何編輯標籤名稱:
按一下標籤左側的向下箭頭。
選取 [重新命名]。
輸入新的標籤名稱,然後按一下 [確定]。
原先在舊標籤名稱底下的郵件將歸類至新標籤底下。整理和刪除標籤
您可以選擇是否在左側清單中顯示標籤。
依序按一下 [設定] 及 [標籤]。
按一下每個標籤旁邊的 [顯示] 或 [隱藏] 連結,指定是否要顯示各個標籤。當您不再需要特定標籤時,請按一下 [移除] (別忘了按一下 [確定] 來確認移除標籤)。
您也可以按一下每個標籤左側的向下箭頭,逐一選擇要顯示、隱藏或刪除該標籤。如果您想為郵件套用某個標籤,並將郵件移至該標籤底下,請在 [移至] 下拉式選單中選取標籤 (按鍵盤快速鍵 v 鍵也可開啟該選單)。
?篩選器:
Gmail 篩選器可供管理內收郵件的流程。 您可以在篩選器中搭用關鍵字、寄件者、收件者及其他欄位,來自動標明 、封存、刪除郵件、為郵件加上星號或轉寄郵件,還可以阻擋垃圾郵件。
建立篩選器的步驟如下:

按一下 [建立篩選器] (在任何 Gmail 頁面頂端 [搜尋網頁] 按鈕旁)。

在適當欄位中輸入您的篩選條件。

如果您要查看 Gmail 中目前有哪些郵件符合篩選字詞,請按一下 [測試搜尋]。 您可以更新條件,並重新搜尋一次,或按一下 [下一步]。

從清單中選取一或多個動作。 這些動作將套用到符合篩選條件的郵件,並按照各種動作排列的順序套用。例如,您可以選擇將符合的郵件 [轉寄] 到特定的電子郵件地址,然後 [刪除] 該郵件。

如果您想將這個篩選器套用到 Gmail 中的郵件,請選取 [同時套用篩選器到以下的 x 個會話群組] 核取方塊。

按一下 [建立篩選器]。
根據郵件建立篩選器的步驟如下:

按一下 [回覆] 旁的下拉式選單。

選取 [篩選這一類的郵件]。

在適當欄位中輸入您的篩選條件。
編輯或刪除現有篩選器的步驟如下︰

按一下任何 Gmail 網頁右上方的 [設定]。

按一下 [篩選器]。

選取您要變更的篩選器,並按一下其 [編輯] 連結,或按一下 [刪除] 來移除篩選器。

如果您要編輯篩選器,請更新適當欄位的篩選器條件,並按 [下一步]。

接著請更新動作,然後按一下 [更新篩選器]。
您可以建立無數個篩選器,但只有 20 個篩選器可以將郵件轉寄到其他地址。 當多個篩選器轉寄郵件的地址相同時,您可以結合多個篩選器 ,來發揮轉寄篩選結果功能。

二、設定信箱在outlook express & outlook
設定 Outlook Express 用戶端使用 Gmail:
在您的電子郵件帳戶中啟用 POP 。設定完成時請記得按一下 [儲存變更]。

開啟 Outlook 或 Outlook Express。

按一下 [工具] 選單,並選取 [帳戶...]。

按一下 [新增] 然後按一下 [郵件...]。

在 [顯示名稱] 欄位中輸入您的姓名,並按一下 [下一步]。

請在 [電子郵件地址] 欄位中輸入完整的 Gmail 電子郵件地址 (使用者名稱@gmail.com),然後按一下[ 下一步]。Google 應用服務使用者請以「username@your_domain.com」格式輸入您的完整地址。

在 [內收郵件 (POP3、IMAP 或 HTTP) 伺服器:] 欄位中輸入 pop.gmail.com。在 [外寄郵件伺服器 - SMTP:] 欄位中輸入 smtp.gmail.com。如果您是「Google 應用服務」使用者,請輸入系統提供的伺服器名稱,且勿在這個步驟中新增網域名稱。

按 [下一步]。

在 [帳戶名稱] 欄位中輸入完整的電子郵件地址 (包含 @gmail.com 或 @您的網域.com),在 [密碼] 欄位中輸入您的電子郵件密碼,然後按一下 [下一步]。

按一下 [完成]。

反白選取 [帳戶] 欄中的 [pop.gmail.com],並按一下 [內容]。

按一下 [進階] 標籤。

填寫下列資訊:*

勾選 [外寄郵件 - SMTP:] 下的 [這個伺服器需要安全連線 - SSL] 方塊。
在 [外寄郵件 - SMTP:] 欄位中輸入 465。
勾選 [外寄郵件 - SMTP:] 下的 [這個伺服器需要安全連線 - SSL] 方塊。
勾選 [內送郵件 - POP3:] 下的 [這個伺服器需要安全連線 - SSL] 方塊,通訊埠將變更為 995。

*每種版本的「外寄」和「內送」郵件伺服器欄位次序不同,請確定您在欄位中輸入了正確的資訊。

返回 [伺服器] 標籤並勾選 [我的伺服器需要驗證] 方塊。

按一下 [確定]。
恭喜!現在已完成設定您的用戶端,可以開始傳送及接收 Gmail 郵件。

星期四, 4月 02, 2009

Oracle 10g expdp impdb

如何使用expdb & impdb
1. 建立exp directory
exp 與 expdp 使用上,最大的不同點在於exp directory
傳統的exp 不用建立,直接在執行的語法中宣告即可,而expdb必須先行宣告在資料庫中。
建立的範例:
create directory expdb_dir as '/u01/expdb';

2. 賦與 exp directory 權限
若一般的使用者想使用此目錄,必須賦與相對應的權限
如:
grant read, write on directory expdb_dir to scott;

當然囉,DBA是有無上的權限…所以如果你是DBA身份,那就不用grant。

3. 導出 expdb 資料

有用過舊版exp 的使用者,經常作的不外乎
α、full database export
β、user export
ν、table export

這邊簡單的列出這幾種需求所執行的指令:
●full database export
expdb username/password@dbname directory=expdb_dir dumpfile=fulldb.dmp full=y
●user export
expdb username/password@dbname directory=expdb_dir dumpfile=schema.dmp schemas=scott
●table export
expdb username/password@dbname directory=expdb_dir dumpfile=table.dmp tables=emp.employer


4. 匯入 impdb 資料

匯入資料一般會作的是
α、full database import
β、user import (to another schema)
ν、table import

這邊簡單的列出這幾種需求所執行的指令:

●impdp username/password@dbname directory=expdb_dir dumpfile=fulldb.dmp full=y
●impdp username/password@dbname directory=expdb_dir dumpfile=fulldb.dmp remap_schema=source_schema:dest_schema
●impdp username/password@dbname directory=expdb_dir dumpfile=fulldb.dmp tables=my,big,list,of,tables

另外,還可以更換原先table的tablespace, 只需增加 remap_tablespace=source_tablespace:dest_tablespace即可

expdp 與 impdp 還有許多選項可以使用,請自參考expdp help=y or impdp help=y

星期一, 3月 09, 2009

星期日, 3月 08, 2009

如何將備份的partition table 還原至現有的table中

如何exp table 中特定的partition

例:將toyman中,fe_tb_cm_session_hist中,partition name為CM_SES_HIST_200812
fe_tb_cm_session_comm_hist中,partition name為CM_SES_COMM_HIST_200812
exp system FILE =toyman-p1.dmp TABLES = toyman.fe_tb_cm_session_hist:CM_SES_HIST_200812,toyman.fe_tb_cm_session_comm_hist:CM_SES_COMM_HIST_200812

我們將12月份的partition export 出來後,必須先在原先的table 中新增partition 為12月份的
不過由於partition table 不能新增一個舊時間的partition, 因此必須利用split partition指令來分割。

ALTER TABLE toyman.FE_TB_CM_SESSION_HIST
SPLIT PARTITION CM_SES_HIST_200901 AT
(TO_DATE(' 2009-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
INTO (PARTITION CM_SES_HIST_200812,
PARTITION CM_SES_HIST_200901);

最後再以imp 的方式將data import 至資料庫

imp system FILE =toyman-p1.dmp TABLES = toyman.fe_tb_cm_session_hist:CM_SES_HIST_200812,toyman.fe_tb_cm_session_comm_hist:CM_SES_COMM_HIST_200812 IGNORE=y

此例中的index 是partition local index, 如果是global index 請記得重新compiler.

星期三, 3月 04, 2009

Oracle DB parameter for OS dependence

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

# for HP-UX DB server only

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

filesystemio_options=setall

hpux_sched_noage=178




This Doc will be continue updated.