Proactively Managing Space by Using the Segment Advisor

Purpose

This tutorial describes how to use the segment advisor to proactively manage space in your database.

Approximately 20 minutes

Topics

This tutorial covers the following topics:

Place the cursor over this icon to load and view all the screenshots for this tutorial. (Caution: Because this action loads all screenshots simultaneously, response time may be slow depending on your Internet connection.)

Note: Alternatively, you can place the cursor over each individual icon in the following steps to load and view only the screenshot associated with that step.

Overview

When space used by an object at steady state is much less than the amount of space allocated to it, it becomes necessary to reclaim the unused space. With previous releases of the Oracle server, space once allocated below the segment's high-water mark (HWM) could be freed only by moving or redefining the segment. In Oracle Database 10g, you can reorganize and shrink segments. When a segment is shrunk, its data is compacted, its HWM is pushed down, and unused space is released back to the tablespace containing the segment. A shrink operation is an online and in-place operation, and does not use extra database space to be executed. In-place means the shrink operation does not create a separate object but rather that the operation is done on the same object.

Oracle Database 10g Release 1 provides a Segment Advisor that helps to identify segments that are good candidates for shrinking based on the amount of free space available in them. In Oracle 10g Release 2, this capability is enhanced by introducing the Automatic Segment Advisor, which proactively runs the Segment Advisor on segments that are likely to need space monitoring (based on system activity as well as space pressures on the tablespace where these segments reside). This feature minimizes the need to run Segment Advisor manually. If the segment that you are considering for shrinking has not already been analyzed by the Automatic Segment Advisor, run the Segment Advisor manually on these segments.

In this tutorial, you create a table, generate activity, and then use the Segment Advisor to determine whether space can be reclaimed.

Back to Topic List

Before starting this tutorial, you should::

1.

Perform the Installing Oracle Database 10g on Windows tutorial.

2.

Download and unzip the space.zip into your working directory (c:\wkdir)

Back to Topic List

To demonstrate the Segment Advisor, you create and generate data activity in a table. This table has its Enable Row Movement option set to Yes. Selecting this option allows for space reclamation on this table. Perform the following steps:

1.

Open your browser and enter the following URL (Replace <hostname> with your own host name or IP address):

http://<hostname>:1158/em

Enter sys as User Name, oracle as Password, SYSDBA in the Connect As field, and click Login.

Move your mouse over this icon to see the image

 

2.

Click the Administration tab.

Move your mouse over this icon to see the image

 

3.

Click Tables in the Schema section.

Move your mouse over this icon to see the image

 

4.

Click Create.

Move your mouse over this icon to see the image

 

5.

Select Standard, Heap Organized and click Continue.

Move your mouse over this icon to see the image

 

6.

Enter EMPLOYEES1 in the Name field. Specify SYSTEM as the schema and EXAMPLE as the tablespace. Click the Define Using drop-down list and select SQL. Enter select * from hr.employees in the CREATE TABLE AS field, and then click the Options tab.

Move your mouse over this icon to see the image

 

7.

Select Yes for Enable Row Movement and click OK to complete the creation of the table.

Move your mouse over this icon to see the image

 

8.

Your table has been created. Click the Database Instance locator link.

Move your mouse over this icon to see the image

 

9.

To start a SQL*Plus session, select Start > Programs > Oracle - OraDb10g_home1 > Application Development > SQL Plus. Enter system as the User Name, oracle as Password and click OK.

Move your mouse over this icon to see the image

 

10.

Execute the following commands to simulate user activity on the EMPLOYEES1 table.

@c:\wkdir\genactivity01

The genactivity01.sql file includes the following:

begin
  for i in 1..1000 loop
    insert into system.employees1
    select * from hr.employees;
    commit;
  end loop;
end;
/
          

Move your mouse over this icon to see the image

 

11.

To simulate more user activity on the EMPLOYEES1 table, execute the following SQL script in your SQL*Plus session:

@c:\wkdir\genactivity02

The genactivity02.sql file includes the following commands:

delete system.employees1 where department_id = 50;
begin
  for i in 1..500 loop
    insert into system.employees1
    select * from hr.employees;
    commit;
  end loop;
end;
/
           

Move your mouse over this icon to see the image

 

12.

To simulate even more user activity on the EMPLOYEES1 table, execute the following SQL script in your SQL*Plus session:

