Question

How can I do reorg rebuild all indexes in all databases? Can some one help me with script?

Asked by: dearvjkumar

How can I do reorg rebuild all indexes in all databases? Can some one help me with script?

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-07-21 at 01:47:58ID24586526
Tags

Sybase - Index Rebuild - All Index in all database

Topic

Sybase Database

Participating Experts
3
Points
0
Comments
19

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Rebuilding Indexes
    Hi, I have an 8.0.5 database instance running in ARCHIVELOG mode. Every week a maintenance job is run that rebuilds all indexes. This results in the creation of many archived logs. I wondering is there any danger in using NOLOGGING when rebuilding the indexes to avoid the...
  2. Rebuild indexes
    Hi, My application is running very slowly... And I'd like to rebuild my indexes to increase the speed. I have a table which contains over 120 000 records, and when I execute this line : "ALTER INDEX IDX_AGENT_NAME REBUILD;" It takes only few seconds.... But I kno...
  3. rebuilding indexes
    Hi all, Can i rebuild all the indexes in a schema at ones? Suppose, if i have 400 indexes in total in the schema SCOTT, now, can i rebuild all the 400 indexes at a time in schema SCOTT rather than giving ALTER INDEX <index name> REBUILD UNRECOVERABLE for each ...
  4. rebuilding Indexes
    We are running the below script every week. We are not rebuilding Indexes every week. Is it a good Idea to rebuild Indexes every week or periodically.(All the indexes in the database) We have a OLTP database. we are not facing any performance problem yet EXECUTE DBMS_STATS....
  5. rebuilding index in oracle 10.2.0.3 online
    Experts, i am planning to rebuild index online. my DB version is 10.2.0.3. i need some suggestion to rebuilding index. how to find which index need to be rebuild? what cases we need to rebuild indexes? how to rebuild local indexes (partitioned indexes)? how to rebuild globa...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: rrjegan17Posted on 2009-07-21 at 02:03:46ID: 24902317

Just run this query:

select "dbcc reindex (" +name +")" +char(10) +"go" from
sysobjects where type="U"

Copy the results, Paste it in a new query window and then Run it.

Hope this helps

 

by: dearvjkumarPosted on 2009-07-21 at 02:41:20ID: 24902558

Hi rrjegan17,

I need a method or script to run reorg rebuild all tables in all databases.

 

by: rrjegan17Posted on 2009-07-21 at 03:19:10ID: 24902788

Hope this helps:

select "reorg rebuild " +name + char(10) +"go" from
sysobjects where type="U"

Copy the results, paste in a new query window and then Run it.

 

by: Joe_WoodhousePosted on 2009-07-21 at 07:55:22ID: 24905243

rrjegan17:

I still run into this at some sites. It's well worth you reading the manuals on what exactly dbcc reindex does. It does not (despite the name, and despite what you seem to be suggesting) rebuild indexes in the way that you think.

"dbcc reindex checks the integrity of indexes on user tables by running a fast version of dbcc checktable. For details, see dbcc checktable on page 226. dbcc reindex drops and rebuilds the indexes where the sort order used is not consistent with the new sort order. When dbcc reindex discovers the first index-related error, it displays a message, and then rebuilds the inconsistent indexes. The System Administrator or table owner should run dbcc reindex after changing the sort order in Adaptive Server."

ie if the sort order of the index matches the sort order of the server, nothing happens.


dearvjkumar:

Be aware that you will need the SELECT INTO option to run REORG REBUILD, it will exclusively lock each table as it runs, and running it on one table at a time serially like this is will be slow. Definitely not something to run while users are doing anything with the system.

Can I ask why you want to run this or think you need to? Certainly Sybase ASE tables should be defragmented... maybe 1-4 times/year depending on what you do to them with INSERTs, UPDATEs and DELETEs.

You can use the "optdiag" tool (included for free with ASE) to get an estimate of how fragmented the tables are. Let's put it this way - you certainly don't have to run this weekly or even (probably) monthly.

 

by: dearvjkumarPosted on 2009-07-21 at 08:55:05ID: 24906046

Hi, thanks for the info. But due to some requirement, i have to enable monthly index rebuild job in our sybase servers. So i m looking for a method to select all database and tables and do reorg rebuild.

But I couldnt find a way to select all database and tables inside each database to execute reorg rebuild.
I need this method not only for reorg rebuild and for someother checking also i required.

So if some has script / proc to execute something on all database and all tables, please help me.

 

by: IncisiveOnePosted on 2009-07-21 at 17:51:03ID: 24910694

Keeping Joe's warning in mind.

If you increase the points to 500, I will give you a script (two actually).  If you do not have the execute immediate command (12.5.3 IIRC), you will need a shell (not SQL) script; if you have it, the scripts will be entirely SQL (which is much easier).  Try:

declare @x char(80)
select @x = "exec sp_who"
exec (@x)

Cheers

 

by: dearvjkumarPosted on 2009-07-21 at 18:23:33ID: 24910796

Hi Incisive,

I need to loop thru all the DB and all the tables inside each DB. I am looking for a script with that requirement. Can you able to help me?

 

by: IncisiveOnePosted on 2009-07-21 at 19:24:19ID: 24911082

Yes, I understood, that.  I have such scripts working.  Not just a script/proc that does the <job> on one db.

 

by: IncisiveOnePosted on 2009-07-21 at 19:35:56ID: 24911145

Note also, along the lines of Joe's post, you have not specified whether you want:

reorg rebuild table
or
reorg rebuild table index

The first de-fragments the heap table and rebuilds all indices.
The second rebuilds just the index (which defrags the index).  I think you want this one, if you are going to execute this monthly.

Cheers


 

by: IncisiveOnePosted on 2009-07-22 at 03:03:47ID: 24912959

This has not been thought out, or you have some non-technical person giving you orders (which will end in tears for everyone).  I do not do such silly things (as reorg rebuild or update stats) in my existing proc, but I do have a working method which executes at the db_name/table/index level.  You simply supply the command (this is important esp. if you are going to do "someother checking as well").

From the SAG manual:

"The following considerations apply to the rebuild subcommand:
reorg rebuild holds an exclusive table lock for its entire duration. On a large table this may be a significant amount of time. However, reorg rebuild accomplishes everything that dropping and re-creating a clustered index does and takes less time. In addition, reorg rebuild rebuilds the table using all of the table's current space management settings. Dropping and re-creating an index does not use the space management setting for reservepagegap.

In most cases, reorg rebuild requires additional disk space equal to the size of the table it is rebuilding and its indexes.

The following restrictions hold:
The table specified in the command, if any, must use either the datarows or datapages locking scheme.

You must be a System Administrator or the object owner to issue reorg.

You cannot issue reorg within a transaction."

What would you like for the DPL/DRL Placement index (the term Clustered Index when applied to DPL/DRL tables is false and misleading, I refuse to use it) ?

Corrections

(The manuals have deteriorated since 11.9.2, some sections are confusing and appear contradictory)

1  Reorg rebuild index does not take out a table lock (reorg rebuild <table> does).

2  Reorg rebuild index does not need select_into set (reorg rebuild <table> does).  That means your log dumps are not suspended.

3  The statement
"However, reorg rebuild accomplishes everything that dropping and re-creating a [placement] clustered index does and takes less time."
is complete nonsense.  In fact, the heap is left unchanged, only the index is rebuilt; drop/create the placement index rewrites and de-fragments the heap.  In my varied experience, it is substantially slower than drop/create placement index (but that does take out a table lock); and it hammers the log one hell of a lot.  The same manual later states:
"Although online index rebuilding is allowed on a placement index, it rebuilds only the index pages. The data pages remain untouched, which means datarows are neither sorted nor rewritten to fresh pages. You can rebuild data pages by dropping a placement index, and then re-creating it."
Note the use of the correct term, Placement.

4  Reorg rebuild index requires very little free space in the db (reorg rebuild <table> requires 125% the table size).

----------

What would you like for the DPL/DRL Placement index, would you like special handling (drop/create instead of reorg rebuild index), or leave as is ?

Cheers

 

by: rrjegan17Posted on 2009-07-22 at 05:46:17ID: 24914061

dearvjkumar,
   Kindly do it in this manner:

1. Tables with heavily fragmented indexes needs to be rebuild
2. Tables with Less fragmented index should be Reorganized.

Just your option to choose either Index Rebuild or Index Reorganize

 

by: Joe_WoodhousePosted on 2009-07-22 at 06:09:06ID: 24914306

dearvjkumar:

Building on all the good comments you've received here so far, I strongly suggest you take a step back and think (and discuss with us) what it is you are trying to achieve before getting distracted by what is the correct shell or SQL syntax to implement a particular approach.

You said "But due to some requirement, i have to enable monthly index rebuild job in our sybase servers."

What is the actual requirement?

You said "I need to loop thru all the DB and all the tables inside each DB."

Is that a technical requirement? Are you forced to do it this way? I agree it is very simple to do it this way, but simple is not the same as "best", "suitable" or "appropriate". Do you actually care whether there are iterative loops that single-thread? Have you timed this? What is your maintenance window in which you propose doing this monthly? How much data is in these databases?

Writing a script to do what you want is very simple. A basic "loop through these databases, and loop through the tables (or other objects) in each of those databases, now perform a command per object" is probably the basis of 90% of all DBA scripts ever written.

... but that doesn't mean it's what you should be doing. I and most of the other high-scoring experts here are generally reluctant to tell you how to do something possibly unwise without knowing more about why you think that's what you need to do.

