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

How to determine which objects/queries are main cause for unusual increase in tempDB

$
0
0

Hi,

From past 2 days, tempdb is growing unexpectedly and completely filling up the Drive. Currently we are restarting the service.

Yesterday, when we ran the below query when tempDB was full, we got 2 queries. But those 2 queries were running since long time and we are surprised how suddenly those queries are responsible for tempDB growth

select top 10
t1.session_id,
t1.request_id,
t1.task_alloc,
     t1.task_dealloc, 
    (SELECT SUBSTRING(text, t2.statement_start_offset/2 + 1,
          (CASE WHEN statement_end_offset = -1
              THEN LEN(CONVERT(nvarchar(max),text)) * 2
                   ELSE statement_end_offset
              END - t2.statement_start_offset)/2)
     FROM sys.dm_exec_sql_text(sql_handle)) AS query_text,
(SELECT query_plan from sys.dm_exec_query_plan(t2.plan_handle)) as query_plan

from      (Select session_id, request_id,
sum(internal_objects_alloc_page_count +   user_objects_alloc_page_count) as task_alloc,
sum (internal_objects_dealloc_page_count + user_objects_dealloc_page_count) as task_dealloc
       from sys.dm_db_task_space_usage
       group by session_id, request_id) as t1,
       sys.dm_exec_requests as t2
where t1.session_id = t2.session_id and
(t1.request_id = t2.request_id) 
     -- and t1.session_id > 50
order by t1.task_alloc DESC

And today, periodically when I was trying to see the tables in "Temporary Tables" in tempdb, I am gettiing TimeOut Period.

Also, after referring below link, I have executed some queries

http://msdn.microsoft.com/en-us/library/ms176029.aspx

--1.Determining the Total Amount of Space 
SELECT SUM(size)*1.0/128 AS [size in MB]
FROM tempdb.sys.database_files
--63478.375000


--2. Determining the Amount Space Used by the Version Store
SELECT SUM(version_store_reserved_page_count) AS [version store pages used],
(SUM(version_store_reserved_page_count)*1.0/128) AS [version store space in MB]
FROM sys.dm_db_file_space_usage;
--176.875000 MB

--3.Determining the Amount of Space Used by Internal Objects
SELECT SUM(internal_object_reserved_page_count) AS [internal object pages used],
(SUM(internal_object_reserved_page_count)*1.0/128) AS [internal object space in MB]
FROM sys.dm_db_file_space_usage;
--0.625000 MB

--4. Determining the Amount of Space Used by User Objects
SELECT SUM(user_object_reserved_page_count) AS [user object pages used],
(SUM(user_object_reserved_page_count)*1.0/128) AS [user object space in MB]
FROM sys.dm_db_file_space_usage;
--1.500000

If we see the above query, total space occupied by tempDB is 63 GB. 

When I tried to see what are the objects making this total of 63 GB(Query 2, 3, 4) they do not sum up to 63 GB.

How can I know what is causing the tempDB to 63 GB and how can I check what is the root cause for this unexepected increase in the tempDB growth

NOTE: Last week, RAM has been increased by 8 GB and  2 processors were added.


Raksha


Recover all sql logins information from crashed sql server(have master db backup file only option)?

$
0
0

sql server crashed and we built another new server and tried to recover all sql logins from old server. only option is we have backup of all system database.

how to recover sql server logins and transfer/create on new server?

Please help.

Backup Strategy

$
0
0

Hi,

Currently, we required to shorten our database recovery time. We review and would like to implement as below. Kindly give me some comments. The instance is SQL 2008 R2 Std x64

  1. Set the database recovery mode to full
  2. Do full backup daily at midnight
  3. After the full backup, do TLog backup every one hour.

We assumed we can have protection every hour. Once the full backup is done on next midnight, does it mean all old full and TLog backup can be deleted?

Clustered Index Key

$
0
0
Hi, Right now our largest table uses as primary clustered key a varchar (40) (not my design). I noticed that all values are unique and have the same length. Can I change it to fixed column char(40) and would the all the indexes have to be rebuilt after that? Thanks

Paula

SQL Server Shuts Down randomly on big data loads on Windows 8

$
0
0

I am responsible for the data processing and analysis for two identical spacecraft for a NASA science mission. I am running one SQL instance for the first spacecraft on a Windows 7 machine and another instance for the second spacecraft on a Windows 8 machine. Both installations were done the same and both have been configured with the same scripts and use the same login credentials.

