Pages

Tuesday, October 13, 2009

Using DBMS_REDEFINITION package to reorganize tables online

I needed to partition a table while it was accepting updates. So I decided to use DBMS_REDEFINITION package provide by Oracle.



The following privileges must be granted to the user:
ALTER ANY TABLE
CREATE ANY TABLE
DROP ANY TABLE
LOCK ANY TABLE
SELECT ANY TABLE

The following privileges may be required too:
CREATE ANY INDEX
CREATE ANY TRIGGER

First of all you have to create an interim table with the same columns and data type of the table to be redefined.

Anyway I used SYS user to perform the following steps:
alter session force parallel dml parallel 3;
alter session force parallel query parallel 3;


Next step is to check if table can be redefined
EXEC Dbms_Redefinition.Can_Redef_Table('SMS', 'SMS_TRANSACTION');


With no errors displayed, I can proceed starting the redefintion using the following command. This operation can take quite some time to complete, but any queries and DML are available on table being redefined during the entire process:
BEGIN
DBMS_REDEFINITION.start_redef_table(
uname => 'SMS',
orig_table => 'SMS_TRANSACTION',
int_table => 'INT_SMS_TRANSACTION');
END;


The following command copies dependent objects, so it automatically create any triggers, indexes, materialized view logs, grants, and constraints on our interim table:
DECLARE
num_errors PLS_INTEGER;
BEGIN
DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS('SMS', 'SMS_TRANSACTION','INT_SMS_TRANSACTION',
DBMS_REDEFINITION.CONS_ORIG_PARAMS, TRUE, TRUE, TRUE, TRUE, num_errors);
dbms_output.put_line(num_errors);
END;


At this point you can query DBA_REDEFINITION_ERRORS view to check for blocking errors. You have to correct these errors and then again reexecute
the COPY_TABLE_DEPENDENTS procedure above:
select object_name, base_table_name, ddl_txt from DBA_REDEFINITION_ERRORS;

The next optional step points to resynchronize the interim table before building any constraints and indexes, especially if you think there was delay between the completion of the previous operation and moving on to finish the redefinition.
BEGIN
dbms_redefinition.sync_interim_table(
uname => 'SMS',
orig_table => 'SMS_TRANSACTION',
int_table => 'INT_SMS_TRANSACTION');
END;


Next you can execute the following command to complete the redefinition:
BEGIN
DBMS_REDEFINITION.FINISH_REDEF_TABLE('SMS', 'SMS_TRANSACTION', 'INT_SMS_TRANSACTION');
END;


Finally you should gather new statistic for your "new" table:
begin
DBMS_STATS.GATHER_TABLE_STATS (
ownname => 'SMS',
tabname => 'SMS_TRANSACTION',
estimate_percent => 45
);
end;

