Quantcast
Channel: SQL Server Database Engine forum
Viewing all 12554 articles
Browse latest View live

Change Data Capture (CDC) cleanup job only removes a few records at a time

$
0
0

Hi everyone, 

Summary of the problem: I'm a beginner with SQL Server. For a project I need CDC to be turned on. I copy the cdc data to another (archive) database and after that the CDC tables can be cleaned immediately. So the retention time doesn't need to be high, I just put it on 1 minute and when the cleanup job runs (after the retention time is already fulfilled) it appears that it only deleted a few records (the oldest ones). Why didn't it delete everything? Sometimes it doesn't delete anything at all. After running the job a few times, the other records get deleted. I find this strange because the retention time has long passed.

Entire explanation of what I did: I set the retention time at 1 minute (I actually wanted 0 but it was not possible) and didn't change the threshold (= 5000). I disabled the schedule since I want the cleanup job to run immediately after the CDC records are copied to my archive database and not particularly on a certain time.
My logic for this idea was that for example there will be updates in the afternoon. The task to copy CDC records to archive database should run at 2:00 AM, after this task the cleanup job gets called. So because of the minimum retention time, all the CDC records should be removed by the cleanup job. The retention time has passed after all?
After a suggestion I just tried to see what happened when I set up a schedule again in the job (with a retention time of an hour this time), like how CDC is meant to be used in general. I had 3 records in that table. I changed 2 records at the same time and a few minutes later another record. After the time has passed I checked the CDC table and turns out it also only deletes the oldest record. I set another schedule again and then it deleted another record (the 2nd record of the 2 that I updated at first). Why aren't they purged all at once? What am I doing wrong?

I made a workaround where I made a new job with the task to delete all records in the CDC tables (and disabled the entire default CDC cleanup job). This works better as it removes everything but it's bothering me because I want to work with the original cleanup job and I think it should be able to work in the way that I want it to.

Thanks,

Kim

PS. I made a tread like this in sql server 2014 yesterday, but it has like 10 views or so. I  thought that this subforum would be appropriate as well. If it's not allowed, I can delete the other thread ofcourse.  


User creation on 100+ servers.

$
0
0
Hi All,

We have around 100+ servers. and i each server has around 5 databases and 
i need to give read only access to 6 developers for all the 115 servers. To do this one by one it will take 2 days to complete.
Is there any easy way to do that?

Thanks for your help

Splitting TempDB into multiple data files.

$
0
0
To avoid contention we have to split tempdb into multiple data files. But as for case suppose, there is 20 GB total space is on the drive containing 1 tempdb data file of 15 GB. And I have to create 3 more tempdb data files, and as recommendation all files should be of same size.Then how to handle this situation and configure all data files with same size?

Pranshul Gupta

SQL database backup issue on Server 2008 standard

$
0
0

Hi

I was running a user database diff backup task on SQL server Agent.  it was working great until i rebooted the server yesterday.

the task ran as SQL server agent service account, and exacutes a cmd like following:

sqlcmd -E -S $(ESCAPE_SQUOTE(SRVR)) -d master -Q "EXECUTE [dbo].[DatabaseBackup] @Databases = 'USER_DATABASES', @Directory = N'E:\USER_DATABASES-DIFF', @BackupType = 'DIFF', @Verify = 'Y', @CleanupTime = 168, @CheckSum = 'Y', @LogToTable = 'Y'" -b

i tried to start this task manually but failed again. and the log is confusing me as following

Log Name:      Application

Source:        MSSQLSERVER

Date:         8/13/2014 9:03:52 AM

Event ID:      3041

Task Category: Backup

Level:        Error

Keywords:      Classic

User:          XXXX

Computer:      XXXXX

Description:

BACKUP failed to complete the command BACKUP DATABASE WSS_Logging WITH DIFFERENTIAL. Check the backup application log for detailed messages.

Event Xml:

<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">

  <System>

    <Provider Name="MSSQLSERVER" />

    <EventID Qualifiers="49152">3041</EventID>

    <Level>2</Level>

    <Task>6</Task>

    <Keywords>0x80000000000000</Keywords>

    <TimeCreated SystemTime="2014-08-13T01:03:52.000Z" />

    <EventRecordID>24281</EventRecordID>

    <Channel>Application</Channel>

    <Computer>BDCSQL.wgti.net</Computer>

    <Security UserID="S-1-5-21-3036625466-2778081229-711462567-17346" />

  </System>

  <EventData>

    <Data>BACKUP DATABASE WSS_Logging WITH DIFFERENTIAL</Data>

    <Binary>E10B00001000000007000000420044004300530051004C0000000C0000005700530053005F004C006F006700670069006E0067000000</Binary>

  </EventData>

</Event>

Binary data:

In Words

0000: 00000BE1 00000010 00000007 00440042
0008: 00530043 004C0051 000C0000 00570000
0010: 00530053 004C005F 0067006F 00690067
0018: 0067006E 0000

In Bytes

0000: E1 0B 00 00 10 00 00 00 á.......
0008: 07 00 00 00 42 00 44 00 ....B.D.
0010: 43 00 53 00 51 00 4C 00 C.S.Q.L.
0018: 00 00 0C 00 00 00 57 00 ......W.
0020: 53 00 53 00 5F 00 4C 00 S.S._.L.
0028: 6F 00 67 00 67 00 69 00 o.g.g.i.
0030: 6E 00 67 00 00 00 n.g...

How do i get the server name of sql server 2008?

$
0
0
How do i get the server name of sql server 2008?, i have tried localhost and it didn't work

micah D

SQL alert blocked processes

$
0
0

Dear all,

 

 

I need to find a way of sending a text message preferably when any blocks occur in sql server. For example, is there a way that it could be set up in the Alerts section within SQL Server engine please?

 

 

 

Thank you in advance!

Rebuil And Reorganise

$
0
0

Hi all,

 i have done fragmentation using below command
 ALTER INDEX ALL ON [dbo].[Table_Name]

---------------

still the value have not been changed, when am checking Fragmentation Percentage (Avg_Fragmentation_In_Percentage) , Using Below Query

    

SELECT 
    OBJECT_NAME(A.[object_id]) as 'TableName', 
    B.[name] as 'IndexName', 
    A.[index_id], 
    A.[page_count], 
    A.[index_type_desc], 
    A.[avg_fragmentation_in_percent], 
    A.[fragment_count] 
FROM 
    sys.dm_db_index_physical_stats(db_id(),NULL,NULL,NULL,'LIMITED') A INNER JOIN 
    sys.indexes B ON A.[object_id] = B.[object_id] and A.index_id = B.index_id .

Please, help me to make my fragmentation percentage to decrease.

Even, i tried using GUI (Standard Reports -> Index Physical Statistics (Checking which all tables have to be REBUILD or REORGANISE), And Getting into the table indexes and rebuild ),

Still the count hasn't changed.

Thanks in advance..


DBCC SHRINKFILE command in maintenance plan job works manually, but not on schedule

$
0
0

In an attempt to release log file empty whitespace, we've added the following t-sql statement task as part of a weekly maintenance plan job:

EXEC master.sys.sp_MSforeachdb
'DECLARE @ln varchar(max)
SET @ln=(SELECT name FROM [?].dbo.sysfiles WHERE fileid=2)
USE [?]

BEGIN TRY
DBCC SHRINKFILE (@ln);
END TRY

BEGIN CATCH
END CATCH'

If I 'Start job at step' that single job manually, it seems to run fine and release quite a bit of unused whitespace.  We have another domain user that runs the agent service, which has full rights to the log files themselves as well as sysadmin server role and seemingly random user mappings.  When checking the job history, it shows that the job completed successfully, but when we view the history of the size of the drive, there is no change at that time.  I'm wondering if anyone has any idea about what might be happening here.

Thanks
jt


Display Count given below

$
0
0

Hi Friends,

I need help from you to resolve my current issue.

I have one table that is

and how do I get the following result

(Created_Date <= AsofDate ) and count of Android, windows phone and iphone downloads for every User_ID

Can any body help me? please.

Thanks in advance.

Index fragmentation

$
0
0

Hi,

Sql Server 2008r2,

Our indexes on POLARX database are highly fragmented (>96%) on two big tables, each table have one clustered and 13 non-clustered indexes, because of size of the table and having short maintenance window I can't run index rebuild/reorganize (off line) for all indexes at one time so I am planning to run below script in a job each day to rebuild one index at a time for several days in order to complete all index rebuild/reorganize work on both tables. Any suggestions would be highly appreciated.

Use POLARX

Go

SET NOCOUNT ON;
DECLARE @objectid int;
DECLARE @indexid int;
DECLARE @partitioncount bigint;
DECLARE @schemaname nvarchar(130);
DECLARE @objectname nvarchar(130);
DECLARE @indexname nvarchar(130);
DECLARE @partitionnum bigint;
DECLARE @partitions bigint;
DECLARE @frag float;
DECLARE @command nvarchar(4000);
-- Conditionally select tables and indexes from the sys.dm_db_index_physical_stats function
-- and convert object and index IDs to names.
SELECT
    object_id AS objectid,
    index_id AS indexid,
    partition_number AS partitionnum,
    avg_fragmentation_in_percent AS frag
INTO #work_to_do
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL , NULL, 'LIMITED')
WHERE avg_fragmentation_in_percent > 10.0 AND index_id > 0;

ALTER database POLARX set recovery bulk_logged

-- Declare the cursor for the list of partitions to be processed.
DECLARE partitions CURSOR FOR SELECT * FROM #work_to_do;

-- Open the cursor.
OPEN partitions;

-- Loop through the partitions.
WHILE (1=1)
    BEGIN;
        FETCH NEXT
           FROM partitions
           INTO @objectid, @indexid, @partitionnum, @frag;
        IF @@FETCH_STATUS < 0 BREAK;
        SELECT @objectname = QUOTENAME(o.name), @schemaname = QUOTENAME(s.name)
        FROM sys.objects AS o
        JOIN sys.schemas as s ON s.schema_id = o.schema_id
        WHERE o.object_id = @objectid;
        SELECT @indexname = QUOTENAME(name)
        FROM sys.indexes
        WHERE  object_id = @objectid AND index_id = @indexid;
        SELECT @partitioncount = count (*)
        FROM sys.partitions
        WHERE object_id = @objectid AND index_id = @indexid;

-- 30 is an arbitrary decision point at which to switch between reorganizing and rebuilding.
        IF @frag < 30.0
            SET @command = N'ALTER INDEX ' + @indexname + N' ON ' + @schemaname + N'.' + @objectname + N' REORGANIZE';
        IF @frag >= 30.0
            SET @command = N'ALTER INDEX ' + @indexname + N' ON ' + @schemaname + N'.' + @objectname + N' REBUILD';
        IF @partitioncount > 1
            SET @command = @command + N' PARTITION=' + CAST(@partitionnum AS nvarchar(10));
        EXEC (@command);
        PRINT N'Executed: ' + @command;
    END;

-- Close and deallocate the cursor.
CLOSE partitions;
DEALLOCATE partitions;
ALTER database POLARX set recovery  FULL
 -- Drop the temporary table.

DROP TABLE #work_to_do;
GO 


SSIS: Execution of the steps

$
0
0

Hi , I have an SSIS package opened in Visio Studio 2008,

there are many steps, and I want to run it manually for some steps together, how to do it , instead of click everyone of it to 'execute task '?

excution plan

$
0
0

Hello

I have a table with 200 million rows (tableA) and an unique non-clustered index (ix_A) on id1 and id2.

when I run a simple query

select b.id1,b. id2, b.otherfield1, b.otherfield2, b.otherfield3 from #temp a join tableA  b on a.id1 = b.id1

The temp table has 15000 rows and the execution plan having a index seek on ix_A. However, when I run same query, but temp table rows increased to 30000, the execution plan change to a table scan on tableA , of cause the running time has increased significantly. Can anyone tell me why? and any advice how to tune it, the table scan execution plan didn't show any missing index on top of execution plan.

Any help would be much appreciated,

Carqu

SQL 2008 R2 - Resource monitor high CPU usage

$
0
0

Hello,

I need some advice for resolving high CPU usage for resource monitor on 2008 R2 SP1.
I have searched but only found some bug on 2008 version.

I am not sure if I am reading this correctly - In Perfmon I have found thread that consumes 30-70 % CPU time - that thread is resource monitor. SQL 2008 R2 SP1, One instance limited to 1,9GB RAM. Global CPU moves around 20/30 with spikes to 70%.

Is there way to control resource monitor or am I supposed to increase memory on instance ? It shouldn't need more than that.

Thanks for all advice

restore the logins under Security ?

$
0
0
We have the SQL Server 2008, everyday we back up the whole instance onto the tape including the System database. 
My question is I want to restore the logins account under Security ? How do I do it ? 
Does the backup include the logins ?

Bulk Data Error, MYSQL to SQL Server

$
0
0

Hi, Everyone,

I have data in bulk, like this. (consist of 2 column id and name). The sparator is "|"

01|Jhonson
02|Jhonson
Park

on the top example, seen name with id 02 is very long so, data of name make a new line.
and then i have error, cause sql server assume, "Park" is different row. 

Script make a bulk :
SELECT * FROM test   INTO OUTFILE '/tmp/database/test.csv' FIELDS TERMINATED BY '|';

Script to import data use bulk.
BULK INSERT dbo.TEST FROM 'C:\csv\TEST.csv' WITH (DATAFILETYPE = 'char', BATCHSIZE=100,FIELDTERMINATOR='|',ROWTERMINATOR='0x0a');N

Note :

Fyi, I will migrate data from mysql to sql server. When i create a bulk, this in mysql and then when i insert data bulk in the sql server.

error :

Msg 4864, Level 16, State 1, Line 1
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 175, column 1 (id).

Thanks for your help, i wait your opinioun about this problem.

thanks,
-infi-


Error 606 occured - Metadata inconsistency for temp table

$
0
0

Hello,

we currently have an issue on a production server running SQL Server 2005 Standard:

Executing a stored procedure, which again executes another stored procedure in which a temporary table #PIVOT_ITEMS is created and filled.

The stored procedure throws an exception that error 606 has occurred. Looking at the SQL Server logs, it contains:

"Metadata inconsistency. Filegroup id 0 specified for table
'dbo.#PIVOT_ITEMS' does not exist. Run DBCC CHECKDB or
CHECKCATALOG
".

DBCC CHECKDB didn't help, so what could this error mean on a temporary table?

I searched a lot in the web, but nobody else ever seemed to have this error 606...

Thanks a lot for helping!

Regards, Jens

Cannot access second instance of SQL Server

$
0
0

I installed SQL Server 2008r2 Express Edition.  Afterwards I installed SQL Server 2008r2 Developer Edition on the same computer.  When connecting to the computer from Management Studio on another computer the computername only connects to the Express instance.  If I type computername\MSSQLSERVER I get an error cannot connect.  I found that the SQL Server Browser service was not started, so I started it in SQL Server Configuration Manager.  This did not help.  I also noticed in the SQL Server Network Configurations that instance MSSQLSERVER had only Shared Memory enabled unlike SQLEXPRESS which had Shared Memory, Named Pipes, and TCP/IP enabled.  So I enabled Named Pipes and TCP/IP for MSSQLSERVER.  Then I restarted SQL Server (MSSQLSERVER) service.  This now produces an error "The request failed or the service did not respond in a timely fashion."  In the event log I am getting this message "Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.  Reason: Failed to open the explicitly specified database.

What do I have setup wrong?

Thanks,

Fred


Fred Schmid

CU patch in 4 node

$
0
0

Hi,

I am going to apply CU10 in 4 node production cluster servers.. Node1,Node2,Node3,Node4. I have 9 databases running on these 4 nodes.

