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

SQL server taking all the CPU and RAM

$
0
0

Dear All,

I have a SQL Server 2008 standard edition with 20 GB RAM and have allocated 17 GB of RAM memory to SQL Server and 4 CPU.
But Since last 1 week i am facing issue in SQL server, The issue is SQL Server reaches 100% CPU usage constantly , have checked there is no single query is running in sql by using below dm views

SELECT Text from sys.dm_exec_request cross apply sys.dm_exec_sql_text(sql_handle)

I have also checked in task manager but only sqlserver.exe taking 100% CPU and Physical Memory Both
Then i have restarted the sql server, during restart process, the utilization gets decreases but Once the service gets started, Again the CPU and Physical Memory reaches to 100 % and it doesn't release the memory.The Only solution which i have used is rebooted the server, but it would not be the solution because the server is in Production.

I thought there might b issue with the antivirus have disabled it but nothing happend good, also checked in counter and found the total sql server memory(KB) is taking all 20GB and all the counter thresh hold values are normal.

I don't know where is the issue, I would thankful to you guys if someone help me.  

Thank you


Linked server_ data transfer job fails due to Query timeout expired or deadlocked on lock resources

$
0
0

Hi Techies,

Please help me out to get a permanent fix for this solution,

Environment:

SQL Server 2008 R2 (sp1) x64  & OS-Windows server 2003 R2 (sp2) x64

The Linked_server datatransfer Job executes on daily basis , it fails once in 3\4 days with either any one of the following error as mentioned below,

Job succeeds run time  <20 minutes   & Job fails run time  <1minute


The OLE DB provider "SQLNCLI10" for linked server "destination_server ip,port" reported an error. Execution terminated by the provider because a resource limit was reached. [SQLSTATE 42000] (Error 7399)  The OLE DB provider "SQLNCLI10" for linked server " destination_server ip " could not INSERT INTO table "[destination_serverip,port].[database_name].[dbo].[table_name]". [SQLSTATE 42000]  (Error 7343)  OLE DB provider "SQLNCLI10" for linked server" destination_server ip,port " returned message "Query timeout expired". [SQLSTATE 01000] (Error 7412).  The step failed.

-or-

Transaction (Process ID 53) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction. [SQLSTATE 40001] (Error 1205).  The step failed.

do help me to find the reason for,

this error and how to resolve the same ?

for example-

i.how to resolve the  resource limit was reached /"Query time out" error ?  -in this environment "Query time out" set to 15 minutes 

ii.how to find and resolve the deadlock part ? 

iii.Is there any best practices / prerequisites to prevent this errors ?




Restoring database

$
0
0

hi,

I am unable to restore complete database using LSN.

        

--Create Database

USE [master];
GO

CREATE DATABASE [FNDBLogTest];
GO
USE [FNDBLogTest];
GO
SET NOCOUNT ON;
GO

-- Create tables 
CREATE TABLE [ProdTable] (
    [c1] INT IDENTITY,
    [c2] DATETIME DEFAULT GETDATE (),
    [c3] CHAR (25) DEFAULT 'a');

CREATE TABLE [ProdTable2] (
    [c1] INT IDENTITY,
    [c2] DATETIME DEFAULT GETDATE (),
    [c3] CHAR (25) DEFAULT 'a');
GO


 --insert correct record in table1
INSERT INTO [ProdTable] DEFAULT VALUES;
GO 1000

-- Take full database backup
BACKUP DATABASE [FNDBLogTest] TO DISK = N'E:\Data\FNDBLogTest_Full.bak' WITH INIT;
GO

--Take initial Log backup
BACKUP LOG [FNDBLogTest] TO DISK = N'E:\Data\FNDBLogTest_Log1.trn' WITH INIT;
GO

--insert another 1000 rows correct record in second table ProdTable2
INSERT INTO [ProdTable2] DEFAULT VALUES;
GO 1000

--Drop first table ProdTable by mistake 

DROP TABLE [ProdTable];
GO

--insert another 1000 rows in second table ProdTable2

INSERT INTO [ProdTable2] DEFAULT VALUES;
GO 1000

 select COUNT(*) from ProdTable2

