Restart SQL Server Periodically

Here in this blog, we are going to discuss, how to use the windows task scheduler to restart the Microsoft SQL Server periodically in a specific time.

Restart SQL Server Periodically

start and stop sql server
Windows Task Scheduler for SQL Server

Getting Started

Recently one day one of my projects database application consumed 80 percent of memory and the application which uses this data base runs very slow.

The number of transactions of the database is as usual as normal days, no extra number of transactions was identified. But suddenly the memory consumption by SQL Server increased.

My team member and I verified everything in the server but did not get success to increase the performance of application and decrease the memory consumption.

Then we thought to stop SQL server and start SQL Server, after stop and start, the memory consumption by SQL server is decreased. Later we come to know that the SQL server is not restarted from longer time and due to SQL Server cache, the memory consumption was increased.

We decided to restart SQL server everyday periodically. To do start and stop SQL server manually is very difficult in our case, so we though to create a crone job to stop SQL server then start SQL server.

The windows also provide same service to achieve our goal that is windows task scheduler, so we decided to use the task scheduler.

Windows Task Scheduler

The Task Scheduler is a crone job which enables you to automatically perform routine tasks on a chosen computer. Task Scheduler does this by monitoring whatever criteria you choose (referred to as triggers) and then executing the tasks when those criteria are met.

You can use the Task Scheduler to execute tasks such as starting an application, sending an email message, or showing a message box. Tasks can be scheduled to execute in response to these events, or triggers.

Why Restart SQL Server Periodically?

Maintaining a healthy SQL Server environment requires attention to performance, resource usage, and stability. While SQL Server is built to run continuously without frequent restarts, there are scenarios where periodic restarts can play a beneficial role.
  1. Memory Pressure Relief:
    • SQL Server aggressively caches data in memory. Over time, the memory footprint may grow due to:
      • Execution plan bloat
      • Ad-hoc workloads
      • Inefficient caching strategies
    • Restarting can temporarily relieve memory pressure and reclaim memory, especially if you're not using Resource Governor or memory capping.
  2. Fixing "Ghost" Connections or Locks: In rare cases, orphaned connections or lingering locks may cause blocking. A restart clears those out, though it should be the last resort after query-level solutions fail.
  3. Log File Growth Management: While not ideal, some systems with poorly managed transaction logs or long-running transactions benefit from restarts that free up or cycle log files.
  4. Apply Patches or Configuration Changes: Most SQL Server patches and some configuration settings (e.g., max memory, trace flags) require a restart to take effect.

Restart SQL Server Periodically using Task Scheduler

The following steps describes how to use the Windows Task Scheduler to stop SQL server and start SQL server. Here two different task scheduler are created to start and stop SQL server.

  1. First get the service name of SQL server, to get the name of SQL server follow the below steps.
    • Open the Windows Services Management Console by typing services.msc in the run
    • If you are windows10 then type services in search.
    • Locate the SQL Service and open its properties.
    • Take note of the Service name for future use: here my database service name is MSSQL$SQLEXPRESS
    SQL Service
  2. Create a task scheduler to stop the SQL Server first, follow the below stpes
    • Open the Task Scheduler by typing Task in the Windows search box.
    • Select Create a Basic Task from the Actions list on the right.
    • Name the task Stop SQL Server and write details in the description (Optional)
    • Click Next and select Daily Trigger
    • Pick a time where there will be no activity
    • Click Next and for the Action select Start a program
    • Type NET in the Program/Script field and in add the arguments type Stop "MSSQL$SQLEXPRESS" as shown in the image
    • Before Finishing, select the Open the Properties dialog option
    • In the General tab select Run whether user is logged in or not and Run with highest privileges
    task scheduler
    stop sql server
  3. Create another task scheduler to start the SQL Service again.
    • To create another task scheduler follow all the steps point number 2
    • Mention the scheduler name as Start SQL Server
    • Make sure that there is mininum 5 minutes delay of running time between stop scheduler and start scheduler
    • In the argument field type Start "MSSQL$SQLEXPRESS"

Note:- You can click on the Entable All Tasks History to monitor your scheduler activity

Best Practices for Scheduled SQL Server Restarts

If you determine a periodic restart is necessary then follow these best practices:
  1. Always restart during low-traffic times, ideally with user approval or downtime scheduled.
  2. Ensure that application teams, DBAs, and users know when the server will go down and how long the outage will last.
  3. Verify Backups and Health
    • Confirm full and transaction log backups are recent.
    • Check SQL Server error logs and system logs.
    • Clear up long-running transactions or open sess
  4. Monitor Post-Restart Behavior
    • Services are running
    • Performance baselines are within range
    • Scheduled jobs and replication (if any) resume correctly

Summary

While periodic restarts can offer short-term relief, they shouldn't replace proactive monitoring, query tuning, proper indexing, and good memory management. If you're frequently needing to restart SQL Server to “fix” performance, it's time for a deeper root cause analysis.

Thanks

Kailash Chandra Behera

An IT professional with over 13 years of experience in the full software development life cycle for Windows, services, and web-based applications using Microsoft .NET technologies. Demonstrated expertise in delivering all phases of project development—from initiation to closure—while aligning with business objectives to drive process improvements, competitive advantage, and measurable bottom-line gains. Proven ability to work independently and manage multiple projects successfully. Committed to the efficient and effective development of projects in fast-paced, deadline-driven environments. Skills: Proficient in designing and developing applications using various Microsoft technologies. Total IT Experience: 13+ years

6 Comments

  1. Really helpful content, keep it up

    ReplyDelete
  2. excellent article

    ReplyDelete
  3. Awasome keep it up

    ReplyDelete
  4. Thank, it helped me

    ReplyDelete
  5. Thank you, it helped me. there are two nuances for the SQLSERVER sd standard, create 2 bat files if there is a SQLSERVERAGENT","NET START "MSSQLSERVER","NET START SQLSERVERAGENT" and also for stops

    ReplyDelete
  6. Thank you so much; it helped me.

    ReplyDelete
Previous Post Next Post

نموذج الاتصال