Transaction replication Error at the subscriber - sql-server

I was working on a transaction replication on SQL server 2017.A delete command can not be replicated because there is no record that matches the delete condition on the subscriber.
Normally I solve this error with this method.
use distribution
go
sp_browsereplcmds '0x001578BC00009709000500000000','0x001578BC00009709000500000000'
In real synchronizing in SQL replication works manually syncing but not automatically. Also manually insert the missing row at the subscriber.

Related

Will SQL Server transactional replication guarantee the insert order in subscriber

We are using SQL Server 2008 and trying to use transaction replication to reduce the pressure on DB. but we have one concern which is whether it can guarantee the same execution order between publisher and subscriber?
for example, if we run following insert in publisher DB
insert into Table A
insert into Table B
will these 2 insert be executed in the same order in subscriber DB
The answer is yes. In transactional replication, Log Reader Agent is responsible for reading the log file and transfer data which are marked for replication from publication database to distribution database. To do this, Log Reader Agent scans the Log file. Log Reader Agent is a continuous job and there is no way that it will skip some transactions and transfer some other transaction of the same table to the distributor.
On the other hand, Replication Distribution Agent transfers transactions from Distributor database to Subscriber databases. This should also happen in the order the transactions are written to the Distributor because if it is not the case there is no consistency of data.
Yes, rows will be inserted in the same order if both tables are in the same publication.
Log reader agent will read the data from transaction log in the order it was written and push to distribution database.
from there distribution agent will read and apply the commands in the same order to subscriber database.

Replication Data Issue

After configuring replication all the data from tables has replicated from publisher to subscriber. Now my requirement is whenever I insert new record in publisher only that record should replicate rather than reinitialize all the records to subscriber because my table is having millions of records.
Rather than drop and reinitialize snapshot cont we store earlier sync data of table in subscriber and only sync the new record.
Is there any way to do this?
If you're using transactional replication (as you say above in your comments), something is configured incorrectly. Transactional replication is supposed to work as you describe (i.e. a one row change gets pushed over and applied as a one row change). I'd guess that you have the immediate_sync property turned on at the publisher and are running the snapshot agent on a schedule. At the very least, turn off the schedule for the snapshot agent and I think you'll see your problem go away.

Resychronize merge replication

I have an issue where there was a merge replication between 2 instances for around 10 articles that has now been dropped. I want to recreate the merge replication - I am looking for inputs on the steps/ different options to set it up again and synchronize.
The subscriber is remote and not a part of the LAN. Please note that I have the scripts to create the replication.
This is what I am thinking of doing:
backup current publisher and restore it to the subscriber instance in a different name
restore a copy of the subscriber in a different name
run compare using a tool that generates scripts, like those from red gate
apply the script generated on the restored subscriber db.
After this, what do you think is the best way to set the replication back to running?
Any advise appreciated. thankyou
There is two thing to check before you backup and restore.
Make sure that you have all data from publisher and subscriber in one database. It could be publisher. If you hadve ETLs which loading you publisher and subscribers database from diffeent source this point is pretty important.
run http://technet.microsoft.com/en-us/library/ms188734%28v=sql.105%29.aspx on both publisher and subscriber
Script out all your indexes if you need reduce backup file. You can create them l8r once you will be in sync.
backup db on publisher and restore it pn subscriber
Next
create publication
create snapshot
add login to the access list of your publication
add articles for publication
create script drop/create indexes. Create scrip to drop/create indexes on tables classified as “big data” to prevent snapshotting indexes.
Do this for constraints, too. They slow up your action..
Just drop them all. From step 9
Snapshot your stuff.
Now subscriber
add pull subscription. You have two steps. Script on publisher and script on subscriber.
stop agents on subscriber and change GENERATION_LEVELING_THRESHOLD if you need or change subscriber agent profile.
You can now start pull agents.
Remember about replication index maintenance
Hope that help

SQL Server 2008R2 Transactional Replication - Move SubscriberDB - Push Subscription

