ERROR OGG-01224 TCP/IP error 110 (Connection timed out); retries exceeded.

Cause

This is generally due due to basic issues like:
* The remote manager process is not running or is running with incorrect port number
* The RMTHOST parameter in the pump extract is not configured correctly.
In other cases, the issue could be due to firewalls that forbid the connection,
blocking certain ports or processes.
This is generally seen when there is a firewall between the source and target machine and
either the ports are not open or just the manager port is open.

Solution

The Extract, Replicat and Ggsci processes use ports normally starting at port 7840 and ascend sequentially.
The ggsci command 'send manager getportinfo detail ' will retrieve the current list of ports that have been
allocated by Manager and their corresponding process IDs.
If you have some port restrictions, then you could use the DYNAMICPORTLIST with some range so that the
collector process will allocate the ports from that range.
In general to overcome this issue, we could do something like below
1. Change the target manager parameter file to use something like the following
port 7809
dynamicportlist 7810-7820
2. Stop and start the manager
3. Open ports 7809 through 7820 in the firewall
4. Re-start the source pump
The port range used in dynamicportlist(7810-7820) and the manager port 7809 is just an example.
You can define your own ports there and have them open.

OGG Extract Pump abended with ERROR OGG-01224 TCP/IP error 110 (Connection timed out); retries exceeded

让人少走弯路的十大忠告

1.买个闹钟,以便按时叫醒你。
  自贪睡和不守时,都将成为你工作和事业上的绊脚石,任何时候都一样。不仅要学会准时,更要学会提前。就如你坐车去某地,沿途的风景很美,你忍不住下车看一看,后来虽然你还是赶到了某地,却不是准时到达。“闹钟”只是一种简单的标志和提示,真正灵活、实用的时间,掌握在每个人的心中。

2.如果你不喜欢现在的工作,要么辞职不干,要么就闭嘴不言。
  初出茅庐,往往眼高手低,心高气傲,大事做不了,小事不愿做。不要养成挑三拣四的习惯。不要雨天烦打伞,不带伞又怕淋雨,处处表现出不满的情绪。记住,不做则已,要做就要做好。

3.每个人都有孤独的时候。
  要学会忍受孤独,这样才会成熟起来。年轻人嘻嘻哈哈、打打闹闹惯了,到了一个陌生的环境,面对形形色色的人和事,一下子不知所措起来,有时连一个可以倾心说话的地方也没有。这时,千万别浮躁,学会静心,学会忍受孤独。在孤独中思考,在思考中成熟,在成熟中升华。不要因为寂寞而乱了方寸,而去做无聊无益的事情,白白浪费了宝贵的时间。

4.走运时要做好倒霉的准备。
  有一天,一只狐狸走到一个葡萄园外,看见里面水灵灵的葡萄垂涎欲滴。可是外面有栅栏挡着,无法进去。于是它一狠心绝食三日,减肥之后,终于钻进葡萄园内饱餐一顿。当它心满意足地想离开葡萄园时,发觉自己吃得太饱,怎么也钻不出栅栏了。相信任何人都不愿做这样的狐狸。退路同样重要。饱带干粮,晴带雨伞,点滴积累,水到渠成。有的东西今天似乎一文不值,但有朝一日也许就会身价百倍。

5.不要像玻璃那样脆弱。
  有的人眼睛总盯着自己,所以长不高看不远;总是喜欢怨天尤人,也使别人无比厌烦。没有苦中苦,哪来甜中甜?不要像玻璃那样脆弱,而应像水晶一样透明,太阳一样辉煌,腊梅一样坚强。既然睁开眼睛享受风的清凉,就不要埋怨风中细小的沙粒。

6.管住自己的嘴巴。
  不要谈论自己,更不要议论别人。谈论自己往往会自大虚伪,在名不副实中失去自己。议论别人往往陷入鸡毛蒜皮的是非口舌中纠缠不清。每天下班后和你的那些同事朋友喝酒聊天可不是件好事,因为,这中间往往会把议论同事、朋友当做话题。背后议论人总是不好的,尤其是议论别人的短处,这些会降低你的人格。

7.机会从不会“失掉”,你失掉了,自有别人会得到。
  不要凡事在天,守株待兔,更不要寄希望于“机会”。机会只不过是相对于充分准备而又善于创造机会的人而言的。也许,你正为失去一个机会而懊悔、埋怨的时候,机会正被你对面那个同样的“倒霉鬼”给抓住了。没有机会,就要创造机会,有了机会,就要巧妙地抓住。

8.若电话老是不响,你该打出去。
  很多时候,电话会给你带来意想不到的收获,它不是花瓶,仅仅成为一种摆设。交了新朋友,别忘了老朋友,朋友多了路好走。交际的一大诀窍就是主动。好的人缘好的口碑,往往助你的事业更上一个台阶。

9.千万不要因为自己已经到了结婚年龄而草率结婚。
  想结婚,就要找一个能和你心心相印、相辅相携的伴侣。不要因为放纵和游戏而恋爱,不要因为恋爱而影响工作和事业,更不要因一桩草率而失败的婚姻而使人生受阻。感情用事往往会因小失大。

10.写出你一生要做的事情,把单子放在皮夹里,经常拿出来看。
  人生要有目标,要有计划,要有提醒,要有紧迫感。一个又一个小目标串起来,就成了你一生的大目标。生活富足了,环境改善了,不要忘了皮夹里那张看似薄薄的单子。

ogg中Time Since Chkpt显示unknown解决

1、异常现象

[oracle@localhost ~]$ ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 11.1.1.0.0 Build 078
Linux, x64, 64bit (optimized), Oracle 10 on Jul 28 2010 13:21:11
Copyright (C) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
GGSCI (localhost.localdomain) 1> info all
Program     Status      Group       Lag           Time Since Chkpt
MANAGER     RUNNING
EXTRACT     RUNNING     EXT-ECP     00:00:00      unknown
EXTRACT     RUNNING     EXT-EDS     00:00:00      unknown
EXTRACT     RUNNING     EXT-XZ      00:00:00      unknown
EXTRACT     RUNNING     P-EDS       00:00:00      unknown
EXTRACT     RUNNING     P-XZ        00:00:00      unknown
REPLICAT    RUNNING     REP-BOS     00:00:00      unknown

2、尝试关闭异常进程重启

