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

Trace Flag 8293 not working

$
0
0

After we enabled Change Tracking, we keep getting the alert below:

"Change Tracking autocleanup is blocked on side table of "tablename". If the failure persists, check whether the table "tablename is blocked by any process."

So we followed this KB article to set Trace Flag 8293, but still we get the alert (11 within one minute), anything we could be missing?

https://support.microsoft.com/en-us/help/4456883/fix-change-tracking-cleanup-message-22123-is-unexpectedly-recorded-in

PS: we are using SQL 2016 SP2



Performance issues using SQL CLR - High PAGEIOLATCH_SH

$
0
0

Dear community, 

let me describe my problem: 

Query: 

SELECT t.value1, t.value2, x.valueA

from My300GBTable t

CROSS APPLY MyTableValuedFunction(varbinary field from table t) x

Usually, this works fine. But in some cases the plan generation takes >30 minutes. The system is showing 0% CPU, 3mb/s disk read and low memory pressure (~700GB available). IO System is 72 disk array. Disk queue length on logical disk is around 1.

dm_exec_session_wait_stats shows high PAGEIOLATCH_SH for the session. 

Once the plan is ready, queries are running fast.

Any ideas how to troubleshoot that? 


Capture Table usage - using Xevents

$
0
0

i need to capture particular table usage (hits - select ,insert,update,delete...)  metrics from a database.

how can i implement this via xevent

i used below xevent , but this one not capture data,


CREATE EVENT SESSION [Xevent_DBA_Capture_Specific_Object] ON SERVER 
ADD EVENT sqlserver.module_end(SET collect_statement=(1)
    WHERE ([sqlserver].[database_name]=N'DATABASENAME' AND [object_name]=N'TABLENAME')),
ADD EVENT sqlserver.rpc_completed(
    WHERE ([sqlserver].[database_name]=N'DATABASENAME' AND [object_name]=N'TABLENAME')),
ADD EVENT sqlserver.sp_statement_completed(
    WHERE ([sqlserver].[database_name]=N'DATABASENAME' AND [object_name]=N'TABLENAME'))
ADD TARGET package0.event_file(SET filename=N'X:\Backups\Xevent\Xevent_DBA_Capture_Specific_Object.xel')
WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=30 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=ON,STARTUP_STATE=OFF)
GO

Microsoft.ACE.OLEDB.16.0 provider is not registered on the local machine. (System.data)

$
0
0

Trying to import data from Excel is giving this message.

Office365 64-bit

Here's what I tried:

1) I installed the 64-bit Access database engine 2016

2) I tried the 2010 & 2007 versions as well

3) I reinstalled Office365

I'm out of ideas. What else could be going on here?

Computer scalar

$
0
0

May I know what exactly there are two computer scalar are doing ???

Check type of hash join

$
0
0

How to check the hash join type in a query execution plan ?

1)In-memory hash join

In build phase table fit completely in memory.<o:p></o:p>

2) Grace hash join

In build phase table does not fit completely in memory and spans to disk.<o:p></o:p>

3) Recursive hash join

In build phase table is very large and have to use many levels of merge joins.<o:p></o:p>


looking for a technique to make date range joins perform better

$
0
0

Hi we run 2017 standard.  I've come across this challenge in the past but never solicited help on the matter.

Often, I come across situations where individual records in table A match only a SINGLE record in table B based on
a datetime range in table B that covers a single datetime column from table A.  And indices dont seem capable of making
the match as efficient as other business scenarios where a datetime range isnt involved.

What do i mean? Lets say table A is the incident table (see index also) shown in the code block and it has 30.5 million
records that are newer (start datetime) than 2 years ago.  and about 27 million older than 2 years ago. 

And table B is the job table (see index also, notice no physical pk defined) shown in the code block and it has 3.3 million
records of which about 1.7 million jobs get a match as explained below.  I should mention that presently endtime is null on jobs that arent finished yet.

It would be great if the following query would run much faster than 8-10 minutes.  I suspect if the match criteria
involved only 1 or 2 column equivalents, it would.  But date ranges seem to perform poorly.  I verified that the indexes
shown in the code block are being used in the execution plan.   Now that I look at the NC on the jobs table, I have to admit that I don't know what we were thinking.

