Archive

Archive for the ‘oracle’ Category

Additional Considerations for Direct-Path INSERT & NOtes added on

September 22nd, 2011 No comments

Advantages of Using Direct-Path INSERT

The following are performance benefits of direct-path INSERT:

During direct-path INSERT, you can disable the logging of redo and undo entries. Conventional insert operations, in contrast, must always log such entries, because those operations reuse free space and maintain referential integrity.

To create a new table with data from an existing table, you have the choice of creating the new table and then inserting into it, or executing a CREATE TABLE … AS SELECT statement. By creating the table and then using direct-path INSERT operations, you update any indexes defined on the target table during the insert operation. The table resulting from a CREATE TABLE … AS SELECT statement, in contrast, does not have any indexes defined on it; you must define them later.

Direct-path INSERT operations ensure atomicity of the transaction, even when run in parallel mode. Atomicity cannot be guaranteed during parallel direct-path loads (using SQL*Loader).

If errors occur during parallel direct-path loads, some indexes could be marked UNUSABLE at the end of the load. Parallel direct-path INSERT, in contrast, rolls back the statement if errors occur during index update.

Direct-path INSERT must be used if you want to store the data in compressed form using table compression.

Enabling Direct-Path INSERT

You can implement direct-path INSERT operations by using direct-path INSERT statements, inserting data in parallel mode, or by using the Oracle SQL*Loader utility in direct-path mode. Direct-path inserts can be done in either serial or parallel mode.

To activate direct-path INSERT in serial mode, you must specify the APPEND hint in each INSERT statement, either immediately after the INSERT keyword, or immediately after the SELECT keyword in the subquery of the INSERT statement.

When you are inserting in parallel DML mode, direct-path INSERT is the default. In order to run in parallel DML mode, the following requirements must be met:

You must have Oracle Enterprise Edition installed.

You must enable parallel DML in your session. To do this, run the following statement:

ALTER SESSION { ENABLE | FORCE } PARALLEL DML;

You must specify the parallel attribute for the target table, either at create time or subsequently, or you must specify the PARALLEL hint for each insert operation.

To disable direct-path INSERT, specify the NOAPPEND hint in each INSERT statement. Doing so overrides parallel DML mode.

How Direct-Path INSERT Works

You can use direct-path INSERT on both partitioned and non-partitioned tables.

Serial Direct-Path INSERT into Partitioned or Non-partitioned Tables
The single process inserts data beyond the current high water mark of the table segment or of each partition segment. (The high-water mark is the level at which blocks have never been formatted to receive data.) When a COMMIT runs, the high-water mark is updated to the new value, making the data visible to users.

Parallel Direct-Path INSERT into Partitioned Tables
This situation is analogous to serial direct-path INSERT. Each parallel execution server is assigned one or more partitions, with no more than one process working on a single partition. Each parallel execution server inserts data beyond the current high-water mark of its assigned partition segment(s). When a COMMIT runs, the high-water mark of each partition segment is updated to its new value, making the data visible to users.

Parallel Direct-Path INSERT into Non-partitioned Tables
Each parallel execution server allocates a new temporary segment and inserts data into that temporary segment. When a COMMIT runs, the parallel execution coordinator merges the new temporary segments into the primary table segment, where it is visible to users.

Specifying the Logging Mode for Direct-Path INSERT

Direct-path INSERT lets you choose whether to log redo and undo information during the insert operation.

You can specify logging mode for a table, partition, index, or LOB storage at create time (in a CREATE statement) or subsequently (in an ALTER statement).

If you do not specify either LOGGING or NOLOGGING at these times:

The logging attribute of a partition defaults to the logging attribute of its table.

The logging attribute of a table or index defaults to the logging attribute of the tablespace in which it resides.

The logging attribute of LOB storage defaults to LOGGING if you specify CACHE for LOB storage. If you do not specify CACHE, then the logging attributes defaults to that of the tablespace in which the LOB values resides.

You set the logging attribute of a tablespace in a CREATE TABLESPACE or ALTER TABLESPACE statements.

Note:
If the database or tablespace is in FORCE LOGGING mode, then direct path INSERT always logs, regardless of the logging setting.
Direct-Path INSERT with Logging
In this mode, Oracle Database performs full redo logging for instance and media recovery. If the database is in ARCHIVELOG mode, then you can archive redo logs to tape. If the database is in NOARCHIVELOG mode, then you can recover instance crashes but not disk failures.

Direct-Path INSERT without Logging
In this mode, Oracle Database inserts data without redo or undo logging. (Some minimal logging is done to mark new extents invalid, and data dictionary changes are always logged.) This mode improves performance. However, if you subsequently must perform media recovery, the extent invalidation records mark a range of blocks as logically corrupt, because no redo data was logged for them. Therefore, it is important that you back up the data after such an insert operation.

Additional Considerations for Direct-Path INSERT

The following are some additional considerations when using direct-path INSERT.

Index Maintenance with Direct-Path INSERT
Oracle Database performs index maintenance at the end of direct-path INSERT operations on tables (partitioned or non-partitioned) that have indexes. This index maintenance is performed by the parallel execution servers for parallel direct-path INSERT or by the single process for serial direct-path INSERT. You can avoid the performance impact of index maintenance by dropping the index before the INSERT operation and then rebuilding it afterward.

Space Considerations with Direct-Path INSERT
Direct-path INSERT requires more space than conventional-path INSERT.

All serial direct-path INSERT operations, as well as parallel direct-path INSERT into partitioned tables, insert data above the high-water mark of the affected segment. This requires some additional space.

Parallel direct-path INSERT into non-partitioned tables requires even more space, because it creates a temporary segment for each degree of parallelism. If the non-partitioned table is not in a locally managed tablespace in automatic segment-space management mode, you can modify the values of the NEXT and PCTINCREASE storage parameter and MINIMUM EXTENT tablespace parameter to provide sufficient (but not excess) storage for the temporary segments. Choose values for these parameters so that:

The size of each extent is not too small (no less than 1 MB). This setting affects the total number of extents in the object.

The size of each extent is not so large that the parallel INSERT results in wasted space on segments that are larger than necessary.

After the direct-path INSERT operation is complete, you can reset these parameters to settings more appropriate for serial operations.

Locking Considerations with Direct-Path INSERT
During direct-path INSERT, the database obtains exclusive locks on the table (or on all partitions of a partitioned table). As a result, users cannot perform any concurrent insert, update, or delete operations on the table, and concurrent index creation and build operations are not permitted. Concurrent queries, however, are supported, but the query will return only the information before the insert operation.

NOtes Added On
(1) in 10.x and previous releases the APPEND hint gets ignored when it is present in an INSERT with VALUES clause and that is the expected behavior for previous versions, including 9i and 10g. On 11g Release 1, the APPEND hint it is not ignored and a direct-path load is executed for an INSERT with VALUES clause, therefore such statements will allocate one row/database block.

(2) On 11g Release 2, there is a new hint “APPEND_VALUES”, i.e. use direct path load only when the “APPEND_VALUES” hint is referenced. On 11g Release 2 the “APPEND” hint is ignored for INSERT statements with VALUES clause. This is the expected behavior on 11g and it is currently implemented only in 11g Release 2.

Categories: Internal, oracle Tags: , ,

Linux Tar安装oracle 10g

September 12th, 2011 No comments

链接:http://www.dbasky.net/archives/2009/04/linux-taroracle-10g.html

最近公司业务的不断扩大,对数据库的使用也不断的增加,导致了基本每天都要进行安装的安装和配置。其实oracle的安装是很简单,不知道是否有更加方便,快捷的安装方式呢?答案:有的,那就是用linux常用的命令tar来进行安装。今天我就来尝试了在linux as4上用tar方式安装oracle 10g,下面简单记录下这次的操作过程。

原数据库所在服务器信息:

kfserver-> more /etc/issue
Red Hat Enterprise Linux AS release 4 (Nahant Update 5)
Kernel \r on an \m

kfserver-> uname -a
Linux kfserver 2.6.9-55.ELsmp #1 SMP Fri Apr 20 17:03:35 EDT 2007 i686 i686 i386 GNU/Linux
新数据库所在服务器信息:

root@testserver:[/root]more /etc/issue
Red Hat Enterprise Linux AS release 4 (Nahant Update 5)
Kernel \r on an \m
root@testserver:[/root]uname -a
Linux testserver 2.6.9-55.ELsmp #1 SMP Fri Apr 20 17:03:35 EDT 2007 i686 i686 i386 GNU/Linux
以上二个系统版本是一样的。

1、在新服务器上添加用户
groupadd oinstall
useradd -g oinstall oracle

2、在新服务器上添加相关目录
mkdir -p /opt/oracle/product

3、设置核心参数
vi /etc/sysctl.conf,添加

# Controls whether core dumps will append the PID to the core filename.
# Useful for debugging multi-threaded applications.
kernel.core_uses_pid = 1
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default = 1048576
net.core.rmem_max = 1048576
net.core.wmem_default = 262144
net.core.wmem_max = 262144

