最近准备考ocp,所以决定按照教程,从头到尾系统的学习一次oracle,也算是为了对得起考证的几千大洋。
在安装oracle 10g的过程中,遇到了checking network configuration requirements is: Not executed的错误提示。
没有执行网络检测,google下,发现是/etc/hosts中没有指定静态ip地址导致,检测/etc/hosts发现果真如此(好久没有装oracle 了,竟然忘记这个基础的东西)修改如下配置
127.0.0.1 ocp localhost.localdomain localhost
192.168.1.55 ocp.xifenfei.com
重新检测,显示正常
Monthly Archives: 十月 2011
rac中的spfile探讨
今天朋友的的rac,因为被同事做数据库升级,分别在两个节点的本地创建了spfile,然后使用这个spfile启动了数据库,因为他不是非常懂oracle,所以向我求救,我改他的建议是:
1、利用备份的原来的pfile文件创建在asm中的spfile,规则是:+ASM/SID/spfileSID
2、dbs目录下创建一个本地的initsid.ora,然后在里面加一个spfile=’+ASM pfile path’(两个节点同样操作,注意sid不同)
3、分别重启数据库
出现该问题的原因分析:
做数据库升级的朋友的同事也不懂rac的spfile的相关规则,应该是在重启数据库的时候,提示spfile不存在,然后自己手工创建利用pfile创建的spfile到dbs下面,然后朋友十一后检测数据库,发现spfile都放置在本地了。
1、通常读取参数文件顺序
我们知道,如果不指定参数文件,oracle是按照这个顺序查找文件来启动数据库的:
spfileSID.ora
spfile.ora
initSID.ora
init.ora
如果这些文件都没有找到,启动会失败。
2、RAC中关于spfile的启动探讨
[rac@cent1 dbs]$ echo $ORACLE_SID RACDB1 [rac@cent1 dbs]$ touch spfileRACDB1.ora <==手工创建一个空白的spfile [rac@cent1 dbs]$ sqlplus / as sysdba SQL*Plus: Release 10.2.0.4.0 - Production on Thu Apr 29 13:45:50 2010 Copyright (c) 1982, 2007, Oracle. All Rights Reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production With the Partitioning, Real Application Clusters, OLAP, Data Mining and Real Application Testing options SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. SQL> startup ORA-27091: unable to queue I/O <== 用sqlplus启动数据库时会报错 ORA-27069: attempt to do I/O beyond the range of the file Additional information: 1 Additional information: 1 SQL> SQL> exit Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production With the Partitioning, Real Application Clusters, OLAP, Data Mining and Real Application Testing options [rac@cent1 dbs]$ crs_stat -t Name Type Target State Host ------------------------------------------------------------ ora....B1.inst application OFFLINE OFFLINE ora....B2.inst application ONLINE ONLINE cent2 ora.RACDB.db application ONLINE ONLINE cent1 ora....SM1.asm application ONLINE ONLINE cent1 ora....T1.lsnr application ONLINE ONLINE cent1 ora.cent1.gsd application ONLINE ONLINE cent1 ora.cent1.ons application ONLINE ONLINE cent1 ora.cent1.vip application ONLINE ONLINE cent1 ora....SM2.asm application ONLINE ONLINE cent2 ora....T2.lsnr application ONLINE ONLINE cent2 ora.cent2.gsd application ONLINE ONLINE cent2 ora.cent2.ons application ONLINE ONLINE cent2 ora.cent2.vip application ONLINE ONLINE cent2 [rac@cent1 dbs]$ srvctl start instance -i racdb1 -d racdb <== 用srvctl启动成功 [rac@cent1 dbs]$ sqlplus / as sysdba SQL*Plus: Release 10.2.0.4.0 - Production on Thu Apr 29 13:47:25 2010 Copyright (c) 1982, 2007, Oracle. All Rights Reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production With the Partitioning, Real Application Clusters, OLAP, Data Mining and Real Application Testing options SQL> select instance_name, status from v$instance; INSTANCE_NAME STATUS ---------------- ------------ RACDB1 OPEN --说明srvctl不是用那个顺序去查找参数文件
3、查看srvctl读取spfile位置
[rac@cent1 dbs]$ srvctl config database -d racdb -a cent1 RACDB1 /rac/product/10.2.0/db cent2 RACDB2 /rac/product/10.2.0/db DB_NAME: RACDB ORACLE_HOME: /rac/product/10.2.0/db SPFILE: +DATA/RACDB/spfileRACDB.ora DOMAIN: WORLD DB_ROLE: null START_OPTIONS: null POLICY: AUTOMATIC ENABLE FLAG: DB ENABLED
4、修改CRS中关于spfile位置
[rac@cent1 dbs]$ srvctl modify database -d racdb -p ' +DATA/RACDB/spfileRACDB1.ora'
利用rowid排序更新大表数据
现在有个案例,有一张很大的表t1,需要更新其中的一个列,然后这个列是参考另外一个表t2中的列
直接sql操作如:
update t1 ta set prov_code=(select area_code from t2 tb where ta.id=tb.id);
利用rowid,分批提交的思路写出如下sql,执行大表更新效率比较高
DECLARE CURSOR cur IS SELECT a.area_code, b.ROWID ROW_ID FROM t2 a, t1 b WHERE a.id = b.id ORDER BY b.ROWID; V_COUNTER NUMBER; BEGIN V_COUNTER := 0; FOR row IN cur LOOP UPDATE t1 SET prov_code = row.area_code WHERE ROWID = row.ROW_ID; V_COUNTER := V_COUNTER + 1; IF (V_COUNTER >= 1000) THEN COMMIT; V_COUNTER := 0; END IF; END LOOP; COMMIT; END;
这里利用了rowid排序,使得update操作是一个一个数据块的进行,减少逻辑读,分批提交减小undo压力
Startup Migrate
1、为什么要使用Startup Migrate
STARTUP MIGRATE was introduced in 9.2 as a mechanism to be sure that most everything that needs to be done to run an upgrade script or a patch script is done automatically. In the past, customers were expected to adjust certain initialization parameters prior to beginning an upgrade or applying a a patch, but most of this is now done automatically by STARTUP MIGRATE. When a customer starts a database in MIGRATE mode, the following ALTER SYSTEM commands will be set automatically:
ALTER SYSTEM ENABLE RESTRICTED SESSION;
ALTER SYSTEM SET “_SYSTEM_TRIG_ENABLED”=FALSE SCOPE=MEMORY;
ALTER SYSTEM SET _undo_autotune=FALSE SCOPE=MEMORY;
ALTER SYSTEM SET undo_retention=900 SCOPE=MEMORY;
ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0 SCOPE=MEMORY;
ALTER SYSTEM SET AQ_TM_PROCESSES=0 SCOPE=MEMORY;
这些我们可以从数据库的Startup Migrate命令启动数据库的日志中可以看出来
Sun Oct 9 21:53:04 2011 ALTER SYSTEM enable restricted session; Sun Oct 9 21:53:04 2011 ALTER SYSTEM SET _system_trig_enabled=FALSE SCOPE=MEMORY; Autotune of undo retention is turned off. Sun Oct 9 21:53:04 2011 ALTER SYSTEM SET _undo_autotune=FALSE SCOPE=MEMORY; Sun Oct 9 21:53:04 2011 ALTER SYSTEM SET undo_retention=900 SCOPE=MEMORY; MMNL started with pid=12, OS id=8452 Sun Oct 9 21:53:04 2011 ALTER SYSTEM SET aq_tm_processes=0 SCOPE=MEMORY; Sun Oct 9 21:53:04 2011 Resource Manager disabled during database migration: plan '' not set Sun Oct 9 21:53:04 2011 ALTER SYSTEM SET resource_manager_plan='' SCOPE=MEMORY; replication_dependency_tracking turned off (no async multimaster replication found) Completed: ALTER DATABASE OPEN MIGRATE
2、Startup Migrate主用作用
在9i,无论升级/降级 数据库都是startup migrate
10g后增加了upgrade参数,升级可直接用startup upgrade,降级仍是startup migrate
3、Startup Migrate辅助作用(解决部分ORA-00701)
SQL> alter index I_H_OBJ#_COL# rebuild; alter index I_H_OBJ#_COL# rebuild * ERROR at line 1: ORA-00701: object necessary for warmstarting database cannot be altered SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> startup migrate; ORACLE instance started. Total System Global Area 139531744 bytes Fixed Size 452064 bytes Variable Size 121634816 bytes Database Buffers 16777216 bytes Redo Buffers 667648 bytes Database mounted. Database opened. SQL> alter index I_H_OBJ#_COL# rebuild; Index altered. SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> startup ORACLE instance started. Total System Global Area 139531744 bytes Fixed Size 452064 bytes Variable Size 121634816 bytes Database Buffers 16777216 bytes Redo Buffers 667648 bytes Database mounted. Database opened.
sqlplus 使用小技巧
1、sqlplus显示语言设置
export NLS_LANG=”AMERICAN_AMERICA.ZHS16GBK”
export NLS_LANG=”SIMPLIFIED CHINESE_CHINA.ZHS16GBK”
注意数据库编码:ZHS16GBK/UTF8
2、dbms_output.put_line显示最前面空格
SQL> set serveroutput on
SQL> exec dbms_output.put_line(‘ abc’);
abc
PL/SQL procedure successfully completed.
SQL> set serveroutput on format wrapped
SQL> exec dbms_output.put_line(‘ abc’);
abc
PL/SQL procedure successfully completed.
3、sqlplus 语句中间查询对象结构
SQL> select owner
2 # desc input
Name Null? Type
—————————————– ——– —————————-
OWNER VARCHAR2(30)
OBJECT_NAME VARCHAR2(30)
SUBOBJECT_NAME VARCHAR2(30)
OBJECT_ID NUMBER
DATA_OBJECT_ID NUMBER
OBJECT_TYPE VARCHAR2(19)
CREATED DATE
LAST_DDL_TIME DATE
TIMESTAMP VARCHAR2(19)
STATUS VARCHAR2(7)
TEMPORARY VARCHAR2(1)
GENERATED VARCHAR2(1)
SECONDARY VARCHAR2(1)
2 ,status from input where rownum<10;
no rows selected
下一行以#开头, 就可以执行一条sql*plus命令, 执行完后, 刚才的语句可以继续输入
4、Sql*plus中sql语句中间有空行
SQL> select owner
2
SQL> ,status from input where rownum<10; SP2-0734: unknown command beginning “,status fr…” – rest of line ignored. 原因是sqlplus遇到空行就认为是语句结束了. 其实要改变这种现象, 只要使用SQLBLANKLINES参数就可以了 SQL> SET SQLBLANKLINES ON
SQL> select owner
2
3 ,status from input where rownum<10;
no rows selected