GGSCI (localhost.localdomain) 2> stop *
Sending STOP request to EXTRACT EXT-ECP ...
ERROR: sending message to EXTRACT EXT-ECP (Timeout waiting for message).
Sending STOP request to EXTRACT EXT-EDS ...
ERROR: sending message to EXTRACT EXT-EDS (Timeout waiting for message).
Sending STOP request to EXTRACT EXT-XZ ...
ERROR: sending message to EXTRACT EXT-XZ (Timeout waiting for message).
Sending STOP request to EXTRACT P-EDS ...
ERROR: sending message to EXTRACT P-EDS (Timeout waiting for message).
Sending STOP request to EXTRACT P-XZ ...
ERROR: sending message to EXTRACT P-XZ (Timeout waiting for message).
Sending STOP request to REPLICAT REP-BOS ...
ERROR: sending message to REPLICAT REP-BOS (Timeout waiting for message).
GGSCI (localhost.localdomain) 3> stop mgr!
Sending STOP request to MANAGER ...
Request processed.
Manager stopped.
GGSCI (localhost.localdomain) 4> info all
Program     Status      Group       Lag           Time Since Chkpt
MANAGER     STOPPED
EXTRACT     RUNNING     EXT-ECP     00:00:00      unknown
EXTRACT     RUNNING     EXT-EDS     00:00:00      unknown
EXTRACT     RUNNING     EXT-XZ      00:00:00      unknown
EXTRACT     RUNNING     P-EDS       00:00:00      unknown
EXTRACT     RUNNING     P-XZ        00:00:00      unknown
REPLICAT    RUNNING     REP-BOS     00:00:00      unknown
GGSCI (localhost.localdomain) 5> kill EXT-ECP
ERROR: Manager not currently running.
GGSCI (localhost.localdomain) 6> kill EXT-EDS
ERROR: Manager not currently running.
GGSCI (localhost.localdomain) 7> info all
Program     Status      Group       Lag           Time Since Chkpt
MANAGER     STOPPED
EXTRACT     RUNNING     EXT-ECP     00:00:00      unknown
EXTRACT     RUNNING     EXT-EDS     00:00:00      unknown
EXTRACT     RUNNING     EXT-XZ      00:00:00      unknown
EXTRACT     RUNNING     P-EDS       00:00:00      unknown
EXTRACT     RUNNING     P-XZ        00:00:00      unknown
REPLICAT    RUNNING     REP-BOS     00:00:00      unknown
GGSCI (localhost.localdomain) 8> exit
--使用stop 进程,stop mgr,kill 进程都不能正常关闭这些进程

3、系统系统级别kill相关ogg进程

[oracle@localhost OGG]$ ps -ef|grep /opt/OGG
oracle    7479     1  0 Nov10 ?        00:03:31 /opt/OGG/extract PARAMFILE /opt/OGG/dirprm/ext-ecp.prm REPORTFILE /opt/OGG/dirrpt/EXT-ECP.rpt PROCESSID EXT-ECP USESUBDIRS
oracle    7480     1  0 Nov10 ?        00:02:30 /opt/OGG/extract PARAMFILE /opt/OGG/dirprm/ext-eds.prm REPORTFILE /opt/OGG/dirrpt/EXT-EDS.rpt PROCESSID EXT-EDS USESUBDIRS
oracle    7482     1  0 Nov10 ?        00:03:07 /opt/OGG/extract PARAMFILE /opt/OGG/dirprm/ext-xz.prm REPORTFILE /opt/OGG/dirrpt/EXT-XZ.rpt PROCESSID EXT-XZ USESUBDIRS
oracle    7483     1  0 Nov10 ?        00:00:01 /opt/OGG/extract PARAMFILE /opt/OGG/dirprm/p-eds.prm REPORTFILE /opt/OGG/dirrpt/P-EDS.rpt PROCESSID P-EDS USESUBDIRS
oracle    7485     1  0 Nov10 ?        00:00:03 /opt/OGG/replicat PARAMFILE /opt/OGG/dirprm/rep-bos.prm REPORTFILE /opt/OGG/dirrpt/REP-BOS.rpt PROCESSID REP-BOS USESUBDIRS
oracle    7518     1  0 Nov10 ?        00:00:01 ./server -p 7847 -k -l /opt/OGG/ggserr.log
oracle    7677     1  0 Nov10 ?        00:00:15 /opt/OGG/extract PARAMFILE /opt/OGG/dirprm/p-xz.prm REPORTFILE /opt/OGG/dirrpt/P-XZ.rpt PROCESSID P-XZ USESUBDIRS
oracle   25261 25112  0 12:48 pts/1    00:00:00 grep /opt/OGG
[oracle@localhost OGG]$ kill -9 7479 7480 7482 7483 7485  7518 7677
[oracle@localhost OGG]$ ps -ef|grep /opt/OGG
oracle   25264 25112  0 12:48 pts/1    00:00:00 grep /opt/OGG

4、重启所有ogg进程

