forked from nate-hughes/dba-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a06d068
commit fa8f605
Showing
8 changed files
with
559 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,18 @@ | ||
IF EXISTS ( | ||
SELECT 1 | ||
FROM tempdb.sys.objects | ||
WHERE [type] = 'U' | ||
AND [object_id] = OBJECT_ID(N'tempdb..#LogInfo') | ||
) | ||
DROP TABLE #LogInfo; | ||
|
||
DECLARE @l_sql NVARCHAR(4000); | ||
/* | ||
Important change to VLF creation algorithm in SQL Server 2014 | ||
https://www.sqlskills.com/blogs/paul/important-change-vlf-creation-algorithm-sql-server-2014/ | ||
*/ | ||
|
||
CREATE TABLE #LogInfo ( | ||
DatabaseName NVARCHAR(128) DEFAULT DB_NAME() | ||
, RecoveryUnitId INT | ||
, FileId INT | ||
, FileSize BIGINT | ||
, StartOffset BIGINT | ||
, FSeqNo INT | ||
, [Status] TINYINT | ||
, Parity TINYINT | ||
, CreateLSN NUMERIC(25,0) | ||
); | ||
SELECT [name] AS 'Database Name' | ||
,COUNT(l.database_id) AS 'VLF Count' | ||
,SUM(vlf_size_mb) AS 'VLF Size (MB)' | ||
,SUM(CAST(vlf_active AS INT)) AS 'Active VLF' | ||
,SUM(vlf_active*vlf_size_mb) AS 'Active VLF Size (MB)' | ||
,COUNT(l.database_id)-SUM(CAST(vlf_active AS INT)) AS 'In-active VLF' | ||
,SUM(vlf_size_mb)-SUM(vlf_active*vlf_size_mb) AS 'In-active VLF Size (MB)' | ||
FROM sys.databases s | ||
CROSS APPLY sys.dm_db_log_info(s.database_id) l | ||
GROUP BY [name] | ||
ORDER BY [name]; | ||
GO | ||
|
||
SET @l_sql = | ||
'USE [?]; | ||
INSERT INTO #LogInfo ( | ||
RecoveryUnitId | ||
, FileId | ||
, FileSize | ||
, StartOffset | ||
, FSeqNo | ||
, Status | ||
, Parity | ||
, CreateLSN | ||
) | ||
EXEC(''DBCC LOGINFO'')'; | ||
|
||
EXEC sp_msforeachdb @l_sql; | ||
|
||
SELECT DBName = DatabaseName | ||
, VLFs = COUNT(FileId) | ||
FROM #LogInfo | ||
GROUP BY DatabaseName | ||
ORDER BY DatabaseName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
DECLARE @l_sql NVARCHAR(4000); | ||
|
||
SET @l_sql = | ||
'USE [?];' | ||
+ ' | ||
SELECT ''USE '' + DB_NAME() + '';''; | ||
SELECT ''GO'' | ||
SELECT DISTINCT ''EXEC sp_refreshview '' + schema_name(so.schema_id) + ''.'' + name + ''; | ||
GO'' | ||
FROM sys.objects AS so | ||
INNER JOIN sys.sql_expression_dependencies AS sed | ||
ON so.object_id = sed.referencing_id | ||
WHERE so.type = ''V'''; | ||
|
||
EXEC sp_msforeachdb @l_sql; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- get table permissions | ||
SELECT grantee, privilege_type | ||
FROM information_schema.role_table_grants | ||
WHERE table_name='table_name' | ||
|
||
-- get table permissions for a role | ||
SELECT grantor, grantee, table_schema, table_name, privilege_type | ||
FROM information_schema.table_privileges | ||
WHERE grantee = 'readonly' | ||
ORDER BY table_name | ||
|
||
SELECT grantee AS user, CONCAT(table_schema, '.', table_name) AS table, | ||
CASE | ||
WHEN COUNT(privilege_type) = 7 THEN 'ALL' | ||
ELSE ARRAY_TO_STRING(ARRAY_AGG(privilege_type), ', ') | ||
END AS grants | ||
FROM information_schema.role_table_grants | ||
WHERE grantee = 'readonly' | ||
GROUP BY table_name, table_schema, grantee | ||
ORDER BY table_name; | ||
|
||
-- grant SELECT permissions on tables in the public schema to a role | ||
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
USE master; | ||
|
||
--SELECT * FROM sys.resource_governor_external_resource_pools; | ||
SELECT * FROM sys.resource_governor_resource_pools; | ||
SELECT * FROM sys.resource_governor_workload_groups; | ||
|
||
-- MAX Memory Grant calc: (Maximum SQL Server memory * 90%) * 20% | ||
-- RG Memory Grant calc: (Maximum SQL Server memory * 90%) * 20% * sys.resource_governor_resource_pools.max_memory_percent | ||
SELECT CAST(value_in_use AS INT) AS MaxMemory_MB | ||
,TRY_CONVERT(INT,(CAST(value_in_use AS INT) * .9) * .2) AS MaxGrant_MB | ||
,TRY_CONVERT(INT,(CAST(value_in_use AS INT) * .9) * .2 * .5) AS ResourceGov_MB | ||
FROM sys.configurations | ||
WHERE name = 'Max Server Memory (MB)'; | ||
|
Oops, something went wrong.