Monday, March 26, 2007

总结进度

前不久准备写的总结进度如下:

1.Linux的锁和Oracle的锁
状态:已开始
进度:60%

2.Linux的内存结构
状态:未开始

3.Oracle的内存结构
状态:未开始

4.文件系统
状态:未开始

5.Oracle的数据块
状态:未开始

6.磁盘
状态:未开始

7.SQL语句的解析过程
状态:未开始


进度原因,最近有个生产系统要上线,大部分时间用来输入一些初始数据和系统测试。
还有就是准备参加10g的OCP考试,花了不少时间看042和043。

Oracle的thin与oci连接方式

应用与oracle的连接分为thin和oci两种模式,前者不需要oracle客户端的支持,后者需要。

jdbc:oracle:thin:@youroraclehost:1521:yoursid
jdbc:oracle:thin:@(description=(address=(host=youroraclehost)(protocol=tcp)(port=1521))(connect_data=(SERVICE_NAME=yourservicename)))

jdbc:oracle:oci:@youroracle-tns-name
jdbc:oracle:oci:@(description=(address=(host=youroraclehost)(protocol=tcp)(port=1521))(connect_data=(SERVICE_NAME=yourservicename)))

昨天把UAT环境上的thin模式改为了oci模式,但是由于jboss的启动脚本有一处错误,导致jboss半天没有起来。这里记录一下使用oci模式需要注意的地方。

大部分情况下,jboss启动不起来是由于环境变量的问题。
LD_LIBRARY_PATH=$ORACLE_HOME/lib32
环境变量LD_LIBRARY_PATH是用来设置共享目标库的,linux系统会在搜索标准库之前搜索共享目标库,而且这里面的函数也会override the functions in standard library

JAVA_OPTS="$JAVA_OPTS -Dprogram.name=$PROGNAME -Djava.library.path=$ORACLE_HOME/lib32"
这个是我们的java启动脚本。需要注意的是-Djava.library.path=$ORACLE_HOME/lib32,它告诉java其native library的搜索路径。

否则你会得到这个错误。
no ocijdbc9 in java.library.path

昨天就是这里错了-Djava.library.path=$ORACLE_HOME/lib32.2

Saturday, March 24, 2007

notes about SQLPLUS & database migration

Start Oracle using SQLPLUS on Windiws NT platform:

As we all know, post-oracle-9i-installation on Windows NT needs some manual operations to startup the database from SQLPLUS.
Here are the steps to notice me long after.

1.Set the ORACLE_SID enviroment.
2.Make sure key HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\HOME0\ORACLE_SID in register table has correct value.
3.Services OracleService and OracleOraHome92TNSListener are of automatic startup.
4.Use oradim to change oracle start type.


ORADIM -STARTUP -SID feelfall -STARTTYPE srvc

Database files migration:

I made a mistake in oracle 9i installation yesterday on my notebook. The datafiles, control files and online logs had been stored at path of oracle\ora92\feelfall, which i was intent to exist at oracle\oraDATA. The problem is not as simple as drag the whole 'feelfall'(coincides my sid) directory into oracle\ then rename it. Here i need a little bit more operations to make the database running okay.
We know that oracle database is conceptually divided into two parts, instance and databse. The parameter file contains part of the inforamtion about oracle instance and has records of the path of database control files. Well, control file contains the whole information about the database part, such like every datafile's location, as well as every online log file's, recovery information and so on. For safe consideration, there are mutiple controfile mirrors, and each one can be used to open a specified database.


open F:\oracle\admin\feelfall\pfile\init.ora.223200716132

###########################################
# File Configuration
###########################################
control_files=("F:\oracle\ora92\feelfall\control01.ctl", "F:\oracle\ora92\feelfall\control02.ctl", "F:\oracle\ora92\feelfall\control03.ctl")

create a file init.ora similar to init.ora.223200716132, then change control_files's value like this:
control_files=("F:\oracle\oraDATA\feelfall\control01.ctl", "F:\oracle\oraDATA\feelfall\control02.ctl", "F:\oracle\oraDATA\feelfall\control03.ctl")



SQL> shutdown
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup nomount pfile='F:\ORACLE\ADMIN\feelfall\PFILE\INIT.ORA'
ORACLE instance started.

Total System Global Area 135338868 bytes
Fixed Size 453492 bytes
Variable Size 109051904 bytes
Database Buffers 25165824 bytes
Redo Buffers 667648 bytes

SQL> alter database mount;
alter database mount
*
ERROR at line 1:
ORA-00205: error in identifying controlfile, check alert log for more info

This error message indicates oracle instance can not locate my control files.
Move control files to the path asigned above.

SQL> alter database mount;

Database altered.

Now i should rename the datafiles and log files, ortherwise i could not accomplish my initial intention.

SQL> alter database rename file 'F:\ORACLE\ORA92\feelfall\SYSTEM01.DBF'
2 to 'F:\ORACLE\ORADATA\feelfall\SYSTEM01.DBF'

Database altered.


...rename others...


I should put a little emphasize on temporary file, cause you cann't rename them.

SQL> alter database tempfile 'F:\ORACLE\ORA92\feelfall\TEMP01.DBF' drop;

Database altered.

...now i openned the datavbase...

SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: 'F:\ORACLE\ORADATA\feelfall\SYSTEM01.DBF'

The open stage failed because i need the rest files.
Copy the files needed to the correct new folder.

SQL> alter database open;

Database altered.

SQL> alter tablespace temp
2 add tempfile 'F:\ORACLE\ORADATA\feelfall\TEMP01.DBF' reuse;

Tablespace altered.

Now, create a new spfile so that not more actions taken when startup.

SQL> create spfile from pfile='F:\ORACLE\ADMIN\feelfall\PFILE\INIT.ORA';

File created.



