FIXING Identity Gaps Using undocunted commands (reproduced)

zhaozj2021-02-16  122

Sybase aSE11.011.511.912.012.5Last Updated: 07 april 2002

FIXING Identity Gaps Using undocunted Commands

Note: the solutions for dealing with identity gaps as described in this article, apply to ASE pre-12.5.1 When using ASE 12.5.1, new features are available to fix identity gaps more easily Details are described here...

Contents

Introduction

DBCC Object_atts

Download 'SP_IDENTITY'

Displaying Identity Tables Through SP_IDENTITY

Displaying The Current Identity Value THROUGH SP_IDENTITY

Changing the Identity Value Through SP_IDENTITY

IntroductionThis document describes a way of using the undocumented command dbcc object_atts to quickly fix identity gaps. Because dbcc object_atts is rather difficult to use, a stored procedure sp_identity has been written which handles the difficult parts for you. This stored procedure can be downloaded from here .Warning: The methods described below are undocumented and not supported by Sybase Use entirely at your own risk Do not call Sybase Technical Support for assistence dbcc object_attsThe command dbcc object_atts provides "back-door" access to the OAM page on which the..! . identity counter is stored Unfortunately, the command is poorly documented and, due to some tricky issues, rather difficult to use The syntax is as follows:. dbcc object_atts (table_name, 0, subcommand, [new_value])

The value for the second argument (0) is mandatory The possible subcommands are get and put:. Get displays the identity value for the table as stored on its OAM page; put modifies this value to the new_value specified (note that there is also a reserve subcommand, but it is unclear exactly what this does). The main problem with dbcc object_atts is that it displays the identity value as a 16-byte hexadecimal string, which you must decode yourself. Unfortunately, how to do this depends on the length of the identity column's underlying numeric datatype. Similarly, setting the identity value using the put subcommand requires that you specify the new value as a 16-byte hex string again. Because of this, dbcc object_atts is next to unusable in practical situations.Fortunately, there is a solution: I wrote a stored procedure sp_identity which handles the decoding / encoding for you; it also gives a quick overview of all tables with an identity column in a database, and their maximum possible ga p sizes Download 'sp_identity'Download sp_identity from here To install, ASE 11.0 or later is required The downloaded file contains two versions:... one for ASE 11.9 / 11.5 / 11.0 (sp_identity.119.sql) and one for ASE 12.0 (sp_identity.120.sql). To install sp_identity in your ASE server, just run the sp_identity.xxx.sql script through isql (xxx = 119 or 120). Displaying identity tables through sp_identitysp_identity has a number of different functions. Without parameters, IT Simply Displays All Tables in The Current Database That Contain An Identity Column. It Also Displays The Maximum Possible Identity Gap Size for Each Table: 1> SP_IDENTITY2> GO

Tables with an identity column in database '':

Owner.Table.Column DataType Maximum Identity GAP -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------

DBO.INVOICES.INV_NR Numeric (18) 500000000000000 (BURN)

DBO.SMALL_GAP_TAB.A NUMERIC (30) 10 (Identity_GAP)

DBO.MY_TABLE.N NUMERIC (6) 500 (BURN)

(Burn) indicates that the identity gap size is determined by the setting of "identity burning set factor"; (identity_gap) means that the identity_gap attribute has been defined for this table.Displaying the current identity value through sp_identityTo determine the current identity value stored On The Oam Page for a Specific Table, You Must Follow A Three-Step Process:

First, Enable Trace Flag 3604 by Running DBCC TRACEON (3604) Run sp_identity specifying the table name: 1> sp_identity invoices

2> Go

Table = Invoice (ID = 1804533462)

Identity Column = a Numeric (18)

Max. Identity GAP = 500000000000000

("Identity Burning Set Factor = 5000 = 0.05%)

Reading Identity Value from Oam Page ...

Object_atts: get: return value = 1

0207E20C: 0001C6BF 52634001 00000000 00000000 .... rc @ .........

0207E21c:.

DBCC EXECUTION completed. If DBCC Printed Error Messages,

Contact A User with System Administrator (SA) Role.

The 16-byte hex stringprinted in bold is the identity value from the oam page. If you forgot To Switch ON Traqu 3604 (SO Go Back to Step 1).

Now Run sp_identity again, and specify the 16-byte hex string That Was Just Printed As The Second Parameter (You Can Leave the Spaces in): 1> sp_identity Invoices, "0001c6bf 52634001 00000000 000,000"

2> Go

Table = Invoice (ID = 1804533462)

Identity column = a numeric (18) max. Identity GAP = 500000000000000

("Identity Burning Set Factor = 5000 = 0.05%)

Decoded Identity Value ON ON ON ON ON ON ON ON ON ON ON ON ON ON ON ON ON ON ON OAM Page = 500000000000001

(HEX = 0001C6BF52634001)

So now we've retrieved and decoded this value from the OAM page, but what does it exactly mean? Well, what you're looking at is what the identity column would jump to in case the server would be shutdown "with nowait". It is not the next value to be assigned to the next row inserted in the table; instead, is the value the server has stored on disk on the OAM page, based on the settings of the configuration option identity burning set factor (or, in . ASE 12.0, the identity_gap option) for this table BTW, when you're running ASE 12.0, you can see (but not modify) this same value in numeric form through the command dbcc listoam; this also shows the in-memory version of .. this value (stored in the object's DES structure (for "descriptor")) Changing the identity value with sp_identityThe identity value on the OAM page can be set to an arbitrary value using sp_identity This requires the following steps:

Determine the value you want to reset the identity column to, let's say 10033. Shut down the server normally (ie do not use with nowait) Restart the server so that no users can access the database, for example, start the server in standalone mode . (-m in the RUN_SERVER file) or change the port number in the interfaces file temporarily Run the command sp_identity table_name, null, new_value; set new_value 1 lower than you want the next identity value to be assigned: 1> sp_identity invoices, null 10032

2> Go

Table = invoices (id = 1804533462) Identity Column = a Numeric (18)

Max. Identity GAP = 500000000000000

("Identity Burning Set Factor = 5000 = 0.05%)

Object_atts: Put: return value = 1

DBCC EXECUTION completed. If DBCC Printed Error Messages,

Contact A User with System Administrator (SA) Role.

Identity Value ON OAM Page Has Been Set To 10032

(HEX = 0x0000000000002730000000000000000000)

You Should Now Do A 'Shutdown with Nowait' Immedierately.

After Restarting the Server, The Value Assigned to the

Next row inserted INTO 'Invoices' Will BE 10033.

Immediately after this, do a shutdown with nowait This is essential;. If you do a normal shutdown, or if you wait too long, the OAM page value may be overwritten with the in-memory value kept in memory Note that this shutdown with. nowait is also the reason for doing a normal shutdown first in step 2 above -! otherwise you'd be creating new identity gaps here Therefore, do not insert rows into any other tables containing identity columns before doing this shutdown with nowait Restart the. server in the normal way Next, when inserting a row into my_table, the identity value assigned will be 10033. Even though these are quite a number of steps, they can be performed relatively fast; in any case, it's all much quicker than the standard remedy of doing a BCP-out of the table, recreating the table, BCP-in, and recreate the indexes.For more information on the background of identity gaps, and ways to prevent identity gaps from occurring, see www.sypron.nl/ Idgaps.html.

转载请注明原文地址:https://www.9cbs.com/read-8872.html

New Post(0)