Home Database Mysql Tutorial Oracle的空间数据库管理技巧

Oracle的空间数据库管理技巧

Jun 07, 2016 pm 03:30 PM
oracle Skill database space manage Enter

欢迎进入Oracle社区论坛,与200万技术人员互动交流 >>进入 在Oracle数据库中,DBA可以通过观测一定的表或视图来了解当前空间的使用状况,进而作出可能的调整决定。 一。表空间的自由空间 通过对表空间的自由空间的观察,可用来判断分配给某个表空间的空间是

欢迎进入Oracle社区论坛,与200万技术人员互动交流 >>进入

  在Oracle数据库中,DBA可以通过观测一定的表或视图来了解当前空间的使用状况,进而作出可能的调整决定。

  一。表空间的自由空间

  通过对表空间的自由空间的观察,可用来判断分配给某个表空间的空间是太多还是不够。请看下列的语句

  SQL > select a.file_id "FileNo",a.tablespace_name   "Tablespace_name",   2 a.bytes "Bytes",a.bytes-sum(nvl(b.bytes,0)) "Used",   3 sum(nvl(b.bytes,0)) "Free",   4 sum(nvl(b.bytes,0))/a.bytes*100 "%free"   5 from dba_data_files a, dba_free_space b   6 where a.file_id=b.file_id(+)   7 group by a.tablespace_name ,   8 a.file_id,a.bytes order by a.tablespace_name;   File Tablespace   No _nameBytes Used Free %free   ―― ―― ―― ―― ―― ――   11IDX_JF .146E+09 849305600 1.297E+09 60.431806   9 JFSJTS 2.146E+09 1.803E+09 343793664 16.016961   10JFSJTS 2.146E+09 1.359E+09 787431424 36.685546   2 RBS523239424 359800832 163438592 31.235909   12RBS1.610E+09 1.606E+09 3104768 .19289495   8 RBSJF 3.220E+09 2.716E+09 504356864 15.662396   7 SFGLTS 2.146E+09 1.228E+09 918159360 42.776014   6 SFSJTS 2.146E+09 1.526E+09 620093440 28.889457   1 SYSTEM 523239424 59924480 463314944 88.547407   3 TEMP 523239424294912 522944512 99.943637   4 TOOLS 15728640 12582912 314572820   5 USERS 7340032 81927331840 99.888393   12 rows selected.

  可以看出,在FileNo为12的表空间RBS中,只有0.19%的分配空间未被使用,这个比例太小了,而在SYSTEM及TEMP等表空间中,高达80%以上的空间未被利用,对于生产型数据库,这个表空间的设置有些偏高。

  关于自由空间的管理,有下面的一些建议:利用Export及Import命令卸出和装入表空间可以释放大量的空间,从而缓解增加另外的数据文件的要求。如果包含具有高插入(insert)和更新(update)活动的表的表空间中自由空间的比重下降到了15%以下,要为此表空间增加更多的空间。对于一个基本是静态表数据的表空间,如果有多于20%的自由空间,则可以考虑减少分配给它的文件空间量。减少SYSTEM表空间的空间量比较困难,因为那要重建数据库。

  二 表及索引的扩展

  A.为了防止表或索引被过分扩展,及时实现对数据库的调整,用户应当经常对有关对象进行观察。我们可以认为,扩展区域大于5个的表或索引为过分扩展(overextended)。请看下面的语句:

  SQL > select substr(segment_name,1,15)

  Segment_name,segment_type,

  2 substr(tablespace_name,1,10)

  Tablepace_name,extents,Max_extents

  3from dba_segments

  4where extents >5 and owner='JFCL'

  5order by segment_name;

  SEGMENT_NAMESEGMENT TABLEPACE_

  EXTENTS MAX_EXTENTS

  _TYPE

  -------------- --------- ----------

  CHHDFYB TABLE JFSJTS 11121

  CHHDFYB_DHHMINDEX JFSJTS9121

  DJHZFYB_BF TABLE JFSJTS 17500

  DJHZFYB_DJHMINDEX IDX_JF6500

  DJHZFYB_JZHMINDEX IDX_JF7500

  GSMFYB TABLE JFSJTS 11121

  JFDHTABLE JFSJTS 14500

  JFDH_DHHM INDEX IDX_JF 61500

  JFDH_JZHM INDEX IDX_JF 64500

  XYKFYB TABLE JFSJTS7121

  YHDATABLE JFSJTS6500

  YHDA_BAKTABLE JFSJTS6500

  YHHZFYB_12 TABLE JFSJTS 10500

  13 rows selected.

  通过观察, DBA可以及时发现问题并进行相应的处理。我们可以利用export卸出表,然后删除表,再利用import命令将表装入,这样,可以将不连续的区域合并成一个连续的空间。

  B.如果用户希望对表的空间设置进行优化,例如,需要改变表EMP的initial参数,可以采用下面的方法:

  1.在将EMP表卸出并删除后执行imp命令时使用indexfile参数:imp userid=scott/tiger file=emp.dmp indexfile=emp.sql Oracle把表和索引的创建信息写到指定的文件,而不是把数据写回。

  2.打开emp.sql文件:

  REM CREATE TABLE "SCOTT"."EMP" ("EMPNO" NUMBER(4, 0), "ENAME"

  REM VARCHAR2(10), "JOB" VARCHAR2(9),

  "MGR" NUMBER(4, 0), "HIREDATE" DATE,

  REM "SAL" NUMBER(7, 2), "COMM" NUMBER

  (7, 2), "DEPTNO" NUMBER(2, 0))

  REM PCTFREE 10 PCTUSED 40 INITRANS 1

  MAXTRANS 255 LOGGING STORAGE(INITIAL

  REM 10240 NEXT 10240 MINEXTENTS 1 MAXEXTENTS

  121 PCTINCREASE 50 FREELISTS

  REM 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)

  TABLESPACE "USER_DATA" ;

  REM …… 14 rows

  对它进行编辑,去除"REM"等信息,找到Initial参数,根据需要改变它。

  3.在SQL*plus中执行emp.sql.

  4.装入数据:

  imp userid=scott/tiger ignore=y file=emp.dmp

  需要注意的是,ignore参数必须设为Y.

  C.可以用下面的语句来观察表或索引距离达到最大扩展的状况,“UNUSE”为距离达到最大扩展的值,在User_extents表中,extent_id是从0开始记述数的。

  SQL >select a.table_name "TABLE_NAME",max

  (a.max_extents) "MAXEXTENTS" ,

  2 max(b.extent_id)+1 "IN USE", MAX

  (a.max_extents)-(max(b.extent_id)+1) "UNUSE"

  3 from user_tables a, user_extents b

  4where a.table_name=b.segment_name

  5 group by a.table_name ORDER BY 4;

  TABLE_NAME MAXEXTENTS IN USEUNUSE

  ---------- ----------- -------- ---------

  YZPHB 98 1 97

  SHJYB 121 1 120

  SHFYB 121 1 120

  RCHDB 121 1 120

  SJTXDZB121 1 120

  SJTXDAB121 1 120

  CHYHB 121 1 120

  JFDH 50014 486

  8 rows selected.

  如果“UNUSE"小到一定的程度,我们就应该加以关注,进行适当的调整处理。

  三 关于连续空间

  可以用下面的语句来查看数据库中的自由空间:

  SQL > select * from dba_free_space

  where tablespace_name='SFSJTS'

  2 order by block_id;

  TABLESPACE FILE_ID BLOCK_ID BYTESBLOCKS

  _NAME

  ----------- --------- --------------

  SFSJTS 6 133455 1064960 130

  SFSJTS 6 133719 1032192 126

  SFSJTS 6 133845 1064960 130

  SFSJTS 6 135275 1064960 130

  SFSJTS 6 135721 606208 74

  SFSJTS 6 139877 901120 110

  SFSJTS 6 143497 737280 90

  SFSJTS 6 220248 737280 90

  SFSJTS 6 246228 491520 60

  SFSJTS 6 261804 1064960 130

  10 rows selected.

  我们可以通过命令的结果来估计相邻自由空间的真正数量。对每一行,用起始快的id(BLOCK_ID)加上自由块(BLOCKS)的数量,如果其和与下一行的块id(BLOCK_ID)相等,则此两行是连续的。如上例第二行和第三行,133719+126=133845,而1338456+130!=135275,所以从block_id为133719开始,有126+130=256个block的连续空间。

  在Oracle数据库的后台,系统监视器(SMON)周期性地合并自由空间相邻的块,以得到更大的连续块。而DBA可以用SQL命令来完成这个工作:

  alter tablespace tablespace_name coalesce;

  Oracle空间管理对数据库的工作性能有重要影响,其管理方法值得我们认真摸索研