If you say "I have no control or ability to influence this; I have been told to produce a script to do it and that's all that I am interested in" then I suppose we can point you at such a script or show you the outline of one here. I don't think you've told us your Sybase version (or even which Sybase product it is) though. Can you give us at least that much please?

 

by: dearvjkumarPosted on 2009-07-22 at 20:08:00ID: 24921553

Hi Joe,
Thanks for your detailed advice. Yes, I know the difficulty of enabling reorg / rebuild in PROD system. But I am forced to do it / enable it in a automated way (weekly/monthly). Most of our systems are reporting systems not online systems.

I dont have other choice of enabling it in our environment, thats the reason I am looking for a script to loop thru all database and all tables. This is not only for enabling reorg/rebuild, for other purpose also. (eg. periodical table list / index list, rowcount etc)

Could you help me with the script?

 

by: dearvjkumarPosted on 2009-07-22 at 20:09:03ID: 24921556

My sybase ASE is 12.5.4 and 15.0.2 under windows and linux as well.

 

by: IncisiveOnePosted on 2009-07-24 at 02:29:41ID: 24933275

I am not sure if you are dealing with Joe exclusively, and ignoring the other posts due to blindness or lack of courtesy.  I have no comment on Joe's post. I have previously provided considerations you should make, I have stated that I have such  scripts, and I am still waiting for you to answer the question:

> What would you like for the DPL/DRL Placement index, would you like special handling: drop/create index; or  reorg rebuild index, same as the rest ?

So that I can include that in the script.

Now you are asking Joe personally if he can help you with the script.  Do you want a script for anyone, or just from Joe ?  Let us know, I am quite happy to step back and let Joe provide the scripts and get the points as well.

Cheers

 

by: Joe_WoodhousePosted on 2009-07-24 at 02:57:24ID: 24933391

IncisiveOne: Just for the record, what you see is what you get, the visible responses here are the only communications I'm involved in or aware of.

If you have a script ready to roll then by all means you should continue here. I've previously done these sorts of iterative loops outside ASE in shell scripts and the like. Your SQL-only solution is more portable and more appropriate when DBA housekeeping has to span multiple platforms.

Summary: Go for it. :)

Comment: Possibly your question is too obscure or arcane for the needs as stated...? (I don't know; I am speculating.) I think we have seen, though, that the needs here are not extremely sophisticated, so the simpler answer (no special handling, ie. reorg rebuild index for the lot) is probably sufficient. (Again, I speculate.)

dearvjkumar: If IncisiveOne puts a script to you, please ensure you select their answer and give them the points. If this were a 500 point question I would ask for 50, but 50/250 is too large a share for what I feel my contribution here has been.

 

by: IncisiveOnePosted on 2009-07-24 at 06:00:11ID: 24934391

I don't think so.  

For 250 points, you can provide the "very simple" script in SQL, shell, whatever, and you take the points.  I would have thought that, from the outset, it was clear that there is one server involved, so going out to the shell is a bit silly, unless you have no choice.  From 24910694 onwards, it should have been clear that execute immediate was a key issue.  Since OP is on 12.5.4, there is definitely no need to go out to the shell to do something completely within ASE.  I said I had no comment on your post.

I do not want any points for the clarifications and considerations I have provided, if they are beyond the ambit of the seeker.  I will refrain from speculating on your speculations.  However, there is no point in trying provide elegant, efficient scripts to seekers who will not consider the issues; or answer questions (three outstanding); or read my posts.  My script is very short, but it is not simple.  Since you find scripts of this kind "very simple", that's a second prevailing reason.

You guys cannot even keep up with my requirement to change the points to 500, which I specifically declared (I never suggested I would do it for 250).  From the looks of the above, without speculation, the lack of response from the seeker leads me to believe he is not interested in the 500 point script, from his only response being directed at you, it looks like he is proceeding with yours for 250.  Third reason that you  should "go for it".  If this is less than clear to you, read the thread again (sans the interpretations and speculations).

Cheers

 

by: dearvjkumarPosted on 2009-07-26 at 18:53:58ID: 24948438

Hi Incisive,
Cool...let us not drag this too much.

>> What would you like for the DPL/DRL Placement index, would you like special handling: drop/create index; or  reorg rebuild index, same as the rest ?

Just reorg rebuild index should be sufficient for me.

 

by: IncisiveOnePosted on 2009-07-27 at 03:12:08ID: 24950012

Great !  I had stripped my proc, and it was ready to go last week.  Actually it executes any command at the index level (yes, across all dbs).

1  Check my profile and drop me an email with full name and company name, address, etc, I will send the legal doc covering IP to you.  Of course it is free, but the acknowledgement of IP and non-disclosure has to be signed.  We cannot post IP on EE.

2  Request attention and ask the mods to change the points to 500.

Given our times zones, you can have it tomorrow.

Cheers

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...