--Use dblog function to view the transaction log records in the active part of the transaction log file for the current database.
select * from fn_dblog(null,null)
SELECT
    [Current LSN],
    [Operation],
    [Context],
    [Transaction ID],
    [Description]
FROM
    fn_dblog (NULL, NULL),
    (SELECT
        [Transaction ID] AS [tid]
    FROM
        fn_dblog (NULL, NULL)
    WHERE
        [Transaction Name] LIKE '%DROPOBJ%') [fd]
WHERE
    [Transaction ID] = [fd].[tid];
GO

-- LSN :0000001c:000001f5:0001 

--take backup log 
BACKUP LOG [FNDBLogTest] TO DISK = N'E:\Data\FNDBLogTest_Log2.trn' WITH INIT;
GO
--Restore database 
RESTORE DATABASE [FNDBLogTest2]
    FROM DISK = N'E:\Data\FNDBLogTest_Full.bak'
WITH
    MOVE N'FNDBLogTest' TO N'E:\Data\FNDBLogTest2.mdf',
    MOVE N'FNDBLogTest_log' TO N'E:\Data\FNDBLogTest2_log.ldf',
    REPLACE, NORECOVERY;
GO

 --Restore Log 
RESTORE LOG [FNDBLogTest2]
    FROM DISK = N'E:\Data\FNDBLogTest_Log1.trn'
WITH
    NORECOVERY;
GO

 --Restore log 
 --STOPBEFOREMARK = '<mark_name>' clause is used to specify that the log record that is immediately before the mark is the recovery point.
RESTORE LOG [FNDBLogTest2]
FROM
    DISK = N'E:\Data\FNDBLogTest_Log2.trn'
WITH
    STOPATMARK = 'lsn:0x0000001c:000001f5:0001 ',
    NORECOVERY;
GO
  

 --restore database 
RESTORE DATABASE [FNDBLogTest2] WITH RECOVERY;
GO

select COUNT(*)as ProdTable from [FNDBLogTest2].[dbo].[ProdTable] 
select COUNT(*) as ProdTable2 from [FNDBLogTest2].[dbo].[ProdTable2]

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

RESULTS

ProdTable
1000

ProdTable2
1000

I am unable to recover 1000 rows inserted into ProdTable2 after the execution of drop statement.How can I roll forward and recover the records executed after DROP?

--urgent

Thanks in advance!


Reduce version ffrom 2012 to 2008r2

$
0
0

Hi -

I have backup ContentDb 2008r2 need to restore in SQL2012.

My intention is need to reduce version from 2012 to 2008 r2..please let me know how to do this?

fragmentation myth

$
0
0

Hi guys,

I wanted to test a couple of things regarding frag/defrag... For that purpose I need a fragmented database... Do you know where can I get a heavily fragmented .bak?

I know I can somehow  create fragmentation on purpose, but it would be quicker to have a fragmented .bak that I can quickly restore...

Thanks in advance!

ps: basically I wanted to test http://www.brentozar.com/archive/2012/08/sql-server-index-fragmentation/ 

I do have  shared storage, and I believe I should  carefully monitor fragmentation!

Error Specified cast is not valid. (SqlManagerUI)

$
0
0

Hi,

I have a backup of DB with version Microsoft sql 2012 and i need restore this data base on instance Microsoft sql 2008 R2

when i try restore database on SQL server 2008 R2  i have the error:

Specified cast is not valid.(SqlManagerUI)

errorllog

$
0
0

Hi,

last target outstanding: 40, avgWriteLatency 32

average writes per second: 195.33 writes/sec 
            average throughput:  18.88 MB/sec, I/O saturation: 10959, context switches 17186

FlushCache: cleaned up 173302 bufs with 14000 writes in 71674 ms (avoided 3965 new dirty bufs) for db 34:0

we getting the above server logged in to error log. This is brand new server, act as subscriber and MI related process runs on it

sql server 2014 x64 std on windows 2012 ent

thanks


Please mark answered if I've answered your question and vote for it as helpful to help other user's find a solution quicker

Execution plan generation with PIVOT + HASH GROUP + WHERE clause fails

$
0
0

SQL Server version:

Microsoft SQL Server 2012 (SP1) - 11.0.3401.0 (X64)
    Jan  9 2014 13:22:15
    Copyright (c) Microsoft Corporation
    Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )

Consider the following structure:

CREATE TABLE TESTE (COL1 VARCHAR(30), GROUP_COLUMN VARCHAR(100))

INSERT INTO TESTE VALUES
('GROUP 1', 'HI'),
('GROUP 1', 'HI'),
('GROUP 1', 'HI'),
('GROUP 1', 'HELLO'),
('GROUP 1', 'SUP'),
('GROUP 1', 'SUP'),
('GROUP 2', 'HI'),
('GROUP 2', 'HI'),
('GROUP 2', 'HELLO'),
('GROUP 2', 'HELLO'),
('GROUP 2', 'SUP'),
('GROUP 2', 'SUP'),
('GROUP 2', 'SUP'),
('GROUP 2', 'SUP')

Now generate the execution plan for the following queries below, without any hints, and check if they are the same I'm getting.

SELECT PIV.* FROM (
SELECT COL1, GROUP_COLUMN, COUNT(GROUP_COLUMN) CNT
FROM TESTE
GROUP BY COL1, GROUP_COLUMN) A
PIVOT (MAX(CNT) FOR GROUP_COLUMN IN ([HI], [HELLO], [SUP])) PIV

SELECT PIV.* FROM ( SELECT COL1, GROUP_COLUMN, COUNT(GROUP_COLUMN) CNT FROM TESTE GROUP BY COL1, GROUP_COLUMN) A PIVOT (MAX(CNT) FOR GROUP_COLUMN IN ([HI], [HELLO], [SUP])) PIV WHERE COL1 = 'GROUP 1'


Essentially the same plan, are they not? Except by the fact that the table scan with the query containing the WHERE clause carries a predicate, but nothing out of the ordinary... The sort operation is necessary to perform the stream aggregate process, which will count entries grouping by COL1 and GROUP_COLUMN. The "Compute Scalar" operator will compute the COLUMNs for the PIVOT table, and the last Stream Aggregate will perform a MAX aggregation for each of the new columns created by the "Compute Scalar" operator, internally performing a CASE logic like this:

CASE WHEN GROUP_COLUMN = 'HELLO' THEN <COUNT EXPRESSION> ELSE NULL END,

CASE WHEN GROUP_COLUMN = 'HI' THEN <COUNT EXPRESSION> ELSE NULL END,

CASE WHEN GROUP_COLUMN = 'SUP' THEN <COUNT EXPRESSION> ELSE NULL END

Now, because I live in a free country (at least in theory), I want the aggregations - all of them - to be run using a hash algorythm. And so I add the HASH GROUP hint to the first query, and generate a new query plan.

SELECT PIV.* FROM (
SELECT COL1, GROUP_COLUMN, COUNT(GROUP_COLUMN) CNT
FROM TESTE
GROUP BY COL1, GROUP_COLUMN) A
PIVOT (MAX(CNT) FOR GROUP_COLUMN IN ([HI], [HELLO], [SUP])) PIV
OPTION (HASH GROUP)

Good, the execution plan for the first query (without the WHERE CLAUSE aka query predicate) has been successfully generated. The sort operation is no longer necessary, and both the COUNT aggregation and the PIVOT MAX calculations are now being physically implemented by means of an in-memory hash table.

I pass on to the query with the WHERE clause.

SELECT PIV.* FROM (
SELECT COL1, GROUP_COLUMN, COUNT(GROUP_COLUMN) CNT
FROM TESTE
GROUP BY COL1, GROUP_COLUMN) A
PIVOT (MAX(CNT) FOR GROUP_COLUMN IN ([HI], [HELLO], [SUP])) PIV
WHERE COL1 = 'GROUP 1'
OPTION (HASH GROUP)

Msg 8622, Level 16, State 1, Line 1
Query processor could not produce a query plan because of the hints defined in this query. Resubmit the query without specifying any hints and without using SET FORCEPLAN.

Trust me when I tell you that I have extensively searched for a solution on the web, without success. I have also tried several query hints I found relevant, to no avail.

I tried to change the literal value to a parameter, even enabling forced parameterization, but that didn't have any effect either.

