Quantcast
Channel: SQL Replication – SQL Authority with Pinal Dave
Viewing all 19 articles
Browse latest View live

SQLAuthority News – Book Review – Pro SQL Server 2005 Replication (Definitive Guide)

$
0
0

SQLAuthority News - Book Review - Pro SQL Server 2005 Replication (Definitive Guide) proreplication

Pro SQL Server 2005 Replication (Definitive Guide) (Hardcover)
by Sujoy Paul (Author)

Link to Amazon

Quick Review:
This is good book for any novice developer to start in the world of database replication implementation and maintenance. Replication is important part of highly availability and one book covers all the concept and methodology at one place.

Detail Review:
Replication is the process of sharing information so as to ensure consistency between redundant resources, such as software or hardware components, to improve reliability, fault-tolerance, or accessibility. Database replication can be used on many database management systems, usually with a master/slave relationship between the original and the copies. The master logs the updates, which then ripple through to the slaves. The slave outputs a message stating that it has received the update successfully, thus allowing the sending of subsequent updates.

This books talks about different replication types and methods. This book explains different scenarios where types of replication can be used. Sujoy Paul (SQL Server – MCP) explains the concept with many screenshots and simple examples. This book is not limited to replication types only but it also covers replication between heterogeneous databases and other objects.

Pros :

  • Lots of screen shots
  • Lots of explanation of how different procedures works
  • Good coverage of different kind of replications
  • Step by Step guidance
  • Complete coverage of any methodology
  • Truly useful to novice programmers

Cons:

  • No discussion about potential errors can come across during replication process
  • Some of the screen shots are hard to read (Apress should look into this matter)
  • Some of the chapters are very blurry

Overall, this is great book for any novice developer who is beginning in the world of replication. Though this book covers many screenshots and material directly from Book On Line this is great collection of all the concept at any place. I have personally used this book when I was new DBA and have learned replication basics from this book.

Stars: 4 Stars

Summary: This a comprehensive single source of information will save lots of time as there is no need to go through multiple books to implement and maintain replication solutions.

Reference : Pinal Dave (http://blog.SQLAuthority.com)

First appeared on SQLAuthority News – Book Review – Pro SQL Server 2005 Replication (Definitive Guide)


SQL SERVER – FIX – ERROR : Cannot drop the database because it is being used for replication. (Microsoft SQL Server, Error: 3724)

$
0
0

I have set up replication at many different organization. One error I quite commonly face is after I have removed replication I can not remove database. When I try to remove the database it gives me following error.

Cannot drop the database because it is being used for replication. (Microsoft SQL Server, Error: 3724)

Fix/Workaround/Solution:

The solution is very simple. Create the empty database with the same name on another server/instance first. Take full back of the same and forced restore over this database.

SQL SERVER - FIX - ERROR : Cannot drop the database because it is being used for replication. (Microsoft SQL Server, Error: 3724) forcerestore

Do let me know if you have any better idea or suggestion.

Reference : Pinal Dave (http://blog.sqlauthority.com)

First appeared on SQL SERVER – FIX – ERROR : Cannot drop the database because it is being used for replication. (Microsoft SQL Server, Error: 3724)

SQL SERVER – ERROR: FIX: Cannot drop server because it is used as a Distributor in replication

$
0
0

Replication has been my favorite subject when it comes to resolving errors. I have found that many DBAs are stuck with the solving of the problem of replication for hours; however, the solution is very easy. One of the very common errors in replication occurs when replication is removed from any server. I have seen the following error as one attempts to remove replication from the same server when the publisher and distributor are on the same server.

Cannot drop server ‘repl_distributor’ because it is used as a Distributor in replication.

Cannot drop the distribution database ‘distribution’ because it is currently in use.

Fix/Workaround/Solution:

Try any of the following option. Either of them should work for you.

EXEC master.dbo.sp_serveroption @server=N'XXXX', @optname=N'dist', @optvalue=N'true'
GO

EXEC sp_dropdistributor @no_checks = 1, @ignore_distributor = 1
GO

Please do let me know your feedback regarding which one of the above options worked for you or if any of the other solution helped to resolve this issue.

Reference: Pinal Dave (http://blog.SQLAuthority.com)

First appeared on SQL SERVER – ERROR: FIX: Cannot drop server because it is used as a Distributor in replication

SQL SERVER – Initializing a Merge Subscription Without a Snapshot

$
0
0

During recent course of Disaster Recovery and Performance Tuning, I had very interesting conversation with students regarding Initializing a Merge Subscription Without a Snapshot and Initializing a Transactional Subscription Without a Snapshot. After the discussion when we were looking at MSDN pages one thing caught my notice was the note on the top of the MSDN page regarding future support of the feature for Initializing a Merge Subscription Without a Snapshot.

In the book on line on the subject Initializing a Merge Subscription Without a Snapshot it suggests that this feature will be deprecated in future, whereas there is no such note on the topic for Transactional Subscription. Well, I want to share this with everybody suggesting that there may be issue with future version if you are not initiating your replication with snapshot in the case of Merge Replication.

I would like to know if you are currently using Merge Replication and initializing it without snapshot. If you are – I would like to know why?

Reference: Pinal Dave (http://blog.SQLAuthority.com)

First appeared on SQL SERVER – Initializing a Merge Subscription Without a Snapshot

SQL SERVER – Fix : Error : 8501 MSDTC on server is unavailable. Changed database context to publisherdatabase

$
0
0

During configuring replication on one of the server, I received following error. This is very common error and the solution of the same is even simpler.

MSDTC on server is unavailable. Changed database context to publisherdatabase. (Microsoft SQL Server, Error: 8501)

SQL SERVER - Fix : Error : 8501 MSDTC on server is unavailable. Changed database context to publisherdatabase msdtc1

Solution:

Enable “Distributed Transaction Coordinator” in SQL Server.

Method 1:

  1. Click on Start–>Control Panel->Administrative Tools->Services
  2. Select the service “Distributed Transaction Coordinator”
  3. Right on the service and choose “Start”

Method 2:

  1. Type services.msc in the run command box
  2. Select “Services” manager; Hit Enter
  3. Select the service “Distributed Transaction Coordinator”
  4. Right on the service and choose “Start”

SQL SERVER - Fix : Error : 8501 MSDTC on server is unavailable. Changed database context to publisherdatabase msdtc2

SQL SERVER - Fix : Error : 8501 MSDTC on server is unavailable. Changed database context to publisherdatabase msdtc4

Reference : Pinal Dave (http://blog.SQLAuthority.com)

First appeared on SQL SERVER – Fix : Error : 8501 MSDTC on server is unavailable. Changed database context to publisherdatabase

SQL SERVER – FIX – Error – Msg 4928, Level 16, State 1. Cannot Alter Column Because it is ‘Enabled for Replication or Change Data Capture’

$
0
0

SQL SERVER - FIX - Error - Msg 4928, Level 16, State 1. Cannot Alter Column Because it is 'Enabled for Replication or Change Data Capture' crosserror-800x800 One of my Facebook followers sent me an interesting situation, where he faced error related replication or change data capture.

Hi Pinal,
We have a database in our QA environment which is restored from Production (we have replication set up in Production). In QA environment, we don’t have any replication or Change Data Capture (CDC). When we are trying to rename one of the fields in the table in the Lab and got the following error:

--Rename column
EXEC sp_rename 'dbo.Foo.Bar', 'Bar1', 'COLUMN';
GO

Msg 4928, Level 16, State 1, Procedure sp_rename, Line 611
Cannot alter column ‘Bar’ because it is ‘enabled for Replication or Change Data Capture’.

I have verified the following:

  • None of the tables have is_tracked_by_cdc = 1.
  • None of the tables or columns have is_replicated = 1
  • Replication was already disabled by using sp_removedbreplication.

Any ideas?
Thanks in advance.
John S.

This was not a pretty situation because the error message is not in line with the data points which they have already verified. I strongly felt that somewhere they have metadata incorrect.

Based on my search on the internet, I found that below has helped few of the others.

execute sp_replicationdboption 'DBName','Publish','False',1

But it didn’t work. So, I thought of playing with CDC by enabling and disabling again because this was a restored copy of the production database.

WORKAROUND/SOLUTION

I have provided below script to enable and disable CDC one more time on the table.

USE YOUR_DATABASE_NAME
GO
EXEC sys.sp_cdc_enable_db
GO
EXEC sys.sp_cdc_enable_table @source_schema = N'dbo'
	,@source_name = N'foo'
	,@role_name = NULL
	,@filegroup_name = N'primary'
	,@supports_net_changes = 1
GO
EXEC sys.sp_cdc_disable_table @source_schema = N'dbo'
	,@source_name = N'foo'
	,@capture_instance = N'ALL'
GO
EXEC sys.sp_cdc_disable_db
GO

As soon as the above was done, we could rename the column.

Have you encountered any such weird situations where the error message was not correct due to metadata problem?

Reference: Pinal Dave (https://blog.sqlauthority.com)

First appeared on SQL SERVER – FIX – Error – Msg 4928, Level 16, State 1. Cannot Alter Column Because it is ‘Enabled for Replication or Change Data Capture’

SQL SERVER – FIX: The Log for Database Cannot be Shrunk Until All Secondaries Have Moved Past the Point Where the Log was Added

$
0
0

SQL SERVER - FIX: The Log for Database Cannot be Shrunk Until All Secondaries Have Moved Past the Point Where the Log was Added shrinkfun While preparing for a demo for a client I was hit with an interesting error in AlwaysOn Availability Group backup and restore scenario. In my lab setup, I had four nodes SQLAUTH1 to SQLAUTH4 and I have always on high availability turned on SQL Server 2016. I played and did several operations with database and found that I have bloated the transaction log file to 100 GB. And now I need to shrink the transaction log on SQLAUTH1. As soon as I did that, I was welcomed with below message about database cannot be shrunk until all secondaries have moved past the point.

The log for database ‘SQLAuth’ cannot be shrunk until all secondaries have moved past the point where the log was added.

It’s worth mentioning that I did add files in the database so above message is valid. I even took transaction log backup, but no luck. File usage was still shown as 99%.

WORKAROUND/SOLUTION

I looked around at AlwaysOn Dashboard and found that one of the secondary was not getting synchronized. Since it was a lab machine I decided to delete the AG and the thing came back to normal.

But in production, if you can’t afford to delete and reconfigure Always On availability group, then you need to find the cause why secondary is not getting synchronized with primary. In theory, the transaction log files on primary would keep on growing due to secondary not synchronizing with primary.  If you find that the data movement is suspended, then you may want to resume it and find the possible cause in the SQL Server ERRORLOG file

SQL SERVER – Where is ERRORLOG? Various Ways to Find ERRORLOG Location

One of the possible case I can think of is a change of the service account.

SQL SERVER – FIX: Msg 35250, Level 16, State 7 – The Connection to the Primary Replica is Not Active. The Command Cannot be Processed

STILL STUCK?

If you are not able to find the cause, feel free to contact me and use my consulting services. As you might know that I have been an independent consultant for a while and one of the services I provide is “On Demand (50 minutes)” service. This service is very helpful for organizations who are in need immediate help with their performance tuning issue. Though, I have set working ours for my regular clients, every single day, I keep two hours available for this offering. This way, I can make sure that anyone who urgently needs my help, can avail the same. Click here to read more about it.

Reference: Pinal Dave (https://blog.sqlauthority.com)

First appeared on SQL SERVER – FIX: The Log for Database Cannot be Shrunk Until All Secondaries Have Moved Past the Point Where the Log was Added

SQL SERVER – Upgrade Error – ALTER DATABASE Statement Not Allowed Within Multi-statement Transaction

$
0
0

Most of the time applying service pack for SQL Server is a child’s play. Double click on exe, keep hitting next, next and finally press update. But when it fails, you would need an expert to fix the issue. Recently, one of my clients faced a problem while installing SQL Server 2014 Sp2. The Service Pack error failed at the final stage. And now the SQL Server services were not starting. This issue can have various variations where SQL Services doesn’t start after patching. Few on my earlier blogs on the same topic are listed below. Let us learn about ALTER DATABASE Statement Not Allowed Within Multi-statement Transaction.

After looking at all the log files we narrowed the issue down to the below section in SQL Server Errorlog. Based on the errors I saw here and based on my previous experiences with such errors, I realized that this is a Script Upgrade failure. Below are the steps which occur during a patching process,

  • Whenever any SQL Server patch is applied, the setup would patch the binaries first.
  • During the restart of the instance, SQL Server startup would go through “script upgrade mode” during the recovery
  • Script upgrade mode is the phase where objects inside the databases are upgraded based on recent patch applied.
  • Based on features installed and a number of databases available, it would take a varying amount of time.

2018-03-11 17:54:38.98 spid9s Upgrading subscription settings and system objects in database [TransRepl].
2018-03-11 17:54:39.12 spid9s Invalid object name ‘MSreplication_objects’.
2018-03-11 17:54:39.12 spid9s Error executing sp_vupgrade_replication.
2018-03-11 17:54:39.12 spid9s Saving upgrade script status to ‘SOFTWARE\Microsoft\MSSQLServer\Replication\Setup’.
2018-03-11 17:54:39.12 spid9s Saved upgrade script status successfully.
2018-03-11 17:54:39.12 spid9s Database ‘master’ is upgrading script ‘upgrade_ucp_cmdw_discovery.sql’ from level 201330692 to level 201331592.
2018-03-11 17:54:39.40 spid9s Database ‘master’ is upgrading script ‘msdb110_upgrade.sql’ from level 201330692 to level 201331592.
2018-03-11 17:54:39.40 spid9s ———————————-
2018-03-11 17:54:39.40 spid9s Starting execution of PRE_MSDB.SQL
2018-03-11 17:54:39.40 spid9s ———————————-
2018-03-11 17:54:39.64 spid9s Error: 15002, Severity: 16, State: 1.
2018-03-11 17:54:39.64 spid9s The procedure ‘sys.sp_dbcmptlevel’ cannot be executed within a transaction.
2018-03-11 17:54:39.64 spid9s —————————————–
2018-03-11 17:54:39.64 spid9s Starting execution of PRE_SQLAGENT100.SQL
2018-03-11 17:54:39.64 spid9s —————————————–
2018-03-11 17:54:39.65 spid9s Error: 226, Severity: 16, State: 6.
2018-03-11 17:54:39.65 spid9s ALTER DATABASE statement not allowed within multi-statement transaction.

From above we can see that we hit an error while executing the Stored Proc – sp_vupgrade_replication And it also said that it was not able to find the object – MSreplication_objects

As per Microsoft documentation sp_vupgrade_replication used for below.

Activated by setup when upgrading a replication server. Upgrades schema and system data as needed to support replication at the current product level. Creates new replication system objects in system and user databases. This stored procedure is executed at the machine where the replication upgrade is to occur.

WORKAROUND/SOLUTION

As per my previous articles on the same topic, I knew that I need to use trace flag 902 to bypass script upgrade mode and fix the real cause of the error. I started SQL using trace flag 902 as below

NET START MSSQL$SQL2014 /T902

Refer: SQL SERVER – 2005 – Start Stop Restart SQL Server from Command Prompt

I was able to connect to SQL Server because the problem script didn’t run due to trace flag.

Then I straight went to the database in question and expanded the System Tables section could see that the table – MSreplication_objects was missing. Now how do we get back this replication related system table? To quickly confirm this fact, we checked for the same in the other databases which were a part of replication and confirmed that this table needs to be present.

I then got an idea to script out this stored proc from the other database and create it here. I went ahead and did the same.

SQL SERVER - Upgrade Error - ALTER DATABASE Statement Not Allowed Within Multi-statement Transaction patch-repl-01

The extracted script looks like below,

SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[MSreplication_objects](
	[publisher] [sysname] NULL,
	[publisher_db] [sysname] NULL,
	[publication] [sysname] NULL,
	[object_name] [sysname] NOT NULL,
	[object_type] [char](2) NOT NULL,
	[article] [sysname] NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO

I was happy to see the script execute successfully. But to my surprise, the stored procedure got created as a user stored proc instead of a system stored proc.

SQL SERVER - Upgrade Error - ALTER DATABASE Statement Not Allowed Within Multi-statement Transaction patch-repl-02

Then to promote this stored proc as a system proc I used an undocumented stored procedure sp_MS_marksystemobject

exec sys.sp_MS_marksystemobject  MSreplication_objects

After that, we can see that the table moved into system tables folder.

SQL SERVER - Upgrade Error - ALTER DATABASE Statement Not Allowed Within Multi-statement Transaction patch-repl-03

Once this was done then, I stopped SQL and started it usually (without trace flag 902), and it was able to start successfully. Have you encountered any other flavor of script upgrade mode?

Reference: Pinal Dave (https://blog.sqlauthority.com)

First appeared on SQL SERVER – Upgrade Error – ALTER DATABASE Statement Not Allowed Within Multi-statement Transaction


SQL Authority News – Brent Ozar Unlimited Office Hours 2018/4/4 – Fun Experience

$
0
0

SQL Authority News - Brent Ozar Unlimited Office Hours 2018/4/4 - Fun Experience Practical_Real_World_Performance_Tuning-800x800 It was my pleasure and honor that I was invited to the Brent Ozar Unlimited Office Hours. During the office hours, we received quite a few interesting questions, some were very complicated and some were super fun. However, the best part of attending the office hours was the company. I was fortunate to have Brent, Richie, and Tara along with me in this office hours. Please note that the questions which we discussed during the session were asked live.

During the office hours, we discussed quite a few subjects here are the list of the questions which we had discussed during the office hours.

  • How do you monitor replication latency?
  • I run out of disk space when I create a clustered index.
  • Is replication a good fit to copy data between servers?
  • How do you prove other services are causing performance problems?
  • Why are vendors telling me to replicate to the cloud?
  • How can I fix performance in a third party app?
  • How has the reception been for SQL ConstantCare?
  • I’ve been getting database mail errors about spawning processes…
  • I need to sync data from a read-only database…
  • How can I reduce blocking between an insert and an update?
  • How can I capture who does what?
  • How can I get my data offsite fast?
  • Should I drop my indexed views when changing replication?

Please watch the following video to know the answers to this questions. Here’s the video on YouTube:

Additionally, here is the link to the class which we had discussed during the webcast. Please note that there are very limited seats available and it is first to come first to serve.

Here is few additional reading on the same subject:

Feel free to ask any question in the comment area, I will be happy to answer!

Reference: Pinal Dave (https://blog.sqlauthority.com)

First appeared on SQL Authority News – Brent Ozar Unlimited Office Hours 2018/4/4 – Fun Experience

SQL SERVER – FIX: Unable to Create Distribution Database on a UNC Share – Configure Distribution

$
0
0

Whenever we try to use Configure Distribution option in SSMS in a SQL Server instance which is configured on a UNC Path, the wizard will not allow us to configure the Distribution database and we will get the below error:

The paths to the distribution database folder and transaction log folder must refer to drives that are local to ‘SQLNODE1’. The paths must begin with a local drive letter and colon (for example, C:). Mapped drive letters or network paths are not valid.

SQL SERVER - FIX: Unable to Create Distribution Database on a UNC Share - Configure Distribution distdb-unc-01

Don’t be surprised. SQL Server instances can be configured on a UNC Share. Starting with SQL Server 2012, system databases and user databases can be installed with Server Message Block (SMB) file server as a storage option. This applies to both SQL Server stand-alone and SQL Server failover cluster installations. The only exception is Filestream which is not currently supported on an SMB file share.

In this scenario, when we are trying to configure Distribution database, the Configure Distribution wizard was not happy with the UNC shares provided and we got an error. I’m not sure if this is a supported model, but it looks like it should be supported as SQL Server is supporting all other system databases.

WORKAROUND/SOLUTION

I adopted the T-SQL method to get the Distribution Database successfully configured. Below are the steps I followed.

In the Configure Distribution wizard, provide an existing path, C:\Temp (or any other valid path)

SQL SERVER - FIX: Unable to Create Distribution Database on a UNC Share - Configure Distribution distdb-unc-02

Then in the Wizard Actions page, uncheck “Configure Distribution” and check “Generate a Script …”

SQL SERVER - FIX: Unable to Create Distribution Database on a UNC Share - Configure Distribution distdb-unc-03

Go ahead and finish the wizard. Then open the script which was saved. It will look like the one below (partial script)

use master
exec sp_adddistributor @distributor = N'SQLAuthorityServer', @password = N'aVerY$tr0nggP@ssw00rd'
GO
exec sp_adddistributiondb @database = N'distribution', @data_folder = N'C:\Temp', @log_folder = N'C:\Temp', @log_file_size = 2, @min_distretention = 0, @max_distretention = 72, @history_retention = 48, @security_mode = 1
GO

We need to change the values “C:\Temp” above to the UNC path where we need to get the Distribution Database configured. Now the script will look like,

use master
exec sp_adddistributor @distributor = N'SQLAuthorityServer', @password = N'aVerY$tr0nggP@ssw00rd'
GO
exec sp_adddistributiondb @database = N'distribution', @data_folder = N' \\dc\ShareOnDC', @log_folder = N' \\dc\ShareOnDC', @log_file_size = 2, @min_distretention = 0, @max_distretention = 72, @history_retention = 48, @security_mode = 1
GO

Note: Make sure this UNC Path has been given all the required permissions. Refer here

Once the values have been changes, please go ahead and run this script in a Query Analyzer window. After the script has executed, you will see the Distribution database created. You can also verify the Distribution database by running,

USE [distribution]
GO
SELECT name
,physical_name
FROM   sys.database_files

Here is the output which confirms the file location.

SQL SERVER - FIX: Unable to Create Distribution Database on a UNC Share - Configure Distribution distdb-unc-04

Hope this helps someone who wants to have such special requirement and configuration.

Reference: Pinal Dave (https://blog.sqlauthority.com)

First appeared on SQL SERVER – FIX: Unable to Create Distribution Database on a UNC Share – Configure Distribution

SQL SERVER – Upgrade Error – Upgrading Subscription Settings and System Objects in Database [DBName].

$
0
0

SQL SERVER - Upgrade Error - Upgrading Subscription Settings and System Objects in Database [DBName]. xerror There are many causes of SQL server patching failure. Looking at right log and finding the right cause is the key to solve it in time. In this blog, we would learn about an upgrade error which comes during “Upgrading subscription settings and system objects in database.”

One of my blog reader reached out to me via email. I offered them my incredibly famous On Demand assistance and I got started working in 10 minutes via GoToMeeting.

When I checked ERRORLOG, I found below.

2018-04-19 14:16:38.98 spid9s Upgrading subscription settings and system objects in database [BAPDB].
2018-04-19 14:16:39.12 spid9s Invalid object name ‘MSreplication_subscriptions’.
2018-04-19 14:16:39.12 spid9s Error executing sp_vupgrade_replication.
2018-04-19 14:16:39.12 spid9s Saving upgrade script status to ‘SOFTWARE\Microsoft\MSSQLServer\Replication\Setup’.
2018-04-19 14:16:39.12 spid9s Saved upgrade script status successfully.
2018-04-19 14:16:39.12 spid9s Database ‘master’ is upgrading script ‘upgrade_ucp_cmdw_discovery.sql’ from level 201330692 to level 201331592.
2018-04-19 14:16:39.40 spid9s Database ‘master’ is upgrading script ‘msdb110_upgrade.sql’ from level 201330692 to level 201331592.

WORKAROUND/SOLUTION

I Informed them they I already have a blog with exact same error SQL SERVER – Upgrade Error – ALTER DATABASE Statement Not Allowed Within Multi-statement Transaction

But they informed that they don’t have any replication as of now and they don’t want to create any system table using the method which I explained in my blog. I thought there could be a chance that some replication metadata was still left over, and script upgrade process thinks replication still persists in this database and was expecting this table. Based on their decision, I started SQL with trace flag 902.

NET START MSSQLSQLSERVER /T902

Refer: SQL SERVER – 2005 – Start Stop Restart SQL Server from Command Prompt

We used the system stored procedure (sp_removedbreplication) to remove replication related config from this database (this is there in ERRORLOG file)

USE BAPDB
GO
sp_removedbreplication 
GO

Once this was done then, I stopped SQL and started it normally (without trace flag 902) and it was able to start successfully.

Reference: Pinal Dave (https://blog.sqlauthority.com)

First appeared on SQL SERVER – Upgrade Error – Upgrading Subscription Settings and System Objects in Database [DBName].

SQL SERVER – Unable to Remove Replication Publication – Could not Delete the Subscription at Subscriber ‘SubServer’ in Database ‘SubDB’

$
0
0

SQL SERVER - Unable to Remove Replication Publication - Could not Delete the Subscription at Subscriber 'SubServer' in Database 'SubDB' replication While playing with my lab server having broken replication, I encountered an error message when I was trying to remove publication. In this blog, we would learn about how to fix error Could not delete the subscription at Subscriber ‘SubServer’ in database ‘SubDB’.

Basically, I was not able to remove Publication ‘PubName’ and it reported the below error message:

Could not delete the subscription at Subscriber ‘SubServer’ in database ‘SubDB’.
Invalid object name ‘dbo.syspublications’. (Microsoft SQL Server, Error:208)

WORKAROUND/SOLUTION

Based on my research, the error should not come if replication objects were cleaned up correctly. This means that in my environment there must be some orphaned replication objects, or some other commands blocked the previous command. I ran below command and it was successful.

EXEC sp_removedbreplication 'PubDB'

Here the documentation of sp_removedbreplication

This stored procedure removes all replication objects on the publication database on the Publisher instance of SQL Server or on the subscription database on the Subscriber instance of SQL Server. Execute in the appropriate database, or if the execution is in the context of another database on the same instance, specify the database where the replication objects should be removed. (ref)

Hope this would help someone who is having basic knowledge of SQL Replication and became accidental DBA.

Reference: Pinal Dave (https://blog.SQLAuthority.com)

First appeared on SQL SERVER – Unable to Remove Replication Publication – Could not Delete the Subscription at Subscriber ‘SubServer’ in Database ‘SubDB’

SQL SERVER – Scripts to Overview HADR / AlwaysOn Local Replica Server

$
0
0

Today, I have received a very interesting script from SQL Server Expert Dominic Wirth. He has written a very helpful script which displays a utilization overview of the local availability group replica server. The overview will contain the number of databases as well as the total size of databases (DATA, LOG, FILESTREAM) and is group by following two categories

  1. Replica role (PRIMARY / SECONDARY)
  2. Availability Group

Let us first see the script:

/*==================================================================
Script: HADR Local Replica Overview.sql
Description: This script will display a utilisation overview
of the local Availability Group Replica Server.
The overview will contain amount of databases as
well as total size of databases (DATA, LOG, FILESTREAM)
and is group by ...
1) ... Replica role (PRIMARY / SECONDARY)
2) ... Availability Group
Date created: 05.09.2018 (Dominic Wirth)
Last change: -
Script Version: 1.0
SQL Version: SQL Server 2014 or higher
====================================================================*/
-- Load size of databases which are part of an Availability Group
DECLARE @dbSizes TABLE (DatabaseId INT, DbTotalSizeMB INT, DbTotalSizeGB DECIMAL(10,2));
DECLARE @dbId INT, @stmt NVARCHAR(MAX);
SELECT @dbId = MIN(database_id) FROM sys.databases WHERE group_database_id IS NOT NULL;
WHILE @dbId IS NOT NULL
BEGIN
SELECT @stmt = 'USE [' + DB_NAME(@dbId) + ']; SELECT ' + CAST(@dbId AS NVARCHAR) + ', (SUM([size]) / 128.0), (SUM([size]) / 128.0 / 1024.0) FROM sys.database_files;';
INSERT INTO @dbSizes (DatabaseId, DbTotalSizeMB, DbTotalSizeGB) EXEC (@stmt);
SELECT @dbId = MIN(database_id) FROM sys.databases WHERE group_database_id IS NOT NULL AND database_id > @dbId;
END;
GO
-- Show utilisation overview grouped by replica role
SELECT AR.replica_server_name, DRS.is_primary_replica AS IsPrimaryReplica, COUNT(DB.database_id) AS [Databases]
,SUM(DBS.DbTotalSizeMB) AS SizeOfAllDatabasesMB, SUM(DBS.DbTotalSizeGB) AS SizeOfAllDatabasesGB
FROM sys.dm_hadr_database_replica_states AS DRS
INNER JOIN sys.availability_replicas AS AR ON DRS.replica_id = AR.replica_id
LEFT JOIN sys.databases AS DB ON DRS.group_database_id = DB.group_database_id
LEFT JOIN @dbSizes AS DBS ON DB.database_id = DBS.DatabaseId
WHERE DRS.is_local = 1
GROUP BY DRS.is_primary_replica, AR.replica_server_name
ORDER BY AR.replica_server_name ASC, DRS.is_primary_replica DESC;
GO
-- Show utilisation overview grouped by Availability Group
SELECT AR.replica_server_name, DRS.is_primary_replica AS IsPrimaryReplica, AG.[name] AS AvailabilityGroup, COUNT(DB.database_id) AS [Databases]
,SUM(DBS.DbTotalSizeMB) AS SizeOfAllDatabasesMB, SUM(DBS.DbTotalSizeGB) AS SizeOfAllDatabasesGB
FROM sys.dm_hadr_database_replica_states AS DRS
INNER JOIN sys.availability_groups AS AG ON DRS.group_id = AG.group_id
INNER JOIN sys.availability_replicas AS AR ON DRS.replica_id = AR.replica_id
LEFT JOIN sys.databases AS DB ON DRS.group_database_id = DB.group_database_id
LEFT JOIN @dbSizes AS DBS ON DB.database_id = DBS.DatabaseId
WHERE DRS.is_local = 1
GROUP BY AG.[name], DRS.is_primary_replica, AR.replica_server_name
ORDER BY AG.[name] ASC, AR.replica_server_name ASC;
GO

Here is the screenshot of the resultset which you will get if you run above script.

SQL SERVER - Scripts to Overview HADR / AlwaysOn Local Replica Server alwaysonreplica

There are many different kinds of reports which you can run via SQL Server Management Studio. However, sometimes the scripts simple as this script are very helpful and returns us quick results. You can further modify the above script to get additional details for your server as well.

Here are few additional scripts which also discusses the various concepts related to AlwaysOn.

If you have any other interesting script, please let me know and I will be happy to publish on the blog with due credit to you.

Reference: Pinal Dave (https://blog.SQLAuthority.com)

First appeared on SQL SERVER – Scripts to Overview HADR / AlwaysOn Local Replica Server

SQL SERVER – How to Fix log_reuse_wait_desc – AVAILABILITY_REPLICA?

$
0
0

Earlier this week I had multiple engagements of Comprehensive Database Performance Health Check. While working with one of the customers we realized that when we query sys.databases for one of the databases, we always see column log_reuse_wait_desc containing reasons  AVAILABILITY_REPLICA. The customer was really curious about what it means. Let us see what we found out after quick research.

SQL SERVER - How to Fix log_reuse_wait_desc - AVAILABILITY_REPLICA? AlwaysOn

First of all, run the following script

SELECT name, log_reuse_wait_desc
FROM sys.databases

Above script will return the name of the database along with the log_reuse_wait_desc. The column displays the reason of transaction log space is currently waiting on to clear. If you see it containing AVAILABILITY_REPLICA, that means an AlwaysOn Availability Groups secondary replica is applying transaction log records of this database to a corresponding secondary database. In another word, your secondary database is being synced at that moment.

There can be multiple reasons for why this particular wait type may show up. Let me quickly list all the reasons here:

Reason 1: Slow Network or Unreachable Network

In this case, you may want to check with your network admin and check the reasons for the slow network. One of my customers had incorrectly configured network card once was slowing down the syncing.

Reason 2: Long Running Transactions

Sometimes it is quite possible you will see both the primary and secondary database both synced but still you will see the log_reuse_wait_desc displaying AVAILABILITY_REPLICA. In that case, it is quite possible that on the primary server there is a long-running transaction, which is currently actively writing in the log file which is yet not shipped to secondary.

Reason 3: Resource Constraint

In a rare incident, it is quite possible that sometimes on the secondary we run out of the worker thread. In that case, you can either restart the sync or if that works, you may have to reset the sync from the beginning.

Well, so far I have found realized that there can be any one of the reasons listed above can be the cause of the AVAILABILITY_REPLICA as a log_reuse_wait_desc. Let me know if you find out any other reasons and solutions for the same.

Reference: Pinal Dave (https://blog.SQLAuthority.com)

First appeared on SQL SERVER – How to Fix log_reuse_wait_desc – AVAILABILITY_REPLICA?

SQL SERVER – Error 21028 : Replication Components are not Installed on This Server

$
0
0

One of my clients, for whom I installed SQL Server and configured AlwaysOn came back to me with an error message. While trying to configure replication they were getting an error message. In this blog, we would learn how to fix error “Microsoft SQL Server Management Studio is unable to access replication components because replication is not installed on this instance of SQL Server”

Here is the exact error message which they received when they tried configuring distributor.

Microsoft SQL Server Management Studio is unable to access replication components because replication is not installed on this instance of SQL Server. For information about installing replication, see the topic Installing Replication in SQL Server Books Online.

ADDITIONAL INFORMATION:
Replication components are not installed on this server. Run SQL Server Setup again and select the option to install replication. (Microsoft SQL Server, Error: 21028)

SQL SERVER - Error 21028 : Replication Components are not Installed on This Server repl-missing-01

WORKAROUND/SOLUTION

As the message says, we need to install replication feature. Since SQL Server product is already installed, we need to “add” replication feature to an existing SQL.

Here are the steps to add the feature.

  1. Launch SQL Server Installation Center and choose below option.
    SQL SERVER - Error 21028 : Replication Components are not Installed on This Server repl-missing-02
  2. Keep the following wizard and here is the screen where you need to make a change in selection. We need to choose the second option and select the instance name.
    SQL SERVER - Error 21028 : Replication Components are not Installed on This Server repl-missing-03
  3. And as mentioned in error message, add replication as shown below.
    SQL SERVER - Error 21028 : Replication Components are not Installed on This Server repl-missing-04
  4. And this is how it should end.
    SQL SERVER - Error 21028 : Replication Components are not Installed on This Server repl-missing-05

All is well that ends well.

Hope this would help some new DBA to fix the error. Please comment and let me know if this was useful.

Reference: Pinal Dave (https://blog.sqlauthority.com)

First appeared on SQL SERVER – Error 21028 : Replication Components are not Installed on This Server


SharePlex – Efficient and High Performance Replication from Oracle to Kafka

$
0
0

Ask any DBA what is their dream infrastructure and I promise you that they will narrate immediately a story which will be centered around no downtime and amazing performance. However, when you ask them if they know what exactly will make them happy as well as run their business most efficient, why are they not going for it? The usual answer is budget. If we ask DBA to presume there is an infinite budget the next answer is Good Tool. In this blog post, we will discuss how we can replicate data from Oracle to Kafka and efficiently and quickly.

SharePlex - Efficient and High Performance Replication from Oracle to Kafka oracletokafka

What is Kafka?

Kafka is used in the real-time streaming data architectures to provide real-time analytics. It is a fast, scalable, robust, fault-tolerant messaging system. If you are familiar with RabbitMQ or AMQP, Kafka can be used as their replacement.

Kafka is known in the recent time for its reliability and higher throughput. In the real world, I have seen very high adoption of Kafka where there are stream processing, high-speed filtering, and pattern matching.

The primary reason for its popularity is easy to use along with it is free and open source.

From Oracle to Kafka – SharePlex

If you are familiar with the Oracle Eco-system, it is very clear that you need a connector when you have to use Oracle to Kafka. I have personally used quite a few connectors where I have to move my data. However, I realized that is not that easy to configure something which can move my data from one source to another source when it is about high transactions streaming data. After long research, I finally have figured out a good replication tool which not efficient but also provides a high performance – SharePlex.

SharePlex for Oracle is a very stable, robust, high-performance, high-availability technology that offers a low-cost alternative to other Oracle replication tools. In addition to the replication, it also provides data compare, repair, in-flight data integrity, in addition to monitoring and alerting.

Why SharePlex?

As I mentioned earlier, I have used many different products including GoldenGate to replicate data from Oracle. I particularly prefer SharePlex over GoldenGate because of many reasons. SharePlex supports Oracle Standard Edition (SE) as well as Enterprise Edition (EE).

Data Accuracy and Integrity – When replicating data across Oracle to Kafka it is very critical that data accuracy is maintained along with peer-to-peer monitoring and conflict detection & resolution.

Improved Performance – SharePlex offloads process-intensive reports outside the main production database server. This helps to improve the overall network performance without increasing resource consumption on the primary database.

Better Price Point – Cost is always a concern and when SharePlex is compared with another similar tool, it is quite inexpensive and also provides lots of value adds.

Next Action Point

If you need to replicate your data from Oracle to Kafka, I strongly suggest you try out SharePlex as it provides zero downtime and zero data loss. Try out SharePlex Now.

Reference: Pinal Dave (https://blog.sqlauthority.com)

First appeared on SharePlex – Efficient and High Performance Replication from Oracle to Kafka

SQL SERVER – Error 9002: The Transaction Log for Database ‘SQLAuthority’ is Full Due to ‘REPLICATION’

$
0
0

Recently one of my clients contacted me to provide them assistance in finding and fixing the cause of a huge transaction log file. There are many caused to get error 9002 in SQL Server ERRORLOG. In this blog, I would explain the cause and fix of error: The transaction tog for database ‘SQLAuthority’ is full due to ‘REPLICATION’.

SQL SERVER - Error 9002: The Transaction Log for Database 'SQLAuthority' is Full Due to 'REPLICATION' full-due-to-replication-800x247

I joined a call with them and ran a few queries to know the state of the database. I always start with the below query.

SELECT name, log_reuse_wait_desc
FROM sys.databases
where name = 'Database_Name'

Here is the complete list as of today from books online. Here are the various values which can be seen in log_reuse_wait_desc in sys.databases catalog view.

  • NOTHING
  • CHECKPOINT
  • LOG_BACKUP
  • ACTIVE_BACKUP_OR_RESTORE
  • ACTIVE_TRANSACTION
  • DATABASE_MIRRORING
  • REPLICATION
  • DATABASE_SNAPSHOT_CREATION
  • LOG_SCAN
  • AVAILABILITY_REPLICA
  • OLDEST_PAGE

In my client’s case, I was seeing “REPLICATION”.

When I queried sys.databases to know about replication using the following query:

SELECT [is_published]
	,[is_subscribed]
	,[is_cdc_enabled]
FROM sys.databases
WHERE name = 'Database_Name' 

I saw this

SQL SERVER - Error 9002: The Transaction Log for Database 'SQLAuthority' is Full Due to 'REPLICATION' log-reuse-repl-01

That was weird! Based on my discussion with them at some point they did try to do a replication. They created a publication but no subscription. When I checked, I found that the log reader job was not running. That explains the cause of the full transaction log.

Fundamentally, SQL Server would keep the data in the transaction log and won’t allow truncation until data is replicated or picked by Log Reader Agent.  You may run into the same issue as there are errors encountered by the log reader agent job.

WORKAROUND/SOLUTION – Full Due to Replication

Since there was no subscriber configured, they were confident enough that we should remove it and it won’t break anything. We attempted to use SQL Server Management Studio to drop the publication, but it was taking a long time. Finally, it got removed but we were still seeing REPLICATION wait. I also used sp_removedbreplication to clean it up. After that, I took transaction log backup and checked log_reuse_wait_desc and it was NOTHING.

After that, I was able to shrink the log file. Here is one of my earlier posts which has a script to shrink the log file of all databases.

DECLARE @ScriptToExecute VARCHAR(MAX);
SET @ScriptToExecute = '';
SELECT
@ScriptToExecute = @ScriptToExecute +
'USE ['+ d.name +']; CHECKPOINT; DBCC SHRINKFILE ('+f.name+');'
FROM sys.master_files f
INNER JOIN sys.databases d ON d.database_id = f.database_id
WHERE f.type = 1 AND d.database_id > 4
-- AND d.name = 'NameofDB'
SELECT @ScriptToExecute ScriptToExecute
EXEC (@ScriptToExecute)

Well, this is how we fixed the Error 9002: The Transaction Log for Database ‘SQLAuthority’ is Full Due to ‘REPLICATION’.

Have you seen such an unexplained situation with SQL Server? Please comment and let me know.

Reference: Pinal Dave (https://blog.sqlauthority.com)

First appeared on SQL SERVER – Error 9002: The Transaction Log for Database ‘SQLAuthority’ is Full Due to ‘REPLICATION’

What is Transactional Replication Supported Version Matrix? – Interview Question of the Week #274

$
0
0

Question: What is the Transactional Replication Supported Version Matrix?

Answer: Most of the projects I do are about Comprehensive Database Performance Health Check. When we start a new project we have limited data and our workflow is not intense. However, I often like to get involved with projects which are not related to performance tuning when I have enjoyed working with them earlier.

What is Transactional Replication Supported Version Matrix? - Interview Question of the Week #274 Supported-Version-800x272

Recently, while working on the health check project, one of the realizations which we had with our client was that we need to have another instance of our server where we can forward our read requests. Now the ideal solution was to configure AlwaysOn but that was not something would work out due to licensing issues of the version which the client had available. Additionally, the need for the data was near real-time hence we can’t do the traditional backup/restore or log shipping.

After carefully thinking we decided to opt for the replication. When we started to work with the replication the very first question raised was about the supported version for the transactional replication.

The rules for the supported versions are pretty simple and clearly written on the Replication Backward Compatibility.

The rules for transactional replications are:

  • A Distributor can be any version as long as it is greater than or equal to the Publisher version
  • A Publisher can be any version as long as it less than or equal to the Distributor version
  • A Subscriber to a transactional publication can be any version within two versions of the Publisher version

In short:

  • Publisher version <= Distributor version
  • Subscriber (two versions) => Publisher or Subscriber (two versions) <= Publisher

For example, our client was using SQL Server 2012 for a publisher. We can use either SQL Server 2012, 2014, 2016, 2017 or 2019 as a distributor and SQL Server 2008/R2, 2012, 2014, or 2016 as a subscriber. You can see the complete matrix over the Transactional Replication Matrix.

Reference: Pinal Dave (http://blog.SQLAuthority.com)

First appeared on What is Transactional Replication Supported Version Matrix? – Interview Question of the Week #274

SQL SERVER – Renaming distributor_admin Bad Idea

$
0
0

A client of Comprehensive Database Performance Health Check, recently send me an email after reading best practices about username and logins in SQL Server. Let us discuss today why Renaming distributor_admin Bad Idea.

SQL SERVER - Renaming distributor_admin Bad Idea Renaming-800x253

My client was doing a security audit of their system and they ended up finding a few usernames and logins which they were not using or familiar with. One of the accounts they found was distributor_admin. This account had sysadmin rights. They wanted to rename it as they found in their error log failed access to login via this account. Here is my suggestion.

One should not rename this account as it is a system account and there may be some dependency if you have already set up replication. If you do not have replication, you can easily disable this account. If you have replication, you can change the configuration of this account in such a way that it only has access to create linked servers and not the system admin or owner.

It is not a good idea to rename any system objects or account and in particular Renaming distributor_admin Bad Idea. However, this advice does not apply to SA account. You can always rename your SA account and here is the blog post for the same: Can Admin Rename SA Account in SQL Server? – Interview Question of the Week #256.

If you have any questions, you can always reach out to me on Twitter.

Reference: Pinal Dave (http://blog.SQLAuthority.com)

First appeared on SQL SERVER – Renaming distributor_admin Bad Idea

Viewing all 19 articles
Browse latest View live