Any SQL Server geeks on here?

insyder

Like a Boss.
Staff member
So I'm helping out this place that suffered a web server meltdown a while back and are trying to recover.

They've restored their IIS and each of the groups of files under wwwroot. But any of their sites that were using a database backend are having trouble with the SQL Server running on the localhost.

I've turned on error logging on the web.config of the following site and get the error shown (SQL Server detected a logical consistency-based I/O error: torn page...)

http://www.crhkids.org/default.aspx

I'm a total noob with configuring or even messing with SQL server stuff so if anyone can point me in the right direction to (quickly) fixing this I'd highly appreciate it.
 

Sane_Man

Totally Tubular
I mostly work with Oracle now, but have you checked to see if it's a Rights issue in accessing the database?
 

PrplHaz4

East Coast Poser
what happened when you ran DBCC CHECKDB? To check permissions, you can explicitly give the "Everyone" group read permissions on all DBs. Also, check that the user 'WEBHOST1\ASPNET' is set up to use the correct default database.

Have you tried to perform a backup and restore? And, make extra sure that the disk is not full, SQL Server has all sorts of issues when the disk fills up...I'd be a little leery about having the data file stored in a web virtual directory as well....
 

insyder

Like a Boss.
Staff member
what happened when you ran DBCC CHECKDB? To check permissions, you can explicitly give the "Everyone" group read permissions on all DBs. Also, check that the user 'WEBHOST1\ASPNET' is set up to use the correct default database.

Have you tried to perform a backup and restore? And, make extra sure that the disk is not full, SQL Server has all sorts of issues when the disk fills up...I'd be a little leery about having the data file stored in a web virtual directory as well....
I'm a complete SQLServer noob. Is there an specific application I need to use to do admin work on the database? On Unix/Oracle, I'd simply use the CLI to jump on the db using SQLplus. Does Microshaft provide a similar method? Or is it a GUI tool?

I'd be happy if anyone knows of a quick start guide for new SQL server DBAs.
 

}Dragon{

(╯°□°)╯︵ ┻━┻ ︵ ╯(°□° ╯)
DBCC CHECKDB
Checks the allocation and structural integrity of all the objects in the specified database.

Syntax
DBCC CHECKDB
( 'database_name'
[ , NOINDEX
| { REPAIR_ALLOW_DATA_LOSS
| REPAIR_FAST
| REPAIR_REBUILD
} ]
) [ WITH { [ ALL_ERRORMSGS ]
[ , [ NO_INFOMSGS ] ]
[ , [ TABLOCK ] ]
[ , [ ESTIMATEONLY ] ]
[ , [ PHYSICAL_ONLY ] ]
}
]

Arguments
'database_name'

Is the database for which to check all object allocation and structural integrity. If not specified, the default is the current database. Database names must conform to the rules for identifiers. For more information, see Using Identifiers.

NOINDEX

Specifies that nonclustered indexes for nonsystem tables should not be checked. NOINDEX decreases the overall execution time because it does not check nonclustered indexes for user-defined tables. NOINDEX has no effect on system tables, because DBCC CHECKDB always checks all system table indexes.

REPAIR_ALLOW_DATA_LOSS | REPAIR_FAST| REPAIR_REBUILD

Specifies that DBCC CHECKDB repair the found errors. The given database_name must be in single-user mode to use a repair option and can be one of the following.

Value Description
REPAIR_ALLOW_DATA_LOSS Performs all repairs done by REPAIR_REBUILD and includes allocation and deallocation of rows and pages for correcting allocation errors, structural row or page errors, and deletion of corrupted text objects. These repairs can result in some data loss. The repair may be done under a user transaction to allow the user to roll back the changes made. If repairs are rolled back, the database will still contain errors and should be restored from a backup. If a repair for an error has been skipped due to the provided repair level, any repairs that depend on the repair are also skipped. After repairs are completed, back up the database.
REPAIR_FAST Performs minor, nontime-consuming repair actions such as repairing extra keys in nonclustered indexes. These repairs can be done quickly and without risk of data loss.
REPAIR_REBUILD Performs all repairs done by REPAIR_FAST and includes time-consuming repairs such as rebuilding indexes. These repairs can be done without risk of data loss.


WITH

Specifies options on the number of error messages returned, locks obtained, or estimating tempdb requirements.

ALL_ERRORMSGS

Displays an unlimited number of errors per object. If ALL_ERRORMSGS is not specified, displays up to 200 error messages for each object. Error messages are sorted by object ID, except for those messages generated from tempdb.

NO_INFOMSGS

Suppresses all informational messages (Severity 10) and the report of space used.

TABLOCK

Causes DBCC CHECKDB to obtain shared table locks. TABLOCK will cause DBCC CHECKDB to run faster on a database under heavy load, but decreases the concurrency available on the database while DBCC CHECKDB is running.

ESTIMATE ONLY

Displays the estimated amount of tempdb space needed to run DBCC CHECKDB with all of the other specified options. The check is not performed.

PHYSICAL_ONLY

Limits the checking to the integrity of the physical structure of the page and record headers, and to the consistency between the pages' object ID and index ID and the allocation structures. Designed to provide a low overhead check of the physical consistency of the database, this check also detects torn pages and common hardware failures that can compromise a user's data. PHYSICAL_ONLY always implies NO_INFOMSGS and is not allowed with any of the repair options.

Remarks
DBCC CHECKDB performs a physical consistency check on indexed views. The NOINDEX option, used only for backward compatibility, also applies to any secondary indexes on indexed views.

DBCC CHECKDB is the safest repair statement because it identifies and repairs the widest possible errors. If only allocation errors are reported for a database, execute DBCC CHECKALLOC with a repair option to repair these errors. However, to ensure that all errors, including allocation errors, are properly repaired, execute DBCC CHECKDB with a repair option rather than DBCC CHECKALLOC with a repair option.

DBCC CHECKDB validates the integrity of everything in a database. There is no need to run DBCC CHECKALLOC or DBCC CHECKTABLE if DBCC CHECKDB either is currently or has been recently executed.

DBCC CHECKDB performs the same checking as if both a DBCC CHECKALLOC statement and a DBCC CHECKTABLE statement were executed for each table in the database.

DBCC CHECKDB does not acquire table locks by default. Instead, it acquires schema locks that prevent meta data changes but allow changes to the data. The schema locks acquired will prevent the user from getting an exclusive table lock required to build a clustered index, drop any index, or truncate the table.

The DBCC statement collects information, and then scans the log for any additional changes made, merging the two sets of information together to produce a consistent view of the data at the end of the scan.

When the TABLOCK option is specified, DBCC CHECKDB acquires shared table locks. This allows more detailed error messages for some classes of errors and minimizes the amount of tempdb space required by avoiding the use of transaction log data. The TABLOCK option will not block the truncation of the log and will allow the command to run faster.

DBCC CHECKDB checks the linkages and sizes of text, ntext, and image pages for each table, and the allocation of all the pages in the database.

For each table in the database, DBCC CHECKDB checks that:

Index and data pages are correctly linked.


Indexes are in their proper sort order.


Pointers are consistent.


The data on each page is reasonable.


Page offsets are reasonable.
Errors indicate potential problems in the database and should be corrected immediately.

By default, DBCC CHECKDB performs parallel checking of objects. The degree of parallelism is determined automatically by the query processor. The maximum degree of parallelism is configured in the same manner as that of parallel queries. Use the sp_configure system stored procedure to restrict the maximum number of processors available for DBCC checking. For more information, see max degree of parallelism Option.

Parallel checking can be disabled by using trace flag 2528. For more information, see Trace Flags.

Result Sets
Whether or not any options (except for the NO_INFOMSGS or NOINDEX options) are specified, DBCC CHECKDB returns this result set for the current database, if no database is specified (values may vary):

DBCC results for 'master'.
DBCC results for 'sysobjects'.
There are 862 rows in 13 pages for object 'sysobjects'.
DBCC results for 'sysindexes'.
There are 80 rows in 3 pages for object 'sysindexes'.
'...'
DBCC results for 'spt_provider_types'.
There are 23 rows in 1 pages for object 'spt_provider_types'.
CHECKDB found 0 allocation errors and 0 consistency errors in database 'master'.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
IF the NO_INFOMSGS option is specified, DBCC CHECKDB returns this result set (message):

The command(s) completed successfully.
DBCC CHECKDB returns this result set when the ESTIMATEONLY option is specified.

Estimated TEMPDB space needed for CHECKALLOC (KB)
-------------------------------------------------
13

(1 row(s) affected)

Estimated TEMPDB space needed for CHECKTABLES (KB)
--------------------------------------------------
57

(1 row(s) affected)

DBCC execution completed. If DBCC printed error messages, contact your system administrator.
Permissions
DBCC CHECKDB permissions default to members of the sysadmin fixed server role or the db_owner fixed database role, and are not transferable.

Examples
A. Check both the current and the pubs database
This example executes DBCC CHECKDB for the current database and for the pubs database.

-- Check the current database.
DBCC CHECKDB
GO
-- Check the pubs database without nonclustered indexes.
DBCC CHECKDB ('pubs', NOINDEX)
GO
B. Check the current database, suppressing informational messages
This example checks the current database and suppresses all informational messages.

DBCC CHECKDB WITH NO_INFOMSGS
GO
 

PrplHaz4

East Coast Poser
The tool you're going to want is SQL Server Management Studio...there's an express version that's downloadable for free. You can run queries from here, specificially, the DBCC CHECKDB query listed above.
https://www.microsoft.com/downloads/details.aspx?familyid=C243A5AE-4BD1-4E3D-94B8-5A0F62BF7796

If you're really interested in SQL Server db administration, the books online series (MS doco) is actually pretty good...
http://msdn.microsoft.com/en-us/library/ms130214(SQL.90).aspx

Both links are for SQL Server 2005, which is what a lot of people are running these days...
 

insyder

Like a Boss.
Staff member
DBCC CHECKDB...
Thanks Dragon. Using DBCC.

The tool you're going to want is SQL Server Management Studio...there's an express version that's downloadable for free...
Using that, thanks! ;)


