| |
| 提高oracle数据库的查询统计速度 |
| |
发布者: 发布时间:2006-05-07 |
|
|
大型数据库系统中往往要用到查询统计,但是对于数据量大的系统,用户在进行复杂的查询统计时往往感到速度很慢,不能满足应用要求,这就要求我们在设计数据库系统时进行合理设置,提高查询统计的速度。本文结合笔者的项目开发经验,阐述具体的设置方法。
以oracle7.33数据库系统为例,我们在开发大型oracle数据库系统时结合项目的特点,本着安全、高效的原则对数据库进行了一些物理设计,从而大大提高了数据库的查询统计速度。总结为如下几点:
1)扩大数据表空间到500m,用于存放本系统的数据;
2)段盘区的初始大小为10k,增长大小为10k,增长幅度为1;
3)用户临时空间增大40m;
4)系统临时表空间和回滚段表空间增大40m,并且新建4个回滚段;
5)需要经常联结查询,而且数据量又大的库存表、名录表、收发料表放在一簇内;
6)提供定时备份,备份文件放在另外的机器上。
设置数据表空间的sql语句如下:
create tablespace wxgl_data1 datafile ''wxgl_data1.ora'' size 500m online; |
增加系统临时表空间和回滚段表空间的sql语句如下:
alter tablespace temporary_data add datafile ''tmp2orcl.ora'' size 40m;alter tablespace rollback_data add datafile ''rbs2orcl.ora'' size 40m; |
将数据空间设置在指定的数据文件的sql语句如下:
create user zbgl identified by zbgl;grant dba to zbgl;alter user zbgl default tablespace wxgl_data1 temporary tablespace temporary_data; |
设置五个回滚段的sql语句如下:
select segment_name from dba_rollback_segs where initial_extent < 512000 anduppper(owner) = ''public'';select upper(status) from dba_rollback_segs where upper(segment_name) = ''''alter rollback segment rb1 offline;alter rollback segment rb2 offline;alter rollback segment rb3 offline;alter rollback segment rb4 offline;alter rollback segment rb5 offline;drop rollback segment rb1;drop rollback segment rb2;drop rollback segment rb3;drop rollback segment rb4;drop rollback segment rb5;create public rollback segment rb1 tablespace rollback_data storage (initial 512000 next 512000 maxextents 121);create public rollback segment rb2 tablespace rollback_data storage (initial 512000 next 512000 maxextents 121);create public rollback segment rb3 tablespace rollback_data storage (initial 512000 next 512000 maxextents 121);create public rollback segment rb4 tablespace rollback_data storage (initial 512000 next 512000 maxextents 121);create public rollback segment rb5 tablespace rollback_data storage (initial 512000 next 512000 maxextents 121);alter rollback segment rb1 online;alter rollback segment rb2 online;alter rollback segment rb3 online;alter rollback segment rb4 online;alter rollback segment rb5 online;commit; |
将数据量大的库存表等放在一簇内的sql语句如下:
kcb=''create table qc_kcb( '' +'' cknm number(8) ,'' +'' qcnm number(10) ,'' +'' ckkc number(12,2),'' +'' snckkc number(12,2),'' +'' ldj number(12,2),'' +'' bz varchar(100),'' +'' primary key(cknm,qcnm))'' +'' tablespace wxgl_data1 '' ;(大数据量的库存表等放在wxgl_data1)qcfl = ''create table qc_qcfl '' + ''(flbh number(2) primary key,'' + '' flmc varchar(20) '' + '' ) '' +'' tablespace wxgl_data2 '' ;(其他表放在wxgl_data2) |
系统的基础数据库存表、名录表大约有数据80m;一个单位一般每年收发300次,收发料单大约有数据50m;系统冗余数据100m,系统辅助数据10m;因此,系统总共需要空间大约是240m,现在系统开辟数据空间500m,完全满足存储要求。由于系统使用了冗余数据,在查询常用数据时,避免了多表联结查询的情况,这样,虽然使用了更多的存储空间,但查询效率大幅度提高;同时,系统将需要经常联结查询的数据放在一簇,即将存放这些数据的空间在物理上相邻,这样也使查询速度大大提高。
另外在oracle7.33数据库的database目录下有一个initorcl.ora文件,改变其中的设置也可以提高查询统计速度。该文件的内容如下:
## $header: init.ora 1.2 94/10/18 16:12:36 gdudey osd<desktop/netware> $ init.ora copyr (c) 1991 oracle################################################################################ example init.ora file## this file is provided by oracle corporation to help you customize# your rdbms installation for your site. important system parameters# are discussed, and example settings given.## some parameter settings are generic to any size installation.# for parameters that require different values in different size# installations, three scenarios have been provided: small, medium# and large. any parameter that needs to be tuned according to # installation size will have three settings, each one commented# according to installation size.## use the following table to approximate the sga size needed for the# three scenarious provided in this file:## -------installation/database size------# small medium large# block 2k 4500k 6800k 17000k# size 4k 5500k 8800k 21000k## to set up a database that multiple instances will be using, place# all instance-specific parameters in one file, and then have all# of these files point to a master file using the ifile command.# this way, when you change a public# parameter, it will automatically change on all instances. this is # necessary, since all instances must run with the same value for many# parameters. for example, if you choose to use private rollback segments, # these must be specified in different files, but since all gc_* # parameters must be the same on all instances, they should be in one file.## instructions: edit this file and the other init files it calls for# your site, either by using the values provided here or by providing# your own. then place an ifile= line into each instance-specific# init file that points at this file.###############################################################################db_name = oracledb_files = 20control_files = c:\orawin95\database\ctl1orcl.oracompatible = 7.3.0.0.0db_file_multiblock_read_count = 8 # initial# db_file_multiblock_read_count = 8 # small # db_file_multiblock_read_count = 16 # medium # db_file_multiblock_read_count = 32 # large db_block_buffers = 200 # initial# db_block_buffers = 200 # small # db_block_buffers = 550 # medium # db_block_buffers = 3200 # large shared_pool_size = 3500000 # initial# shared_pool_size = 3500000 # small# shared_pool_size = 6000000 # medium# shared_pool_size = 9000000 # largelog_checkpoint_interval = 10000processes = 50 # initial# processes = 50 # small # processes = 100 # medium # processes = 200 # large dml_locks = 100 # initial# dml_locks = 100 # small # dml_locks = 200 # medium # dml_locks = 500 # largelog_buffer = 8192 # initial# log_buffer = 8192 # small# log_buffer = 32768 # medium# log_buffer = 163840 # largesequence_cache_entries = 10 # initial# sequence_cache_entries = 10 # small # sequence_cache_entries = 30 # medium # sequence_cache_entries = 100 # large sequence_cache_hash_buckets = 10 # initial# sequence_cache_hash_buckets = 10 # small # sequence_cache_hash_buckets = 23 # medium # sequence_cache_hash_buckets = 89 # large # audit_trail = true # if you want auditing# timed_statistics = true # if you want timed statisticsmax_dump_file_size = 10240 # limit trace file size to 5 meg each # log_archive_start = true # if you want automatic archivinglog_archive_dest=%oracle_home%\database\archive# define directories to store trace and alert filesbackground_dump_dest=%rdbms73%\traceuser_dump_dest=%rdbms73%\tracedb_block_size = 2048snapshot_refresh_processes = 1remote_login_passwordfile = shared |
可以修改该文件的db_file_multiblock_read_count,db_block_buffers,shared_pool_size,processes ,log_buffer,sequence_cache_entries,sequence_cache_hash_buckets等项(文件中均有提示),根据需要和系统使用的数据库服务器的特点适当改大数值,可以提高查询统计速度。这里要注意的是,必须将 log_archive_start = true 项改为false,设置才能生效。
本文介绍的oracle数据库设置方法均在用户实际使用中经过了严格测试,证明是有效和实用的。
|
| (转载文章请保留出处:北天JAVA技术网(www.java114.com)) |
| |
| 更多精彩文章: |
| 为oracle8iforsolaris配置并管理多个数据库 |
| resetlogs后没有备份情况下的数据恢复 |
| 在unix下让oracle定时执行*.sql文件 |
| 如何在oems中成功提交作业 |
| oracleweb应用开发之apache架设与pl/sql页面设计(2) |
| oracleweb应用开发之apache架设与pl/sql页面设计(3) |
| |
| 最近评论: |
|
|
| 你曾悄悄的来过! |
| wow gold,wow gold,wow gold,ffxi gil max(5433) |
|
|
| 冰封的往事! |
| wow power leveling,wow gold,wow power leveling,wow gold
max(853) |
|
|
| 冰封的往事! |
| wow power leveling,wow gold,WoW Gold,wow gold
max(2496) |
|
|
| 飞舞的传奇! |
| 传世私服,传世私服.传奇世界私服传奇世界私服,传世私服传世私服, 传奇世界私服传奇世界私服.传奇私服传奇私服. max(1893) |
|
|
| |
| 免责声明:该文章由网友发表,如果对您造成侵权,请联系站长。 |
|