-
Rebuilding Indexes PL/SQL Script
Hey Guys,
I created Script that will rebuild indexes per schema. I wanted to post for others to enjoy.
BEGIN
FOR INDEx_RECORD IN (select 'SCHEMA_NAME.'||object_name as obj
from dba_objects
where object_type = 'INDEX' and
owner ='SCHEMA_NAME'
) LOOP
execute immediate 'ALTER INDEX '||INDEx_RECORD.obj||' REBUILD';
END LOOP; -- implicit CLOSE occurs
END;
-
Thank you very much, I'm sure somebody will really enjoy it.
so...
... why are you rebuilding all indexes on the schema? any special reason?
... since you are not doing rebuild online you are going to certainly affect business.
... how about partitioned indexes?
... how about statistics?
... have a couple more but I'll wait until you get these solved
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
-
Originally Posted by hozay
Hey Guys,
I created Script that will rebuild indexes per schema. I wanted to post for others to enjoy.
BEGIN
FOR INDEx_RECORD IN (select 'SCHEMA_NAME.'||object_name as obj
from dba_objects
where object_type = 'INDEX' and
owner ='SCHEMA_NAME'
) LOOP
execute immediate 'ALTER INDEX '||INDEx_RECORD.obj||' REBUILD';
END LOOP; -- implicit CLOSE occurs
END;
what a dangerous script to post - i hope you feel ashamed
-
I have an application that likes to delete 36 million rows out of the database per week. It's not a well written app. I really did not want to resort to rebuilding indexes but i seem to have no choice. We are not up 24 x 7. This is done with no users on. So yes please be careful. If you have any better ideas I'm certainly open to hear them.
Thanks
Hoz
-
Originally Posted by hozay
I have an application that likes to delete 36 million rows out of the database per week.
36 million rows deleted a week doesn't sound like whole bunch of them, either you are talking about a very small database or you are just panicking.
Originally Posted by hozay
I really did not want to resort to rebuilding indexes but i seem to have no choice
So... why are you doing it?
Originally Posted by hozay
If you have any better ideas I'm certainly open to hear them.
Do not give the same medicine -specially when you are using a dangerous one- to all your patients; give it only to the ones that need it.
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
-
looks like you (Hoz) got into wrong site? lemme make a guess, this basic knowledge of rebuild indexes coming from Don B?
funky...
"I Dont Want To Follow A Path, I would Rather Go Where There Is No Path And Leave A Trail."
"Ego is the worst thing many have, try to overcome it & you will be the best, if not good, person on this earth"
-
I keep on thinking, what a hot topic this is... rebuild index?.. or it looks like so.. lol
funky...
"I Dont Want To Follow A Path, I would Rather Go Where There Is No Path And Leave A Trail."
"Ego is the worst thing many have, try to overcome it & you will be the best, if not good, person on this earth"
-
btw, i love to see one liners of davey.. wow..
funky...
"I Dont Want To Follow A Path, I would Rather Go Where There Is No Path And Leave A Trail."
"Ego is the worst thing many have, try to overcome it & you will be the best, if not good, person on this earth"
-
There are many queries that go from running in 15mins to 6 hours after about 10 days. The queries are all based on joining of many views. Each of those views many up of many extremely wide tables.
I took a close look at one particular query. First, I tried to make sure I had updated statistics. No affect. Next, I rebuilt the indexes for that query. It returned to a 15min query.
I rebuilt indexes once a week for 3 weeks. The query ran consistently in 15 min. Then I rebuilt indexes for the entire schema. All queries run consistently in 15min.
There is nothing I can do about the SQL. I've been told it cannot be changed.
Database is size 150gb.
Hoz
-
Originally Posted by hozay
I took a close look at one particular query.
Do you still have the trace? Could you please post Wait Events section of it?
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|