Link to home
Create AccountLog in
Microsoft SQL Server

Microsoft SQL Server

--

Questions

--

Followers

Top Experts

Avatar of marrowyung
marrowyung

the CDC and replication makeMSSQL user database log keep growthing
hi all,

from time to time we will see a CDC (change data capture) in MSSQL, when running with replication, around every 6 months, will make the user database's log file growth too large and can't come down in size any more.

the pattern is :
1) whenever the SQL job csc.<user database>_capture job STOPPED, this is a clear indicator that something went wrong, the <user database> log file size will be very large.
2) we then verify if it is the problem by running this:

select log_reuse_wait_desc,name, log_reuse_wait from sys.databases;

Open in new window


we should then we in the log_reuse_waiting_desc column, next to our user database, will show REPLICATION instead of ACTIVE_TRANSACTION.

3) we will see if the user database log size increase dynamically to make log disk full.
4) we also run this:

DBCC SQLPERF(logspace)

Open in new window


to see "log Space Used [%]" if it is 99% >.

5) we will finally use

 DBCC OPENTRAN(<user database>) 

Open in new window

to see if the oldes non-distributed LSN of a transaction has been hold there for a long time and number never change:

Oldest active transaction:
    SPID (server process ID): 158
    UID (user ID) : -1
    Name          : user_transaction
    LSN           : (631159:27303:3)
    Start time    : Jun 25 2015  5:40:47:817AM
    SID           : 0x010500000000000515000000c5369faad8bb12aa5e06187c0d040000
 
Replicated Transaction Information:
        Oldest distributed LSN     : (0:0:0)
        Oldest non-distributed LSN : ([b]631159:25862:1[/b])
DBCC execution completed. If DBCC printed error messages, contact your system administrator.

Open in new window


, then we know there is the CDC and replication both work together to make log size can't come down at all.

solution:

we can only:
1) Make sure that the CDC capture job method above can start again, once start it will keep starting and run by itself.
2) we will run this:

sp_replflush

sp_repldone null, null, 0,0,1

sp_replflush

Open in new window


3) once it is flushed, we can the shrink  the log by release space only.

this is how we due with it but how you guys handle it in a much robust way ? can automate the whole solution so we this problem will be fixed when system detect it ?

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Vitor MontalvãoVitor Montalvão🇨🇭

Are you performing regular transactional log backups on the database?

SOLUTION
Avatar of Máté FarkasMáté Farkas🇭🇺

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of marrowyungmarrowyung

ASKER

Vitor,

no. I knew this question is tough and some DBA who was left leave down notes on who to troubleshoot it and we can only follow.

it works all the time except, once start the CDC jobs, we need to wait for 30 minutes before we can run this:

sp_repldone null, null, 0,0,1

or it will not works.

Mate.

we are using bidirectional merge replication.

Mate,

"• It seems to me that replication does not work properly because log reader should execute automatically and regularly the sp_repldone stored procedure. Check this."

is that mean the replication can not replicate as efficient as possible?

https://social.msdn.microsoft.com/Forums/sqlserver/en-US/1b55cd9c-129c-4b2b-97fb-bd1fdf71bae3/using-sprepldone-to-clear-the-replication-transaction-queue?forum=sqlreplication

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


I think you have experience enough to know that if you don't backup the transaction log regularly it will grow and consume the disk space. If you don't do that then we can't help you much here.

Victor,

you are talking about if we have log backup we will not have this problem.

I can tell you only this server has this problem as only this server has CDC on together with replication.

the steps about is researched by many DBA in our company before and it seems it is the only solution for that.

 I can tell you when this happening, we can't shrink log at all. the CDC and replication will keep locking the log file.

so this is not about the log file big or not, it is about if we don't fixed the CDC the log will keep growth until we execute the command above.

When you use CDC and replication together then replication agent reads a log for both features. So CDC agent must be deactivated and replication agent must be activated.
Then replication agent will truncate the log with sp_repldone.
I suggest to build up again the whole replication and CDC and you have to configure replication first and then CDC.

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


