在运行ORACLE_LOADER类型的外部表查询时报错,无法打开外部表的日志文件。
查询外部表出现KUP-4040错误:
数据库安装在操作系统oracle用户下,默认组为oinstall,当前使用的是操作系统用户tingkun.yang,同样是oinstall组,因此当前用户可以用SYSDBA身份登录数据库。
当前用户tingkun.yang运行sqlplus连接数据库,创建目录和外部表,在读取外部表时报错:
[tingkun.yang@enmoteam2 ~]$ id uid=505(tingkun.yang) gid=501(oinstall) groups=501(oinstall),502(dba) [tingkun.yang@enmoteam2 ~]$ ps -ef|grep lgwr oracle 1552 1 0 Sep07 ? 00:04:14 ora_lgwr_enmot2 505 28312 28185 0 22:52 pts/0 00:00:00 grep lgwr [tingkun.yang@enmoteam2 ~]$ sqlplus olasuser/olasuser SQL*Plus: Release 11.2.0.3.0 Production ON Sat Nov 24 23:24:18 2012 Copyright (c) 1982, 2011, Oracle. ALL rights reserved. Connected TO: Oracle DATABASE 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production WITH the Partitioning, OLAP, DATA Mining AND REAL Application Testing options SQL> CREATE directory d_alert AS '/home/tingkun.yang/sqlldr'; Directory created. SQL> CREATE TABLE t_alert 2 (text varchar2(4000)) 3 organization external 4 (TYPE oracle_loader 5 DEFAULT directory d_alert 6 access parameters 7 (records delimited BY newline 8 FIELDS (text (1:255) CHAR)) 9 location ('alert_enmot2.log')); TABLE created. Elapsed: 00:00:00.31 SQL> SELECT * FROM t_alert WHERE rownum = 1; SELECT * FROM t_alert WHERE rownum = 1 * ERROR at line 1: ORA-29913: error IN executing ODCIEXTTABLEOPEN callout ORA-29400: DATA cartridge error error opening file /home/tingkun.yang/sqlldr/T_ALERT_28321.log |
和上一篇文章有所区别,外部表的路径设置在当前用户的目录下,而不是oracle用户的目录,当执行外部表的查询是,由于oracle用户没有在当前用户目录下的写权限,导致了无法打开日志文件的错误。
将当前用户设置为对oinstall组可读写,问题解决:
SQL> host [tingkun.yang@enmoteam2 ~]$ cd ~/.. [tingkun.yang@enmoteam2 home]$ ls -l |grep tingkun drwx------ 6 tingkun.yang oinstall 4096 Nov 22 14:04 tingkun.yang [tingkun.yang@enmoteam2 home]$ chmod 770 tingkun.yang/ [tingkun.yang@enmoteam2 home]$ exit exit SQL> SELECT * FROM t_alert WHERE rownum = 1; TEXT -------------------------------------------------- Fri Aug 10 13:39:20 2012 |
其实根据这两次的错误的差别已经可以分析出结果,对于外部表访问而言,除了数据库中必须具备的DIRECTORY的读写权限外,需要oracle用户拥有对DIRECTORY对应的操作系统目录的写权限,以及当前访问的操作系统用户对于DIRECTORY对应的操作系统目录的读权限。