This code genenates a script to rebuld all the indexes with height greater than 3 for all the users except for SYS user. The script needs to be executed from SYS schema. This can also be executed from individual schemas by minor changes. If you need to exclude indxes of some other users that can also be added/changed in cGetIdx cursor. To execute this code from any schema other than SYS. Execute on DBMS_SQL must be granted from SYS(not system) to the the specified user.
Indexes with height less than three (3) should not be rebuilded. If you want to go for indexes with less heights that can also be customized by changing the height parameter.
Set serveroutput on size 100000 -
DECLARE
-
vOwner dba_indexes.owner%TYPE; /* Index Owner */
-
vIdxName dba_indexes.index_name%TYPE; /* Index Name */
-
vAnalyze VARCHAR2(100); /* String of Analyze Stmt */
-
vCursor NUMBER; /* DBMS_SQL cursor */
-
vNumRows INTEGER; /* DBMS_SQL return rows */
-
vHeight index_stats.height%TYPE; /* Height of index tree */
-
vLfRows index_stats.lf_rows%TYPE; /* Index Leaf Rows */
-
vDLfRows index_stats.del_lf_rows%TYPE; /* Deleted Leaf Rows */
-
vDLfPerc NUMBER; /* Del lf Percentage */
-
vMaxHeight NUMBER; /* Max tree height */
-
vMaxDel NUMBER; /* Max del lf percentage */
-
CURSOR cGetIdx IS SELECT owner,index_name
-
FROM dba_indexes WHERE OWNER NOT LIKE 'SYS%';
-
BEGIN
-
/* Define maximums. This section can be customized. */
-
vMaxHeight := 3;
-
vMaxDel := 20;
-
-
/* For every index, validate structure */
-
OPEN cGetIdx;
-
LOOP
-
FETCH cGetIdx INTO vOwner,vIdxName;
-
EXIT WHEN cGetIdx%NOTFOUND;
-
/* Open DBMS_SQL cursor */
-
vCursor := DBMS_SQL.OPEN_CURSOR;
-
/* Set up dynamic string to validate structure */
-
vAnalyze := 'ANALYZE INDEX ' || vOwner || '.' || vIdxName || ' VALIDATE STRUCTURE';
-
DBMS_SQL.PARSE(vCursor,vAnalyze,DBMS_SQL.V7);
-
vNumRows := DBMS_SQL.EXECUTE(vCursor);
-
/* Close DBMS_SQL cursor */
-
DBMS_SQL.CLOSE_CURSOR(vCursor);
-
/* Does index need rebuilding? */
-
/* If so, then generate command */
-
SELECT height,lf_rows,del_lf_rows INTO vHeight,vLfRows,vDLfRows
-
FROM INDEX_STATS;
-
IF vDLfRows = 0 THEN /* handle case where div by zero */
-
vDLfPerc := 0;
-
ELSE
-
vDLfPerc := (vDLfRows / vLfRows) * 100;
-
END IF;
-
IF (vHeight > vMaxHeight) OR (vDLfPerc > vMaxDel) THEN
-
DBMS_OUTPUT.PUT_LINE('ALTER INDEX ' || vOwner || '.' || vIdxName || ' REBUILD;');
-
END IF;
-
-
END LOOP;
-
CLOSE cGetIdx;
-
END;
0 17462 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Don |
last post by:
I want the server-side php script to return a browser page that is essentially a copy of the
original client page that contained the <form> which referenced the php script in the first place.
However, the php script will need to change a couple html lines in that returned page. I sure could
you some help on how to go about this.
Thanks in advance,
Don
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
|
by: xo55ox |
last post by:
Hi,
I want to find out what is a good way to identify indexes that need
rebuilding. I tried to run DBCC showcontig and identify them based on
the scan density %. And according to a Microsoft Tech Net - All About
SQL Server Indexes discussion, the expert stated that based on the
Density (below 20%), I can pick out those indexes associated to the
table and run DBCC INDEXDEFRAG. But instead, I ran DBCC DBREINDEX to
rebuild all indexes...
|
by: Matt |
last post by:
Hello
I am trying to rebuild indexes on our DB, but I am running into an
error I am not able to solve.
Server: Msg 1105, Level 17, State 2, Line 1
Could not allocate space for object 'ft' in database 'HastaDemo'
because the 'PRIMARY' filegroup is full.
The statement has been terminated.
|
by: trint |
last post by:
Ok,
This script is something I wrote for bringing up a report in reporting
services and it is really slow...Is their any problems with it or is
their better syntax to speed it up and still provide the same report
results?:
SELECT t1.MemberId, t1.PeriodID, t8.start_date, t6.amount_type_id,
t6.amount_type,
SUM(CASE WHEN t2.amountTypeId = 7 THEN t2.amount
WHEN t2.amountTypeId = 23 THEN - t2.amount END) AS Purchase,
|
by: wackyphill |
last post by:
After rebuilding an index, it still shows as the same amount of
fragmentation. ANy ideas what's wrong?
I'm determining which indexes to rebuild using the following query:
SELECT
OBJECT_NAME(i.object_id) AS TableName,
i.name AS IndexName,
ips.avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL,
| |
by: Dhungu Dhumbak |
last post by:
Dear All,
SOS Please Help.
I have a MS-SQL DB with 4 .ndf files. One (first) .ndf file is missing.
somehow got deleted??. Is there any way can rebuild my DB.
The .MDF and .LDF files are in tact.
Please help asap.
Dhumbak
|
by: digitalox |
last post by:
All efforts to rebuild indexes fails. Not with an error, but they still show high fragmentation.
The environment:
SQL Server 2005 in 2000 compatibility mode
non-clustered indexes on tables that have clustered indexes with unique constraint
Tried so far:
Rebuild, reorganize, manual drop and recreate, setting the db in 2005 mode
This only seems to happen on the tables that also have the clustered index with a unique contraint ( which...
|
by: dsdevonsomer |
last post by:
Hello all,
I am new to managing indexes on large tables and need some help.
Hopefully, I am not repeating question here. I searched as much as I
can, but not finding relatively best answer..
Here is my scenario.
I have 2 tables with more than 4 mil rows (1 - 2.8 Mil, 2 2.1 mil). Of
these tables, there are about 25 ( select ) queries run to help
generate reports every week.
|
by: Okonita via DBMonster.com |
last post by:
Hi all,
I am comming along with all this Linus/DB2/scripting business...I am no
longer scared of it!! (LOL). But,
I need to create a .ksh script that does a REORGCHK and output only tables
recommended for reorg.
My goal is to reorgchk and run reorgs based on entries in this reorg file as
shown in the example below.
I have tried my hand at the following failing script and hope that gurus here
can throw me a lifeline of examples on how to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |