Find the queries which is taking a long time to execute in sqlserver
SQL Server Audit Log: many rows for one query
We just started using the SQL Server Audit Log for SQL Server 2012 and 2016 Enterprise.
We noticed that one query can generate 60 or more rows in the SQL Server Audit log. The more complex the query is, the more rows we get in the Audit log. It may depend on the number of times the single query satisfies the criteria specified in the Server Audit Specification.
If we turn on a little bit of performance monitoring, the SQL Server Audit log goes completely bananas logging VIEW SERVER STATE events, 60 or more rows per query.
Is this a bug in SQL Server, or "works as designed"?
Is this behavior configurable?
Why does the SQL NT service show higher number?
What changes can be done to the system so that we can SQL Server NT service does not show higher number.
Copy ONLY structure of all tables of Database from one SQL Server database to another server by Store Procedure (Automation)?
Question on log file truncation
Hello!
https://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/ms179355%28v%3dsql.105%29
Q: Does that theory mean that with the default setting of autogrowth is enabled and the log file size = 2 097 152 MB the log file will grow up to 2TB even with daily log backups because the truncated VLFs would never be reused?
Thank you in advance,
Michael
Usage of Data cubes in stored procedures and for Tableau reporting
Hi All,
Thanks for visiting my post. I am well versed in working relational databases (rows a& columns - tables) for reporting. In one of my ongoing project, I was asked to use Microsoft data cubes for building dashboards
which I is a fundamentally major shift to me using Data cubes. I have a theoretical understanding of Data cubes which are multi-dimensional data analysis (OLPAP source) but never worked before. Thus I am posting to get better help of understanding of it and
following were initial questions i have.
1.. How data cubes can be access
My understanding is that it will be access through MS Analysis service (SSMS), but is there any physical existence of cubes in Database engine.
I had a communication from cubes development team, we given access to cubes, I checked through Database Engine and navigate to desired database mentioned and found the cubes under tables section (
of course they mentioned as labels). those appear to be a regular tables with rows & columns. am i going in the right direction ? What are the additional questions to be asked?
2. Using cubes in a Stored procedures ( above mentioned tables)
Interestingly, My colleague advised to create stored procedure to obtain data from tables (labeled as cubes which were found undertables section- assuming they were cubes when logged in through
database engine) . Is it really possible to use cubes in stored procedure (SPROC) to get the tdata into my Tableau reporting structure.
Please advise me on above items where to begin with and correct me if am not in a correct direction.
Appreciate your reply.
Thank you
Error in creating backup directory using Ola Hallengren
I am getting the following error after the backup job running, when Ola is creating the directory it gives space between P-GYMDTSU1$P-GYMDTSU1 and \DAM (P-GYMDTSU1$P-GYMDTSU1 \DAM) and because of this the job failed and it is throwing an error 'the system can't find the path, I have uninstalled and reinstalled the Ola script reconfigured the job, I couldn't be successful. But when I take the backup manually it works fine since it has got the right backup path. but from the sql agent job I am getting the following error, if any one who can face this issue please help.
Command: DECLARE @ReturnCode int EXECUTE @ReturnCode = [master].dbo.xp_create_subdir N'\\RDGS.local\backups\DBBackups\Prod\P-GYMDTSU1$P-GYMDTSU1 \DAM\FULL' IF @ReturnCode <> 0 RAISERROR('Error creating directory.', 16, 1)
Msg 22048, Level 16, State 1, Line 0
xp_create_subdir() returned error 3, 'The system cannot find the path specified.'
Msg 50000, Level 16, State 1, Line 1
Error creating directory.
Dereferencing Server name of 4-part name - What is the sequence?
A Linked Server name can be aliased.
a DNS Entry using a CNAME record can alias an "actual server name" in DNS (CNAME record).
These facts alone makes Server Name(/"Identifier") collisions possible in a given network/SQL Server environment (naming collisions that _can_ point to different destinations). This issue can arise especially in situations like: server moves, server retirements, hardware changeovers, etc.
All these factors beg the following question: What sequence does SQL Server utilize to dereference the server name?
Is DNS or the Sys.Servers (Linked Server definitions) queried first to dereference the destination server name, or...what??
Mark Burns, MCAD, MCP
Sr. Microsoft Access Analyst/Developer
Manager LinkedIn.Com community: Professional Microsoft Access Developers Network (PMADN)
Restore from SQL managed instance
Hi all,
With the recent updates to SQL server 2019 versions we have encountered an issue with the version compatibility to Azure managed instance SQL versions.
I am getting this error message when trying to restore a backup file created from a DB on the managed instance -
database was backed up on a server running version 15.00.2000. That version is incompatible with this server, which is running version 15.00.4003. Either restore the database on a server that supports the backup, or use a backup that is compatible with this server.
On the local server i have the latest CU1 installed and still it is not working although the version is higher.
The DBs are from an older instance so mostly compatibility level 110 (SQL server 2012).
Unfortunately the Data-tier export is also failing due to different reasons so i cant use that approach until fixing those.
Any idea on how to complete a restore with the new versions?
Before Azure went to version 15.00.2000 the normal restore process on the SSMS went without any issues when restoring the bak file.
Any help would be appreciated.
Thanks in advance
Use a Parameters inside a Subquery of SQL inside a MS Query in Excel
I'll try to be clear but that's not my first language
I would like to make a connection to my SQL Database via MS Query and make a Query where I could use some Parameter "box" to fullfill the Query.
Here's my Query. Please be kind I'm not good In programming but Would like to find an answer to my problem
SelectYear_One.Customer,
Sum(Year_One.CDN_Amt) as Sum_Y_One,
Sum(Year_two.CDN_Amt) as Sum_Y_Two,
Sum(Year_Three.CDN_Amt) as Sum_Y_Three
From(SelectCustomer.Customer,
Inv_Head.Currency_Conv_Rate,
Inv_Head.Document_date,
Case When Invoice_Detail.Amount is NULL then 0
Else Invoice_Detail.Amount end as Amount,
Inv_Head.Document,
Case When Invoice_Detail.Amount IS Null Then 0
Else Invoice_Detail.Amount/Inv_Head.Currency_Conv_Rate
End as CDN_Amt
From Customer
LEFT JOIN (Select * from Invoice_Header
whereYear(document_date)=? /*got my first parameter to fullfill*/
andMONTH(document_date)>=01
andDAY(Document_Date)>=01
andMONTH(Document_Date)<=12
andDAY(Document_Date)<=31)
as Inv_head
ON Customer.Customer=Inv_head.Customer
LEFT JOIN
Invoice_Detail
ON Inv_head.Document=Invoice_Detail.Document) as year_three
LEFT JOIN
(SelectCustomer.Customer,
Inv_Head.Currency_Conv_Rate,
Inv_Head.Document_date,
Case When Invoice_Detail.Amount is NULL then 0
Else Invoice_Detail.Amount end as Amount,
Inv_Head.Document,
Case When Invoice_Detail.Amount IS Null Then 0
Else Invoice_Detail.Amount/Inv_Head.Currency_Conv_Rate
End as CDN_Amt
From Customer
LEFT JOIN (Select * from Invoice_Header
whereYear(document_date)=?-1 /*this could be the same as the first or I could manage to put the other year*/
andMONTH(document_date)>=01
andDAY(Document_Date)>=01
andMONTH(Document_Date)<=12
andDAY(Document_Date)<=31)
as Inv_head
ON Customer.Customer=Inv_head.Customer
LEFT JOIN
Invoice_Detail
ON Inv_head.Document=Invoice_Detail.Document) as year_two
ON year_three.Customer=year_two.Customer
LEFT JOIN
(SelectCustomer.Customer,
Inv_Head.Currency_Conv_Rate,
Inv_Head.Document_date,
Case When Invoice_Detail.Amount is NULL then 0
Else Invoice_Detail.Amount end as Amount,
Inv_Head.Document,
Case When Invoice_Detail.Amount IS Null Then 0
Else Invoice_Detail.Amount/Inv_Head.Currency_Conv_Rate
End as CDN_Amt
From Customer
LEFT JOIN (Select * from Invoice_Header
whereYear(document_date)=?-2 /*I could manage to read the parameter from another but it need to be a parameter */
andMONTH(document_date)>=01
andDAY(Document_Date)>=01
andMONTH(Document_Date)<=12
andDAY(Document_Date)<=31)
as Inv_head
ON Customer.Customer=Inv_head.Customer
LEFT JOIN
Invoice_Detail
ON Inv_head.Document=Invoice_Detail.Document) as year_one
ON year_three.Customer=year_one.Customer
where Year_One.Customer=?
Group by Year_one.Customer
I read about a lot a forum and it seem to be a issue from many people but the only getaway I see is to manage a Stored Procedure to do so and I'm not really sure of the result
Thanks In advance
Jean-Philippe André
Problem with XML parser memory leak
We're using xml parameters to send a collection of data to stored procedure.
Typical (little simplified) use case would look like:
DECLARE @Values varchar(max) = '<Root><S>1</S><S>2</S><S>3</S></Root>', @h int
DECLARE @Val TABLE(ID smallint)
EXEC sp_xml_preparedocument @h OUTPUT, @Values
INSERT INTO @Val(ID)
SELECT DISTINCT ID FROM OpenXML(@h,'Root/S',8) WITH (ID smallint 'text()')
EXEC sp_xml_removedocument @h
SELECT * FROM @Val
We know we have to properly "pair" sp_xml_preparedocument /sp_xml_removedocument to avoid memory leaks.
Normally, our server works for months without any problems.
(I have to use external image because your portal is giving me "Body text cannot contain images or links until we are able to verify your account." error message) https://imgpile.com/i/I5kAUR
At some point in time we're able to observe a constant growth of xml parser memory usage.
Our system still works, but it appears as if no document is being properly "removed", so our memory
usage graph begins to steadily grow.
(I have to use external image because your portal is giving me "Body text cannot contain images or links until we are able to verify your account." error message) https://imgpile.com/i/I5kLYg
In the graph above 1.5K represents 1500MB. The only way to stop this endless growth is to restart
SQL Server service. After that it starts working just fine.
Is there a way to reclaim back all memory (some kind of overall xml parser memory "reset") without
rebooting the whole service?
Since our stored procedures are running pretty quickly (few seconds max.) is there a way to reclaim
all memory allocated by sp_xml_preparedocument which execution moment is older then some predefined time
(that would simply deallocate all "old" memory used by "old" xml documents)?
Any help would be very useful.
We're using version: Microsoft SQL Server 2014 (SP3-CU4) (KB4500181) - 12.0.6329.1 (X64) Jul 20 2019 21:42:29 Copyright (c) Microsoft Corporation Standard Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
We also had identical problem with SQL Server 2012.
Change tracking auto cleanup not working
We have a production clustered instance running SQL Server 2014 SP3 CU1 (version 12.0.6205.1). It hosts (amongst others), two databases with change tracking enabled. Both have auto cleanup enabled and retention period set to 30 days.
I have noticed however, (querying sys.dm_tran_commit_table) that one has retained transactions going back to 4th November 2019 and the other even further back - 2nd December 2018. The same databases in our test environment both have retained transactions back to 31st December 2019, as I would expect.
By chance, I restored backups of the two production databases onto a dev machine the other day for unconnected reasons but, checking those copies now show transactions back, once again, to the expected 31st December 2019.
The only difference I can see is that the test and dev servers are running SQL Server 2014 SP3 CU4 (we are waiting for a suitable window to upgrade production). Is this a bug in SP3 CU1 or could something else be causing it?
Finding Cause of Performance Issue
Running SQL Server 2008 R2 SP3 on two different servers, with (at a glance) identical configurations.
Both servers are virtual and have the same amount of resources assigned to them. The data drives are on the same SAN and use the same performance tier. Server A has a production database of 40+ GB, while Server B has a production database of 5+ GB.
Both databases have the same schema and indexing, and the activity levels on Server A are higher than Server B. When running queries against Server B they are noticeably slower than executing the same queries against Server A. I can confirm this isn't just activity-based because even in off-hours the issue still presents itself.
Is there anything in terms of configuration at either the server or database level I should be checking? If so, what?
Thanks!
error authenticating proxy - sql agent
Hi we run 2017 std. All of my jobs except one continued running without issue with step 1 in each being ssis and using a cred whose proxy service acct is domaina\userb.
One of my jobs wouldn't run anymore and was issuing the following error. All I can think of that might be relevant is that I did disable it for some time today and also stopped it once while it was running. What can cause this auth problem? I changed the Run as on that step and then changed it back before posting here thinking maybe I can fool agent. And it did start running again. Do you think I fooled agent? I've disabled jobs before but never stopped one. Is it possible stopping the job caused this behavior?
Unable to start execution of step 1 (reason: Error authenticating proxy domain\userb. system error: The user or password is incorrect.). The step failed.
security_error_ring_buffer_recorded error 1332
While parsing the system_health session, I noticed security_error_ring_buffer_recorded
error code 1332
api:LookupAccountSID
Calling_api_name:LookupAccountSidInternal
Running SQL 2014. Google on 1332 gives "No mapping between account names and security IDs was done." but I did not find related entries in SQL log, or in Event Viewer app, sec and syslogs. Looks like related to authentication.
Any ideas how to find the cause?
Thank you,
SSMS shows different value for number of NUMA nodes than sql error log
So, i am trying to calculate MAXDOP on a new server and this is what i see:
SSMS - Processors - Shows 2 numa nodes (0 & 1) each having 10 cpu's
But when i look at the sql error log, i see entries which suggest # of NUMA nodes = 4 (Numa 0,1,2,3)
select numa_node_count from sys.dm_os_sys_info
gives - 4
So i am a bit confused , Do i have 2 numa nodes with 10 cpu's each OR do i have 4 numa nodes with 5 CPU's each?
D
Through Database Audit specification, need to find hostname or IP which done the delete operation
Hi All,
I have enabled the "Database Audit Specification" to audit the delete operation in Database. And below is the Audit_Action_Type, Principal name given.
In the below output, i am getting the delete action, but i need Hostname and IP of that machine to find either user or application deletes.
Please help. Thanks in Advance.
Thanks & Regards,
SQLDBA
SQL Server CDC Scripting from an existing cdc enabled DB
I have a question on the CDC.
I have a CDC enabled DB in my dev vm. Out of the 50 tables in this DB, 32 are cdc enabled.
I want to script out 'create table' along with the CDC metadata like cdc enablement to a .sql file for these tables.
I was expecting when i rightclick on the Db(Tasks->Generate Scripts) or the table(Create table) in Management Studio, it would include the line for cdc enablement. However, i notice that the CDC part is excluded.
Basically, one of my colleagues wants to have the exact schema copy of my db in his dev environment, so i thought of scripting out the tables for him.
I want to give him the CDC enablement script as well, is there a way to script this out from my existing db?
Please help
thanks
Find the job that has sent a particular email
Hi guys,
I have several databases with several jobs that send email to different users. Now I would like to find which job has sent a certain email. The structure of the job is this:
IF EXISTS (Select 1 from [Stopo].[dbo].[CorrectUser]) BEGIN EXEC sp_send_dbmail @profile_name='StopoReports', @recipients='Team@xxxx.com', @subject='CorrectUser', @query=N'Select * from [Stopo].[dbo].[CorrectUser]', @attach_query_result_as_file = 0 END;
Many Thanks
Strange Issues with memory on SQL2016
We have started seeing an issue over the last two weeks where our CPU jumps and causes us to clear the cache for one of our databases on a HA cluster. The server this is occurring on is a read-only node and see a lot of activity (2k batches/sec). Some of our procedures are called 8k - 10k times per minute.
About 10 minutes before the CPU spikes and causes an automated system to kick in that will free the cache in one of the databases, we start seeing two weird things:
1 - Our stored procedures start falling out of the cache when looking at sys.dm_exec_procedure_stats.
2 - We start seeing RESOURCE_MEMPHYSICAL_HIGH IndicatorsSystem = 1 when looking at sys.dm_os_ring_buffers. RESOURCE_MEM_STEAD also have an IndicatorsSystem = 1.
For the dm_os_ring_buffer, we will see results such as this:
EventTimeType IndicatorsProcess IndicatorsSystem Avail Phys Mem, KbAvail VAS, Kb
----------------------- -------------------------------------------------------------------------------------
2019-11-29 14:48:24.440 RESOURCE_MEM_STEADY 0 1 31085396 136037463680
2019-11-29 14:48:24.440 RESOURCE_MEMPHYSICAL_LOW 0 0 31085396 136037463680
2019-11-29 14:48:24.440 RESOURCE_MEMPHYSICAL_HIGH 0 1 31085396 136037463680
2019-11-29 14:48:24.440 RESOURCE_MEM_STEADY 0 0 31085396 136037463680
2019-11-29 14:48:24.440 RESOURCE_MEMPHYSICAL_LOW 0 0 31085396 136037463680
2019-11-29 14:48:23.440 RESOURCE_MEM_STEADY 0 1 31085148 136037463680
2019-11-29 14:48:23.440 RESOURCE_MEMPHYSICAL_HIGH 0 1 31085148 136037463680
2019-11-29 14:48:23.440 RESOURCE_MEM_STEADY 0 0 31085148 136037463680
SQL Server Enterprise - 2016 SP2 CU10
524GB RAM
Min Memory 65,436, Max Memory 471,772
Pages Locked in Memory is set.
Has anyone seen anything like this before?
Ed Mlynar