select count(*) from
(

SELECT
       inc.pk,
       inc.StartTime,
       inc.EndTime,
       inc.machine

FROM dbo.incidents inc (NOLOCK)
JOIN dbo.jobs job (NOLOCK) ON inc.machine = job.machine  
                          AND inc.StartTime >= job.StartTime
                          AND (inc.StartTime < job.EndTime OR job.EndTime IS NULL)
                          AND job.building = inc.building
                          AND (job.EndTime >= DATEADD(MONTH, -24, GETDATE()) OR job.EndTime IS NULL)

WHERE
inc.StartTime >= DATEADD(MONTH,-24,GETDATE())
) x

USE [mydatabase]


SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[incident](
	
	[Id01] [int] NULL,
	[EndTime] [datetime] NULL,
	[Id02] [int] NULL,
	[machine] [int] NULL,
	[Id03] [int] NULL,
	[Id04] [int] NULL,
	[Id05] [int] NULL,
	[Id06] [int] NULL,
	[Id07] [int] NULL,
	[StartTime] [datetime] NULL,
	[pk] [int] NOT NULL,
	[Id08] [int] NULL,
	[building] [varchar](25) NOT NULL,
	
 CONSTRAINT [PK_incident] PRIMARY KEY CLUSTERED 
(
	[pk] ASC,
	[building] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

USE [mydatabase]
GO

CREATE NONCLUSTERED INDEX [IDX_Incident_NCI02] ON [dbo].[Incident]
(
	[StartTime] ASC
)
INCLUDE ( 	[id01],
	[End_Time],
	
	[machine],
	[id02],
	[id03],
	[id04],
	[id05],
	[id06],
	[id07]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO



USE [mydatabase]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[jobs](
	[Id01] [int] NULL,
	[EndTime] [datetime] NULL,
	[Id02] [int] NULL,
	[machine] [int] NULL,
	[jobId] [int] NOT NULL,--<-------------------this and building are unique
	[StartTime] [datetime] NULL,
	[building] [varchar](25) NOT NULL,
) ON [PRIMARY]
GO

USE [mydatabase]
GO

SET ANSI_PADDING ON
GO

CREATE NONCLUSTERED INDEX [IDX_Jobs_NCI02] ON [dbo].[Jobs]
(
	[StartTime] ASC,
	[EndTime] ASC,
	[machine] ASC,
	[building] ASC
)
INCLUDE ( 	[id02]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

non clustered index with pk vs non clustered index without pk

$
0
0

Hi we run 2017 standard. I'm looking at some tables whose non clustered (nc) indexes are definitely being utilized in the execution plan but there is no pk and no clustered index.

Does an nc index perform as well on a table that doesn't have a pk?  Say in comparison with everything being equal except that the second table has a pk that is the clustered index?


SQLServerLogMgr::LogWriter: Operating system error 170(The requested resource is in use.)

$
0
0
Hello Experts,

        We have SQL Server 2012 on Windows server 2012 Failover cluster(VM).  Few days back we have installed Anti virus on Cluster nodes and got the error SQLServerLogMgr::LogWriter: Operating system error 170(The requested resource is in use.) Later we removed antivirus on both nodes. After couple of days again we started getting the same error and sql services are goes to stopped state. And if i perform failover then sql services are starting . Then after couple of hours later again it went to stopped state with the same error. This happened quite frequently in Node2 but on Node 1 it is happening very rarely.  Both nodes has different service packs and Windows CU.

Initially we thought it could be AV and now we completely removed still we are facing the same issue. 

Please help me to solve this nightmare issue.  



system error log

1:20:30 am

BackupIoRequest::ReportIoError: write failure on backup device 'G:\Backup\Dif_bkp\SCMDB_backup_2019_08_14_010128_7899718.bak'. Operating system error 170(The requested resource is in use.).

1:20:30 am

SQLServerLogMgr::LogWriter: Operating system error 170(The requested resource is in use.) encountered.

1:20:30 am 

The log for database 'msdb' is not available. Check the event log for related error messages. Resolve any errors and restart the database.

1:20:30 am 

The system failed to flush data to the transaction log. Corruption may occur in VolumeId: G:, DeviceName: \Device\HarddiskVolume5.
({Device Busy}
The device is currently busy.)

1:20:31 am 

The system failed to flush data to the transaction log. Corruption may occur in VolumeId: H:, DeviceName: \Device\HarddiskVolume3.
({Device Busy}
The device is currently busy.)

SQL Server Errorlog- 

Date,Source,Severity,Message
08/14/2019 07:21:10,spid6s,Unknown,SQL Server shutdown has been initiated
08/14/2019 07:21:10,spid6s,Unknown,Cannot recover the master database. SQL Server is unable to run. Restore master from a full backup<c/> repair it<c/> or rebuild it. For more information about how to rebuild the master database<c/> see SQL Server Books Online.
08/14/2019 07:21:10,spid6s,Unknown,Operating system error 170(The requested resource is in use.) on file "H:\MSSQL11.MSSQLSERVER\MSSQL\DATA\mastlog.ldf" during FixupLogTail.
08/14/2019 07:21:10,spid6s,Unknown,Error: 5159<c/> Severity: 24<c/> State: 13.
08/14/2019 07:21:10,spid6s,Unknown,SQLServerLogMgr::FixupLogTail: Operating system error 170(The requested resource is in use.) encountered.
08/14/2019 07:21:10,spid6s,Unknown,Error: 17053<c/> Severity: 16<c/> State: 1.
08/14/2019 07:21:10,spid6s,Unknown,fcb status 0x42<c/> handle 0x00000000000007A8<c/> size 224 pages
08/14/2019 07:21:10,spid6s,Unknown,blankSize 0x3c0000<c/> blkOffset 0x11a<c/> fileSeqNo 884<c/> totBytesWritten 0x0
08/14/2019 07:21:10,spid6s,Unknown,SQLServerLogMgr::FixupLogTail (failure): alignBuf 0x000000001163E000<c/> writeSize 0xc00<c/> filePos 0x63400
08/14/2019 07:21:10,spid6s,Unknown,374 transactions rolled forward in database 'master' (1:0). This is an informational message only. No user action is required.
08/14/2019 07:21:10,spid6s,Unknown,Starting up database 'master'.
08/14/2019 07:21:10,Server,Unknown,Software Usage Metrics is disabled.
08/14/2019 07:21:10,Server,Unknown,CLR version v4.0.30319 loaded.
08/14/2019 07:21:10,Server,Unknown,Database Instant File Initialization: enabled. For security and performance considerations see the topic 'Database Instant File Initialization' in SQL Server Books Online. This is an informational message only. No user action is required.
08/14/2019 07:21:10,Server,Unknown,Using dynamic lock allocation.  Initial allocation of 2500 Lock blocks and 5000 Lock Owner blocks per node.  This is an informational message only.  No user action is required.
08/14/2019 07:21:10,Server,Unknown,Node configuration: node 0: CPU mask: 0x000000000000000f:0 Active CPU mask: 0x000000000000000f:0. This message provides a description of the NUMA configuration for this computer. This is an informational message only. No user action is required.
08/14/2019 07:21:10,Server,Unknown,This instance of SQL Server last reported using a process ID of 11160 at 8/14/2019 7:21:08 AM (local) 8/14/2019 3:21:08 AM (UTC). This is an informational message only; no user action is required.
08/14/2019 07:21:09,Server,Unknown,Using conventional memory in the memory manager.
08/14/2019 07:21:09,Server,Unknown,Detected 49151 MB of RAM. This is an informational message; no user action is required.
08/14/2019 07:21:09,Server,Unknown,SQL Server is starting at normal priority base (=7). This is an informational message only. No user action is required.
08/14/2019 07:21:09,Server,Unknown,SQL Server detected 1 sockets with 4 cores per socket and 4 logical processors per socket<c/> 4 total logical processors; using 4 logical processors based on SQL Server licensing. This is an informational message; no user action is required.
08/14/2019 07:21:09,Server,Unknown,Command Line Startup Parameters:<nl/>-s "MSSQLSERVER"
08/14/2019 07:21:09,Server,Unknown,Registry startup parameters: <nl/>-d H:\MSSQL11.MSSQLSERVER\MSSQL\DATA\master.mdf<nl/>-e H:\MSSQL11.MSSQLSERVER\MSSQL\Log\ERRORLOG<nl/>-l H:\MSSQL11.MSSQLSERVER\MSSQL\DATA\mastlog.ldf
08/14/2019 07:21:09,Server,Unknown,The service account is 'account\sqlservice'. This is an informational message; no user action is required.
08/14/2019 07:21:09,Server,Unknown,Logging SQL Server messages in file 'H:\MSSQL11.MSSQLSERVER\MSSQL\Log\ERRORLOG'.
08/14/2019 07:21:09,Server,Unknown,Authentication mode is MIXED.
08/14/2019 07:21:09,Server,Unknown,System Manufacturer: 'VMware<c/> Inc.'<c/> System Model: 'VMware Virtual Platform'.
08/14/2019 07:21:09,Server,Unknown,Server process ID is 5280.
08/14/2019 07:21:09,Server,Unknown,All rights reserved.
08/14/2019 07:21:09,Server,Unknown,(c) Microsoft Corporation.
08/14/2019 07:21:09,Server,Unknown,Microsoft SQL Server 2012 (SP4) (KB4018073) - 11.0.7001.0 (X64) <nl/>Aug 15 2017 10:23:29 <nl/>Copyright (c) Microsoft Corporation<nl/>Enterprise Edition: Core-based Licensing (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor)



Thank you

Sai Nadh

tune query

$
0
0

Hi,

abcd..Price  table contains = 1.9billon records

below query take more time bcaz of missing index, how can i tune this with out index creation?

Query:

select itemid,max(ts) lastcostchange from abcd..Price with(nolock) where Price_type='cost' group by itemid

if i created below index that one eat up 70GB of space in my drive,

CREATE NONCLUSTERED INDEX [ncls_price_prictyp_incl_ts_itemid]
ON [dbo].[Price] ([price_type])
INCLUDE ([ts],[itemid]) with (online=on,fillfactor=80)

Monitor SAN Perfmon counters (logical or physical disk counters)

$
0
0

I run Perfmon on Win 2012 R2. Storage is SAN based, hosts are VMWare. Not clear to me if I should use physicalDisk or logicalDisk object counters .

Thank you,


SQL Express question

$
0
0


Hi All,

Need a clarification. I am not seeing BUILTIN\Administrators group under sql logins. Was it removed from any specific version. I am using SQL 2016 Express Edition. 'sa' is also disabled. only windows authentication is turned on.

What are the steps to add a windows user as a sql admin.?

The reason why I am asking this, recently we have got an SQL Express instance which needs to be upgrade (i.e. edition upgrade =Standard) as they hitting 10GB limit on data files. Thats why wanted to know the steps involved to add a user as an sqladmin before performing the edition upgrade.

Also, are there any known issues while performing edition upgrade from SQL2014 express edition to SQL2014 standard edition ?

Thanks,

Sam

Extended Events large query statements

$
0
0

I need to setup Extended Events sessions on a couple of servers running SQL 2012/2014 Ent.

Session should capture the statements (inside procs/ad-hoc queries/rpcs ) that have the largest impact . 

I do not do the multiple executions with same hash/ analyze at this step , just focusing on largest impact statements/queries.

As I see I should only be capturing the sp_statement_completed, sql_statement_completed, rpc_completed and not the module_end or sql_batch_completed, correct?

I am good with the DDL for it, actions/options/targets, etc, just the set of events to capture the high impact statements/queries.

Thank you,

Trace Flag 4199

Getting final column types from Extended Events DMV's

$
0
0

With a query like this.... this is not perfect.... which is the heart of the question.....

I hope, I covered all the necessary five dmv's needed to get the column type level detail.

+++returns too many rows; tried distinct knowing that is not the right way of solving the problem.  Might be missing a join somewhere ++++++++++

select s.name , c.*

from sys.dm_xe_sessions s , sys.dm_xe_session_targets t , sys.dm_xe_packages  p , sys.dm_xe_objects o , sys.dm_xe_object_columns c
where s.address = t.event_session_address and s.name = '
eeDuration'and p.guid = t.target_package_guid and p.guid = o.package_guid
and p.guid = c.object_package_guid and o.type_package_guid = c.type_package_guid

++++++++++++++++++++++++++++++

What I want to get with the above query is the data that are Bolded and Underlinedwithin the following script, so that I can create the final table (from the XML) with appropriate column types, etc.  I don't think these data types are inside the XML (did not even bother to check)…. just want to get them by using the dmv's dynamically.

Also need some help with eventvs. data

drop table if exists eeDuration
go
SELECT event_data = convert(xml, event_data)
INTO eeDuration
 FROM sys.fn_xe_file_target_read_file(N'R:\Mssql\Backup\aStandardManual_0_*.xel', null, null, null);
 go
--SELECT * FROM eeDuration
SELECT
  ts  = event_data.value(N'(event/@timestamp)[1]', N'datetime'),
  [sql]  = event_data.value(N'(event/action[@name="sql_text"]/value)[1]', N'nvarchar(max)'),
  duration  = event_data.value(N'(event/data[@name="duration"]/value)[1]', N'nvarchar(max)'),
  spid  = event_data.value(N'(event/action[@name="session_id"]/value)[1]',N'int'),
  user_nm = event_data.value(N'(event/action[@name="username"]/value)[1]', N'nvarchar(max)'),
  dbname = event_data.value(N'(event/action[@name="database_name"]/value)[1]', N'nvarchar(max)'),
  username = event_data.value(N'(event/action[@name="nt_username"]/value)[1]', N'nvarchar(max)'),
  statement = event_data.value(N'(event/data[@name="statement"]/value)[1]', N'nvarchar(max)')
FROM eeDuration
ORDER BY ts


Travis McGee



Restore is failing ...

$
0
0

Hi Experts,

We are trying to restore a prod database on one of the sub-prod environments. We are doing the restore via sql agent job.
Job is failing and when I see the job history, it shows below message.
There is insufficient free space on disk volume 'E:\' to create the database.
The database requires 636590489600 additional free bytes, while only 206158872576 bytes are available.
[SQLSTATE 42000] (Error 3257)  Problems were identified while planning for the RESTORE statement.

My Question is why does the RESTORE is failing? We are even using WITH REPLACE option which tries to replace existing files and there is around 190 GB free space in drive.
What makes SQL Server tell the user that it needs additional of 636590489600 bytes (593 GB). Can anyone please explain?

Environment details
============================
select @@version
Microsoft SQL Server 2012 (SP4) (KB4018073) - 11.0.7001.0 (X64)
    Aug 15 2017 10:23:29
    Copyright (c) Microsoft Corporation
    Enterprise Edition (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor)


--drive info
Currently E: drive allocate space = 4.62 TB , 191 GB Free.


-- Tried to do restore filelistonly
RESTORE filelistonly
FROM DISK='H:\Backup\db_name_Full_20190813_230453.BAK'

-- checked the current file size

select * from master..sysaltfiles
where dbid = db_id('dbname')


Thanks,
Sam



Enable TCP IP and Named Pipes using T-SQL/PowerShell/CMD

$
0
0

Hi,
I am trying to enable TCP/IP and Named Pipes using the following command. But I have encountered the error:--

WMIC /NAMESPACE:\\root\Microsoft\SqlServer\ComputerManagement10 PATH ServerNetworkProtocol Where ProtocolName=’Np’ CALL SetEnable

Invalid Namespace



Thanks

Multiple mdf, empty one is missing

$
0
0

Hi guys i have a big problem. I know i did such stupid and unforgivable mistake. And know please help me if you can. I wanted to make copy of database. I should make it by backup and then restore as another database but faster option was to stop mssql server service, copy files and then attach as new database. The problem is that few minutes eariel i have created new mdf file on primary filegroup in my database i wantedo to copy. That was empty mdf file, just new one. Then i stoped mssql service and deleted that new empty mdf file from hard drive manually. I dont know why, i thought that: "this was just for tests we dont need anymore". When i copied files, i started mssql service and my database is in "recovery Pending" mode and cant find that empty mdf file. Even if i create the same file from another database ofcourde mssql server knows that this is not proper file. I cant make alter table remove file beacuse of error:

Database cannot be opened due to inaccessible files or insufficient memory ordisk space

Is there any possibilities to recover that database? I have backup but i will lost data from one day.

Please help if you can

Query Store option

$
0
0

One option in query store I get very confused .

Statistics Collection Interval

what does it acutally do ? the default interval is 60mins.

so which mean every 60 mins the execution plan will gather once?

Database Status: Suspect vs Recovery Pending.

$
0
0

what's the different between database status Suspect vs Recovery Pending. ???

what's are the different causes for both Suspect vs Recovery Pending. ???

Viewing all 15911 articles
Browse latest View live


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