SQL Server 2008R2 Transactional Replication - Move SubscriberDB - Push Subscription
I have a requirement to move a subscriber database to a new server outside of a system outage i.e. I cannot stop new transaction from loading into the publisher database.
So far I have attempted to stop the distribution agent and let all un-replicated commands replicate to the subscriber database at Server1. Then backup and restore the subscriber database to Server2. I have then created a new subscription from Server2 to the existing publication.
This works but only transactions created from that point forward are replicated to the Server2 subscriber database. I also require all the old transactions built up at the distributor database destined to only go to Server1.
Is there a replication command available to update the destination of existing transactions at the distributer to the new subscriber.subscriber_DB?
There is 1 publication with multiple articles. The publication is currently only subscribed to by one database at Server1.
You're working too hard. Create a subscription on the new server as though you didn't have an existing subscription at all. There are many ways to do this; pick your favorite. I see in your response to another answer that snapshots are a no-go. I have had a lot of success using the "initialize from backup" option (here, "backup" refers to a backup of the publisher). Once the subscriber is in sync after initialization, you're done. You're now clear to "migrate" to the new server.
Due to the distribution agent being specific to each subscribing server, you can't really have a new subscriber take over where an existing subscriber left off. The only way this would work is if you backup/restore to Server2, temporarily stopped transactions on the publisher, backup/restore log to Server2, create subscriptions with "replication support only", and then re-enable transactions.
Can you not just add subscriptions to the same publication for the new subscriber and kick off the snapshot agent? That will independently sync Server2 while Server1 continues to stay in sync. You should then be able to switch to Server2 seamlessly and remove the subscriptions to Server1.
One note of warning though. I would check the sync_method in syspublications table (or run sp_helppublications) of your publication database to make sure snapshots won't lock the tables in your publisher (by default with SQL Server 2005+, this shouldn't be an issue). Otherwise, what I just suggested will cause blocking on the publisher until the snapshot finishes.
Also, this is a good reference to understanding how to do snapshots one at a time if you setup replication through the GUI using default settings. This will be useful for distributing the snapshots over a larger period of time to reduce publisher server load if you have a lot of data to replicate (gigabytes rather than megabytes).
http://www.replicationanswers.com/TransactionalOptimisation.asp

What is transactional replication used for?

What is transaction replication used? I seemed to create transaction replication following this tutorial:
http://www.sql-server-performance.com/2010/transactional-replication-2008-r2/
And I know when I change some objects i.e any DML or DDL statement, those changes will be reflected to the other server where I did replication. But it's not clear to me why should we use transaction replication. Does SQL server automatically start using the 2nd server where replication was done when the main instance fails? or do we have to manually restore the database from the server where replication was done in case of failure of 1st instance?
Thanks in advance :)
You can use transactional replication to maintain a warm standby SQL server. Transactional replication replicates the data on one server (the publisher) to another server (the subscriber) with less latency than log shipping.
You can implement transactional replication at the database object level such as the table level. Therefore, Microsoft recommends that you use transactional replication when you have less data to protect, and you must have a fast data recovery plan.
This solution is vulnerable to the failure of the publisher and the subscriber at the same time. In such a scenario, you cannot protect your data. In all other scenarios such as the failure of a distributor or a subscriber, it is best to resynchronize the data in the subscriber with the data in the publisher.
You should use transactional replication to maintain a warm standby SQL server only when you do not implement schema changes or you do not implement other changes to your database such as security changes that replication does not support.
Note Replication is not designed for the maintenance of warm standby servers. With replication, you can use replicated data at the subscriber to generate reports. You can also use replication for other general uses without having to perform processing on your relatively busy publisher.
Disadvantages
Schema changes or security changes that are performed at the
publisher after establishing replication will not be available at
the subscriber. The distributor in transactional replication uses an
Open Database Connectivity (ODBC) connection or an OLE Database
(OLEDB) connection to distribute data. However, log shipping uses
the RESTORE TRANSACTION low-level Transact-SQL statement to
distribute the transaction logs. A RESTORE TRANSACTION statement is
much faster than an ODBC connection or an OLEDB connection.
Typically, switching servers erases replication configurations.
Therefore, you have to configure replication two times:
a. When you switch to the subscriber.
b. When you switch back to the publisher.
If a disaster occurs, you must manually switch servers by
redirecting all the applications to the subscriber.
Read more here http://sqlserverdatarecovery.com/transactional_replication.html

Resources