oracle10g优化数据库

合集下载

oracle数据库性能调优

oracle数据库性能调优

oracle数据库性能调优⼀:注意WHERE⼦句中的连接顺序:ORACLE采⽤⾃下⽽上的顺序解析WHERE⼦句,根据这个原理,表之间的连接必须写在其他WHERE条件之前, 那些可以过滤掉最⼤数量记录的条件必须写在WHERE⼦句的末尾.尤其是“主键ID=?”这样的条件。

⼆: SELECT⼦句中避免使⽤ ‘ * ‘:ORACLE在解析的过程中, 会将'*' 依次转换成所有的列名, 这个⼯作是通过查询数据字典完成的, 这意味着将耗费更多的时间。

简单地讲,语句执⾏的时间越短越好(尤其对于系统的终端⽤户来说)。

⽽对于查询语句,由于全表扫描读取的数据多,尤其是对于⼤型表不仅查询速度慢,⽽且对磁盘IO造成⼤的压⼒,通常都要避免,⽽避免的⽅式通常是使⽤索引Index。

三:使⽤索引的优势与代价。

优势:1)索引是表的⼀个概念部分,⽤来提⾼检索数据的效率,ORACLE使⽤了⼀个复杂的⾃平衡B-tree结构. 通常,通过索引查询数据⽐全表扫描要快. 当ORACLE找出执⾏查询和Update语句的最佳路径时, ORACLE优化器将使⽤索引. 同样在联结多个表时使⽤索引也可以提⾼效率. 2)另⼀个使⽤索引的好处是,它提供了主键(primary key)的唯⼀性验证.。

那些LONG或LONG RAW数据类型, 你可以索引⼏乎所有的列. 通常, 在⼤型表中使⽤索引特别有效. 当然,你也会发现, 在扫描⼩表时,使⽤索引同样能提⾼效率.代价:虽然使⽤索引能得到查询效率的提⾼,但是我们也必须注意到它的代价. 索引需要空间来存储,也需要定期维护, 每当有记录在表中增减或索引列被修改时, 索引本⾝也会被修改. 这意味着每条记录的INSERT , DELETE , UPDATE将为此多付出4 , 5 次的磁盘I/O . 因为索引需要额外的存储空间和处理,那些不必要的索引反⽽会使查询反应时间变慢.。

⽽且表越⼤,影响越严重。

使⽤索引需要注意的地⽅:1、避免在索引列上使⽤NOT , 我们要避免在索引列上使⽤NOT, NOT会产⽣在和在索引列上使⽤函数相同的影响. 当ORACLE”遇到”NOT,他就会停⽌使⽤索引转⽽执⾏全表扫描.2、避免在索引列上使⽤计算.WHERE⼦句中,如果索引列是函数的⼀部分.优化器将不使⽤索引⽽使⽤全表扫描.举例:代码如下:低效:SELECT … FROM DEPT WHERE SAL * 12 > 25000;⾼效:SELECT … FROM DEPT WHERE SAL > 25000/12;3、避免在索引列上使⽤IS NULL和IS NOT NULL避免在索引中使⽤任何可以为空的列,ORACLE性能上将⽆法使⽤该索引.对于单列索引,如果列包含空值,索引中将不存在此记录. 对于复合索引,如果每个列都为空,索引中同样不存在此记录. 如果⾄少有⼀个列不为空,则记录存在于索引中.举例: 如果唯⼀性索引建⽴在表的A列和B列上, 并且表中存在⼀条记录的A,B值为(123,null) , ORACLE将不接受下⼀条具有相同A,B值(123,null)的记录(插⼊). 然⽽如果所有的索引列都为空,ORACLE将认为整个键值为空⽽空不等于空. 因此你可以插⼊1000 条具有相同键值的记录,当然它们都是空! 因为空值不存在于索引列中,所以WHERE⼦句中对索引列进⾏空值⽐较将使ORACLE停⽤该索引.代码如下:低效:(索引失效) SELECT … FROM DEPARTMENT WHERE DEPT_CODE IS NOT NULL;⾼效:(索引有效) SELECT … FROM DEPARTMENT WHERE DEPT_CODE >=0;4、注意通配符%的影响使⽤通配符的情况下Oracle可能会停⽤该索引。

SQL语句执行计划变化的原因分析与应对策略-For Oracle 10g

SQL语句执行计划变化的原因分析与应对策略-For Oracle 10g

通常而言,只需按照上文中的两个方面来做,应用的效果会非常的好, 然而在实际进行数据库SQL优化的过程中,当这两个方面的优化措施相互作用 时,却可能产生一些意想不到的情景—产生多版本的执行计划,在一些高访 问负荷,数据量巨大且分布复杂的业务系统中甚至可能引发突然性的性能下 降。 因此,为使业务系统长期稳定运行,以上问题是必须避免的。换言之, 找到多版本执行计划的产生原因并避免由于嵌入变量的处理而导致的执行计 划非正常改变将成为维护好业务系统的关键因素。
六、总结
随着各类业务系统的飞速发展,其数据量和数据复杂性也不断增加,从而引 起的各类由于SQL执行效率不佳所导致的性能问题也日趋严重。 对于数据库开发人员,必须掌握各类业务系统的数据特点。尽量的在开发阶 段就避免今后产生SQL执行计划不佳的现象。 对于数据库维护人员,要充分掌握SQL执行计划变化的各类原因,并能及时处 理因执行计划变差所导致的各类性能问题,确保业务系统的正常运行。
?数据库中触发sql语句硬解析的因素首次sql访问与sql相关对象的ddl操作与sql相关对象的权限变化与sql相关对象的统计信息变化会话或数据库级的优化器参数改变游标过期或共享池刷新三多版本执行计划的产生原因续?多版本执行计划产生的主要原因由此可见由于统计信息与优化器设置是执行计划的决定性因素故造成多版本执行计划产生的根本原因是由于统计信息或优化器参数设置的改变导致在下次触发硬解析时生成了与之前相比不同的执行计划
五、应对策略
在设计阶段确定最优执行计划
A.根据数据分布特性得到最优执行计划:在设计阶段各个数据表的数据特点都是 可预知的,从这些特征出发确定一个执行计划就最为准确,同时也避免了频繁统计收 集。这个执行计划需要与具体的数据无关,不求最快,但求最优,即适合大多数情况。 从技术上而言,可以使用嵌入变量的均值(而非理想或极端值)来创建执行计划。如 果结合优化器指令(HINT)可以更精确的固定一个最优的执行计划,或者缩小BIND- PEEKING所带来的执行计划变化的范围,减少BIND-PEEKING带来的副作用。 如果 很好的应用HINT和嵌入变量,BIND-PEEKING就不会影响到应用的正常运行。 B.适当使用常量与变量的组合:对于数据中的极端值(最大,最小等)可以使用 常量,由数据库自行选定最快执行计划,对于其它值则使用HINT来固定一个折中的执 行计划。

ORACLE数据库性能的调整

ORACLE数据库性能的调整

ORACLE数据库性能的调整摘要由于oracle具备功能和灵活性突出的优越性,因此它是一个功能极其强大和灵活关系型的数据系统。

在数据库的应用类型上是较为复杂的,不同类型的应用对其系统的要求也是不同的,所以为了能够满足不同类型的应用系统,就必须对系统性能进行定期的诊断和调整,以此来提高系统的运行效率。

关键词 oracle;数据库;优化和调整中图分类号tp311 文献标识码a 文章编号1674-6708(2010)22-0187-02随着数据库在信息领域的不断推广,数据库产品也逐渐增多,其中oracle数据库产品在整个数据库产品的应用中占有较为主要的部分,接近1/2,而且还有不断上升的趋势。

因此,对于oracle数据库性能的调整和优化问题也是人们所关注的问题,本文就oracle数据库性能的调整进行了相应的探讨。

1 性能调整与优化概述目前,性能调整作为一项活动在进行,活动可以通过优化应用程序、修改系统参数和改变系统配置来有效的改变系统的性能。

其中性能的调整主要包括了对硬件配置、操作系统和数据库管理系统的配置的调整,并且对所访问的组件的应用进行详细的分析和优化。

性能优化主要是指具备目的性的对所需调整的组件进行有效的改善,使数据库的吞吐量逐渐变大,所对应的响应时间逐渐达到最小化。

对于数据库性能的调整和优化来说,要尽可能的减少磁盘访问,从中获取所需的数据,数据库性能的调整和优化在一定程度上说是相互循环的,想要性能达到相应的优化目的,就必须进行适当的性能调整,最后再查看优化的结果,通过这种反复的检查,最终达到较为满意的结果。

2 数据库系统性能评价指标2.1 系统吞吐量系统的吞吐量是指在单位时间内数据库所完成的sql语句的数目,这主要是以每秒钟的事务量来进行表示。

想要有效的提高系统的吞吐量,就必须通过减少服务时间,并在相同的资源环境内做更加多的工作,或者减少总的响应时间,从而使工作能够做的更加快。

2.2 用户响应时间用户的响应时间主要是指用户在提交sql语句以后来获取相应的结果集的第一行所需要的时间,并且根据应用做出相应的反应时间,这个时间一般都是使用毫秒和秒来进行表示。

Oracle数据库优化原则和方法

Oracle数据库优化原则和方法
一 一
当表 的记录数较大时 , 必然会影响查询速度。 这时 , 通过索引 查 询数据 比全表扫描效率要 高得 多。在写S L Q 语句时 , 应遵循 以 下原则 :避免在索引列上 使用N TI 、 U LI O U L O I N L 、 N TN L 、 NS S LK 等操作符或者 函数计算( IE 如转换字段类型 )否D O al , ] rc 数据 e 库会停止使用索引转而执行全表扫描。实际应用 中 , 有时必须要 在列 中应用函数等条件 ,则可以通过强制索引提示来利用索引。 当然 , 不一定用索引就一定是最优 的, 比如一个表只有两行数据 , 次I 就可 以完成全表 的检索 , / O 而此时用索引则需要两次I 这 / O, 时对这个 表做全表扫描是最好的。
hr d t ,.o ie aeb c mm r m mp ,o u F o e eb n s b w e eee a = .n me h r .n me b e a

