物化视图on prebuilt table

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:物化视图on prebuilt table

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

1、ORA-12059
执行语句:
CREATE MATERIALIZED VIEW mv_t2
on prebuilt TABLE
AS
SELECT * FROM SCOTT.emp
错误提示:
ORA-12059: prebuilt table “CHF”.”MV_T2″ does not exist
错误原因:
物化视图对应的表不存在(物化视图需要和表同名,结构相同)
解决方法:
CREATE TABLE mv_t2 AS
SELECT * FROM scott.emp WHERE 1=0;
2、ORA-23413
执行语句:
CREATE MATERIALIZED VIEW mv_t2
on prebuilt TABLE
WITH REDUCED PRECISION
refresh FAST on demand
AS
SELECT * FROM SCOTT.emp
错误提示:
ORA-23413: table “SCOTT”.”EMP” does not have a materialized view log
错误原因:
使用fast模式刷新物化视图,需要有物化视图日志
解决方法:
1)创建物化视图日志
CREATE MATERIALIZED VIEW LOG ON scott.emp ;
2)刷新模式改为force,其实实质是采用了complete刷新模式
3、ORA-12058
执行语句(mv log是基于rowid,表无主键)
CREATE MATERIALIZED VIEW mv_t2
on prebuilt TABLE
WITH REDUCED PRECISION
refresh FAST on DEMAND
WITH ROWID
AS
SELECT * FROM SCOTT.emp
错误提示:
ORA-12058: materialized view cannot use prebuilt table
错误原因:
fast刷新模式不能基于rowid进行
解决方法:
1)删除mv log,表添加主键,采用基于主键模式重新建mv log和物化视图
DROP MATERIALIZED VIEW mv_t1;
ALTER TABLE mv_t2 ADD PRIMARY KEY (EMPNO);
CREATE MATERIALIZED VIEW LOG ON scott.emp;
CREATE MATERIALIZED VIEW mv_t2
on prebuilt TABLE
WITH REDUCED PRECISION
refresh FAST on DEMAND
–WITH ROWID
AS
SELECT * FROM SCOTT.emp;
2)刷新模式改为force,其实实质是采用了complete刷新模式
4、总结
1)在执行创建物化视图之前,需要先创建同名、同结构表
2)如果使用fast模式刷新(疑惑在线重定义可以通过rowid实现,为什么直接通过物化视图就不可以),物化视图同表需要主键,需要物化视图日志
3)通过drop mv,发现同名表还存在,和on prebuilt table本质区别

ORA-01012: not logged on

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:ORA-01012: not logged on

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

今天接到现场反馈,数据库出现ORA-01012: not logged on错误提示,这个问题上次也出现过一次,当时按照网上说的方法,直接重启数据库了,问题解决了,同时也导致因为数据库重启,现场破坏,而alert日志中无任何异常信息,所以不知从何处下手分析。这次我上数据库准备查看时,发现数据库已经正常,监控也显示正常,说明数据库已经恢复正常。从此我推理这个问题应该是外部因素导致,而不是数据库本身的bug,从而决定要找出该问题的原因来。有个重要的因素,该数据库是我几个月前因为undo损坏做过恢复的,查看相关参数,发现processes是默认值150,是不是该值导致的不敢肯定,因为一般process超了会报ORA-00020错误,而这次只有ORA-01012。但是心中还是没有底,总感觉这个的可能性最大,于是想通过试验来证实下自己的想法
1、数据库版本(10g结果相同)
SQL> select * from v$version where rownum=1;
BANNER
—————————————————————-
Oracle9i Enterprise Edition Release 9.2.0.4.0 – Production
2、创建pfile,修改processes,重启数据库,查看processes值
SQL> select name,value from v$parameter where name=’processes’;
NAME VALUE
——————– ——————–
processes 30
3、查看系统processes数量
SQL> select count(*) from v$process;
COUNT(*)
———-
13
4、添加数据库连接数(为了增加process数目)
[oracle@localhost ~]$ sqlplus chf/xifenfei
SQL*Plus: Release 9.2.0.4.0 – Production on Wed Jul 27 23:11:50 2011
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 – Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 – Production
SQL> !
5、重复3和4,发现当process数量为29时出现激动人心一幕
5.1)继续访问数据库
[oracle@localhost ~]$ sqlplus system/xifenfei
SQL*Plus: Release 9.2.0.4.0 – Production on Wed Jul 27 23:12:06 2011
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
ERROR:
ORA-00020: maximum number of processes (%s) exceeded
Enter user-name:
5.2)使用其他用户访问
[oracle@localhost ~]$ sqlplus /nolog
SQL*Plus: Release 9.2.0.4.0 – Production on Wed Jul 27 23:12:49 2011
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
SQL> conn / as sysdba
Connected to an idle instance.
SQL> select * from dual;
select * from dual
*
ERROR at line 1:
ORA-01012: not logged on
SQL> conn chf/xifenfei
ERROR:
ORA-00020: maximum number of processes (%s) exceeded
[oracle@localhost ~]$ sqlplus “/ as sysdba”
SQL*Plus: Release 9.2.0.4.0 – Production on Wed Jul 27 23:29:52 2011
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected.
SQL> select * from dual;
select * from dual
*
ERROR at line 1:
ORA-01012: not logged on
现象说明:
1)终于发现了ORA-01012错误,期待了很久。发现只有当sys登录系统,对数据库进行查询或者操作之时才会出现ORA-01012,其他用户只要一登录数据库就会提示ORA-00020错误。
2)当process达到数据库最大限时,sysdba登录系统是也显示不正常
2.1)当使用sqlplus “/ as sysdba”登录时,缺少:
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 – Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 – Production
2.2)当使用conn / as sysdba登录时,提示为:
Connected to an idle instance.

