oracle知识

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:
The Process Global Area,它是属于私有内存段,段内的内容只对本进程可见,这不同于sga的共享内存段。
pga的内存结构不需要latch来保护,因为不会有其他进程同时访问。PGA包括两个部分,fixed pga,variable pga。
fixed pga保存一些数据结构和指向variable pga的指针。PGA也是通过freelist和bucket来分配和管理。

UGA:
User Global Area,它包含以下一些信息
 The persistent and runtime areas for open cursors
 State information for packages, in particular package variables
 Java session state
 The roles that are enabled
 Any trace events that are enabled
 The NLS parameters that are in effect
 Any database links that are open
 The session's mandatory access control (MAC) label for Trusted Oracle
 
 和PGA一样,它也分为fixed,variable两个部分,同样通过freelist和bucket分配和管理内存。
 
CGA:
Call Global Area,跟PGA不一样,CGA只是短暂存在的,它只存在于每一次调用周期,当
Parse an SQL statement
Execute an SQL statement
Fetch the outputs of a SELECT statement
的时候它会被使用到
在分析语句的时候产生的递规调用将会使用到CGA,包括用于检查语义,生成执行计划,PL/SQL中的递规调用也会用到它,DML的触发器递规
调用同样会需要它。Java Call Memory也是在CGA中,这也是ORACLE内存管理中唯一一个用到垃圾收集(garbage collection)的内存区域。

关于PGA,UGA,CGA的详细解释请参考Steve Adamas的<>


sort_area_size:
排序空间的最大限制,在完成排序阶段后,oracle将释放内存并保留sort_area_retained_size用于fetch阶段,当最后一条记录被fetch回
客户端后,oracle将会释放sort_area_retained_size。


sort_area_retained_size:
在UGA中分配的排序空间,当oracle发生排序时,先会从UGA中分配内存直到达到sort_area_retained_size的限制,然后会继续在PGA中分配
内存一直到sort_area_size限制,如上面所说的,sort_area_retained_size将会在fetch阶段被保留,在fetch完成后释放给OS或PGA(区别
在于是否UGA是PGA的subheap)


在9iR2版本以前,UGA,CGA一直是PGA的subheap,当它们被释放后将会释放给PGA而不是释放给OS,这是由于PGA的内存分配是通过malloc,brk
来实现的,但是从9iR2版本开始,我们有了选择,_use_realfree_heap参数给我们机会去改变PGA内存的分配方式,当_use_realfree_heap为
true时,PGA的内存分配将会通过mmap来实现,这样当调用munmap的时候将不必将内存返回给进程而直接返回给OS.下面我们来验证一下

 

alter system set "_use_realfree_heap"=true;

ALTER SESSION SET EVENTS
    'immediate trace name heapdump level 1';
   
HEAP DUMP heap name="pga heap"  desc=0xc6a6400
 extent sz=0x206c alt=92 het=32767 rec=0 flg=2 opc=2
 parent=(nil) owner=(nil) nex=(nil) xsz=0xfff8
EXTENT 0 addr=0xb72c0008
******************************************************
******************************************************
HEAP DUMP heap name="top call heap"  desc=0xc6a8c00
 extent sz=0x206c alt=100 het=32767 rec=0 flg=2 opc=2
 parent=(nil) owner=(nil) nex=(nil) xsz=0xfffc
EXTENT 0 addr=0xb72b0004
  Chunk b72b000c sz=    32780    perm      "perm           "  alo=40
  Chunk b72b8018 sz=    31672    free      "               "
  Chunk b72bfbd0 sz=     1072    recreate  "callheap       "  latch=(nil)
     ds  c6a8300 sz=     1072 ct=        1
Total heap size    =    65524
******************************************************
******************************************************
HEAP DUMP heap name="top uga heap"  desc=0xc6a8d20
 extent sz=0xffdc alt=100 het=32767 rec=0 flg=3 opc=3
 parent=(nil) owner=(nil) nex=(nil) xsz=0xfffc
EXTENT 0 addr=0xb72e0004
  Chunk b72e000c sz=    65524    free      "               "
EXTENT 1 addr=0xb72d0004
  Chunk b72d000c sz=       48    free      "               "
  Chunk b72d003c sz=    65476    recreate  "session heap   "  latch=(nil)
     ds b72c7628 sz=    65476 ct=        1
Total heap size    =   131048

当_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
mmap2(0xb7281000, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 7, 0) = 0xb7281000
mmap2(0xb7291000, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 7, 0) = 0xb7291000
mmap2(NULL, 1048576, PROT_NONE, MAP_PRIVATE|MAP_NORESERVE, 7, 0xf1) = 0xb7121000
mmap2(0xb7121000, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 7, 0) = 0xb7121000
mmap2(0xb7131000, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 7, 0) = 0xb7131000
mmap2(0xb7141000, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 7, 0) = 0xb7141000
mmap2(0xb7151000, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 7, 0) = 0xb7151000
mmap2(0xb7161000, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 7, 0) = 0xb7161000

同时可以看到内存分配是通过mmap来实现的

 

 

alter system set "_use_realfree_heap"=false;

ALTER SESSION SET EVENTS
    'immediate trace name heapdump level 1';   
   
HEAP DUMP heap name="pga heap"  desc=0xc6a6400
 extent sz=0x206c alt=92 het=32767 rec=0 flg=3 opc=3
 parent=(nil) owner=(nil) nex=(nil) xsz=0x206c
EXTENT 0 addr=0xc74a7b8
  Chunk  c74a7c0 sz=     8292    free      "               "
EXTENT 1 addr=0xc748740
  Chunk  c748748 sz=     4148    free      "               "
  Chunk  c74977c sz=     4144    freeable  "session heap   "  ds=0xc73332c


当_use_realfree_heap为true时,uga,cga为pga的subheap


strace -p xxxx -o 2.txt
 
brk(0xc7fb000)                          = 0xc7fb000
brk(0xc823000)                          = 0xc823000
brk(0xc852000)                          = 0xc852000
brk(0xc881000)                          = 0xc881000
brk(0xc8b1000)                          = 0xc8b1000
brk(0xc8e0000)                          = 0xc8e0000
brk(0xc90f000)                          = 0xc90f000
brk(0xc93f000)                          = 0xc93f000
brk(0xc96e000)                          = 0xc96e000
brk(0xc99d000)                          = 0xc99d000


同时可以看到内存分配是通过brk来实现的


我们再来看一下在_use_realfree_heap不同设置下uga,pga的内存使用情况


_use_realfree_heap=true


SQL 10G>select * from testsort order by 1,2,3;

398608 rows selected.

SQL 10G>/

NAME                                                             MEM
---------------------------------------------------------------- -----------------------------------------
session uga memory                                               1.8679962158203125M
session uga memory max                                           49.53220367431640625M
session pga memory                                               4.808185577392578125M
session pga memory max                                           62.308185577392578125M

SQL 10G>/

NAME                                                             MEM
---------------------------------------------------------------- -----------------------------------------
session uga memory                                               49.78192901611328125M
session uga memory max                                           49.78192901611328125M
session pga memory                                               52.808185577392578125M
session pga memory max                                           62.308185577392578125M


SQL 10G>/

NAME                                                             MEM
---------------------------------------------------------------- -----------------------------------------
session uga memory                                               .898193359375M
session uga memory max                                           49.78192901611328125M
session pga memory                                               3.808185577392578125M
session pga memory max                                           62.308185577392578125M


可以看到排序结束后UGA,PGA都直接返回给OS

 

_use_realfree_heap=false


SQL 10G>select * from testsort order by 1,2,3;

398608 rows selected.

 

SQL 10G>/

NAME                                                             MEM
---------------------------------------------------------------- -----------------------------------------
session uga memory                                               .699710845947265625M
session uga memory max                                           .91107177734375M
session pga memory                                               3.50872802734375M
session pga memory max                                           3.50872802734375M

SQL 10G>/

NAME                                                             MEM
---------------------------------------------------------------- -----------------------------------------
session uga memory                                               49.081577301025390625M
session uga memory max                                           49.081577301025390625M
session pga memory                                               51.68599700927734375M
session pga memory max                                           51.68599700927734375M

SQL 10G>/

NAME                                                             MEM
---------------------------------------------------------------- -----------------------------------------
session uga memory                                               .61719512939453125M
session uga memory max                                           49.081577301025390625M
session pga memory                                               51.68599700927734375M
session pga memory max                                           51.68599700927734375M


可以看到排序结束后UGA将会释放给PGA,而PGA也不会释放给OS,直到OS内存不足时将会释放出来


再来看一下sort_area_retained_size,sort_area_size设置对排序的影响


_use_realfree_heap=false

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.


SQL 10G>/

NAME                                                             MEM
---------------------------------------------------------------- -----------------------------------------
session uga memory                                               .646923065185546875M
session uga memory max                                           49.081577301025390625M
session pga memory                                               60.620296478271484375M
session pga memory max                                           60.620296478271484375M

SQL 10G>/

NAME                                                             MEM
---------------------------------------------------------------- -----------------------------------------
session uga memory                                               .62007904052734375M
session uga memory max                                           49.081577301025390625M
session pga memory                                               60.620296478271484375M
session pga memory max                                           60.620296478271484375M


可以看到当sort_area_retained_size设置为1024时(实际上sort_area_retained_size的最小值为2*blocksize,
设置成1024将会被置为2*blocksize),它从UGA中先分配2*blocksize(这里是16k)的内存,然后从PGA中分配。


SQL 10G>alter session set sort_area_retained_size=102400000;

Session altered.

SQL 10G>select * from testsort order by 1,2,3;

398608 rows selected.


SQL 10G>/

NAME                                                             MEM
---------------------------------------------------------------- -----------------------------------------
session uga memory                                               49.0844573974609375M
session uga memory max                                           49.0844573974609375M
session pga memory                                               60.620296478271484375M
session pga memory max                                           60.620296478271484375M

SQL 10G>/

NAME                                                             MEM
---------------------------------------------------------------- -----------------------------------------
session uga memory                                               .61717987060546875M
session uga memory max                                           49.0844573974609375M
session pga memory                                               60.620296478271484375M
session pga memory max                                           60.620296478271484375M

如果设置sort_area_retained_size=102400000=sort_area_size时,那么可以看到UGA将会被一直使用


下面是_use_realfree_heap=true时的情况,情况一样,除了整个排序结束后内存是返回给OS而不是进程
_use_realfree_heap=true

SQL 10G>alter session set workarea_size_policy=manual;

Session altered.

SQL 10G>
SQL 10G>
SQL 10G>
SQL 10G>alter session set sort_area_size=102400000;

Session altered.

SQL 10G>
SQL 10G>
SQL 10G>
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.


SQL 10G>/

NAME                                                             MEM
---------------------------------------------------------------- -----------------------------------------
session uga memory                                               .46117401123046875M
session uga memory max                                           .58603668212890625M
session pga memory                                               59.558185577392578125M
session pga memory max                                           59.558185577392578125M

SQL 10G>/

NAME                                                             MEM
---------------------------------------------------------------- -----------------------------------------
session uga memory                                               .46117401123046875M
session uga memory max                                           .58603668212890625M
session pga memory                                               .870685577392578125M
session pga memory max                                           59.558185577392578125M


SQL 10G>alter session set sort_area_retained_size=102400000;

Session altered.

SQL 10G>select * from testsort order by 1,2,3;

398608 rows selected.


SQL 10G>/

NAME                                                             MEM
---------------------------------------------------------------- -----------------------------------------
session uga memory                                               49.78192901611328125M
session uga memory max                                           49.78192901611328125M
session pga memory                                               52.745685577392578125M
session pga memory max                                           59.558185577392578125M

SQL 10G>/

NAME                                                             MEM
---------------------------------------------------------------- -----------------------------------------
session uga memory                                               .898193359375M
session uga memory max                                           49.78192901611328125M
session pga memory                                               3.808185577392578125M
session pga memory max                                           59.558185577392578125M

 

 

sort_area_retained_size同时会对排序性能产生比较大的影响,不恰当的sort_area_retained_size设置将会导致排序性能严重下降。
当sort_area_size大于语句排序空间需求而sort_area_retained_size设置小于语句排序空间需求时就会产生initial run,导致使用
到临时表空间来存放initial run,这样会降低排序的性能。

SQL 10G>alter session set events'10032 trace name context forever,level 1';

Session altered.


SQL 10G>alter session set sort_area_retained_size=102400000;

Session altered.


SQL 10G>select * from testsort order by 1,2,3;

398608 rows selected.

 

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.

 

---- Sort Parameters ------------------------------
sort_area_size                    102400000
sort_area_retained_size           102400000
sort_multiblock_read_count        2
max intermediate merge width      2837
---- Sort Statistics ------------------------------
Input records                             398608
Output records                            398608
Total number of comparisons performed     4977796
  Comparisons performed by in-memory sort 4977796
Total amount of memory used               50689024
Uses version 2 sort
Does not use asynchronous IO
---- End of Sort Statistics -----------------------

 

sort_area_size                    102400000
sort_area_retained_size           16384
sort_multiblock_read_count        2
max intermediate merge width      2837
*** 2005-10-13 18:09:07.352
---- Sort Statistics ------------------------------
Initial runs                              1
Input records                             398608
Output records                            398608
Total disk blocks used                    5527
Total number of comparisons performed     4977796
  Comparisons performed by in-memory sort 4977796
Temp segments allocated                   1
Extents allocated                         44
Total amount of memory used               50689024
Uses version 2 sort
Does not use asynchronous IO


当使用自动管理PGA时,sort_area_retained_size将会被设置成等于sort_area_size

SQL 10G>show parameter work

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
fileio_network_adapters              string
workarea_size_policy                 string      AUTO

SQL 10G>show parameter pga

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
pga_aggregate_target                 big integer 1G

SQL 10G>alter session set events'10032 trace name context forever,level 1';

Session altered.

SQL 10G>set autotrace trace;
SQL 10G>select * from testsort order by 1,2,3;
398608 rows selected.


---- Sort Parameters ------------------------------
sort_area_size                    50689024
sort_area_retained_size           50689024
sort_multiblock_read_count        1
max intermediate merge width      3092
---- Sort Statistics ------------------------------
Input records                             398608
Output records                            398608
Total number of comparisons performed     4977796
  Comparisons performed by in-memory sort 4977796
Total amount of memory used               50689024
Uses version 2 sort
Does not use asynchronous IO

下一次我们将分享自动管理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

你可能感兴趣的:(数据库内容,oracle,session,sql,database,constraints,asynchronous)