调 整操 作 系统
ห้องสมุดไป่ตู้
Oal数据库服务器很 大程度上依 赖于运行 服务器 的操作 rce 系统 , 应尽 可能使O al  ̄ rc n 务器使用资源最大化 , e 特别是在Ci t ln e/ Sre,. evr_  ̄间的I 操作 。在数据库中建 表时, / O 对于一些简单且有特 殊要求 的数据 , 上适 当的完整性约束条件 ; 加 对一些较复杂 的处 理规则 , 可以利用数据 库触 发器来实现 , 数据库触发器 由数据本 身实现。另外 , 通过在O al 据库 中创建存储过程和函数 , rce 数 把复 杂 的s L Q 语句存储在服务器端 , 使应用程序 只需要简单地调用存 储过程和函数 , 网络上只需传输调用 的存储过程或 函数 的名字 在 和输出结果 。 这样都 可以有效地减少在客户端和服务器端之间传 递S L Q 语句的可能性 , 减轻网络I 负担。 / O 通 过 长 期 维 护 经 验 总 结 :0 8 %的性 能 问题 都 是 由不 良的S L Q 语句引起的, 所以调剂 和建立最佳的s L Q 语句对于业务系统的可 扩展性 和响应时间来说都显得尤为重要。影响s L Q 语句执行速度 的主要因素有 : 驱动表 的选择是否恰 当、 查询时是否用到恰当的 索引 、 间的连接顺序及条件顺序是否恰 当等 。对于一段准备 表之 执行 的s L Q 语句 , 首先分析其执行计划 。现在有很多 可视化工具 , 比如P Q 或者T A 等都提供 了非常方便的手段来获取 s L L OD Q 语 句的执行计划 。 通过分析执行计划 , 结合涉及到的表 的数据量 , 我 们 可以估算 或者测试该语句 的执行效率 ,分析表WH R 条件中 EE 涉及的字段 。根据s L Q 语句 中使用的查询条件 , 总能够找到一个 性 能最优 的执行方式 。调整S L Q 语句 的写法 , 可以遵循 以下 优化 原则和方法 : 在基于规则的优化方式 ( ue B sd pmi t n 简 R l ae O i z i , — ao 称为R O)的情况下 ,R M子句 中写在最后 的表将作 为驱 动表 B FO 被最后处理 , 在关 联查 询多个表的情况下 , 应选择最有效率 的表

第一章 oracle数据库10g概述

第一章 oracle数据库10g概述

第一章oracle数据库10g概述1.1 数据库和信息管理服务器必须在多用户环境中管理大量的数据,使得多个用户能够并行访问数据。

所有这些必须能够在高性能的情况下完成,数据库服务器必须防止未经授权的非法访问,保护敏感数据,同时,为故障恢复提供解决方案。

▪客户用员务器环境▪大型数据库和空间管理▪多个并行数据库用户▪连接性▪高事务处理能力▪控制可用性▪开放的、基于工业标准▪管理安全性▪数据库完整性增强▪兼容性▪分布式系统▪复制环境1.2 Oracle 10g服务器Oracle 10g服务器是对象关系数据库管理系统,提供对信息管理的集成方法,一个Oracle服务器包括一个Oracle数据库和一个Oracle服务器实例。

每当数据库启动的时候,系统全局区(SGA)被分配,并启动了Oracle后台进程。

系统全局区是用于数据库用户共享数据库信息的内存区域。

后台进程和内存缓冲区称为Oracle实例。

Oracle实例包含两种类型的进程:用户进程和Oracle进程。

用户进程执行应用操作的代码。

Oracle 进程是执行用户进程和后台进程,对Oracle进行维护的服务器进程。

为了最大化性能和处理多个用户的请求,多进程Oracle系统使用附加进程,这些附加进程称为后台进程。

后台进程能够自动执行I/0和监视Oracle进程,为获得更好的性能和稳定性提供更好的支持。

数据库的物理结构和存储结构之间的关系由后台进程来维持。

数据库拥有多个后台进程,其数量取决于数据库的配置。

这些进程由数据库管理,它们只需要进行很少的管埋。

每个后台进程创建一个跟踪文件。

Oracle在实例操作期间保存跟踪文件。

后台进程跟踪文件的命名约定和位置随操作系统和数据库版本不同而不同。

一般来说,跟踪文件含有后台进程名或后台进程的操作系统进程ID.可以设置init.ora文件的BACKGROUND_DUMP_DEST参数来规定后台进程跟踪文件的位置。

但是有些版本的Oracle忽略这种设置。

ORACLE 10G自动化特性在联通BSS系统性能优化工作中的应用

ORACLE 10G自动化特性在联通BSS系统性能优化工作中的应用

ORACLE 10G自动化特性在联通BSS系统性能优化工作中的应用摘要:在介绍Oracle 9i版本下性能优化的基本方法基础上,着重论述了Oracle 10g版本中的一些自动化特性,以及应用10g中的自动化特性进行数据库系统性能优化的方法和案例。

关键词:Oracle 自动化;10G 优化;ADDMOracle数据库是中国联通核心业务支撑系统中最主要的关系型数据库管理系统。

在联通BSS业务支撑系统的体系结构中,绝大多数的子系统都是典型的在线事务处理系统(OLTP系统),对业务处理的实时性和性能要求非常高。

基于以上情况,对Oralce数据库及BSS应用系统进行不断地性能调整和优化,就成为联通业务支撑工作中一个必不可少的关键性工作。

Oracle 10G中很多性能优化工作可以借助自动化的工具方便快捷地进行,使性能优化工作的效率和效果得以大幅提升。

1Oracle 9i环境下性能优化的典型方法和问题1.1Oracle 9i环境下典型的性能优化步骤通常情况下Oracle 9i环境下的性能优化工作的步骤如下:①用户或应用维护人员反馈:“某个应用场景下,系统反应很慢”;②数据库管理员(DBA)人工观测该应用是否确实比较慢,或者根据以往记录的性能测试数据来比较,确认该性能问题是否确实存在;③使用统计信息收集工具包-StatsPack包(以下简称SP 包),在可能会发生性能问题的时间段,进行性能统计信息搜集(即进行“snapshot快照”);④使用SP包,生成SP分析报告;⑤DBA阅读SP分析报告,结合自己的经验,手工在浩如烟海的信息中找到可能存在的性能瓶颈;⑥对于性能瓶颈,DBA结合自己的经验,手工设计优化方案;⑦DBA或应用系统开发人员,进行数据库配置、数据库对象或应用程序的调整;⑧调整完成后,再次进行性能表现的观测,如果问题没有得到解决,则再次从步骤三开始进行新一轮的过程,直至问题得以解决。

Oracle 9i时期典型的性能优化步骤的示意图如图1所示:图1Oracle9i时期典型的性能优化的步骤1.2Oracle 9i环境下性能优化方法存在的问题从上述步骤中可以明显看出,9i环境下的性能优化,均是DBA人工处理,所有的判断和决策都依靠人来开展,不仅非常耗时耗力,而且对进行优化工作的人员素质要求较高,对DBA 的“经验”要求极高,旺旺只有对业务较熟悉的DBA才能进行一些有效的优化工作。

Oracle数据库10g GIS应用开发:使用Oracle Spatial网络数据模型说明书

Oracle数据库10g GIS应用开发:使用Oracle Spatial网络数据模型说明书

Oracle Database 10g: Building GIS Applications Using the Oracle Spatial Network Data ModelAn Oracle Technical White PaperMay 2005Table of Contents Abstract (3)Introduction (3)Oracle Spatial Network Data Model (5)Network Data Model Schema (5)Network Metadata (6)Network Tables (6)Oracle Spatial Network Data Model APIs (6)Network Data Model Analysis Capabilities (7)Modeling Network Applications (8)Network Constraints (8)Java Representations of Network Elements (8)Software Requirements (9)Using the Network Data Model (9)1. Create a Network (9)2. Visualize or Edit the Network (9)3. Analyze the Network (9)Network Data Model Editor (9)GIS Applications using the Network Data Model (10)Network Tracing Applications (10)Network Routing Applications (10)Network Allocation Applications (11)Using Network Constraints in Analysis (11)New Features in the Oracle Spatial 10g Network Data Model (13)Network Modeling: Link Direction (13)Network Analysis: Maximum Flow Analysis (14)PL/SQL Wrapper Package (14)Conclusion (14)References (14)ABSTRACTNetwork modeling, management, and analysis are common tasks for Geographic Information Systems (GIS). Network analysis includes routing (path computation) in transportation networks, tracing (accessibility) in utility networks, and resource allocation in decision-making and customer relationship management (CRM) applications. In this paper we present the Oracle Spatial network data model, an Oracle Database release 10g feature that lets users model and analyze networks. This feature simplifies network modeling, analysis, and management so that users can focus on application logic. The network data model provides an open, generic data model with many common GIS analysis capabilities. In addition, it fully supports Oracle Spatial objects of type SDO_GEOMETRY. GIS applications based on the Oracle Spatial network data model are discussed in this paper. INTRODUCTIONThere are two common types of GIS applications: applications that deal with spatial proximity, and applications that deal with both spatial proximity and connectivity. For many applications queries on spatial proximity, which mainly consider metrics like Euclidean or geodetic distances, are sufficient. However, there are instances when connectivity needs to be taken into account, such as in finding the shortest distance between two locations in a road network. Many GIS applications are networks that require modeling and analysis on object relationships (connectivity). Figure 1 shows a road network of New York City.Figure 1. New York City Road Network (60384 nodes, 151962 links. Source: NavStreets from NavTech)Oracle Spatial has supported spatial objects since release 8.1.5. A complete set of indexes, operators, and functions is available for managing information based on spatial proximity. The network data model extends Oracle Spatial to deal with connectivity. Currently there are many GIS vendors offering network solutions; however, their solutions may have the following issues:• Their data model is stored in proprietary file formats, and cannot be integrated with their database.• The data model and analysis capabilities cannot be extended.• Application information cannot be separated from connectivity information.• Spatial information management and hierarchical relationships are not directly supported.To address these issues, Oracle Spatial network data model does the following: • Provides an open and persistent network data model.The network data model is stored as relational tables in the database and ismanaged through SQL.• Simplifies network data management and analysisPL/SQL and Java APIs are provided for network data management andanalysis.• Separates connectivity and application information in the data model Connectivity information can be separated from application information.Both application information and connectivity information are managed inthe database. However, only connectivity information is required fornetwork analysis.• Allows the extension of data model and analysis capabilitiesThe Java API provides representations of network elements as JavaInterfaces. Users can define their own network elements by extendingthese interfaces. As a result, users can implement their own user-definedrepresentations and analysis functions.• Integrates with Oracle Spatial technology for spatial information managementThe network data model supports all Oracle Spatial data types.This paper is organized as follows: it presents the network data model database schema, APIs and architecture; shows how to use the data model; presents several GIS network applications built on top of the data model; discusses how to use network constraints to enhance analysis capabilities; and discusses the network data model editor that is used to edit and visualize networks.ORACLE SPATIAL NETWORK DATA MODELThe network data model consists of two parts: a network schema and network APIs. The network schema is the persistent data storage used to store network information. The network APIs contain a PL/SQL package for data management in the database and a Java API for data management and analysis on the client-side (via Java JDBC drivers).Network Data Model SchemaA network contains network metadata, a node table, and a link table. In addition, path information (path table and path-link table) can be stored with the network if desired. Figure 2 shows a schematic view of a network in the database. Note that only connectivity information is stored. Additional application information can be stored in the network tables, or in other tables and referenced by foreign keys.Figure 2. Oracle Network Data Model (Schematic View)Network MetadataNetwork metadata provides general information about networks. It includes the following network details:• Directed or undirected• Logical or spatial• Hierarchical or flat• Information about nodes, links, and paths• Geometry information -- for spatial networksNetwork TablesAn Oracle network contains two tables: a node table and a link table. A path table can be added if needed. Figure 2 shows the schema for the network data model, which includes these tables. The schema represents the information necessary for network management and analysis. Application attributes can be added to these tables or referenced from other application tables (through foreign keys). Note that the network data model is also capable of handling geometry information. That is, the network data model can represent both logical and spatial network applications. Adding geometric data to a logical network will allow the logical network to be displayed.Oracle Spatial Network Data Model APIsThe network data model provides a PL/SQL API and a Java API for network management on the database and client sides. The Java API can also be used for network analysis. The three-tiered network data model application architecture is shown in Figure 3.Figure 3. Network Data Model ArchitectureNetwork Data Model Analysis CapabilitiesThe following analyses are supported in the network data model:• Shortest Path: The shortest path from node A to node B• Accessibility Analysis: Is node A accessible from node B?• Minimum-Cost Spanning Tree: What is the minimum-cost tree that connects all nodes?• Within Cost Analysis: What nodes are within a given cost from (to) a given node?• Nearest Neighbors: What are the N nearest neighbors of a given node?• K Shortest Paths: What are the K shortest paths from node A to node B?• Connected Components Analysis: Label connected components with IDs.• Graph Operations: Graph union, intersection, and difference.• Traveling Salesman Problem: What is the minimum-cost tour that visits a set of cities?• Single Source, Single Sink Maximum Flow Analysis: What is the maximum allowable flow that can flow from the source node to the sink node?(Oracle Spatial 10g Release 2)Modeling Network ApplicationsThe network data model takes a generic approach to solving network problems, by separating connectivity information from application-specific information. Figure 4 shows how a typical network application can be modeled and analyzed. First the network connectivity information (node connections and link cost) is extracted and separated from the application-specific information. Application-specific attributes are stored, if needed, with the connectivity information or separately. Once the connectivity information is extracted, network analysis is conducted on the generic model. Additional network constraints can also be considered. The final result is then mapped to application-related attributes, and displayed. This approach avoids customized network solutions and simplifies the data management of connectivity and application-specific information.Figure 4. Network Modeling and Analysis Using the Network Data ModelNetwork ConstraintsThe network data model introduces the concept of network constraints, which provides a mechanism to guide network analysis. For example, you may want to compute the shortest path that passes through network links of a specific type. With network constraints, applications can easily incorporate application-specific logic into the network data model analysis engine without knowing how the engine works. Other constraints, such as path depth, or cost, can also be included in analysis. The network constraint is a Java interface and must be implemented by the application.Java Representations of Network ElementsThe Java network representations (network, nodes, links, and paths) are defined as Java interfaces and can therefore be extended. These interfaces specify the necessary behaviors for the network and its elements. In addition to these interfaces, user-defined analysis functions can be used by applications, allowing the modeling and analysis capabilities of the network data model to be extended.Software RequirementsThe Spatial network data model is shipped with Oracle Database release 10g. The PL/SQL package is pre-loaded in the database and required Java .jar files are provided; the Java API supports JDK (or JRE) version 1.3 or later. The network editor is also included as a utility tool for the network data model. For more information, see the Oracle Spatial Topology and Network Data Models manual. USING THE NETWORK DATA MODELThis section explains the usage of the network data model. There are three major steps.1. Create a Network1. Create and populate network tables and add metadata to the database.2. Create a Java network object using the Java API and save it to thedatabase.2. Visualize or Edit the Network1. Load a network from the database or an XML representation.2. Visualize or edit the Java network object using the network data modeleditor. Store the network in the database, if needed.3. Analyze the Network1. Load a network into a Java network object.2. Conduct network analysis. Save the path results, if needed.NETWORK DATA MODEL EDITORThe network data model editor is a standalone Java application that helps create, edit, and visualize networks. The editor supports viewing operations such as pan, zoom, and auto-fit. It also provides functions to navigate between network elements. All analysis functions are supported in the editor. With the editor, users can create a network from scratch in the client-side and save it to the database. The editor is configurable on element styles, colors, and sizes. Figure 5 shows the network data model editor.Figure 5. Network Data Model EditorGIS APPLICATIONS USING THE NETWORK DATA MODELGIS network analysis may include network tracing, network routing, and network allocation.Network Tracing ApplicationsTracing applications deal with queries like Is node A reachable from node B? or What are the nodes that are reachable or can be reached from a given node? Such queries are common in water or utility networks. Another type of tracing analysis is to find out how many connected components are in a network. Figure 6 shows some such queries.Figure 6. Reachable and Reaching AnalysisNetwork Routing ApplicationsRouting analysis or path computation, probably the most studied topic in network applications, is divided into the following categories:• Shortest Path or Fastest Path (transitive closure problem) (see Figure 7).• K Shortest Paths: Find k shortest paths from a start node to a destination node.• Traveling Salesman Problem (see Figure 7): Find a minimum-cost tour that passes a set of locations.Figure 7. Shortest Path and Traveling Salesman ProblemNetwork Allocation ApplicationsAllocation analysis deals with designating destination points within a network. It provides information on a service area or coverage for points of interest. The network data model supports the following allocation analyses (see Figure 8):• Within Cost: Find all points of interest within a certain distance from a designated location.• Nearest Neighbors: Find the N nearest restaurants to a designated location.• Minimum-Cost Spanning Tree: Find the cheapest way to connect all nodes.Figure 8. Nearest Neighbors, Within Cost, and Minimum Cost Spanning Tree AnalysisUsing Network Constraints in AnalysisConstraints are conditions to be satisfied during analysis. The network data model supports network constraints so that applications can impose application-specific conditions on the network during analysis. The Java interface NetworkConstraint canbe implemented by the user, and passed into any network data model analysis function. Figure 9 shows analysis information that is available for users to implement their network constraintsFigure 9. Analysis Information for Network ConstraintsThe following are some examples of network constraints:• Depth (number of links), cost, and MBR constraintsNetwork analysis can be limited based on the depth of the search path, thecost limit, or the area (minimum bounding rectangle) where the analysisoccurs. These constraints can be used to specify a preferred subset ofpossible solutions. The network data model provides a SystemConstraintclass (which implements the NetworkConstraint class) for these commonnetwork constraints. Users can create an instance of SystemConstraint anduse it in analysis.• Temporarily inactivated nodes or linksSometimes nodes or links must be temporarily turned off before analysisbegins, for example, road segments (links) under construction in a roadnetwork, or water valves (nodes) shut down for repair in a water network.You can make a node or link inactive by setting its state to false. Networkelements that are inactive will not be considered during analysis. Note thatchanging the state of nodes and links does not affect the persistent datamodel.• Routing with specific types of links and nodesSometimes network analysis must only be conducted through nodes andlinks of specific types or with specific requirements.• Turn restrictionsTurn restrictions are constraints involving two links. They are common inrouting for transportation networks. In the following example, aprohibited turn is represented by a start link and an end link (see Figure10). For intersections with turn restrictions, such as no “U” turn or no leftturn, if the search encounters the start link of a prohibited turn, the searchdoes not continue through the end link of that prohibited turn. This typeof restriction can be easily modeled using NetworkConstraint, sinceinformation on the current link and next link is made available to users.Figure 10. Turn Modeling for Road NetworksNEW FEATURES IN THE ORACLE SPATIAL 10G NETWORK DATA MODELWith Oracle Spatial 10g Release 2, the network data model provides the following features:Network Modeling: Link DirectionThe directionality of a link can be further specified at the link level. Unlike the network directionality that determines the directions of all links, a directed network can have links that are directed or bi-directed. A BIDIRECTED column can be added to the link table and used to indicate if a directed link is bi-directed. This modeling enhancement will reduce the storage requirement for directed networks with non-homogeneous link directions (unidirectional and bidirectional).Network Analysis: Maximum Flow AnalysisThe maximum flow analysis function is provided for a single source and single sink flow network. Each link in a flow network has a flow capacity associated with it. The goal of this function is to find the maximum allowable flow that can flow from the source node to the sink node. This type of analysis is commonly seen in communication or logistics network planning.PL/SQL Wrapper PackagePrior to Oracle Spatial 10g Release 2, only the network data model Java API could be used for network editing and analysis. Now, a PL/SQL wrapper package is also provided that helps users edit and analyze networks in PL/SQL. This wrapper package provides nearly equivalent functionality as the Java API. It is done through database Java stored procedures and Java virtual machine in Oracle. CONCLUSIONThe Oracle Spatial network data model, available with Oracle Spatial 10g, is a generic network (graph) modeling and analysis environment for network applications. GIS applications for routing, tracing, and allocation have been discussed. The network data model provides an open, easy-to-use, scalable, efficient, and manageable approach to developing GIS network applications. We are currently working with our customers and partners to extend the modeling and analysis capabilities of the network data model.REFERENCESOracle Spatial Topology and Network Data Models, Oracle Corporation.Oracle Spatial User’s Guide and Reference, Oracle Corporation.Oracle Linear Referencing System: A Technical White Paper, Oracle Corporation. Oracle Spatial Network Data Model: A Technical White Paper, Oracle Corporation.Building GIS Applications Using the Oracle Spatial Network Data Model: An Oracle Technical White Paper May 2005Author: Jack Chenghua WangContributors: Vishal Rao, Nicole AlexanderOracle CorporationWorld Headquarters500 Oracle ParkwayRedwood Shores, CA 94065U.S.A.Worldwide Inquiries:Phone: +1.650.506.7000Fax: +1.650.506.7200Copyright © 2005, Oracle. All rights reserved.This document is provided for information purposes only and thecontents hereof are subject to change without notice.This document is not warranted to be error-free, nor subject to anyother warranties or conditions, whether expressed orally or impliedin law, including implied warranties and conditions of merchantabilityor fitness for a particular purpose. We specifically disclaim anyliability with respect to this document and no contractual obligationsare formed either directly or indirectly by this document. This documentmay not be reproduced or transmitted in any form or by any means,electronic or mechanical, for any purpose, without our prior written permission.Oracle, JD Edwards, and PeopleSoft are registered trademarks ofOracle Corporation and/or its affiliates. Other names may be trademarksof their respective owners.。

