Results 1 to 11 of 11
  1. #1
    Join Date
    Apr 2004
    Posts
    24

    Unanswered: dbcc dbrepair readpage/writepage

    Does anyone know the syntax for the dbcc dbrepair writepage command? Readpage gives me the raw data but I need to be able to modify it and slap it back in.

  2. #2
    Join Date
    Sep 2003
    Location
    Switzerland
    Posts
    443
    Quote Originally Posted by madamos
    Does anyone know the syntax for the dbcc dbrepair writepage command? Readpage gives me the raw data but I need to be able to modify it and slap it back in.
    Sorry, never hear about it before. Are you sure its not part of MS SQL Server and it is infact Sybase ASE?
    Last edited by trvishi; 09-10-09 at 17:23.

  3. #3
    Join Date
    Apr 2004
    Posts
    24
    Yep, the MSSQL one is dbcc writepage ...

    The command in Sybase is formatted:
    Code:
    dbcc dbrepair(<database name|dbid>, readpage, <page number>)
    This I've tested and it works. The write page looks like it should be similar but I don't have exact syntax.

  4. #4
    Join Date
    Mar 2009
    Location
    Sydney, Australia
    Posts
    258
    Just because MS has a writepage, does not mean that Sybase will have one, there is no such thing, no back door.

    To read a page, the simpler syntax is:
    Code:
    dbcc page ( {dbname | dbid}, <page_no>)
    1 If your page is not damaged (by disk failure):
    Sybase does not allow "pages" or "bytes" to be written to the database. The correct method, is to go through the front door, INSERT, UPDATE, or DELETE; which will ensure that what you "write" complies with all security, RI and constraints in the server/database. There is no use having those structures and rules in place, and then allowing people to come in through the back door and write a few bytes here and there; it would then no longer be ANSI SQL compliant, secure or correct (with reference to rules and constraints).

    2 If your page is damaged:
    exec ordinary dbcc checkalloc (or tablealloc or whatever) with the "fix" option.
    Last edited by Derek Asirvadem; 09-11-09 at 01:21.
    Regards
    Derek Asirvadem (Formerly DerekA)
    Information Architect / Senior Sybase DBA
    Copyright © 2009 Software Gems Pty Ltd

    I answer questions from the Original Poster only. If you have a genuine question, as the moderators have requested, start a new thread.

    http://www.softwaregems.com.au

  5. #5
    Join Date
    Feb 2009
    Location
    Prague
    Posts
    17
    Of course, there is back door in Sybase. Sybedit utility can do this job, but it seems that it"s no more part of ASE distribution. Sybedit looks, in fact, as a wrapper for dbcc commands, so I guess there might be dbcc for direct insert into pages.

  6. #6
    Join Date
    Apr 2004
    Posts
    24
    Whitesands activedba uses these commands as well. It seems needed since there are types of corruption that checkalloc can't fix. 2525 errors for example.

  7. #7
    Join Date
    Mar 2009
    Location
    Sydney, Australia
    Posts
    258
    1 Sybedit was an abortion, that was quickly removed from distribution, many years ago, before ASE 12.0. There was a back door only by accident (not by conscious choice or design) for a very short time, and that was quickly closed ... there is no back door now.
    2 Whitesands needs to learn SQL, and use the front door. Every other front end (reporting tools to DBA tools to developer tools) do not have this "problem", just Whitesands ... but they somehow try to make it someone else's problem !!! Instead of changing DBMSs to fit Whitesands "model", it would be more reasonable to change Whitesands to fit the ANSI SQL model. Check out the other great DBA tools that have no such um "problems".
    3 If dbcc cannot fix it with the "fix" option, there is no chance a developer can fix it by fiddling with the bytes. The internal structures for data and index pages are not published.
    4 Sure, you do get hard errors when a disk fails. If you do not have disk mirroring, then you need backups, that is what the backups are for.
    Regards
    Derek Asirvadem (Formerly DerekA)
    Information Architect / Senior Sybase DBA
    Copyright © 2009 Software Gems Pty Ltd

    I answer questions from the Original Poster only. If you have a genuine question, as the moderators have requested, start a new thread.

    http://www.softwaregems.com.au

  8. #8
    Join Date
    Feb 2009
    Location
    Prague
    Posts
    17
    I'm just trying to say that there are methods how to update pages directly (fixing pointers etc.) though they're not officially supported. Most of the dbcc commands are not supported too or at least are not mentioned in the manuals but they are sometimes very usefull - dbcc prtipage for example. Of course, I agree that tools for updating pages directly should be used only on own risk and as a last resort.

  9. #9
    Join Date
    Mar 2009
    Location
    Sydney, Australia
    Posts
    258
    I'm just trying to say that there are methods how to update pages directly ...
    Maybe in other products; but even there it would be a breach of security/constraints. This thread is about Sybase. There is no "writepage" or equivalent in Sybase.
    Regards
    Derek Asirvadem (Formerly DerekA)
    Information Architect / Senior Sybase DBA
    Copyright © 2009 Software Gems Pty Ltd

    I answer questions from the Original Poster only. If you have a genuine question, as the moderators have requested, start a new thread.

    http://www.softwaregems.com.au

  10. #10
    Join Date
    Sep 2009
    Posts
    2
    You may contact me. I developed a tool call powersybedit.
    sybase?????

  11. #11
    Join Date
    Apr 2004
    Posts
    24
    I wanted to put the final resolution in the thread for anyone else running across this problem. In response to Derek, there is dbcc dbrepair(dbid, writepage, pageno ... , however the syntax isn't perfectly clear and its a pain. You don't always have backups nor do you always control your client's systems and sometimes have to work in ways you may not prefer.

    luzi, thanks for the reply and I'll take a look.

    Here is what I finally did:


    In ISQL

    1>dbcc traceon(3604)
    2>go

    1>dbcc page(dbid, page, 2)
    2>go

    This will yield a copy of the database page with a hex dump of the page contents. Looking at the header and the first two lines of the hex dump will show you what to look for in the header if you need to open the database in a hex editor.
    PAGE HEADER:
    Page header for page 0x2F009000
    pageno=1791072 nextpg=1805145 prevpg=3862817 objid=1086626914 timestamp=0001 32c85f60
    nextrno=67 level=0 indid=0 freeoff=1628 minlen=4
    page status bits: 0x11 (0x0010 (PG_RNOFREE), 0x0001 (PG_DATA))

    WHOLE PAGE:
    2F009000 ( 0): 60541b00 598b1b00 21f13a00 629cc440 `T..Y...!.:.b..@
    2F009010 ( 16): 605fc832 43000000 01005c06 11000400 `_.2C.....\.....

    Using windows calc in scientific mode, pageno=1791072 translates to 1B5460. Commonly when looking at a hex dump the byte order is reversed. Broken into bytes, this number is 1B 54 60. Reversed it is 60 54 1B. Since it’s shown in groups of 4 bytes, this maps to the first word of data: 60541b00. It follows then that the rest of the header is shown pretty much in order. 598b1b00 is the hex nextpg value and 21f13a00 is prevpg. Objid is 629cc440.

    To directly edit the header I had to open the .dat file in a hex editor. I used HxD, a free download. Most should function in the same way. HxD has the advantage of opening very large files. Taking the first 4 words of data and putting them together with no spaces gets us: 60541b00598b1b0021f13a00629cc440. I stopped Sybase and opened the .dat file with HxD. Clicking on Search and then choosing hex values and search direction all, I search on the number we have. This is the row I found: 60 54 1B 00 59 8B 1B 00 21 F1 3A 00 62 9C C4 40. Hex editors will show an offset to the left that is the reference for row you’re on. Jot this down to make finding the start of the page easier.

    Now, for my problem I needed to skip a page. This meant I needed to edit the next page pointer on the last good page in the chain and the previous page pointer on the next good page. Repeat the above for the pages involved (previous, the one you're skipping and the next page). Once you know these values you can translate them to hex, reverse the bytes and write them into the .dat file. For other errors you may be able to simply edit the objid to repair it. This will not fix corruption in the data itself and sometimes will only show you more corruption past the page you fix.

    I would recommend you use dbcc pglinkage to follow the chain of pages in the table to at least ensure you are only trying to fix one bad page. Obviously this entire exercise assumes that you have no good backups as the best policy is simply to restore to a point before your error happens as Derek points out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •