Issue with restoring the database in MS SQL server - sql-server

When I try to restore the DB in Sql Server I am getting the following error message:
Backup mediaset is not complete. Family count:2. Missing family
sequence number :1
I googled for this error and found that the backup of the database wrote its data to two files.
But how can I find those files? I have already dropped the database. I have only abackup copy of that particular DB.

You can get all the information in msdb database even after dropping a database.
please run below query to get the list of all the backup performed on a SQL instance-
select bs.name,bs.backup_size, bs.database_name , bs.backup_start_date , bm.physical_device_name
from msdb.dbo.backupset bs
join msdb.dbo.backupmediafamily bm
on bs.media_set_id = bs.media_set_id
ORDER BY bs.backup_start_date DESC

Related

Replication from Sybase SQL Anywhere to MSSQL

I am trying to replicate or synchronize data between Sybase SQL Anywhere database with MSSQL db.
I tried Proxy Table in SQLA and insert query is working fine. But for actual replication we need update and delete. For that I used INNER JOIN remote database with SQLA db, but it shows error
update operation attempted on non-updatable remote query
. My Update query is below:
UPDATE Test
SET ID = S.accno, Name = S.particulars
FROM "DBA"."acc_ledgers" S
WHERE S.accno <> Test.ID
Update query on remote mssql database is working fine if no join or subquery is used. But when I join the SQLA table it gives error.
What is the problem in this? Can you suggest any solution or alternatives?
Thank you

SQL Server: Backup location

I am working on a SQL Server database and ran the following command to figure out where the database is backing up to:
SELECT TOP 1 M.physical_device_name
FROM msdb..backupset S
JOIN msdb..backupmediafamily M ON M.media_set_id=S.media_set_id
WHERE S.database_name = 'MyDB'
The physical_device_name says: HTSQLServerMyDB
I don't see any maintenance plans or jobs that I can figure out that do this backup. I am trying to figure out where it is doing this backup. If I go into Server Objects then Backup Devices it is empty.
How can I determine where are my backups?
I am running SQL Server 2016 (13.0.4001.0).

Debezium: No maximum LSN recorded in the database; please ensure that the SQL Server Agent is running

This question is related to: Debezium How do I correctly register the SqlServer connector with Kafka Connect - connection refused
In Windows 10, I have Debezium running on an instance of Microsoft SQL Server that is outside of a Docker container. I am getting the following warning every 390 milliseconds:
No maximum LSN recorded in the database; please ensure that the SQL
Server Agent is running
[io.debezium.connector.sqlserver.SqlServerStreamingChangeEventSource]
I checked Debezium's code on Github and the only place that I can find this warning states in the code comments that this warning should only be thrown if the Agent is not running. I have confirmed that the SQL Server Agent is running.
Why is this warning showing up and how do I fix it?
Note:
My current solution appears to only work in a non-production environment - per Docker's documentation.
LSN is the "pieces" of information related about your SQL Server changes. If you don't have LSN, is possible that your CDC is not running or not configured properly. Debezium consumes LSNs to replicate so, your SQL Server need to generate this.
Some approaches:
Did you checked if your table are with CDC enabled? This will list your tables with CDC enabled:
SELECT s.name AS Schema_Name, tb.name AS Table_Name
, tb.object_id, tb.type, tb.type_desc, tb.is_tracked_by_cdc
FROM sys.tables tb
INNER JOIN sys.schemas s on s.schema_id = tb.schema_id
WHERE tb.is_tracked_by_cdc = 1
Your CDC database are enabled and runnig? (see here)
Check if enabled:
SELECT *
FROM sys.change_tracking_databases
WHERE database_id=DB_ID('MyDatabase')
And check if is running:
EXECUTE sys.sp_cdc_enable_db;
GO
Your CDC service are running on SQL Server? See in docs
EXEC sys.sp_cdc_start_job;
GO
On enabling table in CDC, I had some issues with rolename. For my case, configuring at null solved my problem (more details here)
EXEC sys.sp_cdc_enable_table
#source_schema=N'dbo',
#source_name=N'AD6010',
#capture_instance=N'ZZZZ_AD6010',
#role_name = NULL,
#filegroup_name=N'CDC_DATA',
#supports_net_changes=1
GO
Adding more to William's answer.
For the case SQL Server Agent is not running
You can enable it by following :
Control panel >
Administrative Tools >
Click "Services"
Look for SQL Server Agent
Right click and Start
Now you can fire cdc job queries in your mssql.
PS: you need to have login access to windows server.
Another possibility of this error (I just ran into this warning myself this morning trying to bring a new DB online) is the SQL login does not have the permissions needed. Debezium runs the following SQL. Check that the SQL login you are using has access to run this stored procedure and it returns the tables you have set up in CDC. If you get an error or zero rows returned, work with your DBA to get the appropriate permissions set up.
EXEC sys.sp_cdc_help_change_data_capture

How to handle restore fails in log shipping in SQL server 2008 R2?