Has anyone run into this problem and found a solution? Maybe some querytraceon magical flag? Is this a bug? I really don't want to switch back to a CASE logic because that will generate table spools in my original query and slow down performance.

Any ideas?


Just because there are clouds in the sky it doesn't mean it isn't blue. But someone will come and argue that in addition to clouds, birds, airplanes, pollution, sunsets, daltonism and nuclear bombs, all adding different colours to the sky, this is an undocumented behavior and should not be relied upon.




Encryption in SQL Server 2012/2014

$
0
0

We are hosting sharepoint DBs. My boss ask me for possibilities to do the encryption on content DB level, it backup. or on column level?

I read about TDE? it is will slow the DBs? is it practical ?

or better to take at windows level encryption ?

other good options?

BTW , we have AlwaysOn and FCI, is it compatible with this

Release unused disk space

$
0
0

OS: Windows Server 2008 R2 Standard

SQL Server: 2008 SP1 Standard

Hello, 

We have a database with about 500 GB of free disk space on data file and the database is being set to read only mode for the fore-see-able future. We would like to release this unused disk space. We know that we could shrink the data file and then work on re-indexing to remove fragmentation. However, we wanted to check if some other method like backup and restore of the database could free up unused disk space in the data file. We do not have an environment to test this process out quickly and hence the question if someone was able to release unused disk space on data file by implementing a backup and restore.

-Jeelani 

The connection was recovered and rowcount in the first query is not available. Please execute another query to get a valid rowcount

$
0
0

Since we've moved to SQL 2014 we see some of our jobs error with the message in the subject of this post.  What does it mean?  I've looked all over and haven't been able to find anything of value.

Thanks in advance. 


André

Database properties considerations for dataware housing environment

$
0
0

Hi All,

We are setting up the data warehousing environment using SSAS and SQL server.

We need best practices and recommendations to host database according to that.

What should be the database properties to gain maximum performance ?

Kindly reply.

DR option for SharePoint databases? ideas and experiences

$
0
0

First let me clarify that I am not looking for thoughts in terms what is the best or the bad options for a DR for SQL Server. I am just looking for for inputs from experienced people.

We are running Virtual Hyper-V and SQL Sever 2012 with FCI. I have three options here.

  1. AlwaysOn (DR). It seems easy and awesome but it is a new topic for us. I cannot find too much information about it , other challenge is we have a limited support so i'm not sure to go with it unless feel comfortable. we implemented on test environment, but I believe production is a different story.

  2. Database Mirroring (DR) May be the easiest option to go with. and yes I know it a deprecated feature. but still supported in SQl Server 2012, so still we have enough time.

    I like mirroring because it is recommended from Microsoft before Always-on, and secondly it is good in terms of transactions as commit in primary then directory shipped to mirrored database in DR. easy to monitor and stable.

  3. Log shipping(DR) The more robust solution as DR. Microsoft use it in office 365, and very good option in case of slow network. It does need some work to configure and a lot of hands-on to prepare. but it is old and reliable. May be is good for non-critical databases where can I put interval like 24 hours. One cool thing is read only databases where I can switch application in read only mode till primary get fixed unlike mirroring.( Yes Always-On does that).

Again it is for DR only and I would like to hear from you. Consider this for SharePoint databases which means only content and other few databases will be replicated as Microsoft support them only.


Query with WHERE condition that lasts forever

$
0
0

Hi all,

I've a complex view on a SQL 2014 Enterprise Edition. If I query the view with:

SELECT * FROM myComplexView

it takes 14 seconds to completes

if I want a subset of the result and I run the query with a WHERE clause:

SELECT * FROM myComplexView WHERE [Season]='A16'

the query never completes (I've waited 10 minutes and then cancelled the task)

Any advices?

Policy Update UI BUG

$
0
0
I've been tracking down a weird problem where the Target of a Policy is being disabled.

When trying to reproduce the problem I noticed that the T-SQL script generated by the UI has an incorrect value forsp_syspolicy_update_target_set. When I check the check box in the "Against targets" box to enable the target and then generate a script, the value of @enabled is set to FALSE instead of TRUE:

EXECmsdb.dbo.sp_syspolicy_update_target_set@target_set_id=44,@enabled=False

Version Info:
Microsoft SQL Server Management Studio v11.0.5058.0

Microsoft SQL Server 2012 (SP1) - 11.0.3401.0 (X64) 
 Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1)