[oracle@localhost OGG]$ ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 11.1.1.0.0 Build 078
Linux, x64, 64bit (optimized), Oracle 10 on Jul 28 2010 13:21:11
Copyright (C) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
GGSCI (localhost.localdomain) 1> info all
Program     Status      Group       Lag           Time Since Chkpt
MANAGER     STOPPED
EXTRACT     ABENDED     EXT-ECP     00:00:00      unknown
EXTRACT     ABENDED     EXT-EDS     00:00:00      unknown
EXTRACT     ABENDED     EXT-XZ      00:00:00      unknown
EXTRACT     ABENDED     P-EDS       00:00:00      unknown
EXTRACT     ABENDED     P-XZ        00:00:00      unknown
REPLICAT    ABENDED     REP-BOS     00:00:00      unknown
--进程状态还是异常
GGSCI (localhost.localdomain) 2> start mgr
Manager started.
GGSCI (localhost.localdomain) 3> info all
Program     Status      Group       Lag           Time Since Chkpt
MANAGER     RUNNING
EXTRACT     RUNNING     EXT-ECP     00:00:00      unknown
EXTRACT     RUNNING     EXT-EDS     00:00:00      unknown
EXTRACT     RUNNING     EXT-XZ      00:00:00      unknown
EXTRACT     RUNNING     P-EDS       00:00:00      unknown
EXTRACT     RUNNING     P-XZ        00:00:00      unknown
REPLICAT    RUNNING     REP-BOS     00:00:00      unknown
--进程起来了,但是Time Since Chkpt还是不正确
GGSCI (localhost.localdomain) 4> stop ext-ecp
Sending STOP request to EXTRACT EXT-ECP ...
Request processed.
GGSCI (localhost.localdomain) 5> info all
Program     Status      Group       Lag           Time Since Chkpt
MANAGER     RUNNING
EXTRACT     STOPPED     EXT-ECP     unknown       00:00:02
EXTRACT     RUNNING     EXT-EDS     00:00:00      unknown
EXTRACT     RUNNING     EXT-XZ      00:00:00      unknown
EXTRACT     RUNNING     P-EDS       00:00:00      unknown
EXTRACT     RUNNING     P-XZ        00:00:00      unknown
REPLICAT    RUNNING     REP-BOS     00:00:00      unknown
--关闭EXT-ECP测试,状态正常
GGSCI (localhost.localdomain) 6> start ext-ecp
Sending START request to MANAGER ...
EXTRACT EXT-ECP starting
GGSCI (localhost.localdomain) 7> info all
Program     Status      Group       Lag           Time Since Chkpt
MANAGER     RUNNING
EXTRACT     RUNNING     EXT-ECP     unknown       00:00:14
EXTRACT     RUNNING     EXT-EDS     00:00:00      unknown
EXTRACT     RUNNING     EXT-XZ      00:00:00      unknown
EXTRACT     RUNNING     P-EDS       00:00:00      unknown
EXTRACT     RUNNING     P-XZ        00:00:00      unknown
REPLICAT    RUNNING     REP-BOS     00:00:00      unknown
--Lag异常,等待恢复
GGSCI (localhost.localdomain) 8> stop ext-eds
Sending STOP request to EXTRACT EXT-EDS ...
Recovery is not complete.  This normal stop will wait and checkpoint recovery's
work when recovery has finished. To force Extract to stop now,
use the SEND EXTRACT EXT-EDS, FORCESTOP command.
--因为恢复没有完成导致该提示,可以忽略,等待
GGSCI (localhost.localdomain) 9> info all
Program     Status      Group       Lag           Time Since Chkpt
MANAGER     RUNNING
EXTRACT     RUNNING     EXT-ECP     unknown       00:00:02
EXTRACT     STOPPED     EXT-EDS     01:51:12      00:00:01
EXTRACT     RUNNING     EXT-IM      00:00:00      1059:44:26
EXTRACT     RUNNING     EXT-XZ      00:00:00      unknown
EXTRACT     RUNNING     P-EDS       00:00:00      unknown
EXTRACT     RUNNING     P-XZ        00:00:00      unknown
REPLICAT    RUNNING     REP-BOS     00:00:00      unknown
GGSCI (localhost.localdomain) 10> start ext-eds
Sending START request to MANAGER ...
EXTRACT EXT-EDS starting
GGSCI (localhost.localdomain) 11> info all
Program     Status      Group       Lag           Time Since Chkpt
MANAGER     RUNNING
EXTRACT     RUNNING     EXT-ECP     99:53:02      00:00:01
EXTRACT     RUNNING     EXT-EDS     01:51:12      00:00:10
EXTRACT     RUNNING     EXT-XZ      00:00:00      unknown
EXTRACT     RUNNING     P-EDS       00:00:00      unknown
EXTRACT     RUNNING     P-XZ        00:00:00      unknown
REPLICAT    RUNNING     REP-BOS     00:00:00      00:00:00
GGSCI (localhost.localdomain) 12> stop ext-xz
Sending STOP request to EXTRACT EXT-XZ ...
Request processed.
GGSCI (localhost.localdomain) 13> start ext-xz
Sending START request to MANAGER ...
EXTRACT EXT-XZ starting
GGSCI (localhost.localdomain) 15> stop p-eds
Sending STOP request to EXTRACT P-EDS ...
Request processed.
GGSCI (localhost.localdomain) 16> start p-eds
Sending START request to MANAGER ...
EXTRACT P-EDS starting
GGSCI (localhost.localdomain) 17> stop p-xz
Sending STOP request to EXTRACT P-XZ ...
Request processed.
GGSCI (localhost.localdomain) 18> start p-xz
Sending START request to MANAGER ...
EXTRACT P-XZ starting
GGSCI (localhost.localdomain) 19> info all
Program     Status      Group       Lag           Time Since Chkpt
MANAGER     RUNNING
EXTRACT     RUNNING     EXT-ECP     00:00:00      00:00:01
EXTRACT     RUNNING     EXT-EDS     00:00:00      00:00:10
EXTRACT     RUNNING     EXT-IM      00:00:00      1059:45:28
EXTRACT     RUNNING     EXT-XZ      00:00:00      00:00:07
EXTRACT     RUNNING     P-EDS       00:00:00      00:00:04
EXTRACT     RUNNING     P-XZ        00:00:00      00:00:05
REPLICAT    RUNNING     REP-BOS     00:00:00      00:00:05
--重启所有异常进程,ogg工作正常
GGSCI (localhost.localdomain) 20>

5、总结处理步骤
强制关闭mgr,系统级别kill相关ogg进程,开启ogg主进程,重启相关进程

pl/sql的定义者与调用者

一、执行的schema不同,操作的对象也不同

C:\Users\XIFENFEI>sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on 星期日 11月 20 20:39:06 20
Copyright (c) 1982, 2010, Oracle.  All rights reserved.
连接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Productio
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
SQL> create user xffa identified by xifenfei;
用户已创建。
SQL> grant connect,resource to xffa;
授权成功。
SQL> create user xffb identified by xifenfei;
用户已创建。
SQL> grant connect,resource to xffb;
授权成功。
SQL> conn xffa/xifenfei
已连接。
xffa>create table tmp(str varchar2(50));
表已创建。
xffa>insert into tmp values
  2  ('my name is xffa');
已创建 1 行。
xffa>commit;
提交完成。
xffa>create or replace procedure definer_proc as
  2      begin
  3        for x in (select sys_context('userenv', 'current_user') current_user,
  4                         sys_context('userenv', 'session_user') session_user,
  5                         sys_context('userenv', 'current_schema') current_sch
ema,
  6                         str
  7                    from tmp) loop
  8        dbms_output.put_line('Current User:   ' || x.current_user);
  9        dbms_output.put_line('Session User:   ' || x.session_user);
 10        dbms_output.put_line('Current Schema: ' || x.current_schema);
 11        dbms_output.put_line('Tables Value:    ' || x.str);
 12      end loop;
 13    end;
 14    /
过程已创建。
xffa>create or replace procedure invoker_proc AUTHID CURRENT_USER as
  2      begin
  3        for x in (select sys_context('userenv', 'current_user') current_user,
  4                         sys_context('userenv', 'session_user') session_user,
  5                         sys_context('userenv', 'current_schema') current_sch
ema,
  6                         str
  7                    from tmp) loop
  8        dbms_output.put_line('Current User:   ' || x.current_user);
  9        dbms_output.put_line('Session User:   ' || x.session_user);
 10        dbms_output.put_line('Current Schema: ' || x.current_schema);
 11        dbms_output.put_line('Tables Value:    ' || x.str);
 12      end loop;
 13    end;
 14    /
过程已创建。
xffa>grant execute on definer_proc to xffb;
授权成功。
xffa>grant execute on invoker_proc to xffb;
授权成功。
xffa>set serveroutput on
xffa>exec definer_proc;
Current User:   XFFA
Session User:   XFFA
Current Schema: XFFA
Tables Value:    my name is xffa
PL/SQL 过程已成功完成。
xffa>exec invoker_proc;
Current User:   XFFA
Session User:   XFFA
Current Schema: XFFA
Tables Value:    my name is xffa
PL/SQL 过程已成功完成。
xffa>conn xffb/xifenfei
已连接。
xffb>exec xffa.definer_proc;
PL/SQL 过程已成功完成。
xffb>set serveroutput on
xffb>exec xffa.definer_proc;
Current User:   XFFA
Session User:   XFFB
Current Schema: XFFA
Tables Value:    my name is xffa
PL/SQL 过程已成功完成。
--除了session是当前用户的,其他都是这个过程所属用户
xffb>exec xffa.invoker_proc;
BEGIN xffa.invoker_proc; END;
*
第 1 行出现错误:
ORA-00942: 表或视图不存在
ORA-06512: 在 "XFFA.INVOKER_PROC", line 3
ORA-06512: 在 line 1
--根据这个提示,很容易知道是tmp表不存在,也就是说明这个没有调用xffa.tmp表
xffb>create table tmp(str varchar2(50));
表已创建。
xffb>insert into tmp values
  2  ('my name is xffb');