ORA-01031: insufficient privileges

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:ORA-01031: insufficient privileges

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

今天接到开发反馈,说数据库动态sql创建表语句无法执行,提示ORA-01031: insufficient privileges
1、数据库版本
SQL> select * from v$version where rownum=1;
BANNER
—————————————————————-
Oracle9i Enterprise Edition Release 9.2.0.4.0 – Production
2、创建用户并授权
SQL> create user test identified by xifenfei;
User created.
SQL> grant connect,resource to test;
Grant succeeded.
3、查看权限
SQL> SELECT * FROM DBA_SYS_PRIVS WHERE GRANTEE=’TEST’;
GRANTEE PRIVILEGE ADM
—————————— —————————————- —
TEST UNLIMITED TABLESPACE NO
SQL> SELECT * FROM DBA_ROLE_PRIVS WHERE GRANTEE=’TEST’;
GRANTEE GRANTED_ROLE ADM DEF
—————————— —————————— — —
TEST CONNECT NO YES
TEST RESOURCE NO YES
SQL> CONN TEST/XIFENFEI
Connected.
SQL> SELECT * FROM SESSION_PRIVS;
PRIVILEGE
—————————————-
CREATE SESSION
ALTER SESSION
UNLIMITED TABLESPACE
CREATE TABLE
CREATE CLUSTER
CREATE SYNONYM
CREATE VIEW
CREATE SEQUENCE
CREATE DATABASE LINK
CREATE PROCEDURE
CREATE TRIGGER
PRIVILEGE
—————————————-
CREATE TYPE
CREATE OPERATOR
CREATE INDEXTYPE
14 rows selected.
注:目前create table权限是通过resource role授予test用户的
4、创建存储过程(Authid Current_User)
SQL> create or replace procedure create_table(t varchar2) Authid Current_User
2 is
3 P_SQL VARCHAR2(300);
4 BEGIN
5 P_SQL := ‘create table ‘||t||’ as select * from user_tables where 1=0′;
6 EXECUTE IMMEDIATE P_SQL;
END; 7
8 /
Procedure created.
5、执行存储过程
SQL> EXEC CREATE_table(‘a’);
PL/SQL procedure successfully completed.
6、重建存储过程(不包括Authid Current_User)
SQL> create or replace procedure create_table(t varchar2)
2 –Authid Current_User
3 is
4 P_SQL VARCHAR2(300);
5 BEGIN
6 P_SQL := ‘create table ‘||t||’ as select * from user_tables where 1=0′;
7 EXECUTE IMMEDIATE P_SQL;
8 END;
9 /
Procedure created.
SQL> EXEC CREATE_table(‘b’);
BEGIN CREATE_table(‘b’); END;
*
ERROR at line 1:
ORA-01031: insufficient privileges
ORA-06512: at “TEST.CREATE_TABLE”, line 7
ORA-06512: at line 1
7、授权(create table权限)
SQL> conn / as sysdba
Connected.
SQL> grant create table to test;
Grant succeeded.
SQL> conn test/xifenfei
Connected.
SQL> EXEC CREATE_table(‘c’);
PL/SQL procedure successfully completed.
8、查看结果
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
—————————— ——- ———-
A TABLE
C TABLE
9、 查询资料
默认情况下,在调用存储过程用户的角色是不起作用的,即在执行存储过程时只有Public权限。所以如果被调用的存储过程中如果有execute immediate ‘create table..’语句,将会引发ORA-01031: insufficient privileges错误。
存储过程分为两种,即DR(Definer’s Rights ) Procedure和IR(Invoker’s Rights ) Procedure。为什么会有两种存储过程呢?其实考虑完下面的问题就清楚了。比如说用户hrch创建了删除表tar_table的存储过程drop_table(),当用户hrch调用时,即删除用户hrch下的表tar_table;如果是另一个用户scott调用呢?是删除用户scott下的tar_table表呢,还是删除用户hrch下的tar_table呢?另外,如果存储过程中包含建表语句,不管是用户hrch还是用户scott调用都会失败,因为Public没有建表权限,除非为Public grant建表权限。
10、动态sql中执行create table解决方案(10g也存在同样问题)
1)加上Authid Current_User
2)直接赋予create table to 该用户
11、匿名块的动态sql不在此限制中
SQL> conn / as sysdba
Connected.
SQL> SELECT * FROM DBA_SYS_PRIVS WHERE GRANTEE=’TEST’;
GRANTEE PRIVILEGE ADM
—————————— —————————————- —
TEST UNLIMITED TABLESPACE NO
SQL> CONN TEST/XIFENFEI
Connected.
SQL> DECLARE
2 P_SQL VARCHAR2(300);
3 BEGIN
4 P_SQL := ‘create table t_t as select * from user_tables where 1=0’;
5 EXECUTE IMMEDIATE P_SQL;
6 END;
7 /
PL/SQL procedure successfully completed.