Screen shot:








Different execution plan for same query

$
0
0

Hi all,

I've 2 servers one running SQL Server 2008R2 Enterprise Edition, the other running SQL Server 2014 Enterprise Edition. On the 2 servers there is the same database (I've migrated it from 2008 to 2014) if I run the same query on the 2 servers, I get 2 different execution plans and 2 different execution times.

On the 2008 machine the query performs 100x time faster! 

The 2014 machine has better hardware and more resources.

I've updated statistics on the SQL 2014 machine.

Any advices?

This is the query:

SELECT     A.PAKAR AS SKU, A.PADEAR AS [SKU DESCRIPTION], A.MODELLO AS STYLE, DIM_Models.Descrizione AS [STYLE DESCRIPTION], A.PAKLI + SUBSTRING(A.PAKAR, 3, 4) AS [ITEM 6], A.PAKLI + SUBSTRING(A.PAKAR, 3, 4) AS [ITEM 6 DESCRIPTION], 
                      A.PAKLI + SUBSTRING(A.PAKAR, 3, 1) AS UDB, CASE WHEN SUBSTRING(A.PAKAR, 3, 1) = 'M' THEN A.PAKLI + SUBSTRING(A.PAKAR, 3, 1) + ' - ' + RTRIM(B.DESC_LIN) 
                      + ' MAN' WHEN SUBSTRING(A.PAKAR, 3, 1) = 'W' THEN A.PAKLI + SUBSTRING(A.PAKAR, 3, 1) + ' - ' + RTRIM(B.DESC_LIN) + ' WOMAN' WHEN SUBSTRING(A.PAKAR, 
                      3, 1) = 'U' THEN A.PAKLI + SUBSTRING(A.PAKAR, 3, 1) + ' - ' + RTRIM(B.DESC_LIN) + ' UNISEX' ELSE A.PAKLI + SUBSTRING(A.PAKAR, 3, 1) + ' - ' + RTRIM(B.DESC_LIN)
                       + ' CHILDREN' END AS [UDB Description], B.COD_MAR AS BRAND, B.MARCHIO_AGG AS [BRAND DESCRIPTION], 'Seasonal' AS [NOOS FLAG], SUBSTRING(A.PAKAR, 4, 3) 
                      AS Fondo, CASE WHEN MATERIALI.[DescriMateriale] IS NULL THEN SUBSTRING(A.PAKAR, 12, 3) ELSE MATERIALI.[DescriMateriale] END AS MATERIAL, 'NA' AS [PHANTON FLAG], CASE WHEN COLORI.DescriColore IS NULL THEN SUBSTRING(A.PAKAR, 15, 4) ELSE COLORI.DescriColore END AS COLOR, '' as [TEMA DI COLLEZIONE], 
                      '' as [COMPONENTE 1], '' AS [COMPONENTE 2], '' AS [GRUPPO COMMERCIALE], '' AS [TIPOLOGIA PRODOTTO 1], 
                      '' AS [TIPOLOGIA PRODOTTO 2], '' AS [GRUPPO PRINCIPALE], A.PAKLI AS LINEA, 
                      CASE WHEN SUBSTRING(A.PAKAR, 3, 1) = 'M' THEN 'MAN' WHEN SUBSTRING(A.PAKAR, 3, 1) = 'W' THEN 'WOMAN' WHEN SUBSTRING(A.PAKAR, 3, 1) 
                      = 'U' THEN 'UNISEX' ELSE 'CHILDREN' END AS GENDER, B.COD_MAR + B.CAT_MER AS [BRAND PRODUCT CATEGORY], B.CAT_MER AS [PRODUCT CATEGORY], 
                      '' AS [COMBINAZIONE MATERIALE], '' AS [COMBINAZIONE COLORE], 
                      '' AS [GRUPPO MUST],0 AS [STYLE DELETED], 0 AS [SKU DELETED], '' AS [FASCIA COLORI], 
                      'NA' AS [TIPOLOGIA MATERIALE PRINCIPALE], CAST(numerata as CHAR(2)) AS [GRIGLIA TAGLIE], 0 AS DELETED, 'NA' AS [STYLE SOTTOSTAGIONE], 'NA' AS SOTTOSTAGIONE, 
                      'NA' AS PLACEHOLDER, 'NA' AS [SKU REPLACED], 'NA' AS [ORDER TYPE], A.PASG AS Stagione, A.PASG AS [LAST PLANNED SEASON], 
                      A.PASG as [SKU LAST PLANNED SEASON], LEFT(ltrim(rtrim(A.PAKAR)),11) as ITEM11
