Number of Processors(SQL Query)

  • Please help me if there is any method to retreive using query, the number of processors in a server on which sql server is installled

  • Yes, there is. You can use the xp_msver extended procedure. I'm not sure of the security requirements

    exec xp_msver 'ProcessorCount'

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • /* well, this will work, though it is a little elaborate. it does however provide some other cool info about the processer(s)*/

    DECLARE

    @nProcessorCountINT

    ,@vcProcessorModelVARCHAR(5)

    ,@vcProcessorTypeVARCHAR(30)

    ,@vcProcessorNameStringVARCHAR(60)

    CREATE TABLE #tblStats

    (

    [Index] INT,

    [Name] VARCHAR(200),

    Internal_Value VARCHAR(50),

    Character_Value VARCHAR(200)

    )

    INSERT INTO #tblStats

    EXEC master.dbo.xp_msver 'ProcessorCount'

    INSERT INTO #tblStats

    EXEC master.dbo.xp_msver 'ProcessorType'

    INSERT INTO #tblStats

    EXEC master.dbo.xp_msver 'ProcessorType'

    SELECT @nProcessorCount = Internal_Value FROM #tblStats WHERE [Index] = 16

    SELECT @vcProcessorModel = Internal_Value FROM #tblStats WHERE [Index] = 18

    SELECT @vcProcessorType = Character_Value FROM #tblStats WHERE [Index] = 18

    EXEC master.dbo.xp_instance_regreadN'HKEY_LOCAL_MACHINE',

    N'HARDWARE\DESCRIPTION\System\CentralProcessor\0',

    N'ProcessorNameString',

    @vcProcessorNameString OUTPUT,

    N'no_output'

    SELECT

    @nProcessorCount

    ,@vcProcessorModel

    ,@vcProcessorType

    ,@vcProcessorNameString

    DROP TABLE #tblStats

    -- let me know if you have any issues

  • Since MS licenses on actual CPU (and not cores) I needed to find out the actual cpu for our servers. Our sysadmin provided me an executable (attached) that is exactly what I needed. Change the .txt to .exe and you're good-to-go.

    Tim White

  • You can also download this code at http://softwarecommunity.intel.com/articles/eng/2728.htm

    Tim White

  • I thank all of you for all the responses, this has been very useful to me, I have finally decided to use the xp_msver, by Gail Shaw. Thank you very much once again.

  • Just want to make sure you understand that this is a "core" count and not a true cpu count.

    Tim White

  • I understand that it gives the number of cores and not the actual number of physical processors, I believe this is the only option available as I did not see any suggestion which would give the number of physical processors, other than a manual check. I required this as a sql query since i need to run this from a central server on a larger number of servers added as linked servers to the central server. Your replies are enough for me to work on this requirement. Thanks a lot all of you!!

  • Try this, it's something I wrote to automate a program that could be optimized on number of processors used:

    create procedure num_processors

    as

    set nocount on

    declare @numprocs int

    create table #numprocs

    (

    id int,

    colname varchar(128),

    IV int,

    CV varchar(128)

    )

    insert #numprocs

    exec master..xp_msver

    select @numprocs = IV from #numprocs

    where colname like '%ProcessorCount%'

    drop table #numprocs

    return @numprocs

    go

    Hope it helps. It gets the actual internal processor representation from SQL Server so hopefully it is accurate.

    Gaby________________________________________________________________"In theory, theory and practice are the same. In practice, they are not." - Albert Einstein

  • Waseem Jaleel (7/28/2008)


    I thank all of you for all the responses, this has been very useful to me, I have finally decided to use the xp_msver, by Gail Shaw. Thank you very much once again.

    I know this is a really old thread but I found it through Google looking for something else so I am confident others will too. xp_msver does not show physical CPU sockets, it shows logical processors.

    This will show you the number of physical sockets on your server:

    SELECT cpu_count / hyperthread_ratio AS physical_cpu_sockets

    FROM sys.dm_os_sys_info ;

    Credit: http://sqlblog.com/blogs/kalen_delaney/archive/2007/12/08/hyperthreaded-or-not.aspx

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply