提高Oracle的查詢(xún)統(tǒng)計(jì)速度方法簡(jiǎn)介
來(lái)源:易賢網(wǎng) 閱讀:1578 次 日期:2015-04-27 14:53:16
溫馨提示:易賢網(wǎng)小編為您整理了“提高Oracle的查詢(xún)統(tǒng)計(jì)速度方法簡(jiǎn)介”,方便廣大網(wǎng)友查閱!

以O(shè)racle7.33數(shù)據(jù)庫(kù)系統(tǒng)為例,我們?cè)陂_(kāi)發(fā)大型Oracle數(shù)據(jù)庫(kù)系統(tǒng)時(shí)結(jié)合項(xiàng)目的特點(diǎn),本著安全、高效的原則對(duì)數(shù)據(jù)庫(kù)進(jìn)行了一些物理設(shè)計(jì),從而大大提高了數(shù)據(jù)庫(kù)的查詢(xún)統(tǒng)計(jì)速度。總結(jié)為如下幾點(diǎn):

1)擴(kuò)大數(shù)據(jù)表空間到500MB,用于存放本系統(tǒng)的數(shù)據(jù);

2)段盤(pán)區(qū)的初始大小為10KB,增長(zhǎng)大小為10KB,增長(zhǎng)幅度為1;

3)用戶(hù)臨時(shí)空間增大40MB;

4)系統(tǒng)臨時(shí)表空間和回滾段表空間增大40MB,并且新建4個(gè)回滾段;

5)需要經(jīng)常聯(lián)結(jié)查詢(xún),而且數(shù)據(jù)量又大的庫(kù)存表、名錄表、收發(fā)料表放在一簇內(nèi);

6)提供定時(shí)備份,備份文件放在另外的機(jī)器上。

設(shè)置數(shù)據(jù)表空間的SQL語(yǔ)句如下:

CREATE TABLESPACE WXGL_DATA1 DATAFILE 'WXGL_DATA1.ORA' SIZE 500M ONLINE;

增加系統(tǒng)臨時(shí)表空間和回滾段表空間的SQL語(yǔ)句如下:

ALTER TABLESPACE TEMPORARY_DATA ADD DATAFILE 'TMP2ORCL.ORA' SIZE 40M;

ALTER TABLESPACE ROLLBACK_DATA ADD DATAFILE 'RBS2ORCL.ORA' SIZE 40M;

將數(shù)據(jù)空間設(shè)置在指定的數(shù)據(jù)文件的SQL語(yǔ)句如下:

CREATE USER ZBGL IDENTIFIED BY ZBGL;

GRANT DBA TO ZBGL;

ALTER USER ZBGL DEFAULT TABLESPACE WXGL_DATA1 TEMPORARY TABLESPACE TEMPORARY_DATA;

設(shè)置五個(gè)回滾段的SQL語(yǔ)句如下:

SELECT SEGMENT_NAME FROM DBA_ROLLBACK_SEGS WHERE INITIAL_EXTENT UPPPER(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;

將數(shù)據(jù)量大的庫(kù)存表等放在一簇內(nèi)的SQL語(yǔ)句如下:

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 ' ; (大數(shù)據(jù)量的庫(kù)存表等放在WXGL_DATA1)

QCFL = 'CREATE TABLE QC_QCFL '

  + '(FLBH NUMBER(2) PRIMARY KEY,'

  + ' FLMC VARCHAR(20) '

  + ' ) '

  +' TABLESPACE WXGL_DATA2 ' ;(其他表放在WXGL_DATA2)

系統(tǒng)的基礎(chǔ)數(shù)據(jù)庫(kù)存表、名錄表大約有數(shù)據(jù)80M;一個(gè)單位一般每年收發(fā)300次,收發(fā)料單大約有數(shù)據(jù)50M;系統(tǒng)冗余數(shù)據(jù)100M,系統(tǒng)輔助數(shù)據(jù)10M;因此,系統(tǒng)總共需要空間大約是240M,現(xiàn)在系統(tǒng)開(kāi)辟數(shù)據(jù)空間500M,完全滿(mǎn)足存儲(chǔ)要求。由于系統(tǒng)使用了冗余數(shù)據(jù),在查詢(xún)常用數(shù)據(jù)時(shí),避免了多表聯(lián)結(jié)查詢(xún)的情況,這樣,雖然使用了更多的存儲(chǔ)空間,但查詢(xún)效率大幅度提高;同時(shí),系統(tǒng)將需要經(jīng)常聯(lián)結(jié)查詢(xún)的數(shù)據(jù)放在一簇,即將存放這些數(shù)據(jù)的空間在物理上相鄰,這樣也使查詢(xún)速度大大提高。

另外在oracle7.33數(shù)據(jù)庫(kù)的Database目錄下有一個(gè)Initorcl.ora文件,改變其中的設(shè)置也可以提高查詢(xún)統(tǒng)計(jì)速度。該文件的內(nèi)容如下:

#

# $Header: init.ora 1.2 94/10/18 16:12:36 gdudey Osd

$ 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 = oracle

db_files = 20

control_files = C:\ORAWIN95\DATABASE\ctl1orcl.ora

compatible = 7.3.0.0.0

db_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  # LARGE

log_checkpoint_interval = 10000

processes = 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 # LARGE

log_buffer = 8192 # INITIAL

# log_buffer = 8192  # SMALL

# log_buffer = 32768 # MEDIUM

# log_buffer = 163840 # LARGE

sequence_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 statistics

max_dump_file_size = 10240 # limit trace file size to 5 Meg each

# log_archive_start = true # if you want automatic archiving

log_archive_dest=%ORACLE_HOME%\DATABASE\ARCHIVE

# define directories to store trace and alert files

background_dump_dest=%RDBMS73%\trace

user_dump_dest=%RDBMS73%\trace

db_block_size = 2048

snapshot_refresh_processes = 1

remote_login_passwordfile = shared

可以修改該文件的db_file_multiblock_read_count,db_block_buffers,shared_pool_size,processes ,log_buffer,sequence_cache_entries,sequence_cache_hash_buckets等項(xiàng)(文件中均有提示),根據(jù)需要和系統(tǒng)使用的數(shù)據(jù)庫(kù)服務(wù)器的特點(diǎn)適當(dāng)改大數(shù)值,可以提高查詢(xún)統(tǒng)計(jì)速度。這里要注意的是,必須將 log_archive_start = true 項(xiàng)改為False,設(shè)置才能生效。

本文介紹的Oracle數(shù)據(jù)庫(kù)設(shè)置方法均在用戶(hù)實(shí)際使用中經(jīng)過(guò)了嚴(yán)格測(cè)試,證明是有效和實(shí)用的。

更多信息請(qǐng)查看IT技術(shù)專(zhuān)欄

更多信息請(qǐng)查看數(shù)據(jù)庫(kù)
易賢網(wǎng)手機(jī)網(wǎng)站地址:提高Oracle的查詢(xún)統(tǒng)計(jì)速度方法簡(jiǎn)介
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢(xún)回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門(mén)公布的正式信息和咨詢(xún)?yōu)闇?zhǔn)!

2025國(guó)考·省考課程試聽(tīng)報(bào)名

  • 報(bào)班類(lèi)型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢(xún) | 簡(jiǎn)要咨詢(xún)須知 | 加入群交流 | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專(zhuān)用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢(xún)關(guān)注公眾號(hào):hfpxwx
咨詢(xún)QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專(zhuān)用圖標(biāo)