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

SELECT query is taking time

$
0
0

Hi All,

Need some help in tuning the SELECT statement.
Below SELECT query is taking a long time to execute under a specific database.

Brief description about the Issue
=============================
- sql ver :Microsoft SQL Server 2012 (SP4) Standard Edition (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor)
- We have 2 databases say db1 and db2. under db1 query completes in 5 secs but in db2 its taking 30-40 mins.
- Both databases reside on same SQL instance
- max server memory = 85 GB , OS memory = 96 GB RAM
select TOP (50000) * from EXT_data_Hist_TbL
   WHERE CREATE_DATE < dateadd(year,-1,GETDATE())

- Table in qustion: EXT_data_Hist_TbL and it is a HEAP table
- In db1 table rowcount =  24534283 tablesize=187 GB
- In db2 table rowcount =  13290417 tablesize 191 GB
- no blocking
- waittype observed for db2 query is "(5ms)PAGEIOLATCH_SH:db2:3(*)"
- Only difference is that, Initially when both databases are restored on to non-prod env, in db2 , application team has run below DELETE statement twice or thrice ( I don't know the exact number)
and then if they run above SELECT stmt, it runs over 30mins. My doubt is whether these batch DELETES here is causing any issues under the covers? can anyone shed some light here.

 DELETE TOP (50000) EXT_data_Hist_TbL
   WHERE CREATE_DATE < dateadd(year,-1,GETDATE())

- I tried updating the statistics ( there is only 1 though which is a system created one) and run the SELECT query, it didn't help.
- index fragmentation in both the db's is almost same but rowcount differs.

- The execution plan(s) i also same for both query.. i.e. Full table scan since it is a HEAP

How can we make this SELECT faster on db2 as well? Any inputs here please?

Thanks,
Sam


SQL server service report

$
0
0

Hi All,

We need to check the SQL related service for 150 server. Can you please any one have script to check all service status in single server.

Regards,

karthik B

SQL server services are not starting on VM.

$
0
0

Hi Team,

When I am installing SQL server 2016 on VMware , After installation SQL server is not starting.

This Dev server is having 32GB RAM.

We observed in SQL server error log below error message.we troubleshooted and tried to start the SQL services, Still it is not starting.

Kindly help me on this issue  resolution. 

error: 17138, Severity: 16, State: 1.
Unable to allocate enough memory to start 'SQL OS Boot'. Reduce non-essential memory load or increase system memory.
SQL Server shutdown has been initiated

Thanks you.


How to download SQL server 2016 enterprise edition ?

$
0
0

Hi All,

Good Day!!

we need to download SQL server 2016 Enterprise edition media file for one of application and we have enterprise edition license key but we are unable to find the Media download link. please help me to provide the download link...


RAM

Script to find which all tables have JSON data

$
0
0

Hi, 

I am trying to find a script which gives a list of table_names which have JSON columns in it, please let me know, thanks.


D

table total_pages dramatically greater than used_pages which is causing big unused allocated storage space and eating up all size

$
0
0

Hi Guru,

My Azure sql database has a table which is blowing out my storage space. It have already applied for 17GB space, but only used 5.6GB. Everyday both total_pages and used_pages size keeps increasing synchronously. The table has 1 clustered index and 3 non clustered index, the row size is about 1700 bytes. One program keeps inserting records into it with BCP, but no update and delete operations.

Does anyone throw some light on it? What is happening? How do I reclaim those unused allocated space? Thank you very much.

TableNameTotalSpaceMBUsedSpaceMBtotal_pagesused_pagesdata_pagesallocation_unit_typeobject_idrowsnametype_desc
t_view9407.831287.481204202164797164166IN_ROW_DATA11218555098083423PK__t_view__DDB00C7DB4056465CLUSTERED
t_view5070.141043.91648978133620132604IN_ROW_DATA11218555098083423nci_wi_t_view_1C41819A6CC56703B4F368C9ECBBC4C2NONCLUSTERED
t_view5091.951018.06651770130312129551IN_ROW_DATA11218555098083423nci_wi_t_view_5943CD01D00F0CC16C734996B7EB27D2NONCLUSTERED
t_view7651.022274.33979330291114288033IN_ROW_DATA11218555098083423nci_wi_t_view_722F6CDC2C6999CEFE32CD4E45D96C35NONCLUSTERED


MAXDOP = 1 setting is causing longer run times and application timeouts.

$
0
0
MAXDOP = 1 setting is  causing longer run times and application timeouts. Could you please let me know the reason and how to fix it.

Kiran

SQL box migration to Windows server 2019

$
0
0

Currently we have sql server 2016 in windows 2012 server.  we planning for windows server 2019 ( not SQL upgrade).

so create new VM windows server 2019 & install SQL 2016.  there after move database to new server.

which way is works ?  with least downtime?

  • make old server database offline, & move mdf & ldf  file to new  server location & attach database ( is this method works? mean, taking mdf & ldf file from one server & attach in another servers possible?   )
  • take backup of FULL file  from old server DB & restore it into new server with no-recovery  mode , there after apply Diff file to become recovery mode.



VM with SQL server core license

$
0
0

I have a virtual machine used for SQL server 2017 standard edition

The CPU we are going to have is 8 cores.

Which should be better configuration for performance.

2 sockets x 4 cores

Or 

4 sockets x2 cores.

Thanks


Thanks

SQL Database Error 924 – Database is already open and can only have one user at a time

$
0
0

In a Java-application I am working on, I have an updater, which updates the db structure whenever a new version is started for the first time. 
This updater is executed in single user mode, to ensure no one is working on the db in the meantime. 
During this update, I have to request meta data and this request sometimes leads to the Error 924. 
This bug occurs only since I upgraded the mssql-jdbc driver to 6.3.3 or later and I therefor opened an issue on theirGithub page
However, during the discussion in this issue, it turned out, that neither the driver nor our code opens a new connection. Even the SQL Server Profiler logs only one connection. 
During my research, I found an article, which states, that SINGLE_USER can only be used if AUTO_UPDATE_ASYNC is turned OFF. That's the case in my database, but since async jobs on the SQL Server seem to cause problems with single user mode, my guess is, that some statements used by the driver to load the meta data (starting with Line 988) are executed asynchronously. This presumption is reinforced by the fact, that the error only occurs, if the database is stored on a HDD drive. On SSD drives everything works fine, which sounds like some kind of race condition. 
Our current workaround for this is to catch this error and retry the statement after 3 seconds, until it works. Usually it takes about 5 retries or 15 seconds.

Is there some setting in the SQL Server I am missing or what else could cause this issue?

I tried to restore a database and failed due to different versions

$
0
0

That's what appeared to me

TITLE: Microsoft SQL Server Management Studio
------------------------------

Restore of database 'altawqeef_DB' failed. (Microsoft.SqlServer.Management.RelationalEngineTasks)

------------------------------
ADDITIONAL INFORMATION:

System.Data.SqlClient.SqlError: The database was backed up on a server running version 15.00.1400. That version is incompatible with this server, which is running version 15.00.1200. Either restore the database on a server that supports the backup, or use a backup that is compatible with this server. (Microsoft.SqlServer.SmoExtended)

For help, click: https://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=15.0.18206.0+((SSMS_Rel).191029-2112)&LinkId=20476

------------------------------
BUTTONS:

OK

What is the solution

Index fragmentation

$
0
0
Why in a table some indexes are heavily fragmented above 90 % but other indexes are below 10 % ? The indexes were all rebuilt or reorganized just a day before.

how uninstall a ms sql 2008 instance

$
0
0

There are multiple mssql instance in a server and one instance could not be started.

Please tell me how to delete the instance which is corrupt. Thanks!

OPTION (RECOMPILE) makes a difference on an empty plan cache?

$
0
0

I have a rather large and complex query wrapped in sp_executeSql, that will not perform unless I add OPTION (RECOMPILE). Then it performs in 35 seconds.

This can be a well known effect of the query hitting a bad cached plan (due to parameter sniffing).

So I would have thought that emptying the plan cache manually (by any variety of ways), would serve the same purpose. But no, even with an empty plan cache the query will still perform badly, unless I add OPTION (RECOMPILE).

I haven't compared query plans in detail yet and please don't ask me to share them, they are horrendous.

But how can it be that OPTION(RECOMPILE) can make a difference on an empty plan cache?


Non -Yielding scheduler errors on server 2012 r2, sql server 2014

$
0
0

From our Windows Clustering end, we have analysed and observed RHS deadlock events in the below logs from the cluster  :

 

00012bc.000012d4::2019/11/03-05:36:27.467 INFO  [RHS] Enabling RHS termination watchdog with timeout 1200000 and recovery action 3 from source 5.

000012bc.000012d4::2019/11/03-05:36:27.467 ERR   [RHS] Resource Cluster Name handling deadlock. Cleaning current operation and terminating RHS process.

000012bc.000012d4::2019/11/03-05:36:27.467 ERR   [RHS] About to send WER report.

System logs , found event ids 1069,1146,1230, found bugcheck 9e

Application logs : found non-yielding scheduler 17883 event ids.

We do observed that during the backups , we are getting deadlock and non-yielding scheduler errors at the same time. Backup jobs failed.

During the weekend, backup jobs are running around 5am - 6am , errors are observing during those time frame.

rhs deadlock error are also observed in cluster log. have increased the deadlock timeout value from 300000 to 600000

But still observing non-yielding scheduler errors on sql server ,This issue seem to happening when the bare metal backup from backup and storage solution cohesity is running.

Could you please look into this.


swathi


does creating a clustered index after the table is loaded essentially load it again

$
0
0

Hi, we run 2017 std. I'm looking thru some work others have done here and noticed they truncate tables, drop indices, load tables and recreate indices in their etl.

I'm used to seeing this practice on non clustered indexes but not clustered ones.  Don't clustered indexes essentially determine the order in which the data will attempt to be loaded?  Which means creating a clustered index after the data is loaded will effectively reload the entire table?  Which is usually not the most efficient thing in the world? 


Are shared locks taken when a "linked server" is used to select from a table with (NOLOCK)?

$
0
0

Are shared locks taken when a "linked server" is used to select from a table with (NOLOCK)?

After a few tests running some SQL on database server A using a linked server pointing

to database server B and using “with(NOLOCK)”, it appears that shared read locks are taken.

from [linked server name].dbname.dbo.MHDISH with (NOLOCK)                                           --Deliveries

JOIN [linked server name].dbname.dbo.MHDISL with (NOLOCK) ON OQCONO = URCONO AND OQDLIX = URDLIX   --Delivery lines

JOIN [linked server name].dbname.dbo.OOHEAD with (NOLOCK) ON URCONO = OACONO AND URRIDN = OAORNO   --CO header file

JOIN [linked server name].dbname.dbo.OOLINE with (NOLOCK) ON URCONO = OBCONO AND URRIDN = OBORNO

          AND URRIDL = OBPONR AND URRIDX = OBPOSX                                                  --CO line file

JOIN [linked server name].dbname.dbo.MITMAS with (NOLOCK) ON OBCONO = MMCONO AND OBITNO = MMITNO   --Item Master


Table ID

# of shared locks

Table

1083775564

1

MHDISH

1211776020

1

MHDISL

1254503748

1

MITMAS

1268264369

17

OOLINE

2147356006

9

OOHEAD

Initially I thought that maybe the M3 application was taking the locks, but after doing the following twice

-  running sp_lock immediately before the SQL above and seeing no shared locks on the tables,

-  and then running sp_lock during the execution of the SQL above and seeing shared locks on the tables

… it appears to me that shared read locks are being taken.

How to Move SSRS one server to another

$
0
0

hi,

we have serverA Database engine & SSRS,    we moved database engine & all related setup to ServerB.

how to move this SSRS,

taking encription key of server A & attach it in serverB

taking backup of ReportserverDB & reportserverTempdb & attach it in serverB.

taking RDL file & attach it in Server B.

how can i move this subscriptions?  there are scheduled reports are running in old server.

 what is this ReportsParts  how to move this?

issue in creating linked server from SQL Server 2008 to SQL Server 2016

$
0
0

We are trying to create linked server from SQL Server 2008 to SQL Server 2016.

  1. While using SQL Native 10.0, I am getting below error while creating a linked server.

TCP Provider: An existing connection was forcibly closed by the remote host.

OLE DB provider "SQLNCLI10" for linked server "SBO3-SA01-DBRE1" returned message "Client unable to establish connection". (Microsoft SQL Server, Error: 10054)

  1. For SQL Native 11.0, I am able to create linked server but while executing query getting below error.

Msg 7320, Level 16, State 2, Line 1

Cannot execute the query "SELECT "Tbl1002"."name" "Col1004" FROM "DBName"."DBO"."tablename" "Tbl1002"" against OLE DB provider "SQLNCLI11" for linked server"DBLinkedServer".


Regards,
Rohit Garg
(My Blog)
This posting is provided with no warranties and confers no rights.
Please remember to click Mark as Answer and Vote as Helpful on posts that help you. This can be beneficial to other community members reading the thread.

Plan cache

$
0
0

I have following two sps.

ALTER PROCEDURE dbo.withoutlike(@d VARCHAR(20))
AS
BEGIN
    DECLARE @sql VARCHAR(255)

SET @sql='SELECT * FROM dbo.DISTRICT STS WHERE STS.district= '''+@d+''''

EXECUTE(@sql)
END
GO

EXECUTE dbo.withoutlike @d = 'kaski' 
GO
ALTER PROCEDURE dbo.withlike(@d VARCHAR(20))
AS
BEGIN
    DECLARE @sql VARCHAR(255)

SET @sql='SELECT * FROM dbo.DISTRICT STS WHERE STS.districtlike '''+@d+''''
EXECUTE(@sql)
END

go

EXECUTE dbo.withlike @d = 'doti'

Both sps have dynamic sql. When I run the sp with like operator query plan is stored in plan cache witha plan for each value of the like predicate. But when i run sp with= operator the plan is not stored in cache

I tried this with both parameterized simple and forced in database setting.

The sql server version is sql server 2016(sp1).


Viewing all 12963 articles
Browse latest View live


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