The issue that I am having is that the SQL Server on the Windows 8 machine randomly fails and shutsdown when I am submitting a large amount of data into the database tables.  When I do this exact same operation on the Windows 7 machine I have never had any issues.  This of course causes a significant amount of issues in regards to overall data processing since there are up to three difference processing systems working with each of the SQL Instances.

I am not a SQL DBA nor have significant training in SQL but have used it for a decade or so and write a significant amount of C# code interfacing with the system.  As a note, the code that I'm currently using interfaces with the SQL servers via LINQ.

Does anyone have any thoughts on what might cause the issue for the Windows 8 machine and not for the Windows 7 machine?

I would greatly appreciate your help.
In the meantime I've written a small service that looks at the system every minute and if it is shutdown it restarts the service but this is NOT an optimal solution.


Jerry W. Manweiler, Ph.D.

SPID Blocking itself with Sch-S on a table variable.

$
0
0

OK,

 

Here is the problem. I have a SPID that was blocking itself. When you try and kill this SPID it returns the message;

 

"SPID 120: transaction rollback in progress. Estimated rollback completion: 0%. Estimated time remaining: 0 seconds"

 

When looking at this SPID in sys.sysprocesses I can see that the blocking SPID is itself.  The last wait type is LCK_M_SCH_M with a wait type of 0x0002.

 

When looking at the locks by process i can see that in tempdb Owner ID 2063795945 has taken out a Sch-S lock on Object ID 958657192. In the same process there is Owner ID 2063803448 which is waiting to obtain a Sch-M lock on the same object (958657192). This lock request has a Request Status of WAIT.

 

This SPID executed a stored procedure which calls a user defined table value function that splits a comma delimited string into a table variable and returns a table with an integer Column type. The code for this can be seen at the foot of this post.

 

BOL states that Schema stability (Sch-S) locks are used when compiling queries. This lock does not block any transactional locks, but when the Schema stability (Sch-S) lock is used, the DDL operations cannot be performed on the table. Because the table variable definition cannot be changed after the initial DECLARE statement and you cannot drop a table variable WHY is it trying to obtain a Sch-M on that object?!

 

It is the table variable within this function that the process is trying to obtain the Sch-M lock.

 

With this in mind, I have a few of questions.

 

1. Is there any other way of removing this SPID without restarting the service, obviously the KILL statement is not going to work.

 

2. What does the Owner ID in Activity Monitor "Lock By Process" refer to? Is there any way i can trace this back further to establish what has happened

 

3. How can more than one Owner ID exist within the same process when in BOL it states that the owner id is “The owner ID associated with the process”

 

4. How can a process block itself on a table variable in tempdb?

 

Thanks in advance for any help you might be able to offer.

 

Phil Harbour

 

 

FYI

 

dbcc inputbuffer (120,2)

RPC Event 0 dbo.<MyProcName>;1

 

Table Function

 

 
 declare @separator char(1) 
 select @separator = ',' 

 declare @separator_position int  
 declare @array_value varchar(1000)  

 set @array = @array + ',' 

 while patindex('%,%' , @array) <> 0  
 begin 
  select @separator_position =  patindex('%,%' , @array) 
  select @array_value = left(@array, @separator_position - 1) 

  insert @IntTable 
  select (cast(@array_value as int)) 

  select @array = stuff(@array, 1, @separator_position, '') 
 end 

Stored procedure Issue

$
0
0

Due to one stored procedure our data has been deleted.This will execute daily.We have to find when the sp was executed 2 days back.When we executed below query we are getting latest execution time.If there is any other alternative please let us know.

select b.name, a.last_execution_time
    from sys.dm_exec_procedure_stats a
    inner join sys.objects b on a.object_id = b.object_id
    where DB_NAME(a.database_ID) = 'db nama' and a.last_execution_time

Change installation directory for SQL 2008 SP3 or CU

$
0
0

My C drive is full, Server built long time ago. Not enough space available in C Drive but other local drive have storage.

Is there anywhere i can use my other drive for patching or apply CU.

Env: win 2003 ,SQL 2008 SP1


Keep getting errors from application log that indicates transaction log is full but it has plenty of space

$
0
0

Dealing with a 4rd party application that inserts into its log table, but watching sql profiler i see a ton of the same traffic.  Its trying to insert into the table, but generates an error that mentions the transaction log for that DB is full. 

Well, earlier I had reset the recovery mode to simple, from full since this is a test system and dont really care about recovery.

