Quantcast
Channel: SQL Server Replication forum
Viewing all 4054 articles
Browse latest View live

Powershell help for sql server

$
0
0
Hi All,

I wanted to load windows application log into sql server table. I am using below command but it was throwing error.
Can anyone help me on how to fix this problem.

Followed below article to load the windows event log to a table. I created below table and ran below powershell command
https://www.red-gate.com/simple-talk/blogs/storing-windows-event-viewer-output-in-a-sql-server-table-with-powershell/

CREATE TABLE [dbo].[EventViewer]
(
        [Index] [int] NULL,
        [Time] [datetime] NULL,
        [EntryType] [varchar](MAX) NULL,
        [Source] [varchar](MAX) NULL,
        [InstanceID] [varchar](MAX) NULL,
        [Message] [varchar](MAX) NULL
  )
GO


Get-EventLog   -ComputerName  <machine name>  -LogName  Application -After  "30-03-2020" |  select  index,TimeGenerated,EntryType,Source,InstanceID,Message | Out-DataTable | Write-DataTable -ServerInstance<machine name> -Database master -TableName EventViewer


Error message

Out-DataTable : The term 'Out-DataTable' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:159
+ ... Generated,EntryType,Source,InstanceID,Message | Out-DataTable | Write ...
+                                                     ~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Out-DataTable:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException


Powershell version
====================
PS C:\> Get-Host | Select-Object Version                                                                               
Version
-------
5.1.18362.628

Regards,
Sam

Managing space used by 'Change Tracking'

$
0
0
Hi there,
we're using SQL 2008 Change Tracking on some of our databases (Full and Express). I've been told in another thread that Change Tracking counts as part of user data (which is relevant for Express as it counts towards the 2Gig limit), and it was suggested to follow up in this forum.

We are concerned about the amount of space that Change Tracking is using, and the fact that it is rather opaque as to the 'cost' of enabling change tracking.

Is there any published data as to how change tracking is stored, or some formula that would help calculate the cost (eg. days/changes/columns etc)?

I do think it is a bit rough counting change tracking as user data if there isn't an easy way to determine ahead of time how much space it will consume.

-dave


Need to restore a backup on a different drive letter

$
0
0

I have a backup file of a database (approx. 60GB) on drive letter D.

My existing SQL Server instance sits on drive letter C.  Only 20GB is left on this drive.

I want to restore and attach the backup to this to the SQL server instance on C and keep the restored database on the D drive.

Any suggestions? 

Thanks.

Article addition causes severe locking,High waiting task in SQL server 2016 Transactional Replication

$
0
0

Problem Description:

Unusual High Waiting Tasks & Sudden dip in CPU usage with lots of locking while try to add an article Table(s) in an existing Transactional Replication publication which was either initiated from snapshot or initiated from Backup in SQL server 2016 Enterprise edition, it was further observed that articles don’t get replicated after successful generation of snapshot if the distribution agent is in running condition during snapshot generation.

Environment details:

  1. 24 cores of physical machines.
  2. Issue experience on both version of SQL mentioned below
    1. Microsoft SQL Server 2016 (SP1) (KB3182545) - 13.0.4001.0 (X64)  Oct 28 2016 18:17:30   Copyright (c) Microsoft Corporation Enterprise Edition (64-bit) on Windows Server 2012 R2 Standard 6.3 <X64> (Build 9600:)
    2. Microsoft SQL Server 2016 (SP1-CU7-GDR) (KB4057119) - 13.0.4466.4 (X64) Enterprise Edition (64-bit) on Windows Server 2012 R2 Standard 6.3 <X64> (Build 9600)
  3. SQL Server detected 4 sockets with 6 cores per socket and 6 logical processors per socket, 24 total logical processors; using 20 logical processors based on SQL Server licensing

Findings

execsp_helppublication‘Publication Name’

immediate_sync bit        allow_anonymous bit

0                                                                    0

Database size:

 512 GB

Replicated Articles size:

Problem arises irrespective of size of replicated article

------- SpWho2  'Active' Result during snapshot generation

Culprit ID : 6902

6902      SUSPENDED    DBNAME(XXX)       UNKNOWN TOKEN       10142    1455      10/20 10:05:02  Publication Name(XXXXXX\XXXXXX-XXXX-PUB__XXX__REPORTING__ALL__TAB-8)

------- DBCC INPUTBUFFER (6902)

sys.sp_MSactivate_auto_sub;1

-------- Individual Culprit Query

--EXEC %%Object(MultiName = @qualified_name).LockMatchID(ID = @object_id, Exclusive = 1, BindInternal = 0) 

-------- Parent Procedure

 --create procedure sys.sp_MSsetfilteredstatus @object_id int, @forceset bit = 0 as      declare @qualified_name nvarchar(517)       ,@retcode int        ,@setFlag bit   ,@pkkey sysname    ,@source_table sysname   ,@fcdc_tracked bit         exec @retcode = sys.sp_MSreplcheck_publish     if @@ERROR <> 0 or @retcode <> 0         return(1)        exec sys.sp_MSget_qualified_name @object_id, @qualified_name output       BEGIN TRANSACTION   declare @cdc_tracked_tables table (object_id int)     if object_id('cdc.change_tables') is not null   begin   insert @cdc_tracked_tables select distinct source_object_id from cdc.change_tables  end   if (@@rowcount = 0)    set @fcdc_tracked = 0   else    set @fcdc_tracked = 1        if not (@qualified_name is null)     begin          EXEC %%Object(MultiName = @qualified_name).LockMatchID(ID = @object_id, Exclusive = 1, BindInternal = 0)         if @@error <> 0             select @qualified_name = null      end       if @qualified_name is null      begin         raiserror(18750, -1, -1, 'sp_MSsetfilteredstatus', 'object_id');         goto error_abort_exit      end       if exists( select * from sys.objects where type = 'RF' and parent_object_id = @object_id )       or exists( select * from sysarticles A join syspublications P on A.pubid = P.pubid where A.objid = @object_id and (P.allow_queued_tran = 1 or P.allow_sync_tran = 1))       or exists( select * from sysarticles where objid = @object_id and (upper(upd_cmd) like 'CALL%' OR upper(upd_cmd) like 'XCALL%' ) )       or exists( select * from sysarticles where objid = @object_id and (upper(del_cmd) like 'XCALL%' ) )       or exists( select * from sysarticles sa, syssubscriptions ss where sa.objid = @object_id and sa.artid = ss.artid and ss.status = 3)       or @forceset = 1      begin         EXEC %%Relation(ID = @object_id).SetHasFilterProc(Value = 1)      set @setFlag = 1      end     else       begin   if (@fcdc_tracked = 0)         EXEC %%Relation(ID = @object_id).SetHasFilterProc(Value = 0)      set @setFlag = 0      end    --set/reset IsLoggedForRepl for all replicated column (except legacy blobs) depand on if has_replication_filter is set  --this controls logging behavior of offrow columns in deletes     --don't clear the bits if table is still being tracked by cdc  if(@setFlag = 1 or @fcdc_tracked = 0)   begin   declare #hpk cursor local fast_forward for     select name from sys.columns where object_id = @object_id and is_replicated = 1       and system_type_id not in (34, 35, 99) --image, text. ntext      and user_type_id not in  (34, 35, 99) --image, text. ntext   open #hpk    fetch #hpk into @pkkey   while (@@fetch_status = 0)    begin    EXEC %%ColumnEx(ObjectID = @object_id, Name = @pkkey).SetLogForRepl(Value = @setFlag)    IF @@ERROR <> 0     BEGIN     select @source_table = object_name(@object_id)     RAISERROR(15052, -1, -1, @source_table)     return 1     END         fetch #hpk into @pkkey    end   close #hpk    deallocate #hpk             --in case of turning of has_replicate_filter, make sure IsLoggedForRepl is still set for base of pk/computed pk columns   if(@setFlag = 0)    begin    exec @retcode = sp_MSSetLogForRepl @object_id       if @@ERROR <> 0 or @retcode <> 0           return(1)    end   end     COMMIT TRANSACTION      return (0)   error_abort_exit:      IF @@TRANCOUNT = 1         ROLLBACK TRAN      ELSE COMMIT TRAN     return (1)       

Snaps during problem

  • Body text cannot contain images or links until we are able to verify your account.


Can I combine FCI with Replication?

$
0
0

We have replication in place. A publisher and a subscriber(read-only). No High availability set up as of now. 


We are planning to have Failover cluster Instance with MSSQL 2016 standard edition. 

We also need a read-only copy. Will it be possible to have replication (for a read-only copy) on top of FCI. Please suggest.

Any pointers to some articles would be great too! 

Thanks in advance



Question on MAXDOP setting

$
0
0

Hi All,

On one of our newly migrated sup-prod azure vm which is running on SQL Server 2012 EE, we are seeing high 100% CPU. On further looking at server parameters, we see that "maxdop=0" and "cost threshold for parallelism=5" which is by default. From task mgr and perfmon it is evident that sustained 94% of CPU is driven by SQL Server. The VM has 1 socket 8 logical cpu's. Also, CXPACKET is the top 2 contibutor of waits (i..e 75%). Its an OLTP application. So, we tweaked the values as follows :

