16.12.2012 Views

Oracle Magazine - September/October 2007 - Marcelo Machado

Oracle Magazine - September/October 2007 - Marcelo Machado

Oracle Magazine - September/October 2007 - Marcelo Machado

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

DROP TABLE article_draft;<br />

RENAME article_draft_redef<br />

TO article_draft;<br />

There’s really no need to take your<br />

data offline, though. Instead, consider<br />

using the online table redefinition<br />

feature introduced in <strong>Oracle</strong>9i Database<br />

Release 1. Listing 2 shows a PL/SQL<br />

block that migrates the article_draft<br />

table to the structure indicated by the<br />

article_draft_redef table. Online table<br />

definition is very easy to do, and it<br />

makes the migration transparent to<br />

users and applications, because the<br />

table being migrated remains available<br />

the entire time.<br />

If your LOB table happens to be<br />

partitioned, another approach to consider<br />

is partition exchange. You can<br />

specify LOB storage on a perpartition<br />

basis, giving you the option<br />

of migrating one partition at a time<br />

from BasicFiles to SecureFiles. Use the<br />

URL under “nextSTEPS” to go to Arup<br />

Nanda’s article on partitioning features,<br />

“Partition Decisions,” where you will<br />

find an example showing how partition<br />

exchange is done.<br />

Be sure you have enough tablespace<br />

and disk space set aside to support<br />

whatever migration method you<br />

choose. For the online redefinition<br />

approach, you’ll need enough space<br />

for two complete copies of your data<br />

to coexist. Partition exchange requires<br />

only enough disk space to hold two<br />

copies of whichever partition you are<br />

exchanging. Bear in mind that one<br />

downside of partition exchange is that<br />

the partition being swapped needs to<br />

be briefly taken offline. In the end,<br />

you’ll have to weigh the different<br />

approaches and their trade-offs and<br />

choose the approach that works best in<br />

your own situation.<br />

CONFIRMING MIGRATION<br />

You can confirm the SecureFiles status<br />

of a given LOB column by checking<br />

that column’s segment subtype. For<br />

example, execute the following to<br />

confirm that article_content is now a<br />

SecureFiles LOB:<br />

codeLISTING 2: Migrating by online redefinition<br />

DECLARE<br />

error_counter PLS_INTEGER;<br />

BEGIN<br />

--Begin the redefinition process<br />

DBMS_REDEFINITION.START_REDEF_TABLE (<br />

‘gennick’, ’article_draft’, ’article_draft_redef’,<br />

‘article_id, article_stage, article_content’);<br />

--Finish the redefinition process<br />

DBMS_REDEFINITION.FINISH_REDEF_TABLE (<br />

‘gennick’, ’article_draft’, ’article_draft_redef’);<br />

END;<br />

codeLISTING 3: Checking space used by a LOB<br />

DECLARE<br />

seg_blocks NUMBER;<br />

seg_bytes NUMBER;<br />

used_blocks NUMBER;<br />

used_bytes NUMBER;<br />

expired_blocks NUMBER;<br />

expired_bytes NUMBER;<br />

unexpired_blocks NUMBER;<br />

unexpired_bytes NUMBER;<br />

BEGIN<br />

DBMS_SPACE.SPACE_USAGE (<br />

‘GENNICK’, ‘ARTICLE_CONTENT’, ‘LOB’<br />

, seg_blocks, seg_bytes, used_blocks, used_bytes<br />

, expired_blocks, expired_bytes, unexpired_blocks, unexpired_bytes);<br />

DBMS_OUTPUT.PUT_LINE (‘Bytes used = ‘ || to_char(used_bytes));<br />

END;<br />

SELECT segment_subtype<br />

FROM user_segments<br />

WHERE segment_name=’ARTICLE_CONTENT’;<br />

The result you want to see is<br />

SECUREFILE, which indicates<br />

SecureFiles storage. If you see ASSM,<br />

you’re still set for BasicFiles storage.<br />

ENABLING DEDUPLICATION<br />

Having migrated to <strong>Oracle</strong> SecureFiles,<br />

you can choose to enable deduplication,<br />

an <strong>Oracle</strong> SecureFiles feature whereby<br />

the database server stores only one<br />

copy of a given LOB in a given column<br />

within the same partition. Two or more<br />

users can independently store the same<br />

data in a LOB column—storing the<br />

same article draft twice, for example—<br />

and the database keeps track of that<br />

duplication, storing only one copy of<br />

the data. Deduplication is transparent.<br />

Users each perceive that they have their<br />

own copy of deduplicated data, even<br />

though that is not really the case.<br />

In a real-life migration, it would<br />

likely make sense to deduplicate during,<br />

not after, the migration process. For<br />

example purposes, though, it’s nice to<br />

be able to see that removal of duplicates<br />

is actually occurring. Run the<br />

code in Listing 3 to see how many<br />

bytes are in use by the LOB segment.<br />

(Be sure to change the first parameter<br />

of the procedure call to a valid schema<br />

name on your system.) On my system,<br />

the result is<br />

Bytes used = 450560<br />

To deduplicate the data in the<br />

article_content column in the<br />

article_draft table, issue the following<br />

ALTER TABLE statement:<br />

ORACLE MAGAZINE SEPTEMBER/OCTOBER <strong>2007</strong> 79

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!