使设置生效:
sysctl -p

4、修改oracle用户的环境变量
su – oracle
vi .bash_profile 添加:

# User specific environment and startup programs
PATH=$PATH:$HOME/bin

export PATH
unset USERNAME
export PS1=”` /bin/hostname -s ` -> ”
export EDITOR=vi
export ORACLE_SID=nuage
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export ORACLE_CLIENT=$ORACLE_BASE/product/10.2.0/cleint
export LD_LIBRARY=$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin
export NLS_LANG=”SIMPLIFIED CHINESE_CHINA.ZHS16GBK”

5、在原服务器打包程序
把$ORACLE_HOME下的东西打包压缩:
cd $ORACLE_BASE/product
tar cfz oracle10203.tar 10.2

6、传送到新服务器并解压
scp 上传

cd $ORACLE_BASE/product
tar -xzfv oracle10203
7、修改解压后的文件属主

[root@testserver oracle]# chown -R oracle:oinstall /opt/
chown: changing ownership of `/opt/oracle/product/10.2/rdbms/filemap’: No such file or directory

这里出现一个错误,提示文件不存在,经检查这是一个软链接:

[root@testserver oracle]# ls -l /opt/oracle/product/10.2/rdbms/filemap
lrwxrwxrwx 1 root root 22 Jan 10 17:22 /opt/oracle/product/10.2/rdbms/filemap -> /opt/ORCLfmap/prot1_64
经检查,当前的系统确实不存在/opt/ORCLfmap目录,实际上/opt/ORCLfmap是有root.sh生成的,先删除这个软链接:
rm -f /opt/oracle/product/10.2/rdbms/filemap

重新执行root.sh:

[root@testserver opt]# /opt/oracle/product/10.2/root.sh
Running Oracle10 root.sh script…

The following environment variables are set as:
ORACLE_OWNER= oracle
ORACLE_HOME= /opt/oracle/product/10.2

Enter the full pathname of the local bin directory: [/usr/local/bin]:
Copying dbhome to /usr/local/bin …
Copying oraenv to /usr/local/bin …
Copying coraenv to /usr/local/bin …

Creating /etc/oratab file…
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root.sh script.
Now product-specific root actions will be performed.
此时软连接和目录都已经存在:

[root@testserver opt]# ls /opt/oracle/product/10.2/rdbms/filemap
bin etc log
[root@testserver opt]# ls -l /opt/oracle/product/10.2/rdbms/filemap
lrwxrwxrwx 1 root root 22 Jan 10 17:40 /opt/oracle/product/10.2/rdbms/filemap -> /opt/ORCLfmap/prot1_64
8、创建数据库
运行dbca,一步一步设置好就可以。

9、清理原网络相关文件、原密码文件等。

一般会出现的问题:
1、chown: changing ownership of `/opt/oracle/product/10.2/rdbms/filemap’: No such file or directory
这个问题在上文已有描述,这里不再赘述。

2、Exception in thread “main” java.lang.UnsatisfiedLinkError: /opt/oracle/product/10.2/jdk/jre/lib/i386/libawt.so: libXp.so.6: cannot open shared object file: No such file or directory

执行dbca时报错:

testserver ->$ dbca
Exception in thread “main”
testserver ->$
这里报错信息非常少,无法判断是什么原因,再执行netca就可以看得更多的错误信息了:

[oracle@testserver bin]$ netca
Exception in thread “main” java.lang.UnsatisfiedLinkError: /opt/oracle/product/10.2/jdk/jre/lib/i386/libawt.so: libXp.so.6: cannot open shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1586)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1503)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:834)
at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:50)
at java.security.AccessController.doPrivileged(Native Method)
at sun.awt.NativeLibLoader.loadLibraries(NativeLibLoader.java:38)
at sun.awt.DebugHelper.(DebugHelper.java:29)
at java.awt.Component.(Component.java:506)

这个问题主要是缺少一个包xorg-x11-deprecated-libs导致的,把包安装上就可以:
[root@testserver soft]# rpm -ivh xorg-x11-deprecated-libs-6.8.2-1.EL.13.37.i386.rpm
warning: xorg-x11-deprecated-libs-6.8.2-1.EL.13.37.i386.rpm: V3 DSA signature: NOKEY, key ID b38a8516
Preparing… ########################################### [100%]
1:xorg-x11-deprecated-lib########################################### [100%]

注意:虽然系统是64位的,但是这里要安装32位的包。