触发器引起ORA-04091

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:触发器引起ORA-04091

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

原因:在行级触发器中,不能查询自身表
场景重现:通过触发器实现test_count表中统计test表中行数

--创建子表
create table TEST
(id NUMBER, name varchar2(100), primary key (id));
--创建统计表
create table test_count (test_count int);
--创建触发器
CREATE OR REPLACE TRIGGER T_TEST
  AFTER INSERT OR DELETE ON TEST
  FOR EACH ROW
DECLARE
  A NUMBER;
BEGIN
  SELECT  COUNT(*) INTO A FROM TEST;
  UPDATE TEST_COUNT SET TEST_COUNT = A;
END T_TEST;

模拟错误

INSERT INTO TEST (ID,NAME)VALUES(2,'abc');
ORA-04091: table CHF.TEST is mutating, trigger/function may not see it
ORA-06512: at "CHF.T_TEST", line 2
ORA-04088: error during execution of trigger 'CHF.T_TEST'

处理方法
通过自治事务实现(修改触发器)

CREATE OR REPLACE TRIGGER T_TEST
  AFTER INSERT OR DELETE ON TEST
  FOR EACH ROW
DECLARE
  A NUMBER;
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  SELECT  COUNT(*) INTO A FROM TEST;
  UPDATE TEST_COUNT SET TEST_COUNT = A;
  COMMIT;
END T_TEST;

PRAGMA AUTONOMOUS_TRANSACTION
当前的触发器作为已有事务的子事务运行,子事务自治管理,子事务的commit、rollback操作不影响父事务的状态

WARNING: inbound connection timed out (ORA-3136)

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:WARNING: inbound connection timed out (ORA-3136)

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

1、现象
alert文件中
Mon Jun 27 11:12:34 2011
WARNING: inbound connection timed out (ORA-3136)
sqlnet.log文件中
Fatal NI connect error 12170.
VERSION INFORMATION:
TNS for Linux: Version 10.2.0.4.0 – Production
Oracle Bequeath NT Protocol Adapter for Linux: Version 10.2.0.4.0 – Production
TCP/IP NT Protocol Adapter for Linux: Version 10.2.0.4.0 – Production
Time: 27-JUN-2011 11:12:34
Tracing not turned on.
Tns error struct:
ns main err code: 12535
TNS-12535: TNS:operation timed out
ns secondary err code: 12606
nt main err code: 0
nt secondary err code: 0
nt OS err code: 0
Client address: (ADDRESS=(PROTOCOL=tcp)(HOST=211.155.227.20)(PORT=2104))
2、原因
Whenever default timeouts are assigned to a parameter, there may be cases where this default does not work well with a particular application. However, some type of timeout on the connection establishment is necessary to combat Denial of Service attacks on the database. In this case, SQLNET.INBOUND_CONNECT__TIMEOUT and INBOUND_CONNECT_TIMEOUT_listenername were given default values of 60 seconds in Oracle 10.2. It is these timeout values that can cause the errors described in this note.
Also note that it is possilbe the reason the database is slow to authenticate, may be due to an overloaded Oracle database or node.
3、解决
1). set INBOUND_CONNECT_TIMEOUT_listenername=0 in listener.ora
2). set SQLNET.INBOUND_CONNECT_TIMEOUT = 0 in sqlnet.ora of server.
3). stop and start both listener and database.
4). Now try to connect to DB and observe the behaviour
4、具体操作
4.1)修改INBOUND_CONNECT_TIMEOUT_listenername
4.1.1)lsnrctl命令修改
LSNRCTL> set inbound_connect_timeout 0
LSNRCTL>save_config
4.1.2)vi修改
修改listener.ora文件,加入: INBOUND_CONNECT_TIMEOUT_listenername=0
4.2)修改SQLNET.INBOUND_CONNECT__TIMEOUT
修改sqlnet.ora文件,加入: SQLNET.INBOUND_CONNECT__TIMEOUT=0

ORA-38760: 此数据库实例无法启用闪回数据库

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:ORA-38760: 此数据库实例无法启用闪回数据库

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

SQL> startup
ORACLE 例程已经启动。
Total System Global Area 368263168 bytes
Fixed Size 1374668 bytes
Variable Size 276825652 bytes
Database Buffers 83886080 bytes
Redo Buffers 6176768 bytes
数据库装载完毕。
ORA-38760: 此数据库实例无法启用闪回数据库
SQL> alter database flashback off;
数据库已更改。
SQL> alter database open;
数据库已更改。
SQL> alter database flashback on;
数据库已更改。
说明:如果出现以下错误,处理如下
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-38760: This database instance failed to turn on flashback database
SQL> select name from v$restore_point;
If so, drop them:
SQL> drop restore point ;
SQL> alter database flashback off;
.

ORA-01207/ORA-00338恢复

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:ORA-01207/ORA-00338恢复

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

1、模拟环境
拷贝出来控制文件,然后对数据库进行一些操作,然后关闭数据库,使用拷贝出来的控制文件替换原控制文件,启动数据库
出现类此错误:
ORA-00338: 日志 2 (用于线程 1) 比控制文件更新
ORA-00312: 联机日志 2 线程 1: ‘E:\ORACLE\ORADATA\XFF\REDO02’
或者
ORA-01122: 数据库文件 1 验证失败
ORA-01110: 数据文件 1: ‘E:\ORACLE\ORADATA\XFF\SYSTEM01.DBF’
ORA-01207: 文件比控制文件更新 – 旧的控制文件
2、处理思路
1)创建控制文件
1.1)alter database backup controlfile to trace;
1.2)生成控制文件脚本

STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "XFF" NORESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 584
LOGFILE
  GROUP 1 'E:\ORACLE\ORADATA\XFF\REDO01'  SIZE 10M BLOCKSIZE 512,
  GROUP 2 'E:\ORACLE\ORADATA\XFF\REDO02'  SIZE 10M BLOCKSIZE 512,
  GROUP 3 'E:\ORACLE\ORADATA\XFF\REDO03'  SIZE 10M BLOCKSIZE 512
DATAFILE
  'E:\ORACLE\ORADATA\XFF\SYSTEM01.DBF',
  'E:\ORACLE\ORADATA\XFF\SYSAUX01.DBF',
  'E:\ORACLE\ORADATA\XFF\UNDOTBS01.DBF',
  'E:\ORACLE\ORADATA\XFF\USERS01.DBF',
  'E:\ORACLE\ORADATA\XFF\EXAMPLE01.DBF',
  'E:\ORACLE\ORADATA\XFF\O_ORACLE.DBF',
  'E:\ORACLE\ORADATA\XFF\XIFENFEI01.DBF',
  'E:\ORACLE\ORADATA\XFF\P_TEST01.DBF',
  'E:\ORACLE\ORADATA\XFF\SYS_MG01.DBF',
  'E:\ORACLE\ORADATA\XFF\P101.DBF',
  'E:\ORACLE\ORADATA\XFF\P201.DBF',
  'E:\ORACLE\ORADATA\XFF\P301.DBF',
  'E:\ORACLE\ORADATA\XFF\OGG01.DBF',
  'E:\ORACLE\ORADATA\XFF\SPOT01.DBF'
CHARACTER SET ZHS16GBK
;