What I've found is that the .mdf file for the target database is corrupt with a "torn page" I/O error. Appears to have been caused by a ungraceful shutdown/detach from SQL Server. I'm looking at fixes and workarounds.

If they had a proper backup to restore from, we'd be money right now but...:(

This is the output from a DBCC CHECKDB:
Msg 922, Level 14, State 1, Line 1
Database 'Content' is being recovered. Waiting until recovery is finished.
Msg 824, Level 24, State 2, Line 1
SQL Server detected a logical consistency-based I/O error: torn page (expected signature: 0xffffffff; actual signature: 0xffff).
It occurred during a read of page (1:9) in database ID 6 at offset 0x00000000012000 in file 'D:\wwwroot\DATA\Content.mdf'.
Additional messages in the SQL Server error log or system event log may provide more detail.
This is a severe error condition that threatens database integrity and must be corrected immediately.
Complete a full database consistency check (DBCC CHECKDB). This error can be caused by many factors; for more information, see SQL Server Books Online.
 

insyder

Like a Boss.
Staff member
Who doesn't take backups of their production database? What a bunch of monkeys.
Heh. Spend money on having a DBA or someone with DBA duties or spend money hoping a DBA can recover from your disaster.
Whichever one makes you sleep well at night I guess.
 

DESMOnic

Well-known member
Who doesn't take backups of their production database? What a bunch of monkeys.

non-for-profit org.... My guess would be that someone either volunteered to "maintain" the site and did not care much about backups, or they had someone develop the site and than they deciced to "maintain" the site themself.

I come across this situation all the time, smaller businesses do not have or want to spend money on IT.
 

insyder

Like a Boss.
Staff member
...they had someone develop the site and than they deciced to "maintain" the site themself...
That's the case here. They thought it would be adequate to have simple copies of all of the files on a particular drive. Well, the .mdf files were "live" on the DB and weren't backed up "cold" or backed up using SQL Server's utilities. Result, "torn page" error on database file.

Small database(s) from what I see so far. Probably end up being a slightly laborious pain in the ass to get things working again, but still. Backups...srsly.
 

DESMOnic

Well-known member
I do not know how is it done on Windows based servers, but on Unix I always setup cronjob to make at least weekly backups and store one copy on the server and send another to client's email.

Also, some ISPs (Verio) will make daily backups of files, but DBs are not backed up, so I make sure my client's are aware of that. In your case, the damage is already done and I hope they pay you good for getting all that data restored manually.
 

insyder

Like a Boss.
Staff member
I do not know how is it done on Windows based servers, but on Unix I always setup cronjob to make at least weekly backups and store one copy on the server and send another to client's email....
Yep. On my production box at my day job, I use cron call RMAN(Oracle) to do a full hot backup to disk. We have a 5 day retention policy and sweep the entire 5 "backups" mount point to tape which has a 2week retention policy. Furthermore, another cronjob is set to run a script to send archive log files to tape 3 times a day in case we need to roll forward from a hot backup. And "just in case", we have "dataguard" implemented which is basically a mirror of our production box.
 
Last edited:

DESMOnic

Well-known member
Whenever I develop a DB-driven site, I create a CMS for content management as well as DB management. If the client does not want CMS tool as part of the package, I make sure I include in contract that client assumes all responsibility for DB management.

I have dealt with Non-for profits on couple occasions and I know how they are when it comes to budgets for IT.
 
Top