Quantcast
Channel: SQL Server High Availability and Disaster Recovery forum
Viewing all articles
Browse latest Browse all 4689

Running scripts on primary and secondary instances.

$
0
0

Hello,

I created an AlwaysOn Availability group with 4 instances and I added 1 database to the availability group. On every instance the database is readable.

When I run sp_updatestats, on one of the secondary instances, I get this error message.

Msg 15635, Level 16, State 1, Procedure sp_updatestats, Line 21

Cannot execute 'sp_updatestats' because the database is in read-only access mode.

When I runSELECTname, is_read_onlyFROM sys.databaseswherename ='mydb' I get

Name        is_read_only

mydb         0

That probably makes sense because I am looking at a copy of the database on the primary instance and the database on the primary instance is not read only? Or am I looking at a bug? Should the availability group change is_read_only to 1 on the secondary instances?

Is it possible to detect that a database is synchronizing or is read only and that you should not update statistics or rebuild indexes? It has to be dynamic. I do not want to have to exclude and include database when the primary instance changes.

Something like

If (database is on primary availability group instance == true)

  Exec task

Else

  Forget about it

Greetings,

Erik


Viewing all articles
Browse latest Browse all 4689

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>