You said:
"when running with replication, around every 6 months, will make the user database's log file growth too large and can't come down in size any more."
There's no way to shrink a transaction log file without backup it first.

I can tell you only this server has this problem as only this server has CDC on together with replication.
That's because Merge Replication needs CDC.

Victor,

"There's no way to shrink a transaction log file without backup it first."

I mean withtout this problem, the size of the log very stable.

you know if we rebuild index at the same time, the log growth even faster.

"That's because Merge Replication needs CDC. "

but only one serve has this problem and we have 2 x subscribers,

I am not sure how you guys handle this.

you know if we rebuild index at the same time, the log growth even faster.
That's for sure. Reindex heavily uses transaction log.

I am not sure how you guys handle this.
To be honest I never used a Merge Replication. Trying to follow the logic here.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


"That's for sure. Reindex heavily uses transaction log."

but it seems hold there forever, we give up that on that box already, my boss said too scary to do it on that box.

rebuild index don't hold the log forever.

I knew this topic a bit hard as I don't think so much people will have this at all.

rebuild index don't hold the log forever.
Depends how big is the table and how fragmented the index is.

"Depends how big is the table and how fragmented the index is. "

ok, but it still not holding the log forever and let it keep growth for 1xxGB, right?

I never get this before when rebuilding index on a normal server.

now I am focusing on the restoring replication DB in publisher, the keep replication option doesn't shows and diff than normal restore, please see my other ticket. what are we suppose to see after using keep_replication option ?

I am reading this: http://www.sqlservercentral.com/Forums/Topic853719-291-1.aspx, it seem we need to recreate the replication by dropping replication and delete subscriber DB anyway.

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


now I am focusing on the restoring replication DB in publisher, the keep replication option doesn't shows
Has the server any replication enabled?

yes.

that one is in the restore distribution database ticket.

ASKER CERTIFIED SOLUTION
Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.

how about this, the solution can be easier if we detect the job: cdc.<database>_capture job was stopped.

then give us an alert so that we can then, have SQL server start the job automatically followed by the action we define:

1:sp_replflush
2:
3:sp_repldone null, null, 0,0,1
4:
5:sp_replflush

it is easier is no solution for it (I don't think we have a solution as all DBA in US office has tried that before).

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


I can't support you better on this one since as I said before I don't have experience in a similar configuration (Log Shipping & Merge Replication).
If not even Microsoft recommend it why are you using it? Move on to a more simpler solution.

ok. AO you mean, we will series consider that if failover just much easier.

Will do it but let me show you our diagram, I am wondering sth if it works as we have one publisher replicate to

so if we need to protect publisher, Server A and Server B, we should need 3 x AO group and between AO groups, serve can still talk to each other even not all member in any AO failover?
infrastructure.jpg

mate:

"I suggest to build up again the whole replication and CDC and you have to configure replication first and then CDC. "

I thought CDC is created when replication is created, right?

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Many apologizes mate. I just forgot to come back to this question :(

I thought CDC is created when replication is created, right?
Why did you say that?

hi,

because you said:

"That's because Merge Replication needs CDC."

Sorry, my bad.
That statement was only to your case in particular.
From your question:
", then we know there is the CDC and replication both work together to make log size can't come down at all."

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


yes.

so it is still true that replication will create that CDC job as well ?

I don't think so but I never worked with a Merge Replication.
Are you able to create one from the scratch?

no, I can't ! it will destroy everything . AHAHA

I can tell you, since last time we have this problem, it already 2 months and we don't see this anymore and the T-LOG stay still at 8GB,

so I don't think log backup doesn't really help in this case.

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


actually this problems seem known by only very few people in the world and it does happen, my command above can solve it quickly

actually I talked to MS to put replication to  the in memory engine as no lock any more, or the replication will lock a lot of queries.

tks all even it don't solve my problem.
Microsoft SQL Server

Microsoft SQL Server

--

Questions

--

Followers

Top Experts

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.