Download Experiment 3.4 How to analyze the allocations of extents ? Table of

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Database wikipedia , lookup

Information privacy law wikipedia , lookup

Data vault modeling wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Business intelligence wikipedia , lookup

Clusterpoint wikipedia , lookup

B-tree wikipedia , lookup

Disk formatting wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Database model wikipedia , lookup

SQL wikipedia , lookup

Relational model wikipedia , lookup

PL/SQL wikipedia , lookup

Transcript
.4
CSCI315 Database Design and Implementation
Experiment 3.4
How to analyze the allocations of extents ?
Experimented and described by Dr. Janusz R. Getta
School of Computer Science and Software Engineering, University of Wollongong, Australia,
Bldg. 3, room 210, phone +61 02 42214339, fax +61 02 42214170,
e-mail: [email protected], Web: http://www.uow.edu.au/∼jrg, Msn: jgetta, Skype: jgetta007
Table of contents
Step 0 How to begin and what you need to know before you start ?
Step 1 How to find all extents allocated in a segment ?
Step 2 How to find the size of a data block ?
Step 3 How to analyze the extent allocation strategy ?
Step 4 How to create a tablespace with a nondefault block size ?
Step 5 How to clean up after the experiment ?
References
Actions
Step 0 How to begin and what you need to know before you start ?
A printable copy of this experiment in pdf format is available here .A tablespace consist
of segments. A segment consists of extents. A sample diagram of the internal structures of
UNIVERSITY database is available here . An extent is the smallest unit of storage allocated by
the system. An extents consists of data blocks. The system allocates storage in either fixed
size extents (option UNIFORM ) or in variable size extents (option AUTOALLOCATE ).An extent
is a logical unit of database storage space allocation made up of a number of contiguous
0
These are the specifications of the homeworks in a subject Database Design and Implementation
(CSCI315) delivered in January 2009 at Singapore Institute of Management by Dr. Janusz R. Getta
3-1
Experiment 3.4: How to analyze the allocations of extents ?
3-2
data blocks. Each extent consists of at least 5 data blocks (40 Kbytes). Maximum size of an
extent depends on an operation system. The system rounds the size of extent up to integer
multiplicity of the data block size. Turn the system on. Download and uncompress SQL
scripts used in Homework 3. Use cd command to navigate to a folder where the downloaded
and uncompressed SQL scripts are located. Start SQL*Plus client in a way described in
either Experiment 1.1 for XP operating system or in Experiment 1.2 for Linux operating
system. You can use also SQL Developer described in Experiment 1.3. Connect as a user
STUDENT with a password student .Execute a script creatbs-uniall.sql to create a locally
managed tablespace TBS_UNIALL .Execute a script grantquota.sql to grant a user STUDENT 5
Mbytes quota on a tablespace TBS_UNIALL .Next, execute a script makedef.sql to make a
tablespace TBS_UNIALL a default tablespace of a user STUDENT .Next, execute a script file
dbcreate3-4.sql to create a sample database. A sample database contains information about
the positions offered by the employers, applicants, applications raised by applicants, skills
required for the positions and skills possessed by the applicants.
Step 1 How to find all extents allocated in a segment ?
A script file listexts.sql lists information about all extents allocated in a given segment.
For example to list information about all extents allocated in a segment (a relational table)
CUSTOMER owned by a user CSCI315 the script accesses a data dictionary view DBA_EXTENTS in
the following way:
SELECT SEGMENT_NAME,
OWNER,
TABLESPACE_NAME,
EXTENT_ID,
BLOCK_ID,
FILE_ID,
BLOCKS,
BYTES
FROM DBA_EXTENTS
WHERE SEGMENT_NAME = ’CUSTOMER’ AND
OWNER = ’CSCI315’
ORDER BY BLOCK_ID;
Execute a script listexts.sql twice to find information about the extents allocated for the
relational tables APPLICANT and POSITION owned by a user STUDENT .The script lists the
following information: segment name (e.g. a name of relational table), owner name, name
of tablespace that contains a segment, extent number in a segment (EXTENT_ID) , a number of the first block in an extent (BLOCK_ID) , file identifier where an extent is allocated
(FILE_ID) , the total number of bytes in an extent (BYTES) , the total number of blocks in an
Experiment 3.4: How to analyze the allocations of extents ?
3-3
extent (BLOCKS) . File identifier determines which operating system file an extent is located
at. It is the same file identifier as included in a data dictionary view DBA_DATA_FILES . A relational table APPLICANT occupies one extent, which consists of 5 data blocks, 8 Kbytes each.
To list all segments (both DATA and INDEX segments) created in a tablespace TBS_UNIALL execute as script listmap.sql .All segments allocated in a tablespace TBS_UNIALL consist of
single extents each 40 Kbytes long. There is one free extent 520 data blocks long.
Step 2 How to find the size of a data block ?
A data block is the smalles unit of persistent (disk) storage that can be read or written by
a database system. Size of a block determines how much data is read and written within
each block transfer. Size of a data block is installation dependent and tablespace dependent.
If the data block size is not provided when a tablespace is created then a default value is
taken from a system initialization parameter DB_BLOCK_SIZE . A value of system initialization
parameter DB_BLOCK_SIZE is either decided during the system installation procedure (Oracle
9, 10g, 11g) or it is set up automatically (Oracle XE). We decided to set a value of parameter
DB_BLOCK_SIZE at 8 Kbytes for Oracle 10g, 11g. A default value of the same parameter for
Oracle XE is also 8 Kbytes. The smallest block size is 2 Kbytes and the maximum block size
is 32 Kbytes. In the operational database systems where the transactions process a relatively
small amount of rows smaller blocks, ie. 2K, 4K and maximum 8K are recommended. In
the analytical and decision support database systems where the transactions read thousands
of rows large blocks are recommended to access more data per single read operation and
block size is set up at 16 Kbytes or 32 Kbytes. To find a value of a system initialization
parameter DB_BLOCK_SIZE we have to either access a data dictionary view V$PARAMETER or
use SQL*Plus command SHOW PARAMETER . We shall practice both way now. A script file
listpar.sql lists a value of a given system initialization parameter. For example, to list a
value of SHOW PARAMETER the script executes the following statement:
SELECT NAME,
VALUE
FROM
SYS.V_PARAMETER
WHERE UPPER (NAME) = ’DB_BLOCK_SIZE’;
While connected as a user STUDENT , execute the script file. The script accesses a view
V_PARAMETER created by a user SYS over a view V$PARAMETER and granted to a user STUDENT .
It is possible to search for a number of parameters whose names included a common keyword.
For example, execute a script listpar.sql one more an enter a string block when prompted
about System initialization parameter . The system lists the names and values of all
system initialization parameters whose name includes a string block .An easier way to list the
values of system initialization parameters is to use SQL*Plus command SHOW PARAMETERS .
There is one small problem here. You must be connected as a user SYSTEM or SYS . A
Experiment 3.4: How to analyze the allocations of extents ?
3-4
command SHOW PARAMAETERS also allows for a pattern search of the names and values of
system initialization parameters, i.e. it is possible to find the names and values of all system
initialization parameters whose name contains a given string. Connect as a user SYSTEM and
use a command SHOW PARAMETERS to find the names and values of all parameters whose
name includes a string cache Save the results. We shall use these results in a nearest future.
Step 3 How to analyze the extent allocation strategy ?
Connect as a user STUDENT . Execute a script file creatab4k.sql The script creates a relational
table SAMPLE4K in a default tablespace TBS_UNIALL of your user account.
CREATE TABLE SAMPLE4K(
ATTRIBUTE1 CHAR(1024),
ATTRIBUTE2 CHAR(1024),
ATTRIBUTE3 CHAR(1024),
ATTRIBUTE4 CHAR(1024) );
The rows in a table SAMPLE4K are 4 Kbytes long ( 4 attributes of fixed size 1 Kbyte). To be
precise, the allocation of a single row requires a bit more than 4 Kbytes due to an entry in a
row dictionary - but it does not have an important impact on the results of this experiment.
While connected as a user STUDENT , execute a script file listexts.sql to list the extents
allocated so far. Despite that table SAMPLE4K is empty, the system allocated one 40 Kbytes
(5 blocks of 8 Kbytes each) extent. Each time a database object like relational table or
index is created the system takes one data block from the first extent for the organizational
purposes. Hence 4 blocks are left for the insertions. While connected as a user STUDENT ,
execute the following statements to insert a row into a relational table SAMPLE4K and to
commit the insertion:
INSERT INTO SAMPLE4K VALUES (’1’,’2’,’3’,’4’);
COMMIT;
Next, execute a script file listexts.sql to find whether insertion of a row triggered allocation
of the next extent. The system has already used the first data block allocated when a table
SAMPLE4K has been created. The second block 8 Kbytes long is enough to accommodate the
first row. Therefore, no new allocations are required. Remain connected as a user STUDENT .
Next, execute a statement given below to insert and to commit a new row in a relational
table SAMPLE4K .
INSERT INTO SAMPLE4K VALUES (’1’,’2’,’3’,’4’);
COMMIT;
Experiment 3.4: How to analyze the allocations of extents ?
3-5
Then, execute a script file listexts.sql to find whether insertion of a row triggered allocation
of the next extent. Insertion of the first row used more than 4 Kbytes of the second block
from the first allocated extent. Insertion of the second row requires a bit more than 4 Kbytes.
The second row cannot be inserted into the second block because the first row has alredy
consumed more than half of the second block. Therefore, the system inserts the second row
into the third block of the first extent. Execute a script file listexts.sql to find whether
insertion of a row triggered allocation of the next extent. Two blocks remain free in the first
extent. We can still insert two rows without the allocation of the next extent. Execute the
following statements twice to insert two rows into a relational table SAMPLE4K and execute
script listexts.sql to find the extents allocated for a relational table SAMPLE4K .
INSERT INTO SAMPLE4K VALUES (’1’,’2’,’3’,’4’);
COMMIT;
Execute a script listexts.sql to find that the extent was large enough to accomodate the
insertion of the first four rows. Insert and commit the fifth row now.
INSERT INTO SAMPLE4K VALUES (’1’,’2’,’3’,’4’);
COMMIT;
Execute a script listexts.sql to find that the system allocated one more extent for the fifth
row. To find the distribution of rows within the blocks execute a script listrowids.sql .Note,
that each row in a relational table SAMPLE4K is located in a different block. When we would
like to insert 5 rows then the system must allocate 5 blocks. If the first block of the first
extent is used by the system for the organizational purposes then the system must allocate
one more extent to accommmodate 5 rows.
Step 4 How to create a tablespace with a nondefault block size ?
A value of system initialization parameter DB_BLOCK_SIZE determines a default size of a block
for any tablespace created wihout BLOCKSIZE parameter attached to CREATE TABLESPACE statement. It is possible to create a tablespace with a block size equal to either 2 Kbytes, 4 Kbytes,
8Kbytes, 16 Kbytes, or 32 Kbytes. To do so, we have to first increase the size of the repective
data buffer cache such that it can accomodate at least one data block. If we plan to create a
tablespace with a block size equal to 2K bytes then we have to set the size of 2 Kbytes data
buffer cache to a nonzero value. If we plan to create a tablespace with a block size equal to
4 Kbytes then whave to set the size of 4 Kbytes data buffer cache to a nonzero value, and
so on. Connect as a user SYSTEM and execute the following statement to find the names and
sizes of data buffer caches:
show parameters cache
Experiment 3.4: How to analyze the allocations of extents ?
3-6
The system lists the names and values of all system initialization parameters whose names
contain a keyword cache .We would like to create a tablespace with a block size equal to 2
Kbytes. First we have to set a value of system initialization parameter DB_2K_CACHE_SIZE to
12 Mbytes. While connected as a user SYSTEM execute the following statement:
ALTER SYSTEM SET DB_2K_CACHE_SIZE=12M;
While connected as a user SYSTEM execute the following statement again to find the names
and sizes of data buffer caches:
show parameters cache
Next, connect as a user STUDENT and execute a script creatbs-uniall2k.sql to create a
tablespaceTBS_UNIALL2K with a block size equal to 2 Kbytes. Finally, while connected as
a user STUDENT and execute a script listmap.sql to find the total number of data blocks
allocated by a tablespace TBS_UNIALL2K . This time the system allocated 2,520 data blocks.
Step 5 How to clean up after the experiment ?
While connected as a user STUDENT , execute a script makedef.sql to make a tablespace
USERS a default tablespace of a user STUDENT .At the end of the experiment we remove the
tablespaces created so far. While connected as a user STUDENT execute a script droptbs34.sql to drop the tablespaces TBS_UNIALL and TBS_UNIALL2K .Next, while connected as a
user SYSTEM execute a statement:
ALTER SYSTEM SET DB_2K_CACHE_SIZE=0M;
to restore the orginal value of system initialization parameter DB_2K_CACHE_SIZE .
References
SQL Reference, ALTER SYSTEM statement
SQL Reference, CREATE TABLESPACE statement
SQL Reference, DROP TABLESPACE statement
SQL Reference, CREATE TABLE statement
Reference, DBA EXTENTS view
Reference, DBA DATA FILES view