Can I push all the 9databases to Node1 and apply CU10 on other three passive nodes(Node2,Node3,Node4) parallelly? Once patch is completed in three nodes, then will move these databases to patched three nodes and apply cu10 on Node1?

Regards.


Bilal


SQLCMD Mode vs SQLCMD command line Utility

$
0
0

I noticed some strange behavior with column ordering on a view.  When I run the below script using SQLCMD Mode in SSMS, the columns show in the correct order.  If I run the same command using the SQLCMD command line utility, the view's columns get put in ABC order.

CREATE VIEW [dbo].[SomeView] WITH SCHEMABINDING AS

SELECT ACol, QCol, BCol, DCol FROM dbo.SomeTable

I saw in MSDN that the command line utility runs the SQL using ODBC vs the SQLCMD mode uses SQLClient framework but I'm not able to find any information on the differences.  Anyone else experience this behavior?



CHANGE_TRACKING_MIN_VALID_VERSION keeps changing even there are no changes in that table

$
0
0

Hi,

We use stored procedure like below to get the data on intial load as well as subsequent changes. The underllined part of the stored procedure to get the last_sync_version is slightly different from what Microsoft has suggested. (not using CHANGE_TRACKING_CURRENT_VERSION). That is because we download data to staging from multiple sources and from their we want to process data from one source at a time (DATA_SOURCE_KEY filter). 

What we notice is that, when there is no data for a table for sometime, once the change tracking gets purged for that table, we keep hitting the condition @LastVersionId <@MinVersionId. The MIN_VALID_VERSION keeps changing even though there is no change in that table. Looks like the MIN_VALID_VERSION is a global number and not specific to a table. Is there a problem with the way we are getting the @Next_Version. Can we use the CHANGE_TRACKING_CURRENT_VERSION even though we want to download subset of data from the table (only records matching for one data_source_key at a time). Appreciate your answers.

CREATE PROCEDURE  [dbo].[PDW_GetSiteDVAudit](@DataSourceKey AS INT,@LastVersionID AS BIGINT, @NextVersionID AS BIGINT OUTPUT)
AS
BEGIN TRY
BEGIN TRANSACTION
BEGIN
DECLARE @MinVersionID bigint = 0, @max_version bigint = 0;
SELECT @NextVersionID = 0;
SET @MinVersionID = CHANGE_TRACKING_MIN_VALID_VERSION(OBJECT_ID('dbo.SiteDVAudit'));

IF (@LastVersionID < @MinVersionID)
BEGIN
SELECT @NextVersionID = isnull(MAX(SYS_CHANGE_VERSION),@MinVersionID) from CHANGETABLE(CHANGES SiteDVAudit , NULL) CT where DataSource_Key = @DataSourceKey
SELECT 
s.Id,
Site_Id ,
SiteDesc,
Deleted,
Local_Id,
s.DataSource_Key,
Data_Task_Id
FROM 
dbo.SiteDVAudit  s

WHERE
                        s.DataSource_Key = @DataSourceKey
END 
ELSE
BEGIN
SELECT @NextVersionID = isnull(MAX(SYS_CHANGE_VERSION),@LastVersionID) from CHANGETABLE(CHANGES SiteDVAudit , @LastVersionID) CT where DataSource_Key = @DataSourceKey
SELECT 
s.Id,
Site_Id ,
SiteDesc,
Deleted,
Local_Id,
s.DataSource_Key,
Data_Task_Id
FROM 
dbo.SiteDVAudit  s
RIGHT OUTER JOIN 
CHANGETABLE(CHANGES SiteDVAudit, @LastVersionID) CT
ON s.Id = CT.Id  AND
s.DataSource_Key = CT.DataSource_Key
WHERE
                        s.DataSource_Key = @DataSourceKey
END
END


COMMIT TRANSACTION
END TRY

BEGIN CATCH
ROLLBACK TRANSACTION
RETURN -1
END CATCH

Viewing all 12554 articles
Browse latest View live


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