Archive for 十二月, 2007

find命令

星期四, 十二月 20th, 2007

版权声明
本文是zhyfly兄贴在LinuxSir.Org 的一个帖子而整理出来的,如果您对版权有疑问,请在本帖后面跟帖。谢谢;本文的HTML版本由北南南北整理;修改了整篇文档的全角及说明文字中的单词中每个字母空格的问题;为标题加了编号,方便大家阅读;

前言:关于find命令

由于find具有强大的功能,所以它的选项也很多,其中大部分选项都值得我们花时间来了解一下。即使系统中含有网络文件系统( NFS),find命令在该文件系统中同样有效,只你具有相应的权限。

在运行一个非常消耗资源的find命令时,很多人都倾向于把它放在后台执行,因为遍历一个大的文件系统可能会花费很长的时间(这里是指30G字节以上的文件系统)。

(全文…)

imp/exp

星期三, 十二月 19th, 2007

将一个数据库的某用户的所有表导到另外数据库的一个用户下面的例子  
exp userid=system/manager owner=username1 file=expfile.dmp
imp userid=system/manager fromuser=username1 touser=username2 ignore=y file=expfile.dmp

ORACLE数据库有两类备份方法。第一类为物理备份,该方法实现数据库的完整恢复,但数据库必须运行在归挡模式下(业务数据库在非归挡模式下运行),且需要极大的外部存储设备,例如磁带库;第二类备份方式为逻辑备份,业务数据库采用此种方式,此方法不需要数据库运行在归挡模式下,不但备份简单,而且可以不需要外部存储设备。

(全文…)

keep池和cache

星期二, 十二月 18th, 2007

通常为了我们会吧经常访问的小表CACHE到内存,为了防止数据过快老化。其中KEEP是永久保存,除非用户撤销。

alter table table_name cache

ALTER TABLE table_name STORAGE (BUFFER_POOL KEEP)

  (全文…)

for update nowait

星期二, 十二月 18th, 2007

Oracle provides the FOR UPDATE clause in SQL syntax to allow the developer to lock a set of Oracle rows for the duration of a transaction.  The FOR UPDATE clause is generally used in cases where an online system needs to display a set of row data on a screen and they need to ensure that the data does not change before the end-user has an opportunity to update the data.

However, the FOR UPDATE clause in SQL will cause the SQL to “hang” if one of the requested rows is locked by another user.  If you try to access the rows with the NOWAIT clause, you will get an error message, ORA-00054 Resource busy and acquire with NOWAIT specified.

Essentially, the options were either “wait forever” or “don’t wait.  Oracle9i has added additional flexibility to the syntax by allowing the SQL to wait for a pre-defined amount of time for locked rows before aborting.

In this example we select a student row and wait up to 15 seconds for another session to release their lock:

select

   student_last_name

from

   student

where student_id = 12345

FOR UPDATE WAIT 15;

In the real-world, many large online systems do not use the FOR UPDATE clause.  Rather, they ensure data integrity by re-reading the data when the end-user requests a change, and displays an error message if the data has changed since it was initially displayed to the user.

oracle诊断事件

星期二, 十二月 18th, 2007

Oracle为RDBMS提供了多种的诊断工具,诊断事件(Event)是其中一种常用、好用的方法,它使DBA可以方便的转储数据库各种结构及跟踪特定事件的发生.

  一、Event的通常格式及分类  
  1、 通常格式如下:
  EVENT=”<事件名称><动作><跟踪项目><范围限定>”
  
  2、 Event分类
  诊断事件大体上可以分为四类:
  a. 转储类事件:它们主要用于转储Oracle的一些结构,例如转储一下控制文件、数据文件头等内容。
  b. 捕捉类事件:它们用于捕捉一些Error事件的发生,例如捕捉一下ORA-04031发生时一些Rdbms信息,以判断是Bug还是其它原因引起的这方面的问题。
  c. 改变执行途径类事件:它们用于改主一些Oracle内部代码的执行途径,例如设置10269将会使Smon进程不去合并那些Free的空间。
  d. 跟踪类事件:这们用于获取一些跟踪信息以用于Sql调优等方面,最典型的便是10046了,将会对Sql进行跟踪。
  3、 说明:
  a. 如果immediate放在第一个说明是无条件事件,即命令发出即转储到跟踪文件。
  b. trace name位于第二、三项,除它们外的其它限定词是供Oracle内部开发组用的。
  c. level通常位于1-10之间(10046有时用到12),10意味着转储事件所有的信息。例如当转储控制文件时,level1表示转储控制文件头,而level 10表明转储控制文件全部内容。
  d. 转储所生成的trace文件在user_dump_dest初始化参数指定的位置。

trace.jpg

二、说一说设置的问题了  
  可以在init.ora中设置所需的事件,这将对所有会话期打开的会话进行跟踪,也可以用alter session set event 等方法设置事件跟踪,这将打开正在进行会话的事件跟踪。
  
  1、 在init.ora中设置跟踪事件的方法
  a. 语法
  EVENT=”event 语法|,level n|:event 语法|,level n|…”
  b. 举例
  event=”10231 trace name context forever,level 10’
  c. 可以这样设置多个事件:
  EVENT=”
  10231 trace name context forever, level 10:
  10232 trace name context forever, level 10″
  
  2、 通过Alter session/system set events这种方法
  举个例子大家就明白了
  Example:
  Alter session set events ‘immediate trace name controlf level 10’;
  Alter session set events ‘immediate trace name blockdump level 112511416’; (*)
  在oracle8x及之上的版本也有这样的语句:
  Alter system dump datafile 13 block 15;实现的功能与(*)是类似的。
  
  3、 使用DBMS_SYSTEM.SET_EV的方法
  a. 过和定义如下
  DBMS_SYSTEM.SET_EV(
  SI Binary_integer,
  SE Binary_integer,
  EV Binary_integer,
  LE Binary_integer,
  NM Binary_integer);
  
  SI: 即v$session中的sid
  SE:即v$session中的serial#
  EV:要设置的事件
  LE:要设置事件的级别
  NM:名称
  b. 举个例子,以10046为例
  SQL> EXECUTE SYS.DBMS_SYSTEM.SET_EV(sid,serial#,10046,12,”);
  
  4、 使用Oradebug来设置诊断事件的方法
  同样举个例子大家就明白了:
  a. 找到spid
  SQL>select username, sid, serial#, paddr from v$session where username=’qiuyb’;
  
  USERNAME SID SERIAL# PADDR
  ——————————————————–
  HRB3 265 910 C000000084435AD8
  
  SQL>SELECT ADDR,PID,SPID FROM V$PROCESS WHERE ADDR= C000000084435AD8′;
  ADDR PID SPID
  ——————————————
  C000000084435AD8 91 4835
  
  b. 设置事件,以10046为例
  sqlplus /nolog
  SQL>connect / as sysdba;
  SQL>oradebug setospid 4835
  SQL>oradebug unlimit   –不限制转储文件的大小
  SQL> oradebug event 10046 trace name context forever,level 12 –设置事件进行sql跟踪
  
  SQL> oradebug event 10046 trace name context off –关闭跟踪
  
  注意不要用oradug去跟踪oracle的smon,pmon等几个进程,操作不当可能会杀掉这几个后台进和引起宕库。
  
  三、你可能的问题  
  1、 我如何知道在系统中设置了哪些event?
  回答:
  a. 如果你的事件是在init.ora中设置的可以用
  SQL>show parameter event;
  来查看
  b. Michael R.Ault给的SQL
  serveroutput on size 1000000
  declare
  event_level number;
  begin
  for i in 10000..10999 loop
  sys.dbms_system.read_ev(i,event_level);
  if (event_level > 0) then
  dbms_output.put_line(’Event ‘||to_char(i)||’ set at level ‘||
  to_char(event_level));
  end if;
  end loop;
  end;
  /