How to start sql server
How to start sql server
Start, Stop, or Pause the SQL Server Agent Service
On Azure SQL Managed Instance, most, but not all SQL Server Agent features are currently supported. See Azure SQL Managed Instance T-SQL differences from SQL Server for details.
This topic describes how to start, stop, or restart the SQL Server Agent Service in SQL Server by using SQL Server Management Studio.
You can configure the SQL Server Agent service to start automatically when the operating system starts, or you can start it manually when you need to complete jobs. You can stop or pause the SQL Server Agent service to suspend jobs, operator notifications, and alerts.
Before You Begin
Limitations and Restrictions
Microsoft SQL Server Agent must be running as a service in order to automate administrative tasks. For more information, see Configure SQL Server Agent.
Object Explorer only displays the SQL Server Agent node if you have permission to use it.
Security
Permissions
To perform its functions, SQL Server Agent must be configured to use the credentials of an account that is a member of the sysadmin fixed server role in SQL Server. The account must have the following Windows permissions:
Log on as a service (SeServiceLogonRight)
Replace a process-level token (SeAssignPrimaryTokenPrivilege)
Bypass traverse checking (SeChangeNotifyPrivilege)
Adjust memory quotas for a process (SeIncreaseQuotaPrivilege)
For more information about the Windows permissions required for the SQL Server Agent service account, see Select an Account for the SQL Server Agent Service and Setting Up Windows Service Accounts.
Using SQL Server Management Studio
To start, stop, or restart the SQL Server Agent Service
In Object Explorer, click the plus sign to expand the server where you want to manage SQL Server Agent Service.
Right-click SQL Server Agent, and then select either Start, Stop, or Restart.
In the User Account Control dialog box, click Yes.
When prompted if you want to perform the action, click Yes.
Start, stop, pause, resume, and restart SQL Server services
This article describes how to start, stop, pause, resume, or restart the SQL Server Database Engine, the SQL Server Agent, or the SQL Server Browser service on Windows by using SQL Server Configuration Manager, SQL Server Management Studio (SSMS), net commands from a command prompt, Transact-SQL, or PowerShell.
Identify the service
SQL Server components are executable programs that run as Windows services. Windows services can run without displaying any activity on the computer screen and without user interaction on the command line.
Database Engine service
The Database Engine service can be the default instance (limit one per computer) or can be one of many named instances on the computer. Use SQL Server Configuration Manager to find out which instances of the Database Engine are installed on the computer. The default instance (if you install it) is listed as SQL Server (MSSQLSERVER). Named instances (if you install them) are listed as SQL Server ( ). By default, SQL Server Express is installed as SQL Server (SQLEXPRESS).
SQL Server Agent service
The SQL Server Agent service executes scheduled administrative tasks, which are called jobs and alerts. For more information, see SQL Server Agent. SQL Server Agent is not available in every edition of SQL Server. For a list of features that are supported by the editions of SQL Server, see Features Supported by the Editions of SQL Server 2019.
SQL Server Browser service
The SQL Server Browser service listens for incoming requests for SQL Server resources and provides clients information about SQL Server instances installed on the computer. A single instance of the SQL Server Browser service is used by all instances of SQL Server installed on the computer.
Additional Information
If you pause the Database Engine service, users who are already connected can continue to work until their connections are broken, but new users can’t connect to the Database Engine. Use Pause when you want to wait for users to complete their work before you stop the service, which lets them complete transactions that are in progress. Resume allows the Database Engine to accept new connections again. The SQL Server Agent service cannot be paused or resumed.
The SQL Server Configuration Manager and SSMS display the current status of services by using the following icons.
You won’t have access to all possible options when using SQL Server Configuration Manager or SSMS, depending on the state of the service. For example, if the service is already started, Start is unavailable.
When running on a cluster, the SQL Server Database Engine service is best managed by using Cluster Administrator.
Permissions
By default, only members of the local administrator group can start, stop, pause, resume, or restart a service. To grant non-administrators the ability to manage services, see How to grant users rights to manage services in Windows Server 2003. (The process is similar on other versions of Windows Server.)
Stopping the Database Engine by using the Transact-SQL SHUTDOWN command requires membership in the sysadmin or serveradmin fixed server roles, and is not transferable.
SQL Server Configuration Manager
Start SQL Server Configuration Manager
On the Start menu, select All Programs > Microsoft SQL Server > Configuration Tools > SQL Server Configuration Manager.
The SQL Server Configuration Manager is a snap-in for the Microsoft Management Console program, and it may not appear as an application in some versions of Windows. See SQL Server Configuration Manager for more information.
Start, stop, pause, resume, or restart an instance of the SQL Server Database Engine
Start SQL Server Configuration Manager, using the instructions above.
If the User Account Control dialog box appears, select Yes.
In SQL Server Configuration Manager, in the left pane, select SQL Server Services.
In the results pane, right-click SQL Server (MSSQLServer) or a named instance, and then select Start, Stop, Pause, Resume, or Restart.
Select OK to close the SQL Server Configuration Manager.
To start an instance of the Database Engine with startup options, see Configure Server Startup Options (SQL Server Configuration Manager).
Start, stop, pause, resume, or restart the SQL Server Browser or an instance of the SQL Server Agent
Start SQL Server Configuration Manager, using the instructions above.
If the User Account Control dialog box appears, select Yes.
In SQL Server Configuration Manager, in the left pane, select SQL Server Services.
In the results pane, right-click SQL Server Browser, or SQL Server Agent (MSSQLServer) or SQL Server Agent ( ) for a named instance, and then select Start, Stop, Pause, Resume, or Restart.
Select OK to close the SQL Server Configuration Manager.
SQL Server Agent cannot be paused.
SQL Server Management Studio
Start, stop, pause, resume, or restart an instance of the Database Engine
In Object Explorer, connect to the instance of the Database Engine, right-click the instance of the Database Engine you want to start, and then select Start, Stop, Pause, Resume, or Restart.
Or, in Registered Servers, right-click the instance of the Database Engine you want to start, point to Service Control, and then select Start, Stop, Pause, Resume, or Restart.
If the User Account Control dialog box appears, select Yes.
When prompted if you want to act, select Yes.
Start, stop, or restart an instance of the SQL Server Agent
In Object Explorer, connect to the instance of the Database Engine, right-click SQL Server Agent, and then select Start, Stop, or Restart.
If the User Account Control dialog box appears, select Yes.
When prompted if you want to act, select Yes.
Command Prompt window using net commands
The SQL Server services can be started, stopped, or paused by using Windows net commands.
Start the default instance of the Database Engine
From a command prompt, enter one of the following commands:
Start a named instance of the Database Engine
From a command prompt, enter one of the following commands. Replace with the name of the instance you want to manage.
Start the Database Engine with startup options
Add startup options to the end of the net start «SQL Server (MSSQLSERVER)» statement, separated by a space. When started using net start, startup options use a slash (/) instead of a hyphen (-).
For more information about startup options, see Database Engine Service Startup Options.
Start the SQL Server Agent on the default instance of SQL Server
From a command prompt, enter one of the following commands:
Start the SQL Server Agent on a named instance of SQL Server
From a command prompt, enter one of the following commands. Replace instancename with the name of the instance you want to manage.
For information about how to run SQL Server Agent in verbose mode for troubleshooting, see sqlagent90 Application.
Start the SQL Server Browser
From a command prompt, enter one of the following commands:
To pause or stop services from the Command Prompt window
To pause or stop services, modify the commands in the following ways.
To pause a service, replace net start with net pause.
To stop a service, replace net start with use net stop.
Transact-SQL
The Database Engine can be stopped by using the SHUTDOWN statement.
To stop the Database Engine using Transact-SQL
To wait for currently running Transact-SQL statements and stored procedures to finish, and then stop the Database Engine, execute the following statement.
To stop the Database Engine immediately, execute the following statement.
For more information about the SHUTDOWN statement, see SHUTDOWN (Transact-SQL).
PowerShell
Start and stop Database Engine services
In a Command Prompt window, start SQL Server PowerShell by executing the following command.
At a SQL Server PowerShell command prompt, by executing the following command. Replace computername with the name of your computer.
Identify the service that you want to stop or start. Pick one of the following lines. Replace instancename with the name of the named instance.
To get a reference to the default instance of the Database Engine.
To get a reference to a named instance of the Database Engine.
To get a reference to the SQL Server Agent service on the default instance of the Database Engine.
To get a reference to the SQL Server Agent service on a named instance of the Database Engine.
To get a reference to the SQL Server Browser service.
Complete the example to start and then stop the selected service.
Use the ServiceController class
You can use the ServiceController class to programmatically control the SQL Server service, or any other Windows service. For an example using C#, see ServiceController Class.
What’s the best way to start and stop SQL Server from the command line?
I need to start and stop SQL Server from the command line. I am willing to write a small C# program if necessary, but I suspect that there’s something (PowerShell, maybe?) that currently exists that does this gracefully.
6 Answers 6
Trending sort
Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.
It falls back to sorting by highest score if no posts are trending.
Switch to Trending sort
Or, in PowerShell, Stop-Service, Start-Service, or Restart-Service. Note that all of this has to be done on a per-instance basis, just as with the other suggestions here.
Here’s an answer that actually contains a little bonus information. and more thoroughly answers the question. What if you have more than one instance of SQL server? Then you need to know the extended syntax of NET START. You can start services by Name, not just by service moniker (or whatever mssqlserver is an example of):
NET START «sql server (instancename)»
This applies to other services, too. Want to start the System Event Notification Service?
NET START «System Event Notification Service»
Boom goes the dynamite! hehe
For restarting SQL Server and SQL Server Agent you can create a batch file called restartsql.bat with the following commands in it, save it, and run it when needed:
@ECHO OFF net stop «SQL Server Agent (MSSQLSERVER)» net stop MSSQLSERVER net start MSSQLSERVER net start «SQL Server Agent (MSSQLSERVER)»
Start, Stop, or Pause the SQL Server Agent Service
В Управляемом экземпляре Azure SQL в настоящее время поддерживается большинство функций агента SQL Server (но не все). Подробные сведения см. в статье Различия в T-SQL между Управляемым экземпляром SQL Azure и SQL Server.
В этой статье описывается, как запустить, остановить или перезапустить службу агента SQL Server в SQL Server с помощью среды SQL Server Management Studio.
Службу агента SQL Server можно настроить для автоматического запуска вместе с операционной системой или запуска вручную для выполнения определенных заданий. Службу агента SQL Server можно остановить или приостановить, чтобы прекратить выполнение заданий, уведомления операторов и оповещения.
Перед началом
Ограничения
Для автоматизации задач администрирования агент Microsoft SQL Server должен выполняться в качестве службы. Дополнительные сведения см. в статье Configure SQL Server Agent.
Узел агента SQL Server отображается в обозревателе объектов только при наличии у пользователя разрешения на использование узла.
безопасность
Permissions
Для выполнения своих функций агент SQL Server должен быть настроен на использование учетных данных записи, которая является членом предопределенной роли сервера sysadmin в среде SQL Server. Эта учетная запись должна иметь следующие разрешения Windows.
Вход в систему в качестве службы (SeServiceLogonRight)
Замена токена уровня процесса (SeAssignPrimaryTokenPrivilege)
Обход проходной проверки (SeChangeNotifyPrivilege)
Назначение квот памяти процессам (SeIncreaseQuotaPrivilege)
Использование среды SQL Server Management Studio
Запуск, остановка и перезапуск службы агента SQL Server
В обозревателе объектов щелкните знак «плюс», чтобы развернуть сервер, на котором нужно управлять службой агента SQL Server.
Щелкните правой кнопкой мыши элемент Агент SQL Server и выберите команду Запуск, Стоп или Перезапуск.
В диалоговом окне Контроль учетных записей нажмите Да.
При появлении запроса о необходимости выполнения действия нажмите кнопку Да.
Дополнительные сведения можно найти в разделе
Start, stop, and restart SQL Server services on Linux
This article describes how to start, stop, or restart the SQL Server Database Engine and SQL Server Agent on Linux by using the command line, or Transact-SQL.
Identify the service
SQL Server components are executable programs that run as services (also known as daemons on Linux). Linux services can run without displaying any activity on the computer screen and without user interaction on the command line.
Database Engine service
The Database Engine service is the default instance, with a limit of one per computer. Named instances aren’t supported on Linux. To run multiple instances of SQL Server on a single computer using containers, see Deploy and connect to SQL Server Docker containers.
SQL Server Agent service
The SQL Server Agent service executes scheduled administrative tasks, which are called jobs and alerts. For more information, see SQL Server Agent. SQL Server Agent isn’t available in every edition of SQL Server. For a list of features that are supported by the editions of SQL Server, see Features Supported by the Editions of SQL Server 2019.
Additional Information
On Linux, you can’t pause the Database Engine service like you can on Windows. The SQL Server Agent service also can’t be paused or resumed.
When running on a cluster, use the appropriate cluster management tool to manage the Database Engine for your Linux distribution. See Deploy a Pacemaker cluster for SQL Server on Linux for an example using Pacemaker.
Permissions
By default, only members of the local administrator group can start, stop, or restart a service.
Stopping the Database Engine by using the Transact-SQL SHUTDOWN command requires membership in the sysadmin or serveradmin fixed server roles, and is not transferable.
Using command-line tools
The following steps show how to start, stop, restart, and check the status of the SQL Server service on Linux. To manage a SQL Server Docker container, see Troubleshoot SQL Server on Linux.
Check the status of the Database Engine service using this command:
You can stop, start, or restart the Database Engine service as needed using the following commands:
To set up and manage the SQL Server Agent, see Install SQL Server Agent on Linux. To restart the SQL Server Agent service, you must restart the Database Engine service.
Transact-SQL
The Database Engine can be stopped by using the SHUTDOWN statement.
To stop the Database Engine using Transact-SQL
To wait for currently running Transact-SQL statements and stored procedures to finish, and then stop the Database Engine, execute the following statement.
To stop the Database Engine immediately, execute the following statement.
For more information about the SHUTDOWN statement, see SHUTDOWN (Transact-SQL).
Источники информации:
- http://docs.microsoft.com/en-us/sql/database-engine/configure-windows/start-stop-pause-resume-restart-sql-server-services?view=sql-server-ver15
- http://stackoverflow.com/questions/368761/whats-the-best-way-to-start-and-stop-sql-server-from-the-command-line
- http://docs.microsoft.com/ru-ru/sql/ssms/agent/start-stop-or-pause-the-sql-server-agent-service?view=sql-server-2016
- http://docs.microsoft.com/en-us/sql/linux/sql-server-linux-start-stop-restart-sql-server-services?view=sql-server-ver16