Okay!


Monday, March 19, 2007

关QQ

每天在公司都把QQ开着,今天回来的时候忘记关了,导致每次登录都会被公司里的那个给顶下去。怎么办?
使绝招,IP映射!
出于安全考虑,首先SSH到公司的IP,登录到一台Linux。
然后再从那台Linux机器Telnet到路由器。

Username:
Password:
Lili_router>en
Password:
Lili_router#config terminal
Enter configuration commands, one per line. End with CNTL/Z.
Lili_router(config)#ip nat inside source static tcp 192.168.1.32 3389 公司固定IP 3389 extendable


接下来通过windows的远程桌面就可以啦,哈哈哈哈。

Sunday, March 18, 2007

今天买笔记本啦啦啦

看了好几天笔记本,最后选中了HP nx6330 708。
昨天上午到了卖电脑的地方,价格谈好了,8590¥。
结果在付钱的时候忘记了工资卡的密码。-_-!
在刷卡机上试了三次,在ATM机上试了一次,在银行柜台试了两次。
把一天里可以试的次数用完了。 下午回到宿舍,等待第二天再试。

今天8点起床(睡不着啊)。试了一次,通过。
原来是初始密码,由于好久没有取过钱了,给忘记了。
就这样,笔记本买回来了。

从今天中午到现在一直在配置机器上的软件。
整体感觉还不错,就是屏幕亮度觉得还差一些,硬盘偶尔还有拉肚子的声音。
太晚了,睡觉。

Friday, March 16, 2007

三件事


一、前天晚上登录mycim正式环境突然没有了反应。
用vmstat查看jboss服务器的状态,发现PROC的b为1,CPU的id和wa栏位出现异常,两个属性各占50%,说明有进程在等待IO。
ps -aux后发现是和数据库链接的进程在等待IO。
那么问题定位在了ORACLE数据库。
# ssh oracle@192.168.1.2
ssh: connect to host 192.168.1.2 port 22: No route to host

# ping 192.168.1.2
PING 192.168.1.2 (192.168.1.2) 56(84) bytes of data.
From 192.168.1.32 icmp_seq=0 Destination Host Unreachable
From 192.168.1.32 icmp_seq=1 Destination Host Unreachable
From 192.168.1.32 icmp_seq=2 Destination Host Unreachable

重新插了一下网线,问题解决~

二、昨天写了一句特失败的SQL,把表给更新了。结果导致一些数据丢失,应用无法正常运行。具体SQL和解决过程如下。

update named_object o set o.instance_id=(select t.bv from t where o.object='OPERATION' and o.instance_desc=t.a);

ps:本来这张表上有一个主键和一个唯一约束,我把它给disable了。
alter table named_object disable constraint i_named_object;

本打算要用一个小表更新另一个表的一部分数据,而我写的SQL的结果是更新了要更新的数据,然而较大的表中与小表没有关联的数据都被置成了NULL。导致出现严重问题。-_-!

不过,幸好昨天晚上做了dump,而且这个系统没有投入生产,还处于测试阶段。
我是利用dmp文件恢复数据的。
大致就是把dmp文件导入另一个用户backup_315,然后利用新导入的表更新。
先看看被影响的数据量
select count(*) from named_object where instance_id is null;
COUNT(*)
----------
7759

select count(*) from named_object where instance_id is not null;
COUNT(*)
----------
48

select count(*) from backup_315.named_object;
COUNT(*)
----------
7773

有34条今天我新加的数据被修改了,所以问题还不算很严重。
update named_object t set t.instance_id=nvl(select b.instance_id from backup_315.named_object b where t.instance_rrn=b.instance_rrn, o.instance_id);

update named_object o set o.instance_id=nvl(select t.bv from t where o.instance_desc=t.a, o.instance_id) where o.object='OPERATION';

手动修改那34条记录的instance_id。

alter table named_object enable constraint i_named_object;

保险起见,这个时候又做了一次备份。

昨天回去的时候就想,这种办法真笨啊。
回滚段当中应该有记录的,可以通过 select * from table as of xxx xxxxxxx; 查询。
可是出现问题的时候hearbeat出现异常,第一个想到的就是昨天晚上的备份,一堆恢复步骤立即排好了队。-_-!

从回滚段当中恢复已提交的数据,恢复操作必须在回滚窗口内进行。
如果回滚段当中的新数据把老数据给覆盖了,那么这种办法就不行了。

先看一下昨天晚上误操作的时间。
select sql_text, first_load_time, last_load_time from v$sql where sql_text like 'update named_object%'
看哪条update是我要找的,然后记下发生时间。
再看一下smon进程相近的SCN和时间。
select * from sys.smon_scn_time s where s.time_dp between (sysdate-1.2) and (sysdate-0.6) order by s.time_dp desc;

select * from named_object o where object='OPERATION' as of scn 找到的scn ;
(或者可以使用as of timestamp to_timestamp('2007-03-15 19:16:20','yyyy-mm-dd hh24:mi:ss') )

这样就可以看到回滚段当中数据的前镜像了。利用这些数据是可以恢复的。

经验教训:
1.对已有约束不能随意disable,如果要disable,得先考虑清楚。
2.执行SQL之前一定要明白这句SQL会产生的影响。
3.出现问题不要慌,冷静应对。
4.不能只图方便,备份+仔细才能做好事情。

三、温故而知新。
近来准备把过去几个月中看过的书和做过的实验总结一下。
总结很重要,不然很容易忘记。
内容主要是Linux和Oracle各个结构之间的相似和不同之处:
1.Linux的锁和Oracle的锁
2.Linux的内存结构
3.Oracle的内存结构
4.文件系统
5.Oracle的数据块
6.磁盘
7.SQL语句的解析过程

题目好像都有些大。我想从一些底层的东西开始了解。