So the message mentions to check the log_reuse_wait_desc column in sys.databases and there the value is 'CHECKPOINT'. At least at that point in time. 

There is plenty of space in the transaction log and the physical disk has plenty of space as well.

What could be causing the error that seems to suggest the transaction log is full, when in fact it is not?

Database Performance for Newbies

$
0
0

Hello Forum,

the Database I have is now running for 1,5 years.

At the beginnig there where 90.000 login data per month. Now there are over 900.000 login data per month stored in a table.

I am now a little concerned about the performance, because I do not know anithing about it. Maybe the database crashes if 1.000.000 will bereached or what ever. I do not know.

I red few posts here in the forum about performance, but they are to complicated for me or I red the wrong ones.

Can somebody help me getting out some statistics or when the limit of the hardware resources will be reached or something?

I just did the following:

SELECT object_name, counter_name, cntr_value * 8/1024.0 AS SizeMB
FROM sys.dm_os_performance_counters 
WHERE object_name = 'SQLServer:Buffer Manager' 
	 counter_name IN ('Total pages', 'Target pages')

And got as result:

SQLServer:Buffer Manager     Total pages    7943.0000
SQLServer:Buffer Manager     Target pages  27565.8125

And if I go to the computer management console and look at performance it says:

Available MB:  21.759

Guranteed used Bytes (%):  16.9

So maxbe someone has some querys, tools or what ever for me, I can use and know if it looks good and when it will look bad.

Kind regards

Peter

how to monitor load on server

$
0
0

Hi Experts,

What perfmon counters can I use to monitor load on the sql server and trend it over time?

Thank you.

SQL Server 2008 R2 Memory Pressure

$
0
0
I have a SQL Server 2008 R2 Standard (x64 bit). It has 64GB of memory, but memoryclerk_sqloptimizer consumes about 36 GB. How should I clear it and identify what cause the growth of memoryclerk_sqloptimizer. I also have high stolen pages too. Thanks in advance.

avg_fragmentation_in_percent remains high although Rebuild Index task is complete

$
0
0

Hello, 

Reading through online and forums I've seen recommendation if avg_fragmentation_in_percent goes above 40% Rebuild Index. 

I've now completed Rebuilding Index, however the avg_fragmentation_in_percentage remains as high as above 90% for lots of table. 

Is this normal, could you advise?

Best regards, 

Mohan

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

If a database is locked exclusivley does the T-SQL statment get queued and executed when the database is ready?

$
0
0
I have a Database that must be locked exclusively from time to time for various INSERTS.  I am noticing that sometimes I get multiple entries inserted when the database becomes unlocked.

My application attempts to execute a INSERT and if the database is locked I loop in my program a few seconds and try again.  I am noticing that sometimes I might get 2, 3, 4 records inserted.  Is it possible that SQL Server is taking the first TSQL transaction that failed due to the DB being locked and Queuing it to be run after the DB becomes unlocked?

Any help explaining this would greatly be appreciated.

Attach database file option is disabled

$
0
0

Hi,

I have SQL Server 2014 installed. I am trying to attach a database but the option to choose a database is not working. The page looks like this. Not sure what's happening

 Regards

Jatin


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 


SQL Server Agent job between 2 instances fails with Error 18456 - Login Failed for user

$
0
0

Hi,

SQL Server version: 2012 EE

OS: Windows 2008 R2 Enterprise

In my server, i have 2 instances, and I am trying to configure a SQL Server Agent job to query one table in Instance A, and insert some modified data in Instance B, both in the same server.

When i execute the job in instance A, i get the following error:

Executed as user: NT SERVICE\SQLSERVERAGENT. Login Failed for user "NT SERVICE\SQLSERVERAGENT". [SQLSTATE 28000] (Error 18456). The step failed.

I have already configure instance A as Master and disabled encryption, by changing the parameter MsxEncryptChannelOptions to 0 in regedit. I've also made my target instance (instance B) as a Target.

What am i missing?

Thanks for your attention and pacience

Link Server temp table

$
0
0

Hi All. Any one if we have a link server. Can we select a temp table from a link server?

like the follwing:

select * from serverA.tempdb.dbo.#temptable??

Create Cluster on Windows for Always on

$
0
0

Hi all, 

I am trying to configure Windows Cluster on windows 2008r2 and windows 2012 . the Validation went ok During the Cluster creation it erroed out . 

If there is standard documention on Creating a Cluster please povide me .. 

Thanks 

Regards

K.muthus 


k.muthus


Viewing all 12554 articles
Browse latest View live


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