FROM         DIM_Items AS A  INNER JOIN
                      DIM_Lines AS B ON A.PAKLI = B.KLIN
                      left outer join 
                      [TODS_Retail_Planning_ARCA].[dbo].[DIM_Materials] MATERIALI ON A.PAKAR = MATERIALI.SKU AND A.PASG = MATERIALI.STAGIONE
                      left outer join 
                      [TODS_Retail_Planning_ARCA].[dbo].[DIM_Colors] COLORI ON A.PAKAR = COLORI.SKU AND A.PASG = COLORI.STAGIONE
                      left outer join DIM_Models on A.MODELLO = DIM_Models.Modello 
                      left outer join DIM_descrpoet ON A.PAKAR = DIM_descrpoet.SKU18 and A.PASG = DIM_descrpoet.STAGIONE_ST


WHERE
(LEN(A.PAKAR) = 18)

Page life expectancy

$
0
0

Hi, 

I have few servers that are VM and different version of SQL Severs (2008 Express/Standard, 2012, or 2014 Enterprise) and seems all of them have same issue that when I am querying "sys.dm_os_performance_counters" for "[object_name] LIKE '%Buffer Manager%' AND [counter_name] = 'Page life expectancy'" I am getting very big number (Ex, above 100K or some servers 1M). 

Is this number seems fine or acceptable? 


Best Wishes, Arbi; Please vote if you find this posting was helpful or Mark it as answered.

DDL Trigger

$
0
0

Hi All,

In my environment some Windows user have sysadmin permission.

I want to prevent them to create and drop DB as well as  well as table 
what practice should i Do 

What if I would use DDL trigger server level trigger is there any performance issue 

suggest any other idea 

Can not create Listner for High availability group of Always on in SQL 2012 on cluster environment

$
0
0

 I have getting issues when i am creating listener for always On

Error shown as below

Can not bring  the Windows server fail over cluster (WSFC) resources online. (Error Code 5942). The WSFC service may not be running or may not be accessible in its currents states, or the WSFC resources may not be in a state that could accept the request. For information about this error code see "system error code" in windows development documentation 

The attempt to create network name and IP address for the listener is failed. The WSFC service may not be running or may not be accessible in its currents states or the value provide for the network name and IP address may be incorrect. Check the state of the WSFC cluster and validate network name and IP address with network administrator. (Microsoft SQL Server error 41066) 

Please suggest what to do  to ressolve this issues.

Thank You

Nirav Bhatt

SSMS - Error in generating stored procedure script ERROR

$
0
0

All,

    We are trying to generate stored procedure script from SSMS. Version - 2008 R2. We are able to generate the script if we select few procedures from the script generation wizard. But its throwing error, if we select all the stored procedures and try to generate the script. There are more than 1000 stored procedures. We are assuming that the ERROR is  because of huge number of stored procedures.  This is the ERROR::

Microsoft.SqlServer.Management.Smo.SmoException: An exception occurred while executing a Transact-SQL statement. ---> Microsoft.SqlServer.Management.Common.ExecutionFailureException: An exception occurred while executing a Transact-SQL statement or batch. ---> System.Data.SqlClient.SqlException: The server principal "Server\username" is not able to access the database "DBName" under the current security context. at Microsoft.SqlServer.Management.Common.ConnectionManager.ExecuteTSql(ExecuteTSqlAction action, Object execObject, DataSet fillDataSet, Boolean catchException) at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteWithResults(String sqlCommand) --- End of inner exception stack trace

Please suggest.

Thank you


-- Reddy Balaji C. ##Mark as answer if it solves the issue

Viewing all 12554 articles
Browse latest View live


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