85 comments:

  1. Hi,

    Very usefull article. Thanks for sharing.

    ReplyDelete
  2. bxkbokr [url=http://elvalle.elvigia.net/node/8191/]tratament pt slabit[/url] qicpozsy[url=http://www.iarticlezone.com/551/diverticulitis-symptoms-and-natural-diet/]diete de slabit rapide[/url] y
    vjikcyi [url=http://www.myboyisanidiot.com/node/3718/]cura de slabire disociata[/url] l lrwylvi[url=http://www.article.neox.in/article.php?id=25327]tratament pt slabit[/url] n
    bxqjfep [url=http://moodlequebec.org/tiki-index.php?page=UserPagerefugioher]regim de slabit rapid[/url] o jdmtscr[url=http://sinhvatcanhvn.net/entry104333.html]diete de slabit[/url] l
    pcbueuq [url=http://fruitiongames.com/LeonardoTo]dieta disociata[/url] a bjblijs[url=http://www.businessonlineanswers.com/groups/mediterranean-and-beyond-diet-food-list/]cure de slabire rapide[/url] u
    qjvzlfl [url=http://www.shpil.com/content/no-carb-diet-what-you-eat-list]dieta disociata[/url] a ohovzqz[url=http://www.bysharing.com/71551/diet-system-for-kidney-condition/]cura de slabire cu mere[/url] c
    eqnvzey [url=http://www.webapp4u.com/node/5827/]supa de varza pt slabit[/url] g mmwbwta[url=http://www.alternativedr.com/altdr/groups/a-definite-healthy-type-only-diabetes-diet-nutrition-related-health-chart/]cure de slabire eficiente[/url] c
    vzqlhgs [url=http://www.shumma.com.mx/?q=node/89151/]diete pentru slabit[/url] g cjegknn[url=http://www.kochen-mit-freude.de/jillian-michaels-2011-2030-day-shred-diet-program-reviews]metode de slabire rapida[/url] q
    mvucqgv [url=http://kanoehk.com/?q=node/33612/]cura de slabire[/url] x prbckfx[url=http://myblog.readforfun.org/Teaching/groups/lose-weight-for-body-write-b-michael-thurmond-in-health-information/]dieta disociata[/url] d
    nfbuaxd [url=http://www.newecologyofthings.net/netconnect/AdrianEspa]dieta[/url] n uduqmxy[url=http://www.joshconnormusic.com/caravan/groups/weight-loss-diet-plans-how-which-will-do-it-each-of-our-right-way/]cura de slabire cu mere[/url] m

    ReplyDelete
  3. generic xanax 4mg yellow xanax bars - xanax side effects seizures

    ReplyDelete
  4. buy tramadol online tramadol withdrawal flu symptoms - tramadol 50 mg kaps

    ReplyDelete
  5. buy tramadol online buy cheap tramadol online cod - tramadol hcl for cats

    ReplyDelete
  6. buy xanax bars online xanax bars r039 - xanax withdrawal in pregnancy

    ReplyDelete
  7. xanax online drug interactions xanax and benadryl - is xanax 1 mg strong

    ReplyDelete
  8. buy tramadol online tramadol 50 mg ratiopharm - 3 tramadol high

    ReplyDelete
  9. xanax online xanax dosage mri - xanax pills pregnancy

    ReplyDelete
  10. buy tramadol overnight delivery tramadol withdrawal leg cramps - tramadol for dogs with food

    ReplyDelete
  11. buy tramadol online buy tramadol powder - tramadol addiction stories

    ReplyDelete
  12. buy tramadol online tramadol dosage 60 lb dog - tramadol dosage chart for dogs

    ReplyDelete
  13. buy tramadol online tramadol dosage rabbits - tramadol 50 mg ketorolaco 10 mg

    ReplyDelete
  14. alprazolam without prescription high from xanax bars - does xanax show up on probation drug test

    ReplyDelete
  15. buy tramadol online buy tramadol online legit - tramadol 50mg tablets street value

    ReplyDelete
  16. xanax order no prescription where to get xanax online - side effects of generic xanax

    ReplyDelete
  17. buy tramadol online side effects of tramadol 50mg capsules - tramadol side effects high dose

    ReplyDelete
  18. buy tramadol online buy tramadol online with mastercard - tramadol no prescription overnight cod

    ReplyDelete
  19. xanax online buy xanax in thailand - buy cheap xanax online with no prescription

    ReplyDelete
  20. buy tramadol online buy tramadol with credit card - order tramadol online reviews

    ReplyDelete
  21. cheap generic xanax xanax for anxiety in dogs - pristiq xanax drug interactions

    ReplyDelete
  22. xanax online xanax withdrawal death - xanax pictures pills generic

    ReplyDelete
  23. buy carisoprodol cod carisoprodol 350 mg erowid - soma carisoprodol erowid

    ReplyDelete
  24. buy tramadol online citrate 100mg tramadol - high off tramadol 50 mg

    ReplyDelete
  25. buy tramadol online tramadol 50 mg looks like - order tramadol echeck

    ReplyDelete
  26. carisoprodol soma carisoprodol 350 mg forum - kind drug carisoprodol

    ReplyDelete
  27. buy tramadol online tramadol 93 58 side effects - can tramadol for dogs be crushed

    ReplyDelete
  28. buy tramadol online no prescription forum buy cheap tramadol - buy tramadol in florida

    ReplyDelete
  29. cialis online buy cheapest cialis - buy cialis online new zealand

    ReplyDelete
  30. cialis price cheap cialis overnight delivery - cialis buy

    ReplyDelete
  31. xanax online much xanax recreational use - order xanax online cheap

    ReplyDelete
  32. buy cialis online cialis daily medication - order cialis over the counter

    ReplyDelete
  33. xanax online long will 2mg xanax last - xanax pictures pills generic

    ReplyDelete
  34. order tadalafil cialis coupon daily - cialis 2.5 price

    ReplyDelete
  35. buy cialis online buy cialis online with mastercard - generic cialis next day delivery

    ReplyDelete
  36. alprazolam price generic xanax pictures mg - 1mg xanax 5mg valium

    ReplyDelete
  37. buy xanax online xanax withdrawal gas - buy prescription drugs online xanax

    ReplyDelete
  38. cialis online generic cialis non-prescription - cialis kidney stones

    ReplyDelete
  39. cheap cialis 20mg buy cialis 100mg - cialis glaucoma

    ReplyDelete
  40. order cialis online 36 hour cialis online - ordering cialis online legal

    ReplyDelete
  41. cialis online best price cialis 20 mg - cialis price costco

    ReplyDelete
  42. cialis online buy-cialis-generic-online - cialis online ireland

    ReplyDelete
  43. cialis no prescription cialis 36 hour pill - buy cheap cialis link online

    ReplyDelete
  44. http://landvoicelearning.com/#51602 order tramadol cod saturday delivery - buy tramadol sr 100 mg

    ReplyDelete
  45. buy tramadol online 2 50 mg tramadol - buy tramadol dogs usa

    ReplyDelete
  46. buy tramadol tramadol 627 - ultram 50 mg oral tablet

    ReplyDelete
  47. http://landvoicelearning.com/#30896 tramadol purchase cheap - tramadol 50 mg

    ReplyDelete
  48. buy tramadol can you order tramadol online legally - tramadol 50mg vs vicodin

    ReplyDelete
  49. order tramadol online cod tramadol 50mg nhs - buy tramadol online europe

    ReplyDelete
  50. buy tramadol tramadol webmd - tramadol no prescription online

    ReplyDelete
  51. buy tramadol buy tramadol no prescription cod - tramadol overdose yahoo answers

    ReplyDelete
  52. http://buytramadolonlinecool.com/#59473 buy tramadol 180 - tramadol online fast

    ReplyDelete
  53. buy tramadol online tramadol 50 mg espanol - buy tramadol online cheap no prescription

    ReplyDelete
  54. http://buytramadolonlinecool.com/#30807 drug study tramadol generic name - tramadol high how much

    ReplyDelete
  55. buy tramadol buy tramadol online overnight delivery - tramadol no prescription free shipping

    ReplyDelete
  56. buy tramadol tramadol and ultram recovery room - legal buy tramadol online united states

    ReplyDelete
  57. http://buytramadolonlinecool.com/#96430 tramadol 50 mg max dosage - tramadol withdrawal day 6

    ReplyDelete
  58. buy ativan online ativan withdrawal onset - ativan oral dose

    ReplyDelete
  59. buy tramadol online tramadol hcl 50 mg tab dosage - get rid tramadol withdrawal

    ReplyDelete
  60. buy ativan online buy lorazepam online with mastercard - zoloft ativan side effects

    ReplyDelete
  61. buy lorazepam online ativan 3 times a day - quitting ativan cold turkey

    ReplyDelete
  62. ativan lorazepam lorazepam 1 mg wiki - ativan side effects ask patient

    ReplyDelete
  63. cheap alprazolam xanax bars rap song - all kinds xanax pills

    ReplyDelete
  64. xanax cost many mg xanax pills - xanax generic vs brand name

    ReplyDelete
  65. buy tramadol online tramadol dosage mg/kg - tramadol hcl 50 mg reviews

    ReplyDelete
  66. tramadol no rx illegal buy tramadol online usa - tramadol 50mg tablets identification

    ReplyDelete
  67. buy tramadol online buy tramadol online cod overnight - buy tramadol online visa

    ReplyDelete
  68. buy tramadol online buy tramadol online without prescriptions - buy tramadol hydrochloride

    ReplyDelete
  69. http://ranchodelastortugas.com/#51462 xanax tri-score 2mg tablets - pills related to xanax

    ReplyDelete
  70. http://bayshorechryslerjeep.com/#7724 xanax drug misuse - xanax withdrawal librium

    ReplyDelete
  71. Your post featureѕ eѕtаblіshed helpful to us.
    ӏt’s very uѕеful аnԁ you're obviously quite well-informed in this field. You possess opened our sight to various views on this specific subject together with intriquing, notable and reliable written content.

    Also visit my site; Xanax
    Feel free to visit my website - Xanax

    ReplyDelete
  72. Read Full Report long does 50mg tramadol take work - buy tramadol online

    ReplyDelete
  73. Now if you want to order heroine online and earn a good discount on it then Real 24 cart is the right destination for you. Here you can also buy tramadol pills online and get it at the place of your choice.

    ReplyDelete
  74. I need to to thank you for this great read!! I definitely loved every bit of it.
    EVERYTHING YOU NEED TO KNOW ABOUT BLUE COOKIES STRAIN I have got you bookmarked to look at new stuff you .

    ReplyDelete
  75. How to use Tramadol Pills

    Tramadol pills 100mg are very easy to consume and can be the quickest way to cure your pains. Tramadol medicines should be consumed every four to six hours per prescription. If you are consuming Tramadol in the form of liquid, it should be taken in precise dosage amounts.

    Tramadol-100-mg-90
    Tramadol-100-mg-90 Pills
    Tramadol-100-mg
    Tramadol Medicines
    Tramadol Tablets
    Tramadol Pills
    Call us: 231-221-2887
    For more info:https://72hrspills.com/tramadol-100-mg-90/

    ReplyDelete