maxdop set to 4 and cost threshold for parallelism is set to 50.

Now question, is does it apply for ongoing processes /currently running spids?
or these settings will be available for newly spawned threads?
Reason for asking this question is, even after making this changes, still we are seeing sustained high cpu with little difference of 1 or 2 percent.

Regards,
Sam

SQL Server 2019 snapshot agent error

$
0
0

Hello,

I was trying to configure an SQL Server 2019 transactional replication, but the snapshot agent returns the following error:

Error messages:
Message: An unspecified error had occurred in the native SQL Server connection component.
Stack:    at Microsoft.SqlServer.Replication.Snapshot.SqlServer.NativeBcpOutProvider.ThrowNativeBcpOutException(CConnection* pNativeConnectionWrapper)
   at Microsoft.SqlServer.Replication.Snapshot.SqlServer.NativeBcpOutProvider.ThrowConnectionFailureException(CConnection* pNativeConnectionWrapper)
   at Microsoft.SqlServer.Replication.Snapshot.SqlServer.NativeBcpOutProvider.InitializeNativeBcpOutProvider(LogMessageCallback logMessageCallback, String strName, String strApplication, String strHost, String strServer, String strNetwork, Int32 encryptionLevel, String strDatabase, SecurityMode securityMode, String strLogin, SecureString strPassword, Int32 bcpBatchSize, Int32 loginTimeout, Int32 queryTimeout, Int32 packetSize, DeadlockPriority deadlockPriority, String strRowDelimiter, String strFieldDelimiter, Byte syncMethod, Boolean forceOdbcBcp, Boolean forceOleDbBcp, Boolean enableMultipleActiveResultSets, Boolean useReadPastHint, Boolean usePageLockHint, Boolean securePassword)
   at Microsoft.SqlServer.Replication.Snapshot.TransSnapshotProvider.InstantiateBcpOutProviderWorker(String strBcpConnectionName)
   at Microsoft.SqlServer.Replication.Snapshot.SqlServerSnapshotProvider.InstantiateBcpOutProvider(String strBcpConnectionName)
   at Microsoft.SqlServer.Replication.Snapshot.SqlServer.BcpOutThreadProvider.Initialize()
   at Microsoft.SqlServer.Replication.WorkerThread.NonExceptionBasedAgentThreadProc()
   at Microsoft.SqlServer.Replication.AgentCore.BaseAgentThread.AgentThreadProcWrapper() (Source: MSSQL_REPL, Error number: MSSQL_REPL55012)
Get help: http://help/MSSQL_REPL55012

Any idea why?

Best regards,

José Cruz

In Replication, I want only 2 columns of a table to be replicated to subscriber

$
0
0
In Replication, I want only 2 columns of a table to be replicated to subscriber.Is it possible?How to do it?

Kiran


Fixing Latency

$
0
0
There is no latency between publisher and distributor. However, there is latency between distributor to subscriber. How to fix this latency?

Kiran

Minimizing Locks during Transactional replication Snapshots - I'm running out of hair to pull

$
0
0

Found this while reading about Concurrent Snapshots

"Foreign key constraints, check constraints, and triggers at the Subscriber do not require the NOT FOR REPLICATION option because they will be disabled during the concurrent snapshot generation and will be enabled after the snapshot is generated".

Disabled where at the publisher?  Surely this would involve a significant amount of locking to accomplish and would explain the Blocking and Deadlocks I have been getting while attempting to generate a partial Snapshot.  Is this still the case with SQL2012 and later?

Is there a deep dive into the Snapshot process and locks it takes?

Here are my settings.  Can you spot any glaring mistakes?  Is there more I can do to prevent locking/blocking on my publisher during full and partial snapshots?  All I can think of now is that I should haveMaxBcpThreads at 16 or something to minimize the time it takes to create the BCP files for each article. 

:SETVAR filterClause 1=1-- 1=0 no rows to move just structure for Fast Staging DW Build and compare
:SETVAR MaxBcpThreads 1-- Used to set the Agent Profile for the Snapshot Agent.  Set to 1 for Prod to avoid the locking we saw using the default since Sql Server 2012
:SETVAR SyncMethod Concurrent-- Concurrent Concurrent for Tx Minimal Locking on Snapshot Single Thread Distribution;


exec sp_addpublication @Publication=N'$(PublicationName)', 
@description = N'Transactional publication of database ''$(PublicationDatabaseName)'' from Publisher ''$(PublicationServerName)''.',
@sync_method = N'$(SyncMethod)',   -- Concurrent for Tx publ only is Native Mode with no Locks;  
 @retention = 0, 
 @allow_push = N'true',  
 @allow_pull = N'false',-- May 2015 Should this not be false?  not sure what impacts this might have on locking
 @allow_anonymous = N'false',     -- Must be False to have immediate_sync be false which is important (see immediate sync)
 @enabled_for_internet = N'false', 
 @snapshot_in_defaultfolder = N'true', 
 @compress_snapshot = N'false', 
 @ftp_port = 21, @ftp_login = N'anonymous', 
 @allow_subscription_copy = N'false', 
 @add_to_active_directory = N'false', 
 @repl_freq = N'continuous', 
 @status = N'active', 
 @independent_agent = N'true', 
 @immediate_sync = N'false',    -- *** use false to support Delta Snapshots.  
 @allow_sync_tran = N'false', 
 @autogen_sync_procs = N'false', 
 @allow_queued_tran = N'false', 
 @allow_dts = N'false', 
 @replicate_ddl = 1,-- *** To replicate DDL changes such as Column Changes to existing Tables.  FKs and Defaults suppressed by the Schema_Option 0x200, 0x800 in sp_addArticle calls
 @allow_initialize_from_backup = N'true', 
 @enabled_for_p2p = N'false', 
 @enabled_for_het_sub = N'false'

As for my articles I do this for all of them

exec sp_addarticle @Publication=N'$(PublicationName)',@Filter_Clause = '$(FilterClause)',  @article = N'Attachments', @source_owner = N'dbo', @source_object = N'Attachments', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x00000004080350DF, @identityrangemanagementoption = N'manual', @destination_table = N'Attachments', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false',  @ins_cmd = N'CALL [dbo].[sp_MSins_dboAttachments]', @del_cmd = N'CALL [dbo].[sp_MSdel_dboAttachments]', @upd_cmd = N'SCALL [dbo].[sp_MSupd_dboAttachments]'

@schema_option

--HexValueSchema Options Enabled
--0x01 Generates object creation script
--0x02 Generates procs that propogate changes for the article
--0x04 Identity columns are scripted using the IDENTITY property
--0x08 Replicate timestamp columns (if not set timestamps are replicated as binary)
--0x10 Generates corresponding clustered index
--0x40 Create corresponding nonclustered indexes
--0x80 Replicate pk constraints
--0x1000 Replicates column-level collation
--0x4000 Replicates UNIQUE constraints
--0x010000 Replicates CHECK constraints as NOT FOR REPLICATION so are not enforced during sync
--0x020000 Replicates FOREIGN KEY constraints as NOT FOR REPLICATION so are not enforced during sync
--0x08000000 Creates schemas not present on subscriber
--0x0400000000Replicates compression option for data & indexes

Any suggestions as to what to try next to avoid Blocking/Deadlocks?


...Ray

Adding article to transactional replication causing blocking - schema mod lock

$
0
0

We have a transaction replication initialized from backup on a highly transactional OLTP database. When we add new articles(either from SSMS or using T-SQL) it causes massive blocking as the adding of the article process is trying to acquire schema mod lock on all the articles in the publication and not just the one that is being added.  Since we are replicating the entire database, it essentially is trying to lock the entire database exclusively when running  sp_addsubscription 

Note: The issue is with sp_addsubscriptionsp_addarticle just needs schema mode lock on the article that is being added. But sp_addsubscription needs schema mod lock on all the existing articles in the publication. This is also true when trying to add article via sp_addarticle and then sp_refreshsubscriptions.

Does anyone know if this can be avoided?

T-SQL Script used for adding new article:

exec sp_addarticle @publication = N'blocking',@article = N'rep6',@source_owner = N'dbo',@source_object = N'repl6',@type = N'logbased',@identityrangemanagementoption = N'manual',@destination_table = N'repl6',@destination_owner = N'dbo'EXEC sp_addsubscription@publication ='blocking',@article = N'rep6',@subscriber ='sql3\s14',@destination_db ='repl2',@sync_type = N'replication support only'


Replication on SQL Server Always on with failover functionality in SQL Server 2012

$
0
0

Is there a way to setup replication on Always on with full failover functionality in SQL 2012? 

AFAIK distributor DB cannot be replicated in SQL 2012 hence it would be little tricky to implement TRN replication on SQL 2012. 

I have a three node cluster with node in a different subnet.

 


Regards, Ashif Shaikh

