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

Physical IO utilization

$
0
0

Hi

I have an issue with SQL server resource utilization , We are using SQL Server 2008 r2 standard edition and server physical IO is going too high. So is there any option to control
max physical IO with SQL standard edition. i.e without using Resource governance 



SQL Agent jobs are not running after Windows Server restart

$
0
0

Hello,

We have configured Log shipping for around 100 Databases on SQL Server 2008 on different instances.

And there is a planned restart of the physical server every weekend. And SQL server services are starting automatically. All agent jobs were working fine.

But, we were receiving hundreds of LS alerts(out of sync).

To stop those alerts every weekend, we have disabled all LS jobs for 4 hours and enabled after that using 2 agent jobs on each instance. One job disables all LS jobs and another one enables them.

The problem started here..

The LS jobs are not running automatically after Server restart.(all SQL services are up and running). So we have to manually restart SQL Agent Service every time.

Can anyone suggest, what could be possible reasons.

Thanks,

Umesh

Export database linked

$
0
0

Hello guys,

I've SQL Server Express 2012 with linked DB on MySQL and I 'd like to know if is it possible to export all tables of database linked to file (csv or other type).

I've try bcp but give me error on source database linked.

What is the best method for this aim?

Thanks

bye

What does DB: waitresource means in sys.sysprocesses?

$
0
0
I'm monitoring SQL server's health by querying sys.sysprocesses View. There is waitresourcecolumn on which i am confused: there is a lot information about PAG:,TAB:,KEY:,RID: resources, but I can not find any information about DB: resource like DB: 17:67. 17 is database_id, but what means second number, 67?

Thanks!


view taking long time to complete

$
0
0

select top 10 * from [dbo].[v_order_details_status]

View:

                                    

CREATE view [dbo].[v_order_details_status]  
as  

select id,status,trackers,  
case  
when status='Cancelled' Then 0  
when _sdays > _days then 1  
when _sdays <= _days then 0  
when dbo.f_get_business_days(_ts,GETDATE()) > _days then 1  
else 0  
end late_shipment,  
case when status='Cancelled' Then 0 else dbo.f_max(0, _sdays - _days) end late_shipment_days,  
case when status='Cancelled' then null else turnaround end turnover,  
_sd shipdate,  
_snd shipdate_notified,  
expected_shipdate  
from (  
 select  
 d.id,  
 case   
 when MAX(t.id) is null then d.status  
 else 'Shipped'  
 end status,  
 dbo.Conc(tn.tracker) trackers,  
 d._days,  
 d._ts,  
 min(isnull(tn.created,status_date)) _sd,  
 min(isnull(tn.notified_customer_date,status_date)) _snd,  
 min(dbo.f_get_business_days(d._ts,coalesce(tn.created,d.ship_status_date,GETDATE()))) _sdays,  
 MIN(   
  case   
  when coalesce(tn.created,d.ship_status_date,GETDATE())<_exp then dbo.f_get_business_days(d._ts,coalesce(tn.created,d.ship_status_date,GETDATE()))  
  else d._days + datediff(day,_exp,coalesce(tn.created,d.ship_status_date,GETDATE()))  
  end  
 ) turnaround,  
 expected_shipdate  
 from(  
  select   
  od.id,  
  case  
  when od.status='SHIPPED' then 'Shipped'  
  --when not poi.poid is null then 'Invoiced'  
  when os.closed=1   then os.text  
  when os.shippable = 0  then os.text  
  when not od.status is null then od.status  
  when od.poid>0    then 'PO Created'  
  else 'Not Shipped'  
  end status,  
  isnull(po.ts,o.ts) _ts,  
  op.original_leadtime_days _days,  
  dbo.f_get_business_day(isnull(po.ts,o.ts),op.original_leadtime_days) _exp,  
  od.status_date,  
  case when od.status='SHIPPED' then od.status_date else null end ship_status_date,  
  case   
  --when op.expected_shipdate is not null then   
  -- case   
  -- when op.expected_shipdate> getdate() then op.expected_shipdate   
  -- else getdate()   
  -- end  
  when op.expected_shipdate> getdate() then op.expected_shipdate   
  else   
   dbo.f_get_business_day(  
     case   
     when pd.expected> isnull(po.ts,o.ts) then pd.expected   
     else isnull(po.ts,o.ts)   
     end  
     ,  
     dbo.f_max(2,lt.days)  
    )   
  end expected_shipdate  
  from orders_details od  
  join orders_products op on op.id = od.opid  
  join orders o on o.id = op.orderid  
  join orders_status os on os.id = ISNULL(o.status,0)  
  join product_details pd on pd.id = od.itemid  
  join product p on p.id = pd.pid  
  join vendor v on v.id = p.vendor_id  
  left join leadtime lt on lt.id = ISNULL(pd.leadtime,v.default_leadtime_id)  
  left join purchase_order po on po.id = od.poid  
  --join v_product_status ps on ps.id = od.itemid  
  --left join purchase_order po on po.id = od.poid  
  --left join (  
  -- select distinct poid from purchase_order_invoice   
  --) poi on poi.poid = od.poid  
 ) d   
 left join orders_details_trackers t on t.odid = d.id  
 left join tracking_numbers tn on tn.id = t.tracker  
 group by d.id,d.status,d._days,d._ts,d.expected_shipdate  
) t  






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

Fun 1 used: 

CREATE function [dbo].[f_get_business_days](@f date, @t date) returns int  
as  

begin  
/*  
return(  
 select SUM(cast(dbo.f_is_business_day(dateadd(day,i,@f)) as int))  
 from f_get_nums(DATEDIFF(day,@f,@t))   
)  
*/  
 if @f is null or @t is null return null;  
 declare @n int = 0;  
 declare @i int = 0;  
 declare @j int = datediff(day,@f,@t);  
 while(@i<@j)  
 begin  
  set @i = @i + 1;  
  if dbo.f_is_business_day(DATEADD(day,@i,@f))=1 set @n = @n + 1;  
 end  
 return @n;  
end  

-----------

Fun 2 used:

CREATE function [dbo].[f_is_business_day](@ts date) returns bit --with schemabinding  
as  
begin  
if @ts is null return 0;  
if DATEPART(weekday,@ts) in(1,7) return 0  --SATURDAY & SUNDAY  
  
if MONTH(@ts) = 5 and DATEPART(weekday,@ts) = 2  
 AND DAY(@TS)>=25 return 0     --MEMORIAL DAY  
  
if MONTH(@ts) = 7 and DAY(@ts) = 4 return 0  --JULY 4   
if MONTH(@ts) = 7 and DAY(@ts) = 5   
 and DATEPART(WEEKDAY,@ts) = 2 return 0  --JULY 4 SUNDAY   
  
if MONTH(@ts) = 9 and DATEPART(weekday,@ts) = 2  
 AND DAY(@TS)<7 return 0      --LABOR DAY  
  
if MONTH(@ts) = 11 and DATEPART(weekday,@ts) = 5  
 and DAY(@ts) between 22 and 28 return 0  --THANKSGIVING  
  
/*  
if MONTH(@ts) = 11 and DATEPART(weekday,@ts) = 6  
 and DAY(@ts) between 23 and 29 return 0 --BLACK FRIDAY  
*/  
  
if MONTH(@ts) = 12 and DAY(@ts) = 25 return 0 --CHRISTMAS  
if MONTH(@ts) = 12 and DAY(@ts) = 31 return 0 --NEW YEARS EVE  
if MONTH(@ts) = 1 and DAY(@ts) = 1 return 0  --NEW YEARS  
  
return 1  
end  








remove backup destination location from SQL server management Studio

$
0
0

Hi On my SQl Server instances when I click SSMS -> database ->tasks->backup  then I can see last backup location . I need to remove this and should appear as blank . Do you any one how to remove it.

Find And Schedule Index Rebuild

$
0
0

Hi All,

I have found this information. We can use the sys.dm_db_index_physical_stats DMF to analyze the fragmentation level of indexes.
Fragmentation 10 percent or less should not be considered a problem. A best practice is to reorganize indexes with more than 10 percent and up to 30 percent fragmentation. So, if the fragmentation is more than 30 percent, then we should go for  index rebuild.

Is there any way to find those indexes and rebuild automatically with scheduled job?

Thanks,

Ramaraju

Tempdb in the case of Max degree of parallism

$
0
0

Hi,

my server is having 8 cores and i created 8 tempdb files due to contention. Now i want to set max degree of parallelism to 2.

Here my question is setting more tempdb files for parallelism to share the query process between cpu core. if i set max degree of parallelism to 2 then my query will run with 2 cpu core those use 2 tempdb files. This means every 2 use same 2 tempdb files.

so what is the use of creating more tempdb files on server in the case of Max degree of parallelism.


error: 22123, severity: 16, state: 1 after installing SQL Server 2014 SP3

$
0
0

Hi,

After installing the new SP3 for SQL Server 2014, we keep getting the error: 22123, severity: 16, state: 1 - "Change Tracking autocleanup is blocked on side table of <TABLE>. If the failure persists, check if the table <TABLE> is blocked by any process.

I found a related issue with installing the latest SPs with SQL Server 2016 and 2017.  However, this is now resolved with a CU for each of the versions.

It looks to me like a bug in the newer SPs of each version.  However, I don't know why a CU was not released for SQL Server 2014.  Can anyone confirm or provide more information into this?

Thank you in advance for any assistance.

Cheers,

Rocky


Alert - Data/Log File Running Out of Space

$
0
0

We have configured alert for ‘Data/Log File Running Out of Space’ on SQL Servers running inside Azure VM. Current logic depend upon ‘Current Percent Used’.

USE [DATABASE]

SELECT CAST((fileproperty([name],'spaceused') /([size] * .01))ASDECIMAL(5, 1))AS [CurrentPercentUsed]

FROM dbo.SYSFILESWITH (NOLOCK)

ORDERBY FileID

If  [CurrentPercentUsed] > [ThresholdPercent] then fire alert logic to send email. Sometime these alerts are false alarm.

Just want to know, is there any better way to monitor ‘Data/Log File Running Out of Space’ issue?

Please do share any pointers/reference to reduce false alerts.

Thank You,
Dilip

Installing sql 2017

$
0
0

Hi to all

I wanted to install sql server 2017 on windows server 2012 R2 datacenter , when i selected in feature rules pages i have 2 error :

1-oracle Jre 7 update...

2-KB2919355

i searched and see it is a patch for sql 2012!!!!

should i install first 2012 and then 2017?!!!!


SQL Server 2012 syspolicy_purge_history job causes cross-instance login failures w. EraseSystemHealthPhantomRecords

$
0
0

I have unique service accounts set up for multiple instances on the same SQL Server 2012.

When step 3 of the inbuilt syspolicy_purge_history job(Erase Phantom System Health Records) runs, it appears to attempt to run against every instance on the server despite being passed the instance path!

The SQLServer's powershell script call:

if ('$(ESCAPE_SQUOTE(INST))' -eq 'MSSQLSERVER') {$a = '\DEFAULT'} ELSE {$a = ''};
(Get-Item SQLSERVER:\SQLPolicy\$(ESCAPE_NONE(SRVR))$a).EraseSystemHealthPhantomRecords()

so with instances SERVER\X this runs as...

(Get-Item SQLSERVER:\SQLPolicy\SERVER\X).EraseSystemHealthPhantomRecords()

SERVER\X's job will run and I will see login failures in the error logs of SERVER\Y and SERVER\Z for the service account set up for instance X.

It seems Microsoft's only 'accepted solution' to this problem is for me to compromise my security by escalating the access of these service accounts?

Has anyone else run into and corrected this failure?


Replication issue

$
0
0

Hi All,

Getting below error, during transaction replication setup. GoldenGate replication and CDC enabled for publication databases.

Please help to resolve the issue.

Error messages:
The process could not execute 'sp_replcmds' on 'XXXXXXXXXXXX'. (Source: MSSQL_REPL, Error number: MSSQL_REPL20011)
Get help: http://help/MSSQL_REPL20011
Failed to insert rows into Change Data Capture change tables. Refer to previous errors in the current session to identify the cause and correct any associated problems. (Source: MSSQLServer, Error number: 22863)
Get help: http://help/22863
The statement has been terminated. (Source: MSSQLServer, Error number: 3621)
Get help: http://help/3621
The process could not execute 'sp_replcmds' on 'XXXXXXXXXXXX'. (Source: MSSQL_REPL, Error number: MSSQL_REPL22037)
Get help: http://help/MSSQL_REPL22037


Vinai Kumar Gandla

syspolicy_purge_history job connecting to instance under different login

$
0
0

The third step of the job "Erase Phantom System Health Records" is configured to run under the SQL Server Agent Account but it is trying to connect to the instance under the agent account of a different instance. This is being flagged by instance auditing as:

Login failed for user '***'. Reason: Could not find a login matching the name provided. [CLIENT: <local machine>]

However the job itself is not failing. I'm unclear what this job step *actually* executes - i.e. where is the EraseSystemHealthPhantomRecords() module - and why it would be connecting to the instance under the wrong account.

Anyone got any ideas? I've tried dropping and recreating the agent job but that hasn't made any difference.

Best way to store the sql server errors into text file

$
0
0

What is the best way to export the SQL server errors in catch block to text file.I also  need to export some custom errors too for failures of any conditions in the try Block?

We will not be able to use CLR functions or OLE automation procedure.

Is it a good thing to execute SSIS package inside the Stored procedure and load into text File.I will be forced to write the package execution for every place where there is a condition failure?

Is there any disadvantage for using cmdshell?


DEADLOCK_PRIORITY for a job running SSIS package

$
0
0
I have a SQL agent job running on SSIS package on SQL server 2012. Unfortunately I don't have alter permission to this package and have been noticing that the job execution fails because of deadlock. Is there a way I can add a step to the job to increase the deadlock priority of the SSIS package being executed?

Prasenjit Gupta DBA Tata Consultancy Services Ltd.

Who will be announced as the next SQL Server Database Engine Guru? Read more about December 2018 competition!!

$
0
0


What is TechNet Guru Competition?

Each month the TechNet Wiki council organizes a contest of the best articles posted that month. This is your chance to be announced as MICROSOFT TECHNOLOGY GURU OF THE MONTH!

One winner in each category will be selected each month for glory and adoration by the MSDN/TechNet Ninjas and community as a whole. Winners will be announced in dedicated blog post that will be published in Microsoft Wiki Ninjas blog, a tweet from the Wiki Ninjas Twitter account, links will be published at Microsoft TNWiki group on Facebook, and other acknowledgement from the community will follow.

Some of our biggest community voices and many MVPs have passed through these halls on their way to fame and fortune.

If you have already made a contribution in the forums or gallery or you published a nice blog, then you can simply convert it into a shared wiki article, reference the original post, and register the article for the TechNet Guru Competition. The articles must be written in December 2018 and must be in English. However, the original blog or forum content can be from before December 2018.

Come and see who is making waves in all your favorite technologies. Maybe it will be you!


Who can join the Competition?

Anyone who has basic knowledge and the desire to share the knowledge is welcome. Articles can appeal to beginners or discusse advanced topics. All you have to do is to add your article to TechNet Wiki from your own specialty category.


How can you win?

  1. Please copy/Write over your Microsoft technical solutions and revelations to TechNetWiki.
  2. Add a link to your new article on THIS WIKI COMPETITION PAGE (so we know you've contributed)
  3. (Optional but recommended) Add a link to your article at the TechNetWiki group on Facebook. The group is very active and people love to help, you can get feedback and even direct improvements in the article before the contest starts.

Do you have any question or want more information?

Feel free to ask any questions below, or Join us at the official MicrosoftTechNet Wiki groups on facebook. Read More about TechNet Guru Awards.

If you win, people will sing your praises online and your name will be raised as Guru of the Month.


PS: Above top banner came from Vimal Kalathil.

Dave Rendon - wikiazure

Conditional Constraint on a column in a table

$
0
0
I have a table called Products this is how it looks like and I am trying to create a constraint on [IsDefaultProductKey] column, that any time a value is added to it, it needs be an active product key. 

    CREATE TABLE [dbo].[Products](
    [ProductId] [int] IDENTITY(1,1) NOT NULL,
    [Name] [nvarchar](64) NOT NULL,
         [IsActive] [bit] NOT NULL,
        [IsDefaultProductKey] [int] NULL,
    CONSTRAINT [PK_dbo.Products] PRIMARY KEY CLUSTERED 
    (
    [ProductId] 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
    ALTER TABLE [dbo].[Products] ADD  CONSTRAINT [DF_products_IsActive]  DEFAULT ((1)) FOR [IsActive]
    GO
    ALTER TABLE [dbo].[Products]  WITH CHECK ADD  CONSTRAINT [FK_Products_Product_IsDefaultProductKey] FOREIGN KEY([IsDefaultProductKey])
    REFERENCES [dbo].[Products] ([ProductId])
    GO
    
    ALTER TABLE [dbo].[Products] CHECK CONSTRAINT [FK_Products_Product_IsDefaultProductKey]
    GO


If these are the entries in the table, row 4 should not be allowed to have a value of 1, since ProductId 1 is inactive. How can I go about adding a constraint on the table for that

    ProductIdNameIsActiveIsDefaultProductKey
    1         Test10          NULL
    2         Test21          NULL
    3         Test30             2
    4            Test4   0             1 (Should not let me do this)

sql agent job cmdexec step with robocopy

$
0
0

I have below code in sql agent job step of type cmdexec . This step is supposed to copy a file using robocopy and based on the return code apply the if logic to return 0 .

My issue: robocopy step is working but not the if logic. Job is returning what ever the return code returned by robocopy.

ROBOCOPY c:\Source  D:\destination myfile.txt  ^& IF %ERRORLEVEL% LEQ 1 exit 0


Ravi Kumar

fathom fail-login from SQLPS xxx@dbhost

$
0
0

Hi Tech guys,

there are 3 instance on 1 win server (TTSHDB01) using the following 3 engine services account 

- TTSH_MSSQLVC (for instance TTSH)

- DDSH_MSSQLVC (for instance DDSH)

- KKSH_MSSQLVC (for instance KKSH)

there is a constant (everytime @0200am) fail-login notice at instance TTSH.

Login failed for user 'TTSHB01\TTSH_MSSQLSVC'. Reason: Could not find a login matching the name provided. [CLIENT: <local machine>]

below is the application module i manage to find causing the fail-login . Note there is 3 instance running on 1 win server

SQLPS (TTSH_MSSQLSVC@TTSHDB01)  

looking at the event logs, the source is from instance DDSH!! ?? i search any schedule job within instance DDSH but could not found any schedule job at 0200m. 

is there anyway to find out what why is this happening. The only jobs i see that occur on all instance is the default syspolicy_purge_history that is running @0200am but all have been running sucessfully. 

Viewing all 15911 articles
Browse latest View live


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