Saturday, April 28, 2007

Explain plan 和 Statspack

查看查询计划,安装Statspack。都是最常用的东西。
记录一下,方便自己以后查找。

[oracle@database ~]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.4.0 - Production on Sat Apr 28 11:02:37 2007

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.


Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> CREATE PUBLIC SYNONYM PLAN_TABLE FOR PLAN_TABLE;

Synonym created.

SQL> GRANT ALL ON PLAN_TABLE TO PUBLIC;

Grant succeeded.

SQL> @/u1/oracle/product/9.2/sqlplus/admin/plustrce
SQL>
SQL> drop role plustrace;
drop role plustrace
*
ERROR at line 1:
ORA-01919: role 'PLUSTRACE' does not exist


SQL> create role plustrace;

Role created.

SQL>
SQL> grant select on v_$sesstat to plustrace;

Grant succeeded.

SQL> grant select on v_$statname to plustrace;

Grant succeeded.

SQL> grant select on v_$mystat to plustrace;

Grant succeeded.

SQL> grant plustrace to dba with admin option;

Grant succeeded.

SQL>
SQL> set echo off
SQL> GRANT PLUSTRACE TO PUBLIC;

Grant succeeded.

SQL>

/*

SET AUTOT OFF
SET AUTOT ON EXPLAIN
SET AUTOT ON STATISTICS
SET AUTOT ON
SET AUTOT TRACEONLY

*/


---------
Statspack
---------

SQL> CONNECT / AS SYSDBA
Connected.
SQL>

SQL> DEFINE DEFAULT_TABLESPACE='TOOLS'
SQL> DEFINE TEMPORARY_TABLESPACE='TEMP'
SQL> DEFINE PERFSTAT_PASSWORD='MY_PERFSTAT_PASSWORD'
SQL> @/u1/oracle/product/9.2/rdbms/admin/spcreate
.....

.....
Statspack装好之后,执行snap过程
SQL> CONNECT perfstat/my_perfstat_password
SQL> EXECUTE statspack.snap;

在Statspack收集到数据之后才能查看统计结果。
SQL> @/u1/oracle/product/9.2/rdbms/admin/spreport

PS:Ultra edit里面'Alt+F5'和'Ctrl+F5'可以改变大小写。

数据库不完全恢复

今天report突然出现这个错误
EXT-fs Error (device cciss/c0d0p2) in start-transaction ; Journal has aborted.
消息给的很明显,是文件系统的日志被异常终止了。

重启后
mkrootdev: label / not found
mount:error 2 mounting ext3
mount:error 2 mounting none
switchroot: mount failed 22
umount initrd/dev failed : 2
Kernel panic - not syncing : Attempted to kill init !

这个错误搞不定了,决定重装。
由于oracle的数据文件存放在cciss/c0d0p3上,所以恢复起来没有什么问题。

OS安装好后,将参数文件和密码文件复制到dbs下。
但是我没有备份参数文件和密码文件,所以在原来的alter中将参数文件的内容贴了过来(这里要注意,字符类型的需要添加单引号)。
密码文件临时生成
orapwd file=orapwreport password=oracle entries=20

open时报错
ORA-00449: background process 'CKPT' unexpectedly terminated with error 7446
ORA-07446: sdnfy: bad value '' for parameter .

找了半天原因发现跟踪文件目录不存在
*.background_dump_dest='/u1/oracle/admin/report/bdump'
*.user_dump_dest='/u1/oracle/admin/report/udump'
*.core_dump_dest='/u1/oracle/admin/report/cdump'
于是一个一个的mkdir。

mount阶段没有报任何错误,接着采用backup controlfile to trace的技巧恢复数据库。
SQL> alter database backup controlfile to trace;

System altered.

编辑trace文件(new.ora):
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "REPORT" NORESETLOGS NOARCHIVELOG
     MAXLOGFILES 50
     MAXLOGMEMBERS 5
     MAXDATAFILES 100
     MAXINSTANCES 1
     MAXLOGHISTORY 226
LOGFILE
    GROUP 1 '/u1/oracle/oradata/report/redo01.log' SIZE 100M,
    GROUP 2 '/u1/oracle/oradata/report/redo02.log' SIZE 100M,
    GROUP 3 '/u1/oracle/oradata/report/redo03.log' SIZE 100M
DATAFILE
    '/u1/oracle/oradata/report/system01.dbf',
    '/u1/oracle/oradata/report/undotbs01.dbf',
    '/u1/oracle/oradata/report/cwmlite01.dbf',
    '/u1/oracle/oradata/report/drsys01.dbf',
    '/u1/oracle/oradata/report/example01.dbf',
    '/u1/oracle/oradata/report/indx01.dbf',
    '/u1/oracle/oradata/report/odm01.dbf',
    '/u1/oracle/oradata/report/tools01.dbf',
    '/u1/oracle/oradata/report/users01.dbf',
    '/u1/oracle/oradata/report/xdb01.dbf',
    '/u1/oracle/product/9.2/dbs/TBS_LARGE06.dat',
    '/u1/oracle/product/9.2/dbs/TBS_LARGE07.dat',
    '/u1/oracle/product/9.2/dbs/TBS_LARGE08.dat',
    '/u1/oracle/product/9.2/dbs/TBS_LARGE09.dat'

CHARACTER SET AL32UTF8
;

RECOVER DATABASE
ALTER DATABASE OPEN RESETLOGS;
ALTER DATABASE OPEN;

ALTER TABLESPACE TEMP ADD TEMPFILE '/u1/oracle/oradata/report/temp01.dbf' REUSE;

这里发现TBS_LARGE的几个数据文件没有备份,由于不在我指定的数据文件目录下面。
所以修改new.ora文件,去掉TBS_LARGE这几个文件。

SQL> @new.ora
然后成功打开数据库。

Thursday, April 26, 2007

系统挂起

今天系统使用人员反映系统登录很慢。
查看了一下v$session,发现有很多session。
系统基本不能使用DML。

检查一下alert,发现下面的内容:
Wed Apr 25 09:05:43 2007
Database Characterset is AL32UTF8
replication_dependency_tracking turned off (no async multimaster replication found)
Completed: ALTER DATABASE OPEN
Wed Apr 25 23:16:37 2007
ORACLE Instance mycim - Can not allocate log, archival required
Wed Apr 25 23:16:37 2007
ARCH: Connecting to console port...
Thread 1 cannot allocate new log, sequence 44
All online logs needed archiving
Current log# 1 seq# 43 mem#
0: /u1/oracle/product/9.2/oradata/mycim/redo01.log

SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Disabled
Archive destination            /u1/logs/archives
Oldest online log sequence     41
Next log sequence to archive   43
Current log sequence           43

SQL> alter system set log_archive_start=true scope=spfile;

System altered.

SQL> archive log start


Tuesday, April 24, 2007

备份脚本

备份脚本backup

if [ "x$1" != "x" ]; then
echo $1

mknod $1"`date +%G%m`.pipe" p
gzip < $1"`date +%G%m`.pipe" > $1"`date +%G%m%d-%H%M`.dmp.gz" &
exp userid=$1/$1@mycim owner=$1 INDEXES=y \
grants=y \
rows=y \
constraints=y \
compress=N \
file=$1"`date +%G%m`.pipe"
else echo "no schema enterred"
fi
rm $1"`date +%G%m`.pipe" -f

导入
gunzip < file > pipe_file
imp username/password file=pipe_file





gzip < [name-of-pipe] > [name-of-output-dumpfile]
gunzip < [name-of-input-dumpfile] > [name-of-pipe].

Saturday, April 21, 2007

10g OCP考试通过

热烈庆祝,嘿嘿。(正在等证书)
不过,过了OCP还要继续学习。
接下来,可以继续前不久开始的总结工作了。

Thursday, April 5, 2007

性能变差了

昨天把数据库服务器上的RAID重新做了一下,结果发现性能明显下降了。
今天测试一下,晚上再重新做一下。

Sunday, April 1, 2007

小记

Fedora Core 6 硬盘安装Reiserfs 文件系统,需要给kernel传入一个额外的参数。
先用grub引导,然后进入command。
grub> kernel (hd0,10)/fc6/vmlinuz reiserfs
grub> initrd (hd0,10)/fc6/initrd.img
grub> boot
这样引导起来的安装过程是可以使用reiserfs文件系统的。
但是我装完之后不能登录,奇怪,换回ext3就一切正常了。
不知道是Redhat故意的还是笔记本硬件方面的问题。

今天在安装10g的时候报错ORA-04031。
说明安装过程中shared pool没有分配足够大的连续内存区域。
把SGA调大了140MB,安装中就没有报错了。
看来内存还是小了点儿。
数据库正常运行的情况下ORA-04031也可能是其它原因造成的,比如内存碎片。