Background
SQL Server Enterprise 2012
Disk IO errors have occurred, causing two table errors:
DBCC CHECKDB(dbname)
GO
--Output:
--Msg 8939, Level 16, State 98, Line 1
--Table error: Object ID 0, index ID -1, partition ID 0, alloc unit ID 0 (type Unknown), page (3:7432269). Test (IS_OFF (BUF_IOERR, pBUF->bstat)) failed. Values are 133129 and -6.
--Msg 8939, Level 16, State 98, Line 1
--Table error: Object ID 0, index ID -1, partition ID 0, alloc unit ID 0 (type Unknown), page (3:7434265). Test (IS_OFF (BUF_IOERR, pBUF->bstat)) failed. Values are 133129 and -6.
The faulty disk has been replaced, with all files successfully copied to the replacement disk.
Problem
Having replaced the disk, subsequently carrying out a page-level restore from a full backup fortunately taken one day before the errors occurred results in 0 pages processed:
USE MASTER
RESTORE DATABASE dbname PAGE = '3:7434265, 3:7432269' FROM DISK = 'P:\MSSQL_BACKUPS\dbname\dbname\dbname_backup_2016_02_27_050001_8076562.full.bak' WITH NORECOVERY
GO
--Output:
--Processed 0 pages for database 'dbname', file 'dbname_pt0b' on file 1.
--RESTORE DATABASE ... FILE=<name> successfully processed 0 pages in 398.710 seconds (0.000 MB/sec).
Running CHECKDB again confirms the errors are still present. As far as I'm aware this is the correct method to recover from database corruption where only a small number of pages are affected. I know this won't get me to a stage where the database is fully restored - I need to restore the subsequent logs for that - but it should at least be in a state where the table errors have been fixed. What am I missing?
Thanks
Related
I am using a fairly simple PowerShell script to automate the process of restoring databases:
#Script to restore database.
$serverInstance = $args[0]
$dbName = $args[1]
$file = $args[2]
$dataDestination = $args[3]
$logDestination = $args[4]
Import-Module sqlps
$relocateData = New-Object Microsoft.SqlServer.Management.Smo.RelocateFile(###LOGICALFILENAME###, $dataDestination)
$relocateLog = New-Object Microsoft.SqlServer.Management.Smo.RelocateFile(###LOGICALFILENAME###, $logDestination)
Restore-SqlDatabase -ServerInstance $serverInstance -Database $dbName -BackupFile $file -RelocateFile #($relocateData,$relocateLog)
I am looking for a way to dynamically fetch the logical file names of the files contained in a database backup ($file) and store them into a variable so the can be renamed accordingly.
Anyone have any ideas? I've been banging my head against this for way too long! :)
Thanks for your help!
As always with Powershell and SQL Server Invoke-Sqlcmd is your friend. It returns a DataTable that's simple to navigate. EG
$dt = Invoke-Sqlcmd "restore filelistonly from disk='c:\temp\aw.bak'"
$dataFileLogicalName = ""
$logFileLogicalName = ""
foreach ($r in $dt)
{
if ($r.Type -eq "L")
{
$logFileLogicalName = $r.LogicalName
}
if ($r.Type -eq "D")
{
$dataFileLogicalName = $r.LogicalName
}
write-host "$($r.Type) $($r.LogicalName) $($r.PhysicalName)"
}
write-host "data=$dataFileLogicalName log=$logFileLogicalName"
Ok, I was getting a similar error. But in my case I was not using PowerShell, but running it in SSMS.
So the steps to the issue and also how to fix are as follows.
First I downloaded the WideWorldImporters-Standard.bak file from releases here.
Now I run the following command in SSMS in an attemp to restore it.
RESTORE DATABASE WideWorldImporters FROM DISK = N'C:\Users\msi\Downloads\WideWorldImporters-Standard.bak'
This gives the following errors.
Msg 5133, Level 16, State 1, Line 2
Directory lookup for the file "D:\Data\WideWorldImporters.mdf" failed with the operating system error 3(The system cannot find the path specified.).
Msg 3156, Level 16, State 3, Line 2
File 'WWI_Primary' cannot be restored to 'D:\Data\WideWorldImporters.mdf'. Use WITH MOVE to identify a valid location for the file.
Msg 5133, Level 16, State 1, Line 2
Directory lookup for the file "D:\Data\WideWorldImporters_UserData.ndf" failed with the operating system error 3(The system cannot find the path specified.).
Msg 3156, Level 16, State 3, Line 2
File 'WWI_UserData' cannot be restored to 'D:\Data\WideWorldImporters_UserData.ndf'. Use WITH MOVE to identify a valid location for the file.
Msg 5133, Level 16, State 1, Line 2
Directory lookup for the file "E:\Log\WideWorldImporters.ldf" failed with the operating system error 3(The system cannot find the path specified.).
Msg 3156, Level 16, State 3, Line 2
File 'WWI_Log' cannot be restored to 'E:\Log\WideWorldImporters.ldf'. Use WITH MOVE to identify a valid location for the file.
Msg 3119, Level 16, State 1, Line 2
Problems were identified while planning for the RESTORE statement. Previous messages provide details.
Msg 3013, Level 16, State 1, Line 2
RESTORE DATABASE is terminating abnormally.
So now I change the command to include the mdf and ldf file paths as follows.
RESTORE DATABASE WideWorldImporters FROM DISK = N'C:\Users\msi\Downloads\WideWorldImporters-Standard.bak' WITH
MOVE 'WideWorldImporters' TO 'C:\Users\msi\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB\WideWorldImporters.mdf'
,
MOVE 'WideWorldImporters_Log' TO 'C:\Users\msi\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB\WideWorldImporters_Log.ldf'
Now this gives me the error in question as follows.
Msg 3234, Level 16, State 2, Line 5
Logical file 'WideWorldImporters' is not part of database 'WideWorldImporters'. Use RESTORE FILELISTONLY to list the logical file names.
Msg 3013, Level 16, State 1, Line 5
RESTORE DATABASE is terminating abnormally.
Now I run the RESTORE FILELISTONLY command as suggested to get the list as follows.
This shows me the files along with path as follows.
LogicalName PhysicalName Type FileGroupName Size MaxSize FileId CreateLSN DropLSN UniqueId ReadOnlyLSN ReadWriteLSN BackupSizeInBytes SourceBlockSize FileGroupId LogGroupGUID DifferentialBaseLSN DifferentialBaseGUID IsReadOnly IsPresent TDEThumbprint SnapshotUrl
-------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---- -------------------------------------------------------------------------------------------------------------------------------- -------------------- -------------------- -------------------- --------------------------------------- --------------------------------------- ------------------------------------ --------------------------------------- --------------------------------------- -------------------- --------------- ----------- ------------------------------------ --------------------------------------- ------------------------------------ ---------- --------- ------------------------------------------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
WWI_Primary D:\Data\WideWorldImporters.mdf D PRIMARY 1073741824 35184372080640 1 0 0 8D30F4F9-A463-404F-805A-9BD1C634B66B 0 0 11730944 512 1 NULL 623000001720300037 C6D12B8E-E389-4961-ADD4-FE6E468F4E44 0 1 NULL NULL
WWI_UserData D:\Data\WideWorldImporters_UserData.ndf D USERDATA 2147483648 35184372080640 3 37000000095200001 0 28D406E0-78FF-4400-9A4B-3A05D136B1F3 0 0 580124672 512 2 NULL 623000001720300037 C6D12B8E-E389-4961-ADD4-FE6E468F4E44 0 1 NULL NULL
WWI_Log E:\Log\WideWorldImporters.ldf L NULL 104857600 2199023255552 2 0 0 6AC6807E-8774-415B-8EFC-E8C569B0855E 0 0 0 512 0 NULL 0 00000000-0000-0000-0000-000000000000 0 1 NULL NULL
(3 rows affected)
Completion time: 2022-08-28T15:36:18.5341906+05:30
Now after taking note of the output, I modify the RESTORE Command to include all of the required files and paths as follows. This finally works.
RESTORE DATABASE WideWorldImporters FROM DISK = N'C:\Users\msi\Downloads\WideWorldImporters-Standard.bak' WITH
MOVE 'WWI_Primary' TO 'C:\Users\msi\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB\WideWorldImporters.mdf'
, MOVE 'WWI_Log' TO 'C:\Users\msi\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB\WideWorldImporters_Log.ldf'
, MOVE 'WWI_UserData' TO 'C:\Users\msi\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB\WideWorldImporters_UserData.ndf'
I have a database that is about 20 GB in size. I generated script for DB and content and now trying to import to different server. I googled and found such thing:
sqlcmd -S localhost -i C:\Users\Administrator\Downloads\SQL_backup.sql
While executing sqlcmd like this, the process starts but after some time I get an error :
Msg 105, Level 15, State 1, Server WIN-I79PRE6OQTV, Line 793
Unclosed quotation mark after the character string '
172551665 ......
So my question is - if I have generated script using Microsoft SQL Server Management Studio - why do I get such an error while importing the data?
How can I resolve this issue?
P.S the column that this error complains contains XML data stored as string and is very long string.
Is there any other backup/ restore way?
UPDATED
I ran - > dbcc checkdb('CreditInfoDB',REPAIR_ALLOW_DATA_LOSS)
and this is the result
DBCC results for 'CreditInfoDB'.
Service Broker Msg 9675, State 1: Message Types analyzed: 14.
Service Broker Msg 9676, State 1: Service Contracts analyzed: 6.
Service Broker Msg 9667, State 1: Services analyzed: 3.
Service Broker Msg 9668, State 1: Service Queues analyzed: 3.
Service Broker Msg 9669, State 1: Conversation Endpoints analyzed: 0.
Service Broker Msg 9674, State 1: Conversation Groups analyzed: 0.
Service Broker Msg 9670, State 1: Remote Service Bindings analyzed: 0.
Service Broker Msg 9605, State 1: Conversation Priorities analyzed: 0.
DBCC results for 'sys.sysrscols'.
There are 1092 rows in 14 pages for object "sys.sysrscols".
DBCC results for 'sys.sysrowsets'.
There are 147 rows in 3 pages for object "sys.sysrowsets".
DBCC results for 'sys.sysclones'.
There are 0 rows in 0 pages for object "sys.sysclones".
DBCC results for 'sys.sysallocunits'.
There are 172 rows in 2 pages for object "sys.sysallocunits".
DBCC results for 'sys.sysfiles1'.
There are 2 rows in 1 pages for object "sys.sysfiles1".
DBCC results for 'sys.sysseobjvalues'.
There are 0 rows in 0 pages for object "sys.sysseobjvalues".
DBCC results for 'sys.syspriorities'.
There are 0 rows in 0 pages for object "sys.syspriorities".
DBCC results for 'sys.sysdbfrag'.
There are 0 rows in 0 pages for object "sys.sysdbfrag".
DBCC results for 'sys.sysfgfrag'.
There are 0 rows in 0 pages for object "sys.sysfgfrag".
DBCC results for 'sys.sysdbfiles'.
There are 2 rows in 1 pages for object "sys.sysdbfiles".
DBCC results for 'sys.syspru'.
There are 0 rows in 0 pages for object "sys.syspru".
DBCC results for 'sys.sysbrickfiles'.
There are 0 rows in 0 pages for object "sys.sysbrickfiles".
DBCC results for 'sys.sysphfg'.
There are 1 rows in 1 pages for object "sys.sysphfg".
DBCC results for 'sys.sysprufiles'.
There are 2 rows in 1 pages for object "sys.sysprufiles".
DBCC results for 'sys.sysftinds'.
There are 0 rows in 0 pages for object "sys.sysftinds".
DBCC results for 'sys.sysowners'.
There are 14 rows in 1 pages for object "sys.sysowners".
DBCC results for 'sys.sysdbreg'.
There are 0 rows in 0 pages for object "sys.sysdbreg".
DBCC results for 'sys.sysprivs'.
There are 141 rows in 1 pages for object "sys.sysprivs".
DBCC results for 'sys.sysschobjs'.
There are 2271 rows in 52 pages for object "sys.sysschobjs".
DBCC results for 'sys.syscsrowgroups'.
There are 0 rows in 0 pages for object "sys.syscsrowgroups".
DBCC results for 'sys.sysexttables'.
There are 0 rows in 0 pages for object "sys.sysexttables".
DBCC results for 'sys.syscolpars'.
There are 890 rows in 14 pages for object "sys.syscolpars".
DBCC results for 'sys.sysxlgns'.
There are 0 rows in 0 pages for object "sys.sysxlgns".
DBCC results for 'sys.sysxsrvs'.
There are 0 rows in 0 pages for object "sys.sysxsrvs".
DBCC results for 'sys.sysnsobjs'.
There are 1 rows in 1 pages for object "sys.sysnsobjs".
DBCC results for 'sys.sysusermsgs'.
There are 0 rows in 0 pages for object "sys.sysusermsgs".
DBCC results for 'sys.syscerts'.
There are 0 rows in 0 pages for object "sys.syscerts".
DBCC results for 'sys.sysrmtlgns'.
There are 0 rows in 0 pages for object "sys.sysrmtlgns".
DBCC results for 'sys.syslnklgns'.
There are 0 rows in 0 pages for object "sys.syslnklgns".
DBCC results for 'sys.sysxprops'.
There are 0 rows in 0 pages for object "sys.sysxprops".
DBCC results for 'sys.sysscalartypes'.
There are 34 rows in 1 pages for object "sys.sysscalartypes".
DBCC results for 'sys.systypedsubobjs'.
There are 0 rows in 0 pages for object "sys.systypedsubobjs".
DBCC results for 'sys.sysidxstats'.
There are 227 rows in 4 pages for object "sys.sysidxstats".
DBCC results for 'sys.sysiscols'.
There are 419 rows in 2 pages for object "sys.sysiscols".
DBCC results for 'sys.sysendpts'.
There are 0 rows in 0 pages for object "sys.sysendpts".
DBCC results for 'sys.syswebmethods'.
There are 0 rows in 0 pages for object "sys.syswebmethods".
DBCC results for 'sys.sysbinobjs'.
There are 23 rows in 1 pages for object "sys.sysbinobjs".
DBCC results for 'sys.sysaudacts'.
There are 0 rows in 0 pages for object "sys.sysaudacts".
DBCC results for 'sys.sysobjvalues'.
There are 234 rows in 22 pages for object "sys.sysobjvalues".
DBCC results for 'sys.syscscolsegments'.
There are 0 rows in 0 pages for object "sys.syscscolsegments".
DBCC results for 'sys.syscsdictionaries'.
There are 0 rows in 0 pages for object "sys.syscsdictionaries".
DBCC results for 'sys.sysclsobjs'.
There are 16 rows in 1 pages for object "sys.sysclsobjs".
DBCC results for 'sys.sysrowsetrefs'.
There are 0 rows in 0 pages for object "sys.sysrowsetrefs".
DBCC results for 'sys.sysremsvcbinds'.
There are 0 rows in 0 pages for object "sys.sysremsvcbinds".
DBCC results for 'sys.sysxmitqueue'.
There are 0 rows in 0 pages for object "sys.sysxmitqueue".
DBCC results for 'sys.sysrts'.
There are 0 rows in 0 pages for object "sys.syscommittab".
DBCC results for 'sys.filetable_updates_2105058535'.
There are 0 rows in 0 pages for object "sys.filetable_updates_2105058535".
CHECKDB found 0 allocation errors and 0 consistency errors in database 'CreditInfoDB'.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
You can, and should, use ETL to backup to a file and import it to the new server. ETL is going to be way more effective than scripts for large data sets.
Microsoft provides SSIS to do this exact thing. You can export to a RAW file (don't go via CSV or XLSX option), and import it into the other server.
More likely your script file is being truncated at some point in the process. The parser have a file size limit (you are using multiple processes [create, load, execute, etc.]).
The best way to perform such task would be a database backup/restore.
Edit: Based on comment from OP, added information.
If the data is corrupted then it makes no difference what approach you take. And as far as wanting a new database, well; the idea is to restore as a New Database, not to override the old one.
Before taking the backup run an integrity check on the source database. After the backup; verify your backup media.
Have you tried to increase packet size and see if the error is gone or another error comes up?
sqlcmd -S localhost -a 32767 -i C:\Users\Administrator\Downloads\SQL_backup.sql
On top of running backup/restore you could also try just moving the database as is by either detaching the database and then reattaching it in it's new location or using the move database.
Both methods are covered on msdn Detach MsSQL database 2008 - 2016 and Move MsSQL database 2008 - 2016 (I wouldn't normally post links but this is direct from the official support site so should stand up for a few years)
I have a backup and I want it to restore it to a new
Database Wss_Content3
The backfile is a backup of the Wss_Content database.
When I run the following code:
USE Master;
GO
RESTORE DATABASE Wss_Content3 FROM DISK = 'f:\Fill_Wss_Content.bak'
WITH
MOVE 'Wss_Content3' TO 'E:\MSSQL\MSSQL11.SHP2013PROD\MSSQL\Data\Wss_Content3.mdf',
---------------------------------------^^^^^
MOVE 'Wss_Content3_log' TO 'F:\MSSQL\MSSQL11.SHP2013PROD\MSSQL\Data\Wss_Content3_log.ldf';
I get:
Msg 1834, Level 16, State 1, Line 3 The file
'E:\MSSQL\MSSQL11.SHP2013PROD\MSSQL\Data\WSS_Content.mdf' cannot be
overwritten. It is being used by database 'WSS_Content'. Msg 3156,
Level 16, State 4, Line 3 File 'WSS_Content' cannot be restored to
'E:\MSSQL\MSSQL11.SHP2013PROD\MSSQL\Data\WSS_Content.mdf'. Use WITH
MOVE to identify a valid location for the file. Msg 1834, Level 16,
State 1, Line 3 The file
'F:\MSSQL\MSSQL11.SHP2013PROD\MSSQL\Data\WSS_Content_log.ldf' cannot
be overwritten. It is being used by database 'WSS_Content'. Msg 3156,
Level 16, State 4, Line 3 File 'WSS_Content_log' cannot be restored to
'F:\MSSQL\MSSQL11.SHP2013PROD\MSSQL\Data\WSS_Content_log.ldf'. Use
WITH MOVE to identify a valid location for the file. Msg 3119, Level
16, State 1, Line 3 Problems were identified while planning for the
RESTORE statement. Previous messages provide details. Msg 3013, Level
16, State 1, Line 3 RESTORE DATABASE is terminating abnormally.
It's like to restore on the database Wss_Content but I want to do it on a new database Wss_Content3.
How can I do it?
EDIT:
With:
USE Master;
GO
RESTORE DATABASE Wss_Content3 FROM DISK = 'f:\Fill_Wss_Content.bak'
WITH
MOVE 'Wss_Content' TO 'E:\MSSQL\MSSQL11.SHP2013PROD\MSSQL\Data\Wss_Content3.mdf',
---------------------------------------^^^^^
MOVE 'Wss_Content_log' TO 'F:\MSSQL\MSSQL11.SHP2013PROD\MSSQL\Data\Wss_Content3_log.ldf';
I get:
Msg 3154, Level 16, State 4, Line 2
The backup set holds a backup of a database other than the existing 'Wss_Content3' database.
Msg 3013, Level 16, State 1, Line 2
RESTORE DATABASE is terminating abnormally.
EDIT2:
USE Master;
GO
RESTORE FILELISTONLY FROM DISK = 'f:\Fill_Wss_Content.bak'
WSS_Content E:\MSSQL\MSSQL11.SHP2013PROD\MSSQL\Data\WSS_Content.mdf D PRIMARY 163158360064 35184372080640 1 0 0 140B6DD4-DCA0-4FD8-BA65-59390D5FC3B5 0 0 162484191232 512 1 NULL 133075000000938400215 F50C4B9C-B575-4158-B5D6-F44B92FE0380 0 1 NULL
WSS_Content_log F:\MSSQL\MSSQL11.SHP2013PROD\MSSQL\Data\WSS_Content_log.ldf L NULL 22918791168 2199023255552 2 0 0 C83B63C2-B68E-4101-A52B-07EFC08446D7 0 0 0 512 0 NULL 0 00000000-0000-0000-0000-000000000000 0 1 NULL
EDIT3:
I've tried this (with Wss_Content5.mdf and Wss_Content5_log.ldf
) non existing:
RESTORE DATABASE Wss_Content3 FROM DISK = 'f:\Fill_Wss_Content.bak'
WITH
MOVE 'Wss_Content' TO 'E:\MSSQL\MSSQL11.SHP2013PROD\MSSQL\Data\Wss_Content5.mdf',
---------------------------------------^^^^^
MOVE 'Wss_Content_log' TO 'F:\MSSQL\MSSQL11.SHP2013PROD\MSSQL\Data\Wss_Content5_log.ldf
Unfortunately I get this error:
Msg 3154, Level 16, State 4, Line 5
The backup set holds a backup of a database other than the existing 'Wss_Content3' database.
Msg 3013, Level 16, State 1, Line 5
RESTORE DATABASE is terminating abnormally.
You need to use the following option:
WITH REPLACE
If you're using the wizard from SQL Management Studio to restore the database rather than the command line, there is a corresponding option that needs to be checked: "Overwrite the existing database (WITH REPLACE)"
I have a error like Table error: Object ID 3, index ID 1, Page is missing a reference from previous page.
DBCC results for 'RKB'.
Msg 8978, Level 16, State 1, Line 1
Table error: Object ID 3, index ID 1, partition ID 196608, alloc unit ID 196608 (type In-row data).
Page (1:452) is missing a reference from previous page (1:16153).
Possible chain linkage problem.
CHECKDB found 0 allocation errors and 1 consistency errors in table 'sys.sysrscols' (object ID 3).
Msg 7995, Level 16, State 1, Line 1
Database 'RKB': consistency errors in system catalogs prevent further DBCC checkdb processing.
CHECKDB found 0 allocation errors and 1 consistency errors in table '(Object ID 99)' (object ID 99).
CHECKDB found 0 allocation errors and 2 consistency errors in database 'RKB'.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
I am try with DBCC CHECKDB (RKB, REPAIR_ALLOW_DATA_LOSS) WITH ALL_ERRORMSGS but my consistency errors not solved. How can I fix this error? can anyone help me?
You can try recreating or reloading the table. You can have more info on this link
http://www.sqlsoldier.com/wp/sqlserver/introductiontointegritychainlinkageproblems
But if you see frequent errors like this, you should check you I/O sub system.
Hello A client of mine has had an HD crash an a SQL DB got corrupt :
They did not make backups so they have a big problem.
When I tried (an ultimate measure) to DBCC-repair I got the following message.
Can anybody help me with this ?
Server: Msg 8966, Level 16, State 1, Line 1
Could not read and latch page (1:872) with latch type SH. sysindexes failed.
Server: Msg 8944, Level 16, State 1, Line 1
Table error: Object ID 2, index ID 0, page (1:872), row 11. Test (columnOffsets->IsComplex (varColumnNumber) && (ColumnId == COLID_HYDRA_TEXTPTR || ColumnId == COLID_INROW_ROOT || ColumnId == COLID_BACKPTR)) failed. Values are 2 and 5.
The repair level on the DBCC statement caused this repair to be bypassed.
CHECKTABLE found 0 allocation errors and 1 consistency errors in table 'sysindexes' (object ID 2).
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
Paul Randal's blog has a really good article on CHECKDB.
http://www.sqlskills.com/BLOGS/PAUL/category/CHECKDB-From-Every-Angle.aspx