HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Excluding Read only databases using Ola Hallengren script

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
scriptdatabasesreadexcludinghallengrenusingolaonly

Problem

Is there a way to exclude Standby or Read only databases from Index maintenance and also from backups using Ola Hallengren scripts.

Solution

It's available for backups.

Though it's a somewhat recent addition, so you may need to upgrade your scripts.

For index maintenance, database status is checked so commands don't actually run on databases that aren't fully accessible.

IF DATABASEPROPERTYEX(@CurrentDatabaseName,'Status') = 'ONLINE'
AND (@CurrentIsDatabaseAccessible = 1 OR @CurrentIsDatabaseAccessible IS NULL)
AND DATABASEPROPERTYEX(@CurrentDatabaseName,'Updateability') = 'READ_WRITE'
BEGIN


Hope this helps!

Code Snippets

IF DATABASEPROPERTYEX(@CurrentDatabaseName,'Status') = 'ONLINE'
AND (@CurrentIsDatabaseAccessible = 1 OR @CurrentIsDatabaseAccessible IS NULL)
AND DATABASEPROPERTYEX(@CurrentDatabaseName,'Updateability') = 'READ_WRITE'
BEGIN

Context

StackExchange Database Administrators Q#192419, answer score: 5

Revisions (0)

No revisions yet.