spfile排错小tip |
有时候我们会不小心修改了spfile的某些参些参数导致数据库不能启动,这时候改怎么让数据库重新跑起来呢,oracle针对spfile还是提供了几种方法来修复的。
1.创建pfile
SQL> alter system set processes=10000 scope=spfile;
System altered.
SQL> shutdown
Database closed. Database dismounted. ORACLE instance shut down.
SQL> startup
ORA-00064: object is too large to allocate on this O/S (1,9960000) SQL> create pfile from spfile;
File created.
SQL> host notepad D:/oracle/ora92/database/INITtest.ORA
修改processes=150
SQL> startup pfile=D:/oracle/ora92/database/INITtest.ORA
ORACLE instance started.
Total System Global Area 101785428 bytes
Fixed Size 454484 bytes Variable Size 75497472 bytes Database Buffers 25165824 bytes Redo Buffers 667648 bytes Database mounted. Database opened.
2.创建pfile,再从pfile创建spfile
SQL> alter system set processes=10000 scope=spfile;
System altered.
SQL> shutdown
Database closed. Database dismounted. ORACLE instance shut down.
SQL> startup
ORA-00064: object is too large to allocate on this O/S (1,9960000) SQL> create pfile from spfile;
File created.
SQL> host notepad D:/oracle/ora92/database/INITtest.ORA
修改processes=150
SQL> create spfile from pfile;
File created.
SQL> startup
ORACLE instance started.
Total System Global Area 101785428 bytes
Fixed Size 454484 bytes Variable Size 75497472 bytes Database Buffers 25165824 bytes Redo Buffers 667648 bytes Database mounted. Database opened. SQL>
3.修改pfile,覆盖参数
修改pfile
spfile=D:/oracle/ora92/database/SPFILETEST.ORA
processes=150
SQL> startup pfile=D:/oracle/ora92/database/INITtest.ORA
ORACLE instance started.
Total System Global Area 101785428 bytes
Fixed Size 454484 bytes Variable Size 75497472 bytes Database Buffers 25165824 bytes Redo Buffers 667648 bytes Database mounted. Database opened. |
oracle排序系列二 |
上一期讲了oracle在什么情况下需要排序,这次我们把注意力集中到与排序相关的几个内存组件 PGA: UGA: 关于PGA,UGA,CGA的详细解释请参考Steve Adamas的<
alter system set "_use_realfree_heap"=true; ALTER SESSION SET EVENTS 当_use_realfree_heap为true时,pga,uga,cga为独立的heap strace -p xxxx -o 1.txt mmap2(0xb7271000, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 7, 0) = 0xb7271000 同时可以看到内存分配是通过mmap来实现的
alter system set "_use_realfree_heap"=false; ALTER SESSION SET EVENTS
398608 rows selected. SQL 10G>/ NAME MEM SQL 10G>/ NAME MEM
NAME MEM
_use_realfree_heap=false
398608 rows selected.
SQL 10G>/ NAME MEM SQL 10G>/ NAME MEM SQL 10G>/ NAME MEM
SQL 10G>alter session set workarea_size_policy=manual; Session altered. SQL 10G>alter session set sort_area_size=102400000; Session altered. SQL 10G>alter session set sort_area_retained_size=1024; Session altered. SQL 10G>select * from testsort order by 1,2,3; 398608 rows selected.
NAME MEM SQL 10G>/ NAME MEM
Session altered. SQL 10G>select * from testsort order by 1,2,3; 398608 rows selected.
NAME MEM SQL 10G>/ NAME MEM 如果设置sort_area_retained_size=102400000=sort_area_size时,那么可以看到UGA将会被一直使用
SQL 10G>alter session set workarea_size_policy=manual; Session altered. SQL 10G> Session altered. SQL 10G> Session altered.
398608 rows selected.
NAME MEM SQL 10G>/ NAME MEM
Session altered. SQL 10G>select * from testsort order by 1,2,3; 398608 rows selected.
NAME MEM SQL 10G>/ NAME MEM
sort_area_retained_size同时会对排序性能产生比较大的影响,不恰当的sort_area_retained_size设置将会导致排序性能严重下降。 SQL 10G>alter session set events'10032 trace name context forever,level 1'; Session altered.
Session altered.
398608 rows selected.
SQL 10G>alter session set sort_area_retained_size=1024; Session altered.
398608 rows selected.
---- Sort Parameters ------------------------------
sort_area_size 102400000
SQL 10G>show parameter work NAME TYPE VALUE SQL 10G>show parameter pga NAME TYPE VALUE SQL 10G>alter session set events'10032 trace name context forever,level 1'; Session altered. SQL 10G>set autotrace trace;
下一次我们将分享自动管理PGA |
set constraint,alter session set constraint,有条件的unique限制 |
set constraint 子句是用来设置deferrable constraint的状态的,可以设置constraint的状态为immediate或deferred,具体语法请看
http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_104a.htm#2066962
它的作用域在事务级别,一旦事务结束constraint的状态恢复初始值
SQL 10G>create table t
( x int constraint check_x check ( x > 0 ) deferrable initially immediate, y int constraint check_y check ( y > 0 ) deferrable initially deferred ) / SQL 10G>conn test/test Connected. SQL 10G>desc user_constraints Name Null? Type ----------------------------------------- -------- ---------------------------- OWNER NOT NULL VARCHAR2(30) CONSTRAINT_NAME NOT NULL VARCHAR2(30) CONSTRAINT_TYPE VARCHAR2(1) TABLE_NAME NOT NULL VARCHAR2(30) SEARCH_CONDITION LONG R_OWNER VARCHAR2(30) R_CONSTRAINT_NAME VARCHAR2(30) DELETE_RULE VARCHAR2(9) STATUS VARCHAR2(8) DEFERRABLE VARCHAR2(14) DEFERRED VARCHAR2(9) VALIDATED VARCHAR2(13) GENERATED VARCHAR2(14) BAD VARCHAR2(3) RELY VARCHAR2(4) LAST_CHANGE DATE INDEX_OWNER VARCHAR2(30) INDEX_NAME VARCHAR2(30) INVALID VARCHAR2(7) VIEW_RELATED VARCHAR2(14 查看constraint的初始值
SQL 10G> select CONSTRAINT_NAME,CONSTRAINT_TYPE,STATUS,DEFERRABLE,DEFERRED from user_constraints where table_name='T';
CONSTRAINT_NAME C STATUS DEFERRABLE DEFERRED
------------------------------ - -------- -------------- --------- CHECK_X C ENABLED DEFERRABLE IMMEDIATE CHECK_Y C ENABLED DEFERRABLE DEFERRED
由于x列的初始值为immediate,所以当发生insert的时候就直接报错了
SQL 10G>insert into t values(-1,1); insert into t values(-1,1) * ERROR at line 1: ORA-02290: check constraint (TEST.CHECK_X) violated
设定constraint为deferred
SQL 10G>set constraints all deferred;
Constraint set.
SQL 10G>insert into t values(-1,1);
1 row created.
SQL 10G>commit;
commit * ERROR at line 1: ORA-02091: transaction rolled back ORA-02290: check constraint (TEST.CHECK_X) violated
可以看到constraint设置起作用了
再次insert又报错误,因为set constraint的作用域是事务级的,已经恢复到初始设置
SQL 10G>insert into t values(-1,1); insert into t values(-1,1) * ERROR at line 1: ORA-02290: check constraint (TEST.CHECK_X) violated
使用alter session 来进行session级别的constraint设置
SQL 10G>alter session set constraints=deferred;
Session altered.
SQL 10G>insert into t values(-1,1);
1 row created.
SQL 10G>commit;
commit * ERROR at line 1: ORA-02091: transaction rolled back ORA-02290: check constraint (TEST.CHECK_X) violated SQL 10G>insert into t values(-1,1);
1 row created.
SQL 10G>commit;
commit * ERROR at line 1: ORA-02091: transaction rolled back ORA-02290: check constraint (TEST.CHECK_X) violated
可以发现在session级别内constraint的设置都保持有效
下面来演示一下有条件的unique限制
SQL 10G>drop table t;
Table dropped.
SQL 10G>create table t(a varchar2(10),b number);
Table created.
SQL 10G>create unique index uni_t
2 on t( case when a = 'ACTIVE' then b end );
Index created.
SQL 10G>insert into t values('a',1);
1 row created.
SQL 10G>insert into t values('a',1);
1 row created.
SQL 10G>commit;
Commit complete.
SQL 10G>insert into t values('ACTIVE',1);
1 row created.
SQL 10G>insert into t values('ACTIVE',1);
insert into t values('ACTIVE',1) * ERROR at line 1: ORA-00001: unique constraint (TEST.UNI_T) violated
通过函数索引就实现了有条件的unique限制,不考虑性能问题的话倒是一个好的方法
|
数据库打开情况下删除数据文件会发生什么(unix) |
创建测试表空间及表
SQL 10G>create tablespace testearse datafile '/opt/oracle/oradata/dbtest/testearse.dbf' size 1m;
Tablespace created.
SQL 10G>create table testearse(a number) tablespace testearse;
Table created.
看看有哪些进程关联到这个数据文件
SQL 10G>!
[oracle@csdba ~]$ lsof |grep testearse oracle 4424 oracle 33uW REG 8,9 1056768 852911 /opt/oracle/oradata/dbtest/testearse.dbf oracle 25121 oracle 15u REG 8,9 1056768 852911 /opt/oracle/oradata/dbtest/testearse.dbf
删除这个数据文件
[oracle@csdba ~]$ rm /opt/oracle/oradata/dbtest/testearse.dbf [oracle@csdba ~]$
再观看lsof的结果,发现相关的状态已经变成deleted,但是文件还是保持打开状态
[oracle@csdba ~]$ lsof |grep testearse oracle 4424 oracle 33uW REG 8,9 1056768 852911 /opt/oracle/oradata/dbtest/testearse.dbf (deleted) oracle 25121 oracle 15u REG 8,9 1056768 852911 /opt/oracle/oradata/dbtest/testearse.dbf (deleted)
oracle 4424 1 0 Sep14 ? 00:00:35 ora_dbw0_dbtest
oracle 25121 25893 0 14:41 ? 00:00:00 oracledbtest (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
SQL 10G>insert into testearse values(10);
1 row created.
SQL 10G>commit;
Commit complete.
SQL 10G>alter system checkpoint;
System altered.
SQL 10G>insert into testearse values(10);
1 row created.
SQL 10G>commit;
SQL 10G>select * from testearse;
A
---------- 10 10 SQL 10G>ALTER SESSION SET EVENTS 'immediate trace name flush_cache';
Session altered.
SQL 10G>select * from testearse;
A
---------- 10 10
由于本身sqlplus的process和testearse.dbf还建立连接,所以这时仍然可以对这个表进行操作
退出sqlplus,重新开启sqlplus
SQL 10G>exit Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning and Data Mining Scoring Engine options
[oracle@csdba ~]$ lsof |grep testearse
oracle 4424 oracle 33uW REG 8,9 1056768 852911 /opt/oracle/oradata/dbtest/testearse.dbf (deleted)
这时只剩下dbwr进程和testearse.dbf还建立连接
[oracle@csdba bdump]$ sqlplus "/ as sysdba"
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Oct 10 15:47:58 2005
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning and Data Mining Scoring Engine options
SQL 10G>conn test/test
Connected. SQL 10G>select * from testearse;
A
---------- 10 10
SQL 10G>ALTER SESSION SET EVENTS 'immediate trace name flush_cache';
Session altered.
刷新buffer cache,写入数据文件
这时由于原来sqlplus和testearse.dbf的连接已经关闭,新连接由于数据文件被删除而无法建立
,所以这时候不能对testearse进行操作
SQL 10G>select * from testearse;
select * from testearse * ERROR at line 1: ORA-01116: error in opening database file 13 ORA-01110: data file 13: '/opt/oracle/oradata/dbtest/testearse.dbf' ORA-27041: unable to open file Linux Error: 2: No such file or directory Additional information: 3 SQL 10G>alter system checkpoint;
System altered.
[oracle@csdba ~]$ lsof |grep testearse |
限制subprogram传递null参数 |
如何限制procedure里传递null的参数呢,tom提供了一个简便的方法,使用subtype来实现
create or replace package my_pkg
as subtype mystring is varchar2(4000) NOT NULL; procedure p( p_input mystring ); end; / create or replace package body my_pkg as
procedure p( p_input mystring )
is begin null; end;
end;
/
SQL 10G>exec my_pkg.p(null);
BEGIN my_pkg.p(null); END;
*
ERROR at line 1: ORA-06550: line 1, column 16: PLS-00567: cannot pass NULL to a NOT NULL constrained formal parameter ORA-06550: line 1, column 7: PL/SQL: Statement ignored |