I am working on log shipping from primary Server1(sql server 2008 R2) to secondary Server2(sql server 2008 R2) in stand by mode.
So there are 3 jobs:
backup on server1,
copy,
restore on server2.
Path for backup source and destination are on server2 and no issue of folder access.
Now first job runs and creates backup and 2nd job creates copy and the restore.
All working fine at first time but as I scheduled them with 5 mins, 7 mins and 9 mins.
But its not working on second attempt even restore jobs throw below errors despite I run it manually:
The restore operation completed with errors. Secondary ID:
could not find a log backup file that could be applied to secondary database.
Is this happening because There is one more log backup going on primary server?? IF yes then how can i manage both log backup(outer log backup and log shipping).
Message
2015-10-13 21:09:05.13 *** Error: The file ‘C:\LS_S\LSDemo_20151013153827.trn’ is too recent to apply to the secondary database ‘LSDemo’.(Microsoft.SqlServer.Management.LogShipping) ***
2015-10-13 21:09:05.13 *** Error: The log in this backup set begins at LSN 32000000047300001, which is too recent to apply to the database. An earlier log backup that includes LSN 32000000047000001 can be restored.
RESTORE LOG is terminating abnormally.(.Net SqlClient Data Provider) ***
Above error is a shown in failure of the history of restore job. If the failure is more than configured thresholds, then we would start seen below error in SQL ERRORLOG on secondary also:
2015-10-14 06:22:00.240 spid60 Error: 14421, Severity: 16, State: 1.
2015-10-14 06:22:00.240 spid60 The log shipping secondary database PinalServer.LSDemo has restore threshold of 45 minutes and is out of sync. No restore was performed for 553 minutes. Restored latency is 4 minutes. Check agent log and logshipping monitor information.
To start troubleshooting, we can look at Job activity monitor on secondary which would fail with the below state:
SQL SERVER - Log Shipping Restore Job Error: The file is too recent to apply to the secondary database LS-Restore-01
If you know SQL transaction log backup basics, you might be able to guess the cause. If we look closely to the error, it talks about LSN mismatch. Most of the cases, a manual transaction log backup was taken. I remember few scenarios where a 3rd party tool would have taken transaction log backup of database which was also part of a log shipping configuration.
Since we know the cause now, what we need to figure out is – where is that “out of band” backup? Here is the query which I have written on my earlier blog.
-- Assign the database name to variable below
DECLARE #db_name VARCHAR(100)
SELECT #db_name = 'LSDemo'
-- query
SELECT TOP (30) s.database_name
,m.physical_device_name
,CAST(CAST(s.backup_size / 1000000 AS INT) AS VARCHAR(14)) + ' ' + 'MB' AS bkSize
,CAST(DATEDIFF(second, s.backup_start_date, s.backup_finish_date) AS VARCHAR(4)) + ' ' + 'Seconds' TimeTaken
,s.backup_start_date
,CAST(s.first_lsn AS VARCHAR(50)) AS first_lsn
,CAST(s.last_lsn AS VARCHAR(50)) AS last_lsn
,CASE s.[type] WHEN 'D'
THEN 'Full'
WHEN 'I'
THEN 'Diff`enter code here`erential'
WHEN 'L'
THEN 'Transaction Log'
END AS BackupType
,s.server_name
,s.recovery_model
FROM msdb.dbo.backupset s
INNER JOIN msdb.dbo.backupmediafamily m ON s.media_set_id = m.media_set_id
WHERE s.database_name = #db_name
ORDER BY backup_start_date DESC
,backup_finish_date
Once we run the query, we would get list of backups happened on the database. This information is picked from MSDB database.
Below picture is self-explanatory.
SQL SERVER - Log Shipping Restore Job Error: The file is too recent to apply to the secondary database LS-Restore-02
Once we found the “problematic” backup, we need to restore it manually on secondary database. Make sure that we are using either norecovery or standby option so that other logs can be restored. Once file is restored, the restore job would be able to pick-up from the same place and would catch up automatically.
enter code here
What are the other problems you have seen with Log-shipping? If you can share some of the common errors, it would be of great help for others and I will try to blog about them too with your help.
Reference: Pinal Dave (https://blog.sqlauthority.com)

Data visibility between linked server

Please consider the following situation
I have Prod instance of SQL server 2012
Also Archive instance of SQL server express 2012
Prod sees Archive as linked server and is able to write data with similar query from some .net code that creates a transaction and the transaction is committed at the end.
insert into <ArchiveServer>.<database>.<schema>.<table>
Select * from <ProductionServer>.<database>.<schema>.<table> Where <some conditions>
Now after the transaction finishes I am able to execute the following query
select count(1) from <ArchiveServer>.<database>.<schema>.<table>
and it returns correct number of records in the context of production server.
Same query
select count(1) from <database>.<schema>.<table>
in the context of Archive server returned 0 records.
What might be the problem? I am out of clues.
Thanks

Resources