Skip to content

Commit

Permalink
latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nate-hughes committed Jan 7, 2022
1 parent a06d068 commit fa8f605
Show file tree
Hide file tree
Showing 8 changed files with 559 additions and 43 deletions.
3 changes: 2 additions & 1 deletion alwayson-pause-resume-synchronization.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Primary database: The primary database stops data movement to every connected se
SELECT database_name
,'ALTER DATABASE ' + database_name + ' SET HADR SUSPEND;' AS PauseStmt
,'ALTER DATABASE ' + database_name + ' SET HADR RESUME;' AS ResumeStmt
FROM sys.availability_databases_cluster;
FROM sys.availability_databases_cluster
ORDER BY database_name;
GO

57 changes: 16 additions & 41 deletions database-get-log-file-VLF-count.sql
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;
15 changes: 15 additions & 0 deletions database-refresh-views.sql
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;
23 changes: 23 additions & 0 deletions postgresql-get-role-permissions.sql
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;
14 changes: 14 additions & 0 deletions server-get-max-memory-grant.sql
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)';

Loading

0 comments on commit fa8f605

Please sign in to comment.