Space management skills for Oracle databases

Source: Internet
Author: User
Tags dba insert oracle database
oracle| Skills | data | Database in an Oracle database, DBAs can make possible adjustment decisions by observing a certain table or view to see how the current space is being used.

I. Free space in the table space

By observing the free space of the table space, it can be used to determine whether the space allocated to a table space is too much or not enough. Take a look at the following statement



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

Rows selected.

Can see that in the Fileno 12 table space RBS, only 0.19% of the allocated space is not used, this proportion is too small, and in the system and temp table space, up to 80% of the space is not utilized, for production databases, this table space is somewhat high.

With regard to the management of free space, there are some suggestions as follows:

Using the export and import commands to unload and load tablespaces frees up a lot of space to ease the need to add additional data files.

If the proportion of free space in a table space that contains a table with high insert (insert) and update (update) activity drops below 15%, add more space to the table space.

For a table space that is basically static table data, if you have more than 20% free space, you can consider reducing the amount of file space that is allocated to it.

It is more difficult to reduce the amount of space in the system table space, because the database is rebuilt.

The expansion of two tables and indexes

A. In order to prevent the table or index from being excessively extended and to adjust the database in a timely manner, users should always observe the objects concerned.

We can assume that a table or index with an extended region greater than 5 is overly extensible (overextended). Take a look at the following statement:





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

Rows selected.


By observing, the DBA can discover the problem in time and handle it accordingly.
We can use export to unload the table, then delete the table, and then use the Import command to load the table so that the discontinuous areas can be merged into a contiguous space.

B. If the user wants to optimize the table's space settings, for example, you need to change the initial parameter of the table EMP, use the following method:

1. Use the Indexfile parameter when performing IMP commands when the EMP table is unloaded and deleted:

IMP Userid=scott/tiger file=emp.dmp indexfile=emp.sql Oracle writes table and index creation information to the specified file, rather than writing the data back.

2. Open Emp.sql File:





REM CREATE TABLE "SCOTT". " EMP "(" EMPNO "
Number (4, 0), "ename"
REM VARCHAR2 (Ten), "JOB" VARCHAR2 (9),
"MGR" number (4, 0), "HireDate" DATE,
REM "SAL" number (7, 2), "COMM" number
(7, 2), "DEPTNO" number (2, 0))
REM PCTFREE pctused Initrans 1
Maxtrans 255 LOGGING STORAGE (INITIAL
REM 10240 NEXT 10240 minextents 1 maxextents
121 Pctincrease Freelists
REM 1 freelist GROUPS 1 buffer_pool DEFAULT)
Tablespace "User_data";
Rem... Rows


Edit it, remove the "REM" information, find the initial parameter, and change it as needed.

3. Perform emp.sql in Sql*plus.

4. Loading data:





MP Userid=scott/tiger Ignore=y File=emp.dmp


It is important to note that the Ignore parameter must be set to Y.

C. You can use the following statement to observe the maximum expansion of the table or index distance, "Unuse" for the maximum extension of the distance, in the User_extents table, the extent_id is from 0 to record the number.





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.


If the "Unuse" is small to a certain extent, we should pay attention to the appropriate adjustment and treatment.

Three about continuous space

You can use the following statement to view the free space in the database:



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

Ten rows selected.
We can estimate the real number of adjacent free spaces by the result of the command. For each row, with the starting Quick ID (block_id) plus the number of free blocks (BLOCKS), if it is equal to the Block ID (block_id) for the next line, the two lines are contiguous. As in the second and third lines of the example above, the 133719+126=133845, and the 1338456+130!=135275, have a contiguous space of 126+130=256 blocks starting from block_id 133719.

In the background of an Oracle database, System Monitor (Smon) periodically merges contiguous blocks of free space to get larger contiguous blocks. The DBA can use SQL commands to do this work:



Alter Tablespace Tablespace_name COALESCE;
Oracle Space management has an important effect on the performance of database, and its management method is worthy of our careful exploration.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.