Oracle的空间数据库管理技巧

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How long will Oracle database logs be kept? How long will Oracle database logs be kept? May 10, 2024 am 03:27 AM

The retention period of Oracle database logs depends on the log type and configuration, including: Redo logs: determined by the maximum size configured with the "LOG_ARCHIVE_DEST" parameter. Archived redo logs: Determined by the maximum size configured by the "DB_RECOVERY_FILE_DEST_SIZE" parameter. Online redo logs: not archived, lost when the database is restarted, and the retention period is consistent with the instance running time. Audit log: Configured by the "AUDIT_TRAIL" parameter, retained for 30 days by default.

Oracle database server hardware configuration requirements Oracle database server hardware configuration requirements May 10, 2024 am 04:00 AM

Oracle database server hardware configuration requirements: Processor: multi-core, with a main frequency of at least 2.5 GHz. For large databases, 32 cores or more are recommended. Memory: At least 8GB for small databases, 16-64GB for medium sizes, up to 512GB or more for large databases or heavy workloads. Storage: SSD or NVMe disks, RAID arrays for redundancy and performance. Network: High-speed network (10GbE or higher), dedicated network card, low-latency network. Others: Stable power supply, redundant components, compatible operating system and software, heat dissipation and cooling system.

How much memory does oracle require? How much memory does oracle require? May 10, 2024 am 04:12 AM

The amount of memory required by Oracle depends on database size, activity level, and required performance level: for storing data buffers, index buffers, executing SQL statements, and managing the data dictionary cache. The exact amount is affected by database size, activity level, and required performance level. Best practices include setting the appropriate SGA size, sizing SGA components, using AMM, and monitoring memory usage.

Oracle scheduled tasks execute the creation step once a day Oracle scheduled tasks execute the creation step once a day May 10, 2024 am 03:03 AM

To create a scheduled task in Oracle that executes once a day, you need to perform the following three steps: Create a job. Add a subjob to the job and set its schedule expression to "INTERVAL 1 DAY". Enable the job.

How much memory is needed to use oracle database How much memory is needed to use oracle database May 10, 2024 am 03:42 AM

The amount of memory required for an Oracle database depends on the database size, workload type, and number of concurrent users. General recommendations: Small databases: 16-32 GB, Medium databases: 32-64 GB, Large databases: 64 GB or more. Other factors to consider include database version, memory optimization options, virtualization, and best practices (monitor memory usage, adjust allocations).

How to start the listening program in oracle How to start the listening program in oracle May 10, 2024 am 03:12 AM

Oracle listeners are used to manage client connection requests. Startup steps include: Log in to the Oracle instance. Find the listener configuration. Use the lsnrctl start command to start the listener. Use the lsnrctl status command to verify startup.

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

See all articles