1.3)关闭数据库
shutdown abort;
1.4)删除现在的控制文件
1.5)执行生成控制文件脚本
2)恢复数据库
recover database;
3)打开数据库
alter database open;
4)添加临时文件
alter tablespace temp add tempfile
‘E:\ORACLE\ORADATA\XFF\TEMP01.DBF’ size 20m reuse;
说明:可以使用备份的控制文件进行恢复
1:startup mount;
2:recover database using backup controlfile until cancel;
然后根据情况,指定archive log和redo file。
3:alter database open resetlogs;

ORA-01410: invalid ROWID 分析

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:ORA-01410: invalid ROWID 分析

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

1、跟踪错误表
alter session set max_dump_file_size=unlimited;
alter session set db_file_multiblock_read_count=1;
alter session set events ‘10200 trace name context forever, level 1’;
执行下面语句
SELECT COUNT(*) FROM QXTDEV1.TAB_SMS_MT_DOWN
报错
ORA-01410: invalid ROWID
alter session set events ‘10200 trace name context off’;
2、查看跟踪文件尾部
Consistent read started for block 0 : 00400652
env: (scn: 0x0abf.1ee04657 xid: 0x0000.000.00000000 uba: 0x00000000.0000.00 statement num=0 parent xid: xid: 0x0000.000.00000000 scn: 0x0000.00000000 0sch: scn: 0x0000.00000000)
Consistent read finished for block 0 : 400652
Consistent read finished for block 0 : 400652
通过这个文件看到文件读到400652的块的时候终止了,错误应该在这块上
3、分析400652块内容
–转换为10进制
SELECT to_number(‘400652′,’xxxxxxxx’) FROM dual;
–求文件号和块号
SELECT DBMS_UTILITY.DATA_BLOCK_ADDRESS_FILE(4195922),
DBMS_UTILITY.DATA_BLOCK_ADDRESS_BLOCK(4195922)
FROM DUAL;
4、dump文件号为1,块号为1618的内容
alter system dump datafile 1 block 1618;
Block header dump: 0x00400652
Object id on Block? Y
seg/obj: 0xde csc: 0xabf.1e400c0c itc: 2 flg: O typ: 1 – DATA
fsl: 0 fnx: 0x0 ver: 0x01
得到object_id为de,转化为十进制
SELECT to_number(‘de’,’xx’) FROM dual;
查询all_objects表
SELECT * FROM All_Objects WHERE object_id=222;
发现这个数据库(绝对块号400652,相对:文件号1,块号1618)指向的表为dual
5、得出结论
我们的QXTDEV1.TAB_SMS_MT_DOWN表中的数据块指向了sys.dual表,从而出现了ORA-01410错误

ora-nnnnn 错误记录

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:ora-nnnnn 错误记录

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

一、ORA-00257解决
原因:空间不足错误
解决:检查数据文件和日志文件的存储空间,发现问题,进行添加相应数据文件或者对归档日志重新设置归档路径
注意:在10g及其以上版本中,可能是闪回日志文件(系统默认2g)不足
解决方案一:关闭闪回日志的功能
alter database flashback off;
解决方案二:增大闪回日志文件
alter system set DB_RECOVERY_FILE_DEST_SIZE=10g
解决方案三:修改闪回日志文件到一个大目录中
ALTER SYSTEM SET db_recovery_file_dest=’/u01/app/oracle/flash_recovery_area’
二、ORA-16038: 日志 3 序列号 5035 无法归档
ORA-19809: 超出了恢复文件数的限制
ORA-00312: 联机日志 3 线程 1:
……REDO03.LOG
当启动数据库时,有类此上述错误
原因:日志组3的数据文件损坏或丢失
解决:
1、查看alter文件
2、查询v$log视图,确定给日志文件是否归档
3、如果已经归档
用CLEAR命令重建该日志文件
alter database clear logfile group 3;
4、如果没有归档需要先归档
alter database clear unarchived logfile group 3;
5、启动数据库
alter database open;
三、ORA-12162: TNS:net service name is incorrectly specified
新装数据库,使用sqlplus连接,出现上述错误
原因:环境变量ORACLE_SID没有设置
解决vi .profile
export ORACLE_SID=orcl
四、TNS-12555: TNS: permission denied error solution
现象:安装11g r2 的grid中
TNS-12555: TNS: permission denied
TNS-12560: TNS: protocol adapter error
TNS-00525: Insufficient privilege for operation
Linux Error: 1: Operation not permitted
解决:
chmod 777 / var / tmp / .oracle
五、TNS-12547: TNS:lost contact
现象:TNS-12547: TNS:lost contact
TNS-12560: TNS:protocol adapter error
TNS-00517: Lost contact
Linux Error: 104: Connection reset by peer
解决:在/etc/hosts中添加
127.0.0.1 localhost