Re-Sync Bi-Directional Tran Replication

$
0
0

I have a setup of Bi-Directional Tran Replication of database "XYZ" between servers "A" and "B".  We believe the databases are out of sync.  However, some data in each database "XYZ" (on servers "A" and "B") is "the latest". 

How do I re-sync this replication?

Best option for SQL Server log shipping for disaster recovery in the cloud?

$
0
0

We have a standard license, the enterprise licenses is too expensive for a company of this size at 20K a license, so we'd be looking at 40K just for two licensed servers plus hardware, so always on availability groups are out.

Log shipping to AWS S3 or EC2 or even Azure seems like the other alternative. Anyone done this before and know which service is best/most cost effective for this?

Have you used AWS RDS for log shipping SQL Server as a fail over environment?

$
0
0

Our on prem SQL 2014 instance with standard license doesn't have Always on Availability groups. We don't want to spend the money to upgrade to an enterprise license or get more servers and another SAN for a geo cluster or other HA solution.

I'm looking at AWS RDS services with a standard license, has anyone used this successfully with log shipping? What have been your costs and experiences?


2 Way replication issue faced of records skipping/not replicating.

$
0
0
We have a replication setup wherein data entry is done at head office and also at multiple branch locations; data replicates from h.o. to multiple branch locations; also data entry done at branch locations gets replicated back at h.o. location and from h.o. replicates to all branches so that each branch can see other branch data as well as h.o. data.

Many times issue faced is that a) even though; the replication monitor does not show any issue; but few records are skipped while replicating from say branch A location to h.o.

b) at other times issue faced is that even though data from say branch A comes to h.o.; it does not replicate to branch B.

Thanks in advance.

Shrink Database on a DB flagged for replication. Thoughts?

$
0
0

Fellow SQLers

1- Database A is the primary databse, it is replicated to database B on another server.

2 - We need to do a LOT of purging on the A db. About half the data. So the USED amount of space will drop from 780 GB to about 400 GB.

3 - I WILL HAVE an outage window of over 24 hours.

There are number of performance hits and observcations here. 

1 - Left as is, the massive deletes will be replicated.

2 - Blocking will not be an issue because I have an outage window where apps will not be hitting the db.

3 - When done, we want to free up the unused space on A. Due to processing changes, it will be unlikely it will grow back that big again and we can use the space. So this shrink scenario makes sense.

My question is the best way around this?

To me, it appears that the easiest approach might be to cease all replication. Do the deletes on A. Do the shrink on A. Then reinitialize the snapshot to B.  thoughts?

Thanks

MG

Replication distribution database in Always On availability group

$
0
0

Hi,  Configured distributor  in Availability Group, there are 2 replicas for distributor server,configured listener name. When I create a publication , snapshot agent is created with Primary Replica Instance name in the Snapshot Agent Job step 2, however Log reader agent job is getting created with Distributor Listener name in the Log Reader Agent Job Step 2. 

How can I force the snapshot agent to use listener name instead of using Instance name of the primary replica. 

This is how snapshot agent is getting created, which will not work once I fail-over the distributor, since primary role will change, I want Listener name in the Distributor Parameter.

-Publisher [Publisher/InstanceName] -PublisherDB [Data] -Distributor [DISTRIBUTOR/InstanceName] -Publication [TestPub] -DistributorSecurityMode 1

Even If I change the Distributor to Listener Name, I am losing those changes once I fail-over the distributor.

Please advise any ideas on how I can fix this.

Thanks


Failure on Replication Insert cause a rollback on Pub?

$
0
0

Fellow SQLers,

We have a transactional replication setup.  The pub going to just one Subscriber - push process on the same box.

we had an insert failure into the subscriber. We can replicate it and we know why - it was tied to the settings setting up the publication.

The record count on the pub table and the sub table were the same before the insert transaction and after the insert transaction.

1 - Is it correct that if the replication part failes on the sub that the transaction on the pub will be rolled back under this type of replication?  I have different opinions on this but this scenario seems to prove it does.

2 - If the answer to 1 is Yes, then it would be interprettted that the transaction is not truly committed for the entire process until the replicated step is clean. Correct?

Thanks,

MG

Database compatibility level and 2 version limit in SQL Server replication

$
0
0
Greetings, does database compatibility have anything to do with the 2 version limitation in a replication topology? For instances a SQL Server 2008 R2 instance with a publisher having an 80 compatibility level, publisher having a 100 compatibility level, multiple subscribers one having a 120 compatibility level or is that requirement only for the instance database server version?
Viewing all 4054 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>