Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

SQL Diagnostic Manager The following documentation allows you to monitor SQL Server instances without SysAdmin rights. However, these lowered permissions limit the availability of data.

...

create a user with the necessary permissions for SQL Diagnostic Manager, allowing the new user to gather diagnostic data from a monitored instance successfully. 

Anchor
onpremisestwo
onpremisestwo
Recommended permissions on-premises

Follow the next steps to create a new user with recommended permissions for SQL Diagnostic Manager to function.

...

SQL Diagnostic Manager now includes a SQL script to create new user with minimum permissions necessary for the product to function

  1. Use the Find/Replace function to locate and replace all references of 'SQLdmCollectionUser' with the SQL user that is being used for monitoring the SQL Server instance.
  2. Connect to the SQL Server that you want to monitor with Admin user and run this script to create the SQL user with the minimum permissions required to view the data on most of the screens of the application.
    Find the MinimumPermissionsOnPremises.sql script below:
    Attachments
    uploadfalse
    oldfalse
    patternsMinimumPermissionsOnPremises.sql
    sortByname
    pageUser creation scripts

...

SQL Diagnostic Manager also includes a SQL script to create new user with minimum permissions necessary for the product to function.

  1. Open the script with the source code editor of your preference.
  2. Find and replace all the following instances:
    1. '$SQLdmMonitorRole' with the desired name of the custom server role.
    2. '$username' with the account name that SQLDM will use to collect diagnostic data. You may use a SQL account (e.g. SQLdmService ) or a domain account (e.g. DOMAIN\SQLdmService ).

    3. '$password' with the password related to the account. Only if you are using a SQL account.

      Tip
    1. Use the Find/Replace function to locate and replace all references

    of 'SQLdmCollectionUser' with the SQL user that is being used for monitoring the SQL Server instance.
  1. Connect to the SQL Server that you want to monitor with Admin user and run this script to create the SQL user with the recommended permissions to view the data on most of the screens of the application.
    Find the RecommendedPermissionsOnPremises.sql script below:
    Attachments
    previewfalse
    uploadfalse
    oldfalse
    patternsRecommendedPermissionsOnPremises.sql
    sortByname
    pageUser creation scripts
    1. from the script.

  2. Execute the script against the target monitored instance using an account with sysadmin rights. This means you should execute the script on each instance you intend to monitor with the user created.

Below you can find the script for user creation on-premises, also you can download it by clicking here.

Code Block
languagesql
titleCreate a user with recommended permission on-premises
collapsetrue
USE master
IF NOT EXISTS(SELECT [name] FROM [sys].[server_principals] WHERE [type]='R' AND [name]='$SQLdmMonitorRole')
	CREATE SERVER ROLE [$SQLdmMonitorRole]	
IF NOT EXISTS(SELECT [name] FROM [sys].[server_principals] WHERE ([type]=N'S' OR [type]=N'U') AND [name]='$username')
	BEGIN TRY 
		IF CHARINDEX('\','$username') <> 0
			CREATE LOGIN [$username] FROM WINDOWS WITH DEFAULT_DATABASE=[master]
		ELSE
			CREATE LOGIN [$username] WITH PASSWORD=N'$password', DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=ON, CHECK_POLICY=ON
	END TRY
	BEGIN CATCH 
		SELECT ERROR_NUMBER() AS ErrorNumber
			, ERROR_SEVERITY() AS ErrorSeverity
			, ERROR_STATE() AS ErrorState
			, ERROR_PROCEDURE() AS ErrorProcedure
			, ERROR_LINE() AS ErrorLine
			, ERROR_MESSAGE() AS ErrorMessage; 
		RETURN;
	END CATCH

IF NOT EXISTS(SELECT [name] FROM [sys].[database_principals] WHERE [type] = N'S' AND [name] ='$username')
		CREATE USER [$username] FOR LOGIN [$username]

ALTER SERVER ROLE [$SQLdmMonitorRole] ADD MEMBER [$username]

GRANT EXECUTE on xp_loginconfig to [$username]
GRANT EXECUTE on xp_regread to [$username]
GRANT EXECUTE on xp_readerrorlog to [$username]
GRANT EXECUTE on xp_instance_regread to [$username]
GRANT EXECUTE on sp_OACreate to [$username]
  
-- GRANT SERVER LEVEL PERMISSIONS --
GRANT VIEW ANY DEFINITION TO [$SQLdmMonitorRole]
GRANT VIEW ANY DATABASE TO [$SQLdmMonitorRole]
GRANT VIEW SERVER STATE TO [$SQLdmMonitorRole]
GRANT ALTER SETTINGS TO [$SQLdmMonitorRole]
  
-- GRANT ADDITIONAL XEVENTS AND TRACE PERMISSIONS --
GRANT ALTER ANY EVENT SESSION TO [$SQLdmMonitorRole]
GRANT ALTER TRACE TO [$SQLdmMonitorRole]
GRANT CREATE ANY DATABASE TO [$SQLdmMonitorRole]

/** The following script adds the user to the database with the required permissions**/

SET @cmd = '
    USE [?]
	IF ((SELECT is_read_only FROM sys.databases WHERE name = DB_NAME()) = 0)
		BEGIN
			IF ((SELECT state FROM sys.databases WHERE name = DB_NAME())=0) 
				BEGIN
					IF NOT EXISTS(SELECT [name] FROM [sys].[database_principals] WHERE ([type] = N''S'' OR [type] = N''U'') AND [name]=''$username'')
							CREATE USER [$username] FOR LOGIN [$username]

					ALTER ROLE [db_owner] ADD MEMBER [$username]														 
					IF (DB_NAME()=''msdb'')
						ALTER ROLE [SQLAgentOperatorRole] ADD MEMBER [$username]										 
	
					IF (SELECT COUNT(*)FROM [sys].[database_mirroring] WHERE [mirroring_guid] IS NOT NULL) > 0
						ALTER SERVER ROLE [dbm_monitor] ADD MEMBER [$SQLdmMonitorRole]						
				END
		END'									

EXEC sp_MSforeachdb @cmd

When running the script above, it is added:

  • A new user (a Windows or a SQL Server account) to the SQL Server instance.
  • A new SQL Server level role.
  • The db_owner role to view Databases > Summary.
  • The SQLAgentOperatorRole role to the msdb database. Which lets you view, start,  or stop SQL Agent Jobs.
  • The dbm_monitor role, allowing you to monitor the database mirroring. Only required if there are any databases participating in mirroring.
Info
titleGRANT DATABASE PERMISSIONS

Restored databases onto the instance later must have the monitor account added as a bd_owner.




Scroll pdf ignore
Scroll pdf ignore
SQL Diagnostics Manager for SQL Server performance monitoring, alerting, and diagnostics for SQL Server.
Newtabfooter
aliasIDERA
urlhttp://www.idera.com
|
 
Newtabfooter
aliasProducts
urlhttps://www.idera.com/productssolutions/sqlserver
|
 
Newtabfooter
aliasPurchase
urlhttps://www.idera.com/buynow/onlinestore
|
Newtabfooter
aliasSupport
urlhttps://idera.secure.force.com/
|
Newtabfooter
aliasCommunity
urlhttp://community.idera.com
|
Newtabfooter
aliasResources
urlhttp://www.idera.com/resourcecentral
|
Newtabfooter
aliasAbout Us
urlhttp://www.idera.com/about/aboutus
|
Newtabfooter
aliasLegal
urlhttps://www.idera.com/legal/termsofuse