已创建 1 行。
xffb>commit;
提交完成。
xffb>exec xffa.invoker_proc;
Current User:   XFFB
Session User:   XFFB
Current Schema: XFFB
Tables Value:    my name is xffb
PL/SQL 过程已成功完成。
--这个可以看出当时调用者的时候,执行的完全是当前用户下面的对象

在定义者(definer)权限下,执行的用户操作的schema为定义者,所操作的对象是定义者在编译时指定的对象。
在调用者(invoker)权限下,执行的用户操作的schema为当前用户,所操作的对象是当前模式下的对象。

二、执行的权限不同

xffb>create or replace procedure createtbl_definer as
  2      begin
  3        execute immediate 'create table xff_definer (id number)';
  4      end;
  5      /
过程已创建。
xffb>create or replace procedure createtbl_invoker AUTHID CURRENT_USER  as
  2      begin
  3        execute immediate 'create table xff_invoker (id number)';
  4      end;
  5      /
xffb>grant execute on createtbl_definer to xffa;
授权成功。
xffb>grant execute on createtbl_invoker to xffa;
授权成功。
xffb>exec createtbl_definer;
BEGIN createtbl_definer; END;
*
第 1 行出现错误:
ORA-01031: 权限不足
ORA-06512: 在 "XFFB.CREATETBL_DEFINER", line 3
ORA-06512: 在 line 1
--提示权限不足,很明显是缺少创建表的权限
xffb>exec createtbl_invoker;
PL/SQL 过程已成功完成。
xffb>desc xff_invoker;
 名称                                      是否为空? 类型
 ----------------------------------------- -------- ----------------------------
 ID                                                 NUMBER
--调用者创建成功
xffb>conn xffa/xifenfei
已连接。
xffa>exec xffb.createtbl_definer;
BEGIN xffb.createtbl_definer; END;
*
第 1 行出现错误:
ORA-01031: 权限不足
ORA-06512: 在 "XFFB.CREATETBL_DEFINER", line 3
ORA-06512: 在 line 1
--定义者同样提示没有权限创建表,通过1中的试验,我们知道
--定义者执行的这个过程定义者的对象,也就是说,是因为xffb无权创建表导致该提示
xffa>exec xffb.createtbl_invoker;
PL/SQL 过程已成功完成。
xffa>desc xff_invoker;
 名称                                      是否为空? 类型
 ----------------------------------------- -------- ----------------------------
 ID                                                 NUMBER
xffa>conn / as sysdba
已连接。
SQL>select owner,table_name from dba_tables where table_name=upper('xff_invoker');
OWNER                          TABLE_NAME
------------------------------ ------------------------------
XFFB                           XFF_INVOKER
XFFA                           XFF_INVOKER
--xffa用户执行成功,并且在自己的schema下面创建了表,证明了1的正确
SQL>GRANT CREATE TABLE TO XFFB;
授权成功。
SQL>conn xffb/xifenfei
已连接。
xffb>exec createtbl_definer;
PL/SQL 过程已成功完成。
xffb>desc xff_definer;
 名称                                      是否为空? 类型
 ----------------------------------------- -------- ----------------------------
 ID                                                 NUMBER
--说明直接授权是的定义者操作成功,但是角色(resource)不能使其操作成功
xffb>conn xffa/xifenfei
已连接。
xffa>exec xffb.createtbl_definer;
BEGIN xffb.createtbl_definer; END;
*
第 1 行出现错误:
ORA-00955: 名称已由现有对象使用
ORA-06512: 在 "XFFB.CREATETBL_DEFINER", line 3
ORA-06512: 在 line 1
--因为定义者执行的是过程创建者的对象,因为XFFB.CREATETBL_DEFINER已经创建成功

在定义者(definer)权限下,当前用户的权限为角色无效情况下所拥有的权限。
在调用者(invoker)权限下,当前用户的权限为当前所拥有的权限(含角色)。

三、执行的效率不同
在定义者(definer)权限下,过程被静态编译静态执行(相对而言),所执行sql语句在共享区池中是可被共享使用的
在调用者(invoker)权限下,过程静态编译,但动态执行,虽然执行的语句相同,但不同用户执行,其sql语句在共享池中并不能共享。

参考:http://www.itpub.net/thread-935634-1-1.html

rman从多份备份中还原操作

1、现象重现

RMAN> shutdown immediate
database dismounted
Oracle instance shut down
RMAN> startup
connected to target database (not started)
Oracle instance started
database mounted
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of startup command at 11/18/2011 14:40:40
ORA-01157: cannot identify/lock data file 11 - see DBWR trace file
ORA-01110: data file 11: '/opt/oracle/oradata/test/xifenfei03.dbf'
RMAN> restore datafile 11;
Starting restore at 2011-11-18 14:41:04
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=157 devtype=DISK
channel ORA_DISK_1: restoring datafile 00011
input datafile copy recid=13 stamp=767543949 filename=/tmp/11.dbf
destination for restore of datafile 00011: /opt/oracle/oradata/test/xifenfei03.dbf
ORA-19505: failed to identify file "/tmp/11.dbf"
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
ORA-19600: input file is datafile-copy 13 (/tmp/11.dbf)
ORA-19601: output file is datafile 11 (/opt/oracle/oradata/test/xifenfei03.dbf)
failover to previous backup
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00011 to /opt/oracle/oradata/test/xifenfei03.dbf
channel ORA_DISK_1: reading from backup piece /tmp/test_full_01mrkqdh_1_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/tmp/test_full_01mrkqdh_1_1 tag=TAG20111114T124433
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
Finished restore at 2011-11-18 14:41:08

虽然整个过程datafile 11恢复成功了,但是在恢复过程中,先是去读取/tmp/11.dbf的copy文件,读取这个文件失败,然后继续使用/tmp/test_full_01mrkqdh_1_1来恢复数据文件,为什么会出现这样的情况呢?

2、原因分析

RMAN> list copy of datafile 11;
List of Datafile Copies
Key     File S Completion Time     Ckp SCN    Ckp Time            Name
------- ---- - ------------------- ---------- ------------------- ----
13      11   A 2011-11-18 14:39:09 11517136   2011-11-14 12:44:33 /tmp/11.dbf
--确实存在datafile 11的copy文件/tmp/11.dbf,并且有效
--checkpoint time为:2011-11-14 12:44:33,创建时间为:2011-11-18 14:39:09
RMAN> list backup of datafile 11;
List of Backup Sets
===================
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
1       Full    9.32G      DISK        00:04:24     2011-11-14 12:48:57
        BP Key: 1   Status: AVAILABLE  Compressed: NO  Tag: TAG20111114T124433
        Piece Name: /tmp/test_full_01mrkqdh_1_1
  List of Datafiles in backup set 1
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  11      Full 11517136   2011-11-14 12:44:33 /opt/oracle/oradata/test/xifenfei03.dbf
--backupset中也有datafile 11
--checkpoint time为:2011-11-14 12:44:33,创建时间为:2011-11-14 12:48:57
--通过比较这两个关于datafile 11的备份时间,rman自动选择了创建时间比较新的备份恢复
RMAN> crosscheck copy of datafile 11;
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=157 devtype=DISK
validation failed for datafile copy
datafile copy filename=/tmp/11.dbf recid=13 stamp=767543949
Crosschecked 1 objects
RMAN> list copy of datafile 11;
List of Datafile Copies
Key     File S Completion Time     Ckp SCN    Ckp Time            Name
------- ---- - ------------------- ---------- ------------------- ----
13      11   X 2011-11-18 14:39:09 11517136   2011-11-14 12:44:33 /tmp/11.dbf
--通过检测发现/tmp/11.dbf是无效的,所以rman继续使用backupset进行恢复datafile 11

在有些时候,当rman对中关于一个对象的备份有多个(备份时间不一致),rman会从最新备份的开始还原,如果第一个失败,使用下一个备份,但是在有些时候可能第一个失败后,rman不自动使用下一个,这个时候的处理思路是:使用crosscheck backup/copy检测无效的备份,删除掉,继续执行

imp乱码分析–解决建议

最近有位朋友一直在为exp/imp操作的乱码问题纠结,总是搞不清楚为什么,而且经常莫名其妙的出现乱码,为此我做了一个实验,来说明这个问题的处理思路
一、准备工作

C:\Users\XIFENFEI>sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on 星期四 11月 17 18:43:00 2011
Copyright (c) 1982, 2010, Oracle.  All rights reserved.
连接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
SQL> create table TEST_EXP
  2  (
  3    A1 NUMBER,
  4    A2 VARCHAR2(10 CHAR),
  5    A3 VARCHAR2(10),
  6    A4 NVARCHAR2(10),
  7    A5 CHAR(10),
  8    A6 NCHAR(10)
  9  );
表已创建。
SQL> comment on column TEST_EXP.A1
  2    is '数字类型----惜分飞';
注释已创建。
SQL> comment on column TEST_EXP.A2
  2    is 'varchar类型1----惜分飞';
注释已创建。
SQL> comment on column TEST_EXP.A3
  2    is 'varchar类型2----惜分飞';
注释已创建。
SQL> comment on column TEST_EXP.A4
  2    is 'nvarchar类型----惜分飞';
注释已创建。
SQL> comment on column TEST_EXP.A5
  2    is 'char类型----惜分飞';
注释已创建。
SQL> comment on column TEST_EXP.A6
  2    is 'nchar类型----惜分飞';
注释已创建。
SQL> insert into test_exp values(1,'xifenfeicf','xifenfeicf','xff','xifenfei','xifenfei');
已创建 1 行。
SQL> insert into test_exp values(1,'惜分飞来向大家问好啦',
2    '杭州惜分飞','杭州惜分飞','杭州惜分飞','杭州惜分飞');
已创建 1 行。
SQL> commit;
提交完成。
SQL> col parameter for a30
SQL> col value for a20
SQL> select * FROM v$nls_parameters WHERE parameter LIKE '%CHARACTERSET%';
PARAMETER                      VALUE
------------------------------ --------------------
NLS_CHARACTERSET               ZHS16GBK
NLS_NCHAR_CHARACTERSET         AL16UTF16
SQL> exit
从 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options 断开
C:\Users\XIFENFEI>exp chf/xifenfei tables=test_exp
file=d:\test_exp.dmp log=d:\test_exp.log
Export: Release 11.2.0.1.0 - Production on 星期四 11月 17 18:46:10 2011
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
已导出 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集
即将导出指定的表通过常规路径...
. . 正在导出表                        TEST_EXP导出了           2 行
成功终止导出, 没有出现警告。

二、使用AL32UTF8编码导入

C:\Users\XIFENFEI>set NLS_LANG=american_america.AL32UTF8
C:\Users\XIFENFEI>imp chf/xifenfei tables=test_exp
file=d:/test_exp.dmp log=d:/test_exp.log fromuser=chf touser=chf
Import: Release 11.2.0.1.0 - Production on Thu Nov 17 19:24:58 2011
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Produc
tion
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
Export file created by EXPORT:V11.02.00 via conventional path
import done in AL32UTF8 character set and AL16UTF16 NCHAR character set
import server uses ZHS16GBK character set (possible charset conversion)
export client uses ZHS16GBK character set (possible charset conversion)
. importing CHF's objects into CHF
. . importing table                     "TEST_EXP"          2 rows imported
Import terminated successfully without warnings.
--注意此处提示,编码发生了转换
--导出来文件编码为:ZHS16GBK
--现在客户端编码为:AL32UTF8
--导入服务器编码为:ZHS16GBK
--现在的转换是ZHS16GBK-->AL32UTF8 -->ZHS16GBK
--其中ZHS16GBK-->AL32UTF8说成转换也许不太合适
--(因为ZHS16GBK是已经生产的dmp文件中数据的编码,而AL32UTF8是导入客户端的编码,这个到底是否转换待定)
C:\Users\XIFENFEI>sqlplus chf/xifenfei
SQL*Plus: Release 11.2.0.1.0 Production on Thu Nov 17 19:25:58 2011
Copyright (c) 1982, 2010, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
SQL> col comments for a30
SQL> SELECT  COLUMN_NAME,comments FROM DBA_COL_COMMENTS WHERE owner='CHF' AND TABLE_NAME='TEST_EXP';
COLUMN_NAME                    COMMENTS
------------------------------ ------------------------------
A1                             数字类型----惜分飞
A2                             varchar类型1----惜分飞
A3                             varchar类型2----惜分飞
A4                             nvarchar类型----惜分飞
A5                             char类型----惜分飞
A6                             nchar类型----惜分飞
6 rows selected.
SQL>select * from test_exp;
        A1 A2                   A3         A4                   A5         A6
---------- -------------------- ---------- -------------------- ---------- --------------------
         1 xifenfeicf           xifenfeicf xff                  xifenfei   xifenfei
         1 惜分飞来向大家问好啦 杭州惜分飞 杭州惜分飞           杭州惜分飞 杭州惜分飞
--在新窗口查询,编码修改客户端编码造成影响

三、使用US7ASCII编码导入

C:\Users\XIFENFEI>set NLS_LANG=american_america.US7ASCII
C:\Users\XIFENFEI>imp chf/xifenfei tables=test_exp
file=d:/test_exp.dmp log=d:/test_exp.log fromuser=chf touser=chf
Import: Release 11.2.0.1.0 - Production on Thu Nov 17 19:35:10 2011
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Produc
tion
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
Export file created by EXPORT:V11.02.00 via conventional path
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses ZHS16GBK character set (possible charset conversion)
export client uses ZHS16GBK character set (possible charset conversion)
. importing CHF's objects into CHF
. . importing table                     "TEST_EXP"          2 rows imported
Import terminated successfully without warnings.
SQL> col comments for a30
SQL> SELECT  COLUMN_NAME,comments FROM DBA_COL_COMMENTS WHERE owner='CHF' AND TABLE_NAME='TEST_EXP';
COLUMN_NAM COMMENTS
---------- ------------------------------
A1         ????----???
A2         varchar??1----???
A3         varchar??2----???
A4         nvarchar??----???
A5         char??----???
A6         nchar??----???
6 rows selected.
--sqlplus和plsql dev中均为乱码
SQL> select * from test_exp;
        A1 A2         A3         A4         A5         A6
