"Is it okay to run Ola Hallengren’s index rebuild and stats update script from a separate database instead of master, and will this impact fragmentation handling?"

N B 0 Reputation points
2025-08-26T18:17:37.55+00:00

In my organisation, we run Ola Hallengren’s index rebuild and update stats script on a separate database instead of the master database. Is this a recommended practice, and will it affect index fragmentation or reorganisation?"

SQL Server Database Engine
0 comments No comments

Answer recommended by moderator
Dinesh Yadlapalli 85 Reputation points Microsoft External Staff Moderator
2025-11-13T10:55:53.36+00:00

Hi @N B,

Thank you for reaching out to the Microsoft Q & A Forum.

You can create a dedicated maintenance database like DBAUtility or MaintenanceDB to store Ola’s scripts. It Keeps master clean and avoids cluttering system databases. It makes version upgrades and script management easier. And It improves portability across environments.

Ola’s scripts are designed to work from any database, as long as the procedures have the correct permissions. And the jobs reference the right procedure names and parameters.

Fragmentation handling is not affected by the database where the procedure resides.

  1. The script dynamically connects to the target databases and indexes based on the parameters you pass like below syntax.

@Databases = 'USER_DATABASES'.

  1. It uses sys.dm_db_index_physical_stats on the target database, not the database where the procedure is stored.
  2. Rebuild/reorganize operations happen in the target database, so fragmentation is handled exactly the same way.

Please check the below things.

  1. Ensure the SQL Agent jobs point to the correct database where the procedures are installed.
  2. The account running the job must have sufficient permissions on all target databases.
  3. If you use CommandLog or OutputFileDirectory, make sure paths and logging tables exist in the maintenance database.

Note: Install Ola’s scripts in a dedicated maintenance database. Configure SQL Agent jobs to call procedures from that database. No impact on fragmentation or statistics updates, the logic is database-agnostic.

I hope this information helps. Please do let us know if you have any further queries.

 

Regards,

Dinesh

Was this answer helpful?


1 additional answer

Sort by: Most helpful
  1. Alberto Morillo 35,506 Reputation points MVP Volunteer Moderator
    2025-08-26T19:51:26.39+00:00

    On Azure SQL Database, I create Ola scripts (stored procedures) on each user database and execute them in the context of each user database. Rest assured that if has no impact on defragmentation and statistics update. The results are the same. In fact, it is not good practice to create user objects on the master database.

     

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.