Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

Reduce number of rows in table 'msdb..

backupfile' to less than 10000

Reduce number of rows in table 'msdb..backupmediafamily' to less than 10000


Reduce number of rows in table 'msdb..backupmediaset' to less than 10000
Reduce number of rows in table 'msdb..backupset' to less than 10000

USE msdb;

GO

EXEC sp_delete_backuphistory @oldest_date = '01/14/2010';

Enable 'disallow results from triggers' option as the ability to return result sets from triggers
will be removed in a future version

Use the disallow results from triggers option to control whether triggers return result
sets. Triggers that return result sets may cause unexpected behavior in applications that
aren't designed to work with them.

-- Check the current value for the option


SELECT [name], value_in_use
FROM sys.configurations
WHERE [name] LIKE 'disallow results from triggers';

-- Set the disallow results from triggers option to 1. This is an advanced option so that must be
enabled first
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
GO

-- Set the disallow results from triggers option


EXEC sp_configure 'disallow results from triggers', 1;
EXEC sp_configure 'show advanced options', 0;
RECONFIGURE
GO

-- Validate that the option is set to 1


SELECT [name], value_in_use
FROM sys.configurations
WHERE [name] LIKE 'disallow results from triggers';
GO
Disable 'show advanced options' option

USE master;
GO

EXEC sp_configure 'show advanced option', '1'; --Enable


advanced options
RECONFIGURE;

EXEC sp_configure --Show all the options

EXEC sp_configure 'show advanced option', '0'; --Always


disable advanced options
RECONFIGURE;

Review non-default value 1 for the 'clr enabled' option


1SELECT * FROM sys.configurations WHERE name LIKE 'clr strict security';

EXEC sp_configure 'clr enabled' , '1';


RECONFIGURE;

Review non-default value 2147483647 for the 'max text repl size' option

SSMS

1. In Object Explorer, right-click a server and select Properties.

2. Click the Advanced node.

3. Under Miscellaneous, change the Max Text Replication


Size option to the desired value.
USE AdventureWorks2022;
GO
EXEC sp_configure 'show advanced options', 1 ;
RECONFIGURE ;
GO
EXEC sp_configure 'max text repl size', -1 ;
GO
RECONFIGURE;
GO

Review non-default value 1024 for the 'min server memory (MB)' option

SSMS

1. In Object Explorer, right-click a server and select Properties.

2. Click the Memory node.

3.

sp_configure 'show advanced options', 1;


GO
RECONFIGURE;
GO
sp_configure 'min server memory', 2048;
GO
RECONFIGURE;
GO

Review non-default value 60 for the 'remote login timeout (s)' option

1. In Object Explorer, right-click a server and select Properties.

2. Click the Advanced node.

3. Under Network, select a value for the Remote Login Timeout box.

Use the remote login timeout option to specify the number of


seconds to wait before returning from a failed remote login
attempt.
USE AdventureWorks2022;
GO
EXEC sp_configure 'remote login timeout', 35 ;
GO
RECONFIGURE ;
GO

Review non-default value 90 for the 'cost threshold for parallelism'


option

SELECT (cpu_count / hyperthread_ratio) AS PhysicalCPUs,

cpu_count AS logicalCPUs

FROM sys.dm_os_sys_info;

1. In Object Explorer, right-click a server and select Properties.

2. Select the Advanced node.

3. Under Parallelism, change the Cost Threshold for


Parallelism option to the value you want. Type or select a value
from 0 to 32767.

USE master;
GO
EXEC sp_configure 'show advanced options', 1;
GO
RECONFIGURE
GO
EXEC sp_configure 'cost threshold for parallelism', 10;
GO
RECONFIGURE
GO

Enable 'backup compression default' option

SELECT value

FROM sys.configurations

WHERE name = 'backup compression default' ;

GO
1. In Object Explorer, right-click a server and select Properties.

2. Click the Database settings node.

3. Under Backup and restore, Compress backup shows the current


setting of the backup compression default option. This setting
determines the server-level default for compressing backups, as
follows:

 If the Compress backup box is blank, new backups are


uncompressed by default.

 If the Compress backup box is checked, new backups


are compressed by default.

If you are a member of the sysadmin or serveradmin fixed server


role, you can also change the default setting by clicking
the Compress backup box.

EXEC sp_configure 'backup compression default', 1 ;

RECONFIGURE;

GO

Review non-default value 1 for the 'Database Mail XPs' option

Verificar is necesitan la opción MAIL

SELECT value FROM sys.configurations


WHERE NAME = 'Database Mail XPs'

sp_configure 'show advanced options', 1;

GO

RECONFIGURE;

GO

sp_configure 'Database Mail XPs', 1;

GO
RECONFIGURE

GO

Use 'RECONFIGURE' after 'sp_configure' to update run value. Config value is different from
run value in: affinity mask

Review non-default value 1000 for the 'user connections' option

1. In Object Explorer, right-click a server and select Properties.

2. Select the Connections node.

3. Under Connections, in the Max number of concurrent


connections box, type or select a value from 0 through 32767 to
set the maximum number of users that are allowed to connect
simultaneously to the instance of SQL Server.

4. Restart SQL Server.

USE AdventureWorks2022;

GO

EXEC sp_configure 'show advanced options', 1;

GO

RECONFIGURE ;

GO

EXEC sp_configure 'user connections', 325 ;

GO

RECONFIGURE;

GO
Use <join_hint>, <query_hint> and <table_hint> in specific cases only since SQL Server Query
Optimizer typically selects best execution plan for queries

Caution

Because the SQL Server query optimizer typically selects the best execution plan
for a query, we recommend that <join_hint>, <query_hint>, and <table_hint>
be used only as a last resort by experienced developers and database
administrators.

Enable trace flag 1117 to enable filegroup auto-grow

https://techcommunity.microsoft.com/t5/sql-server-blog/sql-server-2016-
changes-in-default-behavior-for-autogrow-and/ba-p/384692

Trace Flag 1117


1. Trace flag 1117 for user databases is replaced by a new ALTER DATABASE setting at the
FILEGROUP level.
2. Default value is to grow a single file – AUTOGROW_SINGLE_FILE (which is same as the
trace flag not being enabled).
3. This setting is at the file group level (not the entire database level).
4. For a database that contains many files, the AUTOGROW_ALL_FILES setting has to be to
enabled for each filegroup.

Syntax
ALTER DATABASE <dbname> MODIFY FILEGROUP <filegroup>
{ AUTOGROW_ALL_FILES | AUTOGROW_SINGLE_FILE }

2016 en adelante no es necesario

Best Practice: Carefully consider whether to use trace flag 1117 because it affects all
databases. Instead, consider preallocating space to tempdb files to accommodate typical
workloads.

2016 para arriba

SELECT name Filegroup_Name, is_autogrow_all_files FROM


sys.filegroups
ALTER DATABASE Adventureworks MODIFY FILEGROUP [PRIMARY]
AUTOGROW_SINGLE_FILE -- AUTOGROW_ALL_FILES is the default behavior
GO

2014 para abajo

DBCC TRACESTATUS();

DBCC TRACEON(1117,-1);

DBCC TRACEOFF(1117,-1);

Enable trace flag 174 to increase plan cache bucket count


SQL PLAN: queries con planes de ejecución diferentes.
select name, type, buckets_count
from sys.dm_os_memory_cache_hash_tables
where name IN ( 'SQL Plans' , 'Object Plans' , 'Bound Trees' )

select name, type, pages_kb, entries_count


from sys.dm_os_memory_cache_counters
where name IN ( 'SQL Plans' , 'Object Plans' , 'Bound Trees' )

DBCC TRACESTATUS();

DBCC TRACEON(174,-1);

DBCC TRACEOFF(174,-1);

Enable trace flag 1118 to force page allocations on uniform extents

2016

Trace Flag 1118


1. Trace flag 1118 for user databases is replaced by a new ALTER DATABASE setting –
MIXED_PAGE_ALLOCATION.
2. Default value of the MIXED_PAGE_ALLOCATION is OFF meaning allocations in the
database will use uniform extents.
3. The setting is opposite in behavior of the trace flag (i.e. TF 1118 OFF and
MIXED_PAGE_ALLOCATION ON provide the same behavior and vice-versa).

Syntax
ALTER DATABASE <dbname> SET MIXED_PAGE_ALLOCATION { ON | OFF }
For more information, see https://msdn.microsoft.com/en-US/library/bb522682.aspx
Example
–Default value is OFF so all allocations in AdventureWorks will use uniform extents. To disable and
use mixed extents turn the setting to on.
ALTER DATABASE AdventureWorks SET MIXED_PAGE_ALLOCATION ON;

2014

DBCC TRACESTATUS();

DBCC TRACEON(1118,-1);

DBCC TRACEOFF(1118,-1);

Enable trace flag 6534 to enable performance improvement of query


operations with spatial data types

DBCC TRACESTATUS();

DBCC TRACEON(6534,-1);

DBCC TRACEOFF(6534,-1);

Enable trace flag 7412 to enable lightweight profiling infrastructure for live query
performance troubleshooting

DBCC TRACESTATUS();

DBCC TRACEON(7412,-1);
DBCC TRACEOFF(7412,-1);

Enable trace flags 6532 and 6533 to improve spatial data performance

DBCC TRACESTATUS();

DBCC TRACEON(6532,-1);

DBCC TRACEOFF(6532,-1);

Enable trace flag 834 to use large-page allocations to improve analytical and data
warehousing workloads

To Enable Trace Flag 834 on startup:

 Open the SQL Server Configuration Manager


 Right Click on SQL Server (<<YourInstanceName>>) and select "Properties"
 Move to the Advanced Tab
 Scroll down to the "Startup Parameters" and add: ;-T834
 Click OK
 Restart the SQL Server service

Enable trace Flag 2371 to allow linear recompilation threshold for statistics

Trace Flag 2371 causes SQL Server to change the fixed update statistics threshold to a linear
update statistics threshold. This is especially useful to keep statistics updated on large tables.
Starting with SQL Server 2016, for databases using compatibility level 130 and above, this
behavior is controlled by the engine and trace flag 2371 has no effect.

SQL Server 2014 or below: default is the old threshold. You can use trace flag 2371 to activate new
threshold
SQL Server 2016: Default is new threshold if database compatibility level is 130. If database
compatibility is below 130, old threshold is used (unless you use trace flag 2371)
Trace Flag 4199 enables Query Optimizer fixes. Verify need to set a non-default trace flag
with the current system build and configuration

https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-
database-transact-sql-compatibility-level?view=sql-server-ver16

https://support.microsoft.com/en-us/topic/kb974006-sql-server-query-
optimizer-hotfix-trace-flag-4199-servicing-model-cd3ebf5c-465c-6dd8-7178-
d41fdddccc28

How to enable trace flag 4199


You can enable trace flag 4199 at startup or in a user session. This trace flag has either global-level or session-level
effect. To enable trace flag 4199, use the DBCC TRACEON command or use –T 4199 as a startup parameter.

If DBCC TRACEON\TRACEOFF is used this does not regenerate a new cached plan for stored procedures. Plans could be
in cache that were created without the trace flag.

https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/
scm-services-configure-server-startup-options?view=sql-server-
ver16&redirectedfrom=MSDN

You might also like