---------- ---------- ---------- ---------- ---------- ----------
         1 xifenfeicf xifenfeicf xff        xifenfei   xifenfei
         1 ?????????? ?????      ?????      ?????      ?????
--在plsql dev中查询是正常,sqlplus中不正常
--这里为什么plsql dev中能够显示正常,而comment在plsql dev中显示不正常,还有待研究
--说明:这里由于ZHS16GBK转换为US7ASCII的过程不能识别汉字,所以会导致汉字变成了问号

四、使用ZHS16GBK编码

C:\Users\XIFENFEI>set NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK
C:\Users\XIFENFEI>imp chf/xifenfei tables=test_exp
file=d:/test_exp.dmp log=d:/test_exp.log fromuser=chf touser=chf
Import: Release 11.2.0.1.0 - Production on 星期四 11月 17 20:26:39 2011
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
经由常规路径由 EXPORT:V11.02.00 创建的导出文件
已经完成 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集中的导入
. 正在将 CHF 的对象导入到 CHF
. . 正在导入表                      "TEST_EXP"导入了           2 行
成功终止导入, 没有出现警告。
--注意提示,没有发生任何的编码转换
QL> col comments for a30
SQL> SELECT  COLUMN_NAME,comments FROM DBA_COL_COMMENTS WHERE owner='CHF' AND TABLE_NAME='TEST_EXP';
COLUMN_NAME                    COMMENTS
------------------------------ ------------------------------
A1                             数字类型----惜分飞
A2                             varchar类型1----惜分飞
A3                             varchar类型2----惜分飞
A4                             nvarchar类型----惜分飞
A5                             char类型----惜分飞
A6                             nchar类型----惜分飞
6 rows selected.
SQL>select * from test_exp;
        A1 A2                   A3         A4                   A5         A6
---------- -------------------- ---------- -------------------- ---------- --------------------
         1 xifenfeicf           xifenfeicf xff                  xifenfei   xifenfei
         1 惜分飞来向大家问好啦 杭州惜分飞 杭州惜分飞           杭州惜分飞 杭州惜分飞

五、原因分析,解决建议
在导入过程中,最多会发生三次编码转换:
1、执行exp时,数据库中数据的编码会转换为导出客户端编码
2、执行imp时,dmp文件的编码转换为导入客户端编码
3、导入客户端编码转换为目标端数据库的数据库编码

在exp/imp操作的过程中,经常出现乱码的原因就是编码的相互转换的过程中出现了丢失或者相互不能转换导致。要解决这个问题,最好的办法就是通过NLS_LANG的灵活设置,减少编码转换的次数(如果相邻的转换操作编码一致,那么不会发生编码转换,如试验中的ZHS16GBK编码测试,就没有转换发生),或者使得相互的转换能够兼容,可以最大程度的减少乱码的出现。
如果已经有了exp导出的dmp文件,然后在导入的过程中,出现乱码,一般的处理建议是nls_lang的编码设置和dmp文件的一致,让转换发生在导入客户端和数据库服务器间(要求:编码可以相互转换)

深入理解LOG_ARCHIVE_DEST_n与STANDBY_ARCHIVE_DEST

一、案例引入
朋友的dg配置如下,问我为什么归档日志都放在了use_db_recovery_file_dest

主库
log_archive_dest_1='location=/U01/app/oracle/oradata/bfodb/arch,valid_for=(ONLINE_LOGFILE,ALL_ROLES)'
log_archive_dest_2='service=tnsname,ARCH SYNC NOAFFIRM delay=0 OPTIONAL max_failure=0 max_connections=1   reopen=300  register net_timeout=180  valid_for=(online_logfile,primary_role)'
standby_archive_dest='location=use_db_recovery_file_dest'
备库
log_archive_dest_1='location=/U01/app/oracle/oradata/bfodb/arch,valid_for=(ONLINE_LOGFILE,ALL_ROLES)'
log_archive_dest_2='location=location=use_db_recovery_file_dest,valid_for=(STANDBY_LOGFILE,STANDBY_ROLE)'
standby_archive_dest='location=use_db_recovery_file_dest'

我很惯性的回答,直接传输过来的日志放到LOG_ARCHIVE_DEST_n下面,fal_*过来的归档放置在standby_archive_dest中,也没有过多的思考为什么,因为我们的库都是这样的规则,我已经认为是一种准则了。这个规则也整合符合了他们的要求(都在use_db_recovery_file_dest)中,没有仔细的去看他们的配置,当朋友说到valid_for的属性的时候,我感觉有点不对头了。
1)他们的log_archive_dest_1配置的是ONLINE_LOGFILE,这个是备库,所以肯定不会放到这里
2)难道是通过log_archive_dest_2使得直接传输过来的日志放置到了use_db_recovery_file_dest中?让朋友查询v$standby_log,发现他们的库没有使用standby redo logfile,也就是说,log_archive_dest_2不可能用来传输日志了,现在剩下来可以传输日志的,只有standby_archive_dest了。
3)问题解决了,都传输到use_db_recovery_file_dest,因为LOG_ARCHIVE_DEST_n都不能用(只是从排除法证明)

二、问题深入分析
standby_archive_dest和log_archive_dest_*到底有什么关系,在什么情况下传输到对应的目录中?

如果备库利用standby redo log在备库端自动归档,那么归档日志将会被放置到LOG_ARCHIVE_DEST_n
如果备库是利用主库的arch进程传输过来的归档,那么将会被放置到STANDBY_ARCHIVE_DEST
补充说明:
1)主库的LOG_ARCHIVE_DEST_n='service'默认的arch传输方式,primary会远程将archived log传输到standby_archive_dest下
2)fal_*是通过arch传输过来的,所以使用的是STANDBY_ARCHIVE_DEST目录,如果不存在这个目录,就使用LOG_ARCHIVE_DEST_n
3)If both parameters are specified, the STANDBY_ARCHIVE_DEST initialization parameter
  overrides the directory location specified with the LOG_ARCHIVE_DEST_n parameter.
如果STANDBY_ARCHIVE_DEST和LOG_ARCHIVE_DEST_n两个参数指定,STANDBY_ARCHIVE_DEST初始化覆盖LOG_ARCHIVE_DEST_n目录指定位置参数。
4)If none of the initialization parameters have been specified, then archived redo log files are stored in the default location for the STANDBY_ARCHIVE_DEST initialization parameter.
如果STANDBY_ARCHIVE_DEST和LOG_ARCHIVE_DEST_n都没有配置,将会把归档日志放到STANDBY_ARCHIVE_DEST的默认目录
5)如果STANDBY_ARCHIVE_DEST未配置,而配置了LOG_ARCHIVE_DEST_n,那么产生的归档将放置到LOG_ARCHIVE_DEST_n
6)建议:STANDBY_ARCHIVE_DEST和LOG_ARCHIVE_DEST_n=‘location’的配置相同
7)在11g,已经不建议使用STANDBY_ARCHIVE_DEST,也就是说建议配置dg的时候尽量使用standby redo logfile

Oracle常用用户权限视图

DBA_SYS_PRIVS 用户所拥有的系统权限

[oracle@ECP-UC-DB1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.4.0 - Production on Wed Nov 16 13:26:09 2011
Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> create user xff identified by xifenfei;
User created.
SQL> grant connect to xff;
Grant succeeded.
SQL> select * from DBA_SYS_PRIVS where grantee='XFF';
no rows selected
SQL> REVOKE CONNECT FROM XFF;
Revoke succeeded.
SQL> grant create session to xff;
Grant succeeded.
SQL>  select * from DBA_SYS_PRIVS where grantee='XFF';
GRANTEE                        PRIVILEGE                                ADM
------------------------------ ---------------------------------------- ---
XFF                            CREATE SESSION                           NO
SQL> grant select  on chf.t_1 to xff;
Grant succeeded.
SQL>  select * from DBA_SYS_PRIVS where grantee='XFF';
GRANTEE                        PRIVILEGE                                ADM
------------------------------ ---------------------------------------- ---
XFF                            CREATE SESSION                           NO
--说明只能查询系统权限,不能查询角色,不能查询用户权限

DBA_SYS_PRIVS 用户所拥有的角色

SQL> grant resource to xff;
授权成功。
SQL> SELECT * FROM DBA_ROLE_PRIVS WHERE GRANTEE='XFF';
GRANTEE                        GRANTED_ROLE                   ADM DEF
------------------------------ ------------------------------ --- ---
XFF                            RESOURCE                       NO  YES

ROLE_SYS_PRIVS 角色所拥有的系统权限

SQL> SELECT * FROM ROLE_SYS_PRIVS WHERE ROLE='CONNECT';
ROLE                           PRIVILEGE                                ADM
------------------------------ ---------------------------------------- ---
CONNECT                        CREATE SESSION                           NO
SQL> SELECT * FROM ROLE_SYS_PRIVS WHERE ROLE='RESOURCE';
no rows selected
SQL> SELECT * FROM SESSION_ROLES;
ROLE
------------------------------
CONNECT
SQL> CONN / AS SYSDBA
Connected.
SQL> SELECT * FROM ROLE_SYS_PRIVS WHERE ROLE='RESOURCE';
ROLE                           PRIVILEGE                                ADM
------------------------------ ---------------------------------------- ---
RESOURCE                       CREATE TRIGGER                           NO
RESOURCE                       CREATE SEQUENCE                          NO
RESOURCE                       CREATE TYPE                              NO
RESOURCE                       CREATE PROCEDURE                         NO
RESOURCE                       CREATE CLUSTER                           NO
RESOURCE                       CREATE OPERATOR                          NO
RESOURCE                       CREATE INDEXTYPE                         NO
RESOURCE                       CREATE TABLE                             NO
8 rows selected.
--很多时候只能使用sysdba(或者具体特定权限)才能够查询角色有哪些系统权限

ROLE_ROLE_PRIVS: 角色被赋予的角色

SQL> SELECT *FROM ROLE_ROLE_PRIVS WHERE ROLE='DBA';
ROLE                           GRANTED_ROLE                   ADM
------------------------------ ------------------------------ ---
DBA                            OLAP_DBA                       NO
DBA                            SCHEDULER_ADMIN                YES
DBA                            DELETE_CATALOG_ROLE            YES
DBA                            EXECUTE_CATALOG_ROLE           YES
DBA                            WM_ADMIN_ROLE                  NO
DBA                            EXP_FULL_DATABASE              NO
DBA                            SELECT_CATALOG_ROLE            YES
DBA                            JAVA_DEPLOY                    NO
DBA                            GATHER_SYSTEM_STATISTICS       NO
DBA                            JAVA_ADMIN                     NO
DBA                            XDBADMIN                       NO
ROLE                           GRANTED_ROLE                   ADM
------------------------------ ------------------------------ ---
DBA                            IMP_FULL_DATABASE              NO
DBA                            XDBWEBSERVICES                 NO
13 rows selected.

SESSION_PRIVS 当前用户所拥有的全部权限

SQL> conn xff/xifenfei
Connected.
SQL> select * from session_privs;
PRIVILEGE
----------------------------------------
CREATE SESSION
SQL> conn / as sysdba
Connected.
SQL> revoke create session from xff;
Revoke succeeded.
SQL> grant connect to xff;
Grant succeeded.
SQL> conn xff/xifenfei
Connected.
SQL> select * from session_privs;
PRIVILEGE
----------------------------------------
CREATE SESSION
--只能查看系统权限或者角色中包含的系统权限,不能查看用户权限

SESSION_ROLES: 当前用户被激活的角色

SQL> SELECT * from SESSION_ROLES;
no rows selected
SQL> show user;
USER is "SYS"
SQL> conn xff/xifenfei
Connected.
SQL> SELECT *FROM SESSION_ROLES;
ROLE
------------------------------
CONNECT
--sysdba查询无role选项,全部是由系统权限构成

查询某用户的所有系统权限

SQL> SELECT PRIVILEGE, ADMIN_OPTION
  2    FROM DBA_SYS_PRIVS
  3   WHERE GRANTEE = &USERNAME
  4  UNION
  5  --角色转换为权限
  6  SELECT PRIVILEGE, ADMIN_OPTION
  7    FROM ROLE_SYS_PRIVS
  8   WHERE ROLE IN
  9         (SELECT GRANTED_ROLE FROM DBA_ROLE_PRIVS WHERE GRANTEE = &USERNAME)
 10  UNION
 11  --角色的角色转为权限
 12  SELECT PRIVILEGE, ADMIN_OPTION
 13    FROM ROLE_SYS_PRIVS
 14   WHERE ROLE IN (SELECT GRANTED_ROLE
 15                    FROM ROLE_ROLE_PRIVS
 16                   WHERE ROLE IN (SELECT GRANTED_ROLE
 17                                    FROM DBA_ROLE_PRIVS
 18                                   WHERE GRANTEE = &USERNAME));
输入 username 的值:  'XFF'
原值    3:  WHERE GRANTEE = &USERNAME
新值    3:  WHERE GRANTEE = 'XFF'
输入 username 的值:  'XFF'
原值    9:        (SELECT GRANTED_ROLE FROM DBA_ROLE_PRIVS WHERE GRANTEE = &USERNAME)
新值    9:        (SELECT GRANTED_ROLE FROM DBA_ROLE_PRIVS WHERE GRANTEE = 'XFF')
输入 username 的值:  'XFF'
原值   18:                                  WHERE GRANTEE = &USERNAME))
新值   18:                                  WHERE GRANTEE = 'XFF'))
PRIVILEGE                                ADM
---------------------------------------- ---
CREATE CLUSTER                           NO
CREATE INDEXTYPE                         NO
CREATE OPERATOR                          NO
CREATE PROCEDURE                         NO
CREATE SEQUENCE                          NO
CREATE SESSION                           NO
CREATE TABLE                             NO
CREATE TRIGGER                           NO
CREATE TYPE                              NO
UNLIMITED TABLESPACE                     NO
已选择10行。

表相关权限视图