3、ORA-12547: TNS: 丢失连接
在创建数据库前,简单测试一下sqlplus是否正常,发现了这个问题:

testserver ->$ sqlplus “/as sysdba”

SQL*Plus: Release 10.2.0.3.0 – Production on 星期四 1月 10 17:51:35 2008

Copyright (c) 1982, 2006, Oracle. All Rights Reserved.

oraclenewdemo: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
ERROR:
ORA-12547: TNS: 丢失连接

请输入用户名:

引起问题的原因是libaio系统包,把相关包安装即可:

[root@testserver soft]# ls
libaio-0.3.105-2.i386.rpm libaio-0.3.105-2.x86_64.rpm libaio-devel-0.3.105-2.x86_64.rpm
[root@testserver soft]# rpm -ivh *
warning: libaio-0.3.105-2.i386.rpm: V3 DSA signature: NOKEY, key ID b38a8516
Preparing… ########################################### [100%]
1:libaio ########################################### [ 33%]
2:libaio ########################################### [ 67%]
3:libaio-devel ########################################### [100%]

同样,这里也需要安装两个32位的包。

4、ORA-01031: insufficient privileges
testserver ->$ sqlplus “/as sysdba”

SQL*Plus: Release 10.2.0.3.0 – Production on 星期五 1月 11 10:48:35 2008

Copyright (c) 1982, 2006, Oracle. All Rights Reserved.

ERROR:
ORA-01031: insufficient privileges

请输入用户名:

这个问题是因为用户组不一致造成的。

原库:

[oracle@kfserver oraInventory]$ id -a
uid=500(oracle) gid=500(oinstall) groups=500(oinstall),501(dba) context=user_u:system_r:unconfined_t
新库:

[oracle@testserver oraInventory]$ id -a
uid=500(oracle) gid=500(oinstall) groups=500(oinstall) context=user_u:system_r:unconfined_t
在新库上为oracle用户添加组就可以了:

[root@testserver ~]# usermod -G dba oracle

Categories: 排错 Tags:

PRAGMA EXCEPTION_INIT的用法

September 1st, 2011 No comments
 如果要处理未命名的内部异常,必须使用OTHERS异常处理器或PRAGMA EXCEPTION_INIT 。PRAGMA由编译器控制,或者是对于编译器的注释。PRAGMA在编译时处理,而不是在运行时处理。EXCEPTION_INIT告诉编译器将异常名与ORACLE错误码结合起来,这样可以通过名字引用任意的内部异常,并且可以通过名字为异常编写一适当的异常处理器。
  
  在子程序中使用EXCEPTION_INIT的语法如下:
  PRAGMA EXCEPTION_INIT(exception_name, -Oracle_error_number);
Read more…
Categories: PL/SQL Tags:

ORACLE PL/SQL异常处理(Exception)学习笔记

September 1st, 2011 No comments
1、PL/SQL错误类型
错误类型
报告者
处理方法
编译时错误
PL/SQL编译器
交互式地处理:编译器报告错误,你必须更正这些错误
运行时错误
PL/SQL运行时引擎
程序化地处理:异常由异常处理子程序引发并进行捕获
Read more…
Categories: PL/SQL Tags: , ,

Oracle10GR2 中的RESTORE POINT

July 2nd, 2010 1 comment

RESTORE POINT

还原点是10GR2新增加的一个功能,它是建立在数据库层面上的, 跟savepoint不同. 必须在数据库处于ARCHIVELOG模式下才可以使用,主题思想是在数据库的某个时间点创建一个restore point,在随后的某个时间点可以将表或数据库falshback 到这个restore point.那么能否真正的完成flashback,依赖于创建的restore point类型和flashback要操作的对象.flashback database需要SYSDBA权限,flashback table需要 FLASHBACK ANY TABLE的权限.
Read more…

Categories: 备份与恢复, oracle Tags:

EZCONNECT

March 23rd, 2010 No comments

From Oracle FAQ

Jump to: navigation, search

EZCONNECT is Oracle’s easy connect naming method. EZCONNECT eliminates the need for service name lookups in tnsnames.ora files when connecting to an Oracle database across a TCP/IP network. In fact, no naming or directory system is required when using this method as it provides out-of-the-box connectivity. It extends the functionality of the host naming method by enabling clients to connect to a database with an optional port and service name in addition to the host name of the database.

Read more…
Categories: 连接 Tags:

32位oracle数据库迁移至64位oracle的实例(rman Convert database)

February 12th, 2010 No comments