Oracle数据库性能优化与案例分析

Oracle数据库性能优化与案例分析
技术创新,变革未来
Oracle数据库性能优化与案例分析
性能优化探讨
• 原因:为什么? • 慢(响应时间) • 慢(吞吐量)
性能优化探讨
• 目的:为了什么? • 快(响应时间) • 快(吞吐量)
性能优化之案例分析
• 案例之方法论 • 案例之登录访问 • 案例之资源 • 案例之锁
性能优化方法论发展
• 登录输入指标测量 • Logons:= EndSnap. logons cumulative– StartSnap. logons
cumulative。 • Logons Per Second:= Logons / TimeInterval
案例之登录访问
登录输出指标测量:
Logon Response Time:= Network Response Time * 10 + Native TCP Logon :=Network Response Time * 10 + Listener Response Time + Native IPC Logon Time 。
案例之登录访问
• 例:

某医院HIS业务系统的账户登录操作异常缓慢,部分情况下
甚至会出现长时间的卡壳情况,业务影响主要发生在每天早上
的上班时刻。
案例之登录访问
优化过程: • 账户登录过程一般涉及到在账户表格以及对应日志表格上的冲
突,比如Buffer busy waits或者TX lock。AWR未体现该特征。 • AWR报告显示connection management call elapsed time时间偏长
成功率:98% 高 失败率:2% 低
失败人数:500*2%=10
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

一基本概念1实例和数据库(1)什么是实例:数据库启动以后,各个进程调入到内存中,各个进程之间的相互协调构成了实例(2)什么是数据库:各个数据文件的集合: 10.0\oradata\%sid%\目下有各种文件(CTL(控制文件),LOG(日志文件),DBF(数据文件))(3)数据库的物理结构系统的初始化参数:存放的位置为% oracle_home%\product\10.0\Db_1\database\initorcl.ora 数据库日志文件:分为联机日志文件(重做日志文件(redo日志文件):不停的覆盖)和归档日志文件(在数据库热备份的时候使用);联机日志文件写完以后,依次往下写,全部写满,重新覆盖原来的,此时就是非归档形式。

控制文件:控制日志文件和数据文件。

数据库启动的时候,首先启动控制文件,然后由控制文件打开数据文件,对应数据中的形式就是:database mount ,然后是database open。

查看数据库得文件:数据库的连接:sqlplus system/bjsxt as sysdba对应的控制文件从v$controlfile视图中查看。

desc v$controlfile (查看描述)select status ,controlfile from v$controlfile。

(查看内容)对应的数据文件从v$datafile视图中查看。

desc v$datafileselect status, name from v$datafile对应的日志文件从v$logfile视图中查看。

desc v$logfileselect member from v$logfile2内存结构(1)SGA(系统全局区)的各个缓冲区SGA被实例的所有进程所共享,包含高速缓存区(DB Buffer)、大的共享区、共享池、日志缓冲区、固定的SGA。

DB 高速缓冲区:使用系统内存,加快数据库访问数据文件中的数据。

共享池:缓冲执行的SQL语句、程序块、执行计划、常用的数据字典。

Redo buffer:日志文件缓冲区。

大共享区:提供了一个可选的内存块区,当需要备份或者执行大的SQL语句时可能需要它。

固定SGA:完全由oracle内部控制。

查看SGA的使用情况:SELECT NAME, BYTES FROM SYS.V_$SGASTAT ORDER BY NAME ASC3逻辑结构(1)表空间(2)段(3)盘区(4)数据块查看数据文件的信息:desc dba_data_files;select substr(file_name,1,50),tablespace_name,blocks from dba_data_files;查看表空间信息:desc dba_tablespaces;查看段信息:desc dba_segments查看盘区信息:desc dba_extents;二调优工具介绍1SQL_TRACE(1)SQL_TRACE说明:注意:从oracle 10g开始,SQL_TRACE成为了动态参数SQL_TRACE为true,表示运行,会对整个实例产生严重的性能影响,所以在产品环境下,如非必要,一定不要设置这个参数。

如果必须在系统下启动SQL_TRACE,必须保证以下条件对系统性能影响最小:保证25%的cpu idle为user_dump_dest分配足够的空间。

(2)在使用SQL_TRACE之前,几个注意事项需要说明一下: 初始化参数TIMED_STATISTICS参数TIMED_STATISTICS最好设置为true,否则一些重要信息将无法收集设MAX_DUMP_FILE_SIZE在9i中默认为unlimited,表示可以任意大小Alter session set MAX_DUMP_FILE_SIZE=unlimited(3)SQL_TRACE可以通过初始化参数来设置,也可以通过alter system (从10g开始)在全局中设置,也可以在具体的session中设置在参数文件中设置(pfile/spfile)指定:Sql_trace=true;在oracle 10g动态全局指定Alter system set sql_trace=true;在当前session中指定Alter session set sql_trace =true;2使用tkprof工具来查询sql性能工具SQL trace工具集收集正在执行的sql的性能状态数据,并将数据记录到一个跟踪文件中,这个跟踪文件提供很多有用的信息,如cpu时间,总消耗时间,读取磁盘数量,查询中返回的记录数目等。