@c:\wkdir\genactivity03

The genactivity03 file includes the following commands:

begin
  for i in 1..500 loop
     insert into system.employees1
     select * from hr.employees;
     commit;
  end loop;
end;
/

Move your mouse over this icon to see the image

 

13.

To simulate more user activity on the EMPLOYEES1 table, execute the following SQL script in your SQL*Plus session:

@c:\wkdir\genactivity04

The genactivity04.sql file includes the following commands:

delete system.employees1 where department_id = 30;
commit;
delete system.employees1 where department_id = 100;
commit;
delete system.employees1 where department_id = 50;
commit;
delete system.employees1 where department_id = 80;
commit;

Move your mouse over this icon to see the image

 

14.

Switch back to Enterprise Manager. Now, you can take a look at the table segment statistics. From the Administration tab, click the Tables link.

Move your mouse over this icon to see the image

 

15.

To locate the SYSTEM.EMPLOYEES1 table, enter SYSTEM in the Schema field and emp in the Object Name field, and then click Go.

Move your mouse over this icon to see the image

 

16.

Click Edit.

Move your mouse over this icon to see the image

 

17.

Click the Segments tab.

Move your mouse over this icon to see the image

 

18.

Note the percentage of wasted space in the EMPLOYEES1 table. (Your actual values may differ from the ones in this screenshot.) You can use the Segment Advisor to reclaim the unused space in this table. Click the Database Instance locator link.

Move your mouse over this icon to see the image

 

Back to Topic List

Reclaiming Space by Using the Segment Advisor

Perform the following steps:

1.

Scroll down to the bottom of the page. Click the Advisor Central link in the Related Links section.

Move your mouse over this icon to see the image

Note: In Oracle Database 10g Release 2, the Segment Advisor automatically runs at various intervals. As a result, you see the number of Segment Advisor Recommendations represented on the Home page after a period of time.

 

2.

Click Segment Advisor.

Move your mouse over this icon to see the image

 

3.

Select Schema Objects and click Next.

Move your mouse over this icon to see the image

 

4.

Click Add.

Move your mouse over this icon to see the image

 

5.

Select Table for Type, enter system as Schema and employees1 as Object, then click Search.

Move your mouse over this icon to see the image

 

6.

In the Results section, select the SYSTEM.EMPLOYEES1 table and click OK.

Move your mouse over this icon to see the image

 

7.

Click Next.

Move your mouse over this icon to see the image

 

8.

In the Schedule window, ensure that the Schedule Type is Standard and Start is Immediately. Click Next.

Move your mouse over this icon to see the image

 

9.

Click Submit.

Move your mouse over this icon to see the image

 

10.

Click Refresh.

Move your mouse over this icon to see the image

 

11.

Select SEGMENTADV_<number>, the result for the request you have just submitted and click View Result.

Move your mouse over this icon to see the image

 

12.

Click Recommendation Details.

Move your mouse over this icon to see the image

 

13.

Select the EMPLOYEES1 segment and click Shrink in the Recommendation column. (Your values may differ slightly from the ones on the screenshot).

Move your mouse over this icon to see the image

 

14.

Click Implement.

Move your mouse over this icon to see the image

 

15.

Click Submit.

Move your mouse over this icon to see the image

 

16.

Now you can check how much space was actually freed from the table. Click the Database Instance locator link.

Move your mouse over this icon to see the image

 

17.

Click the Tables on the Administration page.

Move your mouse over this icon to see the image

 

18.

Enter SYSTEM as Schema and EMP as Object Name and click Go.

Move your mouse over this icon to see the image

 

19.

Select EMPLOYEES1 and click Edit.

Move your mouse over this icon to see the image

 

20.

Click the Segments tab.

Move your mouse over this icon to see the image

 

21.

The wasted space has been reduced significantly. (Your actual values may be different from the ones displayed in this screenshot).

Move your mouse over this icon to see the image

 

22.

Return to your SQL*Plus session and execute the following SQL script :

@c:\wkdir\cleanup

The cleanup.sql file includes the following commands:

drop table system.employees1 purge;

exit

Move your mouse over this icon to see the image

 

Back to Topic List

In this tutorial, you learned how to reclaim space in a table by using the Segment Advisor.

Back to Topic List

Place the cursor on this icon to hide all screenshots.