1、原来在64位win7下装的是32位的oracle,启动数据库后不断在alert.log报错:  

OER 7451 in Load Indicator : Error Code = OSD-04500: 指定了非法选项
O/S-Error: (OS 1) 函数不正确。 !  

 很烦人。查了一下,必须使用64位的oracle。  

正好可以使用rman的Convert database特性进行跨平台迁移数据了。  
Read more…

Categories: 备份与恢复 Tags: , ,

常用sql

February 9th, 2010 No comments
1、查看表空间的名称及大小

select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size
from dba_tablespaces t, dba_data_files d
where t.tablespace_name = d.tablespace_name
group by t.tablespace_name;
Read more…

Categories: 脚本 Tags:

用Oracle的 DBMS_XPLAN函数轻松格式化EXPLAIN PLAN结果

September 13th, 2009 No comments

EXPLAIN PLAN命令的输出结果是解决SQL效率低下问题的最重要的诊断工具之一。此命令加载一个工作表格(默认名称为PLAN_TABLE),表格中带有Oracle优化器为SQL语句计算的执行计划步骤。例如:

EXPLAIN PLAN FOR

SELECT empno, ename

FROM emp

WHERE ename LIKE ‘S%’;

由于PLAN_TABLE中的行形成了一个等级,对其进行查询需要应用SELECT语句中的两个复杂子语句——START WITH与CONNECT BY。第一次在Oracle 9i中出现并在10g中得到扩充的DBMS_XPLAN使格式化及显示执行计划更为容易。

DBMS_XPLAN.DISPLAY是一个表格标值函数,它显示PLAN_TABLE的内容。与常规的纯量函数SUBSTR或总计函数SUM不同的是,表格函数返回一个完整的行集合(rowset)。它们用在SELECT语句的FROM子语句中,前面必须加上TABLE这个词。如:

SELECT *

FROM TABLE(DBMS_XPLAN.DISPLAY);

列表A显示的是上述EXPLAIN PLAN语句的结果,并由DBMS_XPLAN.DISPLAY格式化。

值得注意的是,DBMS_XPLAN还能从存储在系统全局区(System Global Area, SGA)内的指针显示“实时”执行计划。列表B显示的是由用户SCOTT执行的同一SQL语句。通过查看V$SESSION视图,你可以找到执行SCOTT任务的最后一个SQL ID。这反过来又可输入到DBMS_XPLAN.DISPLAY_CURSOR中,获得指针所使用的执行计划。

最后,DBMS_XPLAN.DISPLAY_AWR函数可用来查寻Oracle 10g的自动负荷信息库(Automatic Workload Repository, AWR)获得的历史SQL语句,并显示它的执行计划。它显示一个你可以访问的含七天历史记录的滚动窗口。

所有这三个函数都是协调SQL语句的强大工具。

Categories: oracle, SQL优化, 执行计划 Tags:

Oracle分区表(Partition Table)的数量限制

September 10th, 2009 No comments
oracle分区表是不是有最大分区个数限制 ,我有一张大约20G的表,有好多分区(按时间),结果根据这个时间条件查询就报ORA-03113 end-of-file on communication channel错误,然后断开链接,硬件与网络都没问题. 后来我删了几个分区就一切OK了,这是咋回事呢? 系统环境 win2003

oracle分区表是不是有最大分区个数限制,我有一张大约20G的表,有好多分区(按时间),结果根据这个时间条件查询就报ORA-03113 end-of-file on communication channel错误,然后断开链接,硬件与网络都没问题. 后来我删了几个分区就一切OK了,这是咋回事呢? 系统环境 win2003 server + oracle9201

我猜测他这个问题并非遇到了分区个数的限制,因为这个限制很难达到,至少到目前为止我尚未听说有人达到这个分区限制。

那么Oracle最大允许存在多少个分区呢?

我们可以从Oracle的Concepts手册上找到这个信息,对于Oracle9iR2:

Tables can be partitioned into up to 64,000 separate partitions.

对于Oracle10gR2,Oracle增强了分区特性:

Tables can be partitioned into up to 1024K-1 separate partitions.

真的会有人尝试来突破这个分区极限吗? 你的数据库最大的分区表有多少个分区呢?

关于何时应该进行分区,Oracle有如下建议:

■ Tables greater than 2GB should always be considered for partitioning.
■ Tables containing historical data, in which new data is added into the newest partition. A typical example is a historical table where only the current month’s data is updatable and the other 11 months are read only.

 

Categories: oracle Tags:

Videos, Slideshows and Podcasts by Cincopa Wordpress Plugin