使用命令查看一下tkprof的帮助fkprof 然后回车在这些参数比较有用的是:fchela (按照elapsed time fetching来对分析的结果排序)sys这个参数设置为no可以阻止所有以sys用户执行的sql被显示出来使用步骤:⏹在数据库上设置TIMED_STATISTICS为TRUE(在9i上默认为true,可以使用命令:show parameter timed_statistics查看);Alter system set timed_statistics=true;⏹启动当前会话的sql_trace:alter session set sql_trace=true;(停止当前会话的sql_trace: alter session set sql_trace=false;)⏹跟踪文件的存放位置由初始化参数user_dump_dest控制,(可以用命令show parameter user_dump_dest来查看).可能通过修改时间来找到最新生成的跟踪文件。

生成的跟踪文件扩展名为.trc.是二进制文件。

找到了对应的跟踪文件orcl_ora_3888.trc.⏹对trace文件使用tkprof工具进行分析Tkprof tracefile outfile [options]例子:tkprof orcl_ora_3576.trc report.txt sort=fchcpu sys=no;Tfprof文件参数解析:⏹CALL:每次SQL语句的处理都分成三个部分(Parse,Execute,Fetch)⏹Parse:这步将SQL语句转换成执行计划,包括检查是否有正确的授权和所需要用到的表、列以及其他引用到的对象是否存在。

⏹Execute:这步是真正的由Oracle来执行语句。

对于insert、update、delete操作,这步会修改数据,对于select操作,这步就只是确定选择的记录。

⏹Fetch:返回查询语句中所获得的记录,这步只有select语句会被执行。

⏹COUNT: 这个语句被parse、execute、fetch的次数。

⏹CPU:这个语句对于所有的parse、execute、fetch所消耗的cpu的时间,以秒为单位。

⏹ELAPSED:这个语句所有消耗在parse、execute、fetch的总的时间。

⏹DISK:从磁盘上的数据文件中物理读取的块的数量。

一般来说更想知道的是正在从缓存中读取的数据而不是从磁盘上读取的数据。

⏹QUERY:在一致性读模式下,所有parse、execute、fetch所获得的buffer的数量。

一致性模式的buffer是用于给一个长时间运行的事务提供一个一致性读的快照,缓存实际上在头部存储了状态。

⏹CURRENT:在current模式下所获得的buffer的数量。

一般在current模式下执行insert、update、delete操作都会获取buffer。

在current模式下如果在高速缓存区发现有新的缓存足够给当前的事务使用,则这些buffer都会被读入了缓存区中。

⏹ROWS: 所有SQL语句返回的记录数目,但是不包括子查询中返回的记录数目。

对于select语句,返回记录是在fetch这步,对于insert、update、delete操作,返回记录则是在execute这步。

问题判断:⏹elapsed/cpu 太大表示执行过程中花费了大量的时间等待某种资源⏹cpu OR elapsed 太大表示执行时间过长,或消耗了大量的CPU时间,应该考虑优化3在pl/slq中使用set timing on与使用sql_trace的区别三调优方式:(SQL)1在数据量比较大表上建立相关的索引Create index abc_b_index on abc(b);2Where 子句的连接顺序⏹ORACLE采用自上而下的顺序解析WHERE子句,根据这个原理,表之间的连接必须写在其他WHERE条件之前,那些可以过滤最大数据记录的条件必须写在WHERE子句的末尾。

select empno,ename,job,sal from emp wherejob='PRESIDENT' and sal>1000select empno,ename,job,sal from emp where sal>1000and job='PRESIDENT'注:(select count(*) from emp where sal>1000:(查询的数目为15068))(select count(*) from emp where job='PRESIDENT'; 查询的数目为1952)3Select 子句中避免使用’*’;如果在select子句中查询所有的字段,使用*是比较方便的,但是效率比较低,原因在于ORACLE在解析* 的时候,要将* 依次转化为字段名称,这个转化过程是通过查询数据字典完成的。

4减少访问数据库的次数当执行每条sql语句时,ORACLE在内部执行很多工作:解析SQL,估算索引的利用率,绑定变量,读数据块等。

查询编号为34的员工的姓名,工作,工资;再查询一下编号为35的员工(低效)select ename,job,sal from emp where empno=34;select ename,job,sal from emp where empno=35;在一个sql直接实现查询编号为34和35的员工信息(高效)select ename,job,sal from emp where empno=34 or empno=355使用DECODE函数来减少处理时间(1)DECODE使用说明:decode(条件,值1,翻译值1,值2,翻译值2,...值n,翻译值n,缺省值)该函数的含义如下:IF 条件=值1 THENRETURN(翻译值1)ELSIF 条件=值2 THENRETURN(翻译值2)......ELSIF 条件=值n THENRETURN(翻译值n)ELSERETURN(缺省值)END IF(2)使DECODE可以避免重复扫描相同记录或者重复连接相同的表select count(*),sum(sal) from emp where ename='SMITH' and deptno=20;select count(*),sum(sal) from emp where ename='SMITH' and deptno=10select count(decode(deptno,10,'X',NULL)) D10_COUNT, count(decode(deptno,20,'X',NULL)) D20_COUNT,sum(decode(deptno,10,sal,NULL)) D10_sum,sum(decode(deptno,20,sal,NULL)) D20_sumfrom emp where ename = 'SMITH'6删除重复记录Oracle中,每一条记录都有一个rowid,rowid在整个数据库中是唯一的,rowid确定了每条记录是在ORACLE中的哪一个数据文件、块、行上。

相关文档
最新文档