SELECT *FROM TABLE_PRIVILEGES;
SELECT * FROM dba_TAB_PRIVS;
SELECT * FROM ROLE_TAB_PRIVS;

drop database操作

一、sql操作

[oracle@node1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Tue Nov 15 15:00:15 2011
Copyright (c) 1982, 2011, Oracle.  All rights reserved.
Connected to an idle instance.
SQL> startup mount;
ORACLE instance started.
Total System Global Area  417546240 bytes
Fixed Size                  2228944 bytes
Variable Size             285216048 bytes
Database Buffers          121634816 bytes
Redo Buffers                8466432 bytes
Database mounted.
SQL> drop database;
drop database
*
ERROR at line 1:
ORA-12719: operation requires database is in RESTRICTED mode
SQL> alter system enable restricted session;
System altered.
SQL> drop database;
Database dropped.
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options

二、alert日志内容

Tue Nov 15 15:00:18 2011
Adjusting the default value of parameter parallel_max_servers
from 320 to 135 due to the value of parameter processes (150)
Starting ORACLE instance (normal)
LICENSE_MAX_SESSION = 0
LICENSE_SESSIONS_WARNING = 0
Picked latch-free SCN scheme 3
Using LOG_ARCHIVE_DEST_1 parameter default value as USE_DB_RECOVERY_FILE_DEST
Autotune of undo retention is turned on.
IMODE=BR
ILAT =27
LICENSE_MAX_USERS = 0
SYS auditing is disabled
Starting up:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options.
ORACLE_HOME = /opt/oracle/product/11.2.0/db_1
System name:    Linux
Node name:      node1.srtcloud.com
Release:        2.6.18-238.19.1.el5
Version:        #1 SMP Fri Jul 15 07:31:24 EDT 2011
Machine:        x86_64
Using parameter settings in server-side spfile /opt/oracle/product/11.2.0/db_1/dbs/spfilet1.ora
System parameters with non-default values:
  processes                = 150
  memory_target            = 400M
  control_files            = "/opt/oracle/oradata/t1/control01.ctl"
  control_files            = "/opt/oracle/fast_recovery_area/t1/control02.ctl"
  db_block_size            = 8192
  compatible               = "11.2.0.0.0"
  db_recovery_file_dest    = "/opt/oracle/fast_recovery_area"
  db_recovery_file_dest_size= 4122M
  undo_tablespace          = "UNDOTBS1"
  remote_login_passwordfile= "EXCLUSIVE"
  db_domain                = ""
  dispatchers              = "(PROTOCOL=TCP) (SERVICE=t1XDB)"
  local_listener           = "LISTENER_T1"
  audit_file_dest          = "/opt/oracle/admin/t1/adump"
  audit_trail              = "DB"
  db_name                  = "t1"
  open_cursors             = 300
  diagnostic_dest          = "/opt/oracle"
Tue Nov 15 15:00:22 2011
PMON started with pid=2, OS id=26704
Tue Nov 15 15:00:22 2011
PSP0 started with pid=3, OS id=26706
Tue Nov 15 15:00:23 2011
VKTM started with pid=4, OS id=26708 at elevated priority
VKTM running at (1)millisec precision with DBRM quantum (100)ms
Tue Nov 15 15:00:23 2011
GEN0 started with pid=5, OS id=26712
Tue Nov 15 15:00:23 2011
DIAG started with pid=6, OS id=26714
Tue Nov 15 15:00:23 2011
DBRM started with pid=7, OS id=26716
Tue Nov 15 15:00:23 2011
DIA0 started with pid=8, OS id=26718
Tue Nov 15 15:00:23 2011
MMAN started with pid=9, OS id=26720
Tue Nov 15 15:00:23 2011
DBW0 started with pid=10, OS id=26722
Tue Nov 15 15:00:23 2011
LGWR started with pid=11, OS id=26724
Tue Nov 15 15:00:23 2011
CKPT started with pid=12, OS id=26726
Tue Nov 15 15:00:23 2011
SMON started with pid=13, OS id=26728
Tue Nov 15 15:00:23 2011
RECO started with pid=14, OS id=26730
Tue Nov 15 15:00:23 2011
MMON started with pid=15, OS id=26732
Tue Nov 15 15:00:23 2011
MMNL started with pid=16, OS id=26734
starting up 1 dispatcher(s) for network address '(ADDRESS=(PARTIAL=YES)(PROTOCOL=TCP))'...
starting up 1 shared server(s) ...
ORACLE_BASE from environment = /opt/oracle
Tue Nov 15 15:00:23 2011
ALTER DATABASE   MOUNT
Successful mount of redo thread 1, with mount id 2578048199
Database mounted in Exclusive Mode
Lost write protection disabled
Completed: ALTER DATABASE   MOUNT
Tue Nov 15 15:00:33 2011
drop database
ORA-12719 signalled during: drop database...
Tue Nov 15 15:00:47 2011
Stopping background process MMNL
Stopping background process MMON
Starting background process MMON
Tue Nov 15 15:00:49 2011
MMON started with pid=15, OS id=26788
Starting background process MMNL
Tue Nov 15 15:00:49 2011
MMNL started with pid=16, OS id=26790
ALTER SYSTEM enable restricted session;
Tue Nov 15 15:01:06 2011
drop database
Deleted file /opt/oracle/oradata/t1/system01.dbf
Deleted file /opt/oracle/oradata/t1/sysaux01.dbf
Deleted file /opt/oracle/oradata/t1/undotbs01.dbf
Deleted file /opt/oracle/oradata/t1/users01.dbf
Deleted file /opt/oracle/oradata/t1/redo01.log
Deleted file /opt/oracle/oradata/t1/redo02.log
Deleted file /opt/oracle/oradata/t1/redo03.log
Deleted file /opt/oracle/oradata/t1/temp01.dbf
Deleted file /opt/oracle/product/11.2.0/db_1/dbs/snapcf_t1.f
Shutting down archive processes
Archiving is disabled
Create Relation ADR_CONTROL
Create Relation ADR_INVALIDATION
Create Relation INC_METER_IMPT_DEF
Create Relation INC_METER_PK_IMPTS
USER (ospid: 26761): terminating the instance
Instance terminated by USER, pid = 26761
Tue Nov 15 15:01:18 2011
Deleted file /opt/oracle/oradata/t1/control01.ctl
Deleted file /opt/oracle/fast_recovery_area/t1/control02.ctl
Completed: drop database
Shutting down instance (abort)
License high water mark = 1
Tue Nov 15 15:01:32 2011
Instance shutdown complete

三、后续工作
1、清除相关日志trace文件$ORACLE_BASE/diag
2、删除fast_recovery_area文件$ORACLE_BASE/fast_recovery_area
3、删除归档日志(根据配置)
4、删除/etc/oratab中关于该数据库的记录(t1:/opt/oracle/product/11.2.0/db_1:N)

四、补充说明
1、在能够使用dbca删除数据库的情况下,应该选择dbca,这个删除的更加干净
2、dbca删除数据库也需要清理部分文件(如:归档日志)
3、如果对数据库的存储结构比较了解,可以人工关闭数据库后,手工删除相关文件
4、drop database使用于10g及其以上版本