Tag: SQL on Linux

  • Check & Restart SQL Server Services on Linux

    Check & Restart SQL Server Services on Linux

    As of the 2017 Edition of SQL Server we have been able to install SQL Server on Linux. Linux will likely be more of an unfamiliar environment for traditional Microsoft SQL DBAs. This guide should hopefully help you when you need to check the status of SQL Services and Stop/Start services on a Linux host.

    Microsoft Docs have a page on this – Start, stop, and restart SQL Server services on Linux

    The examples provided in this post utilise the systemctl command. Many Linux distributions use systemctl as a tool for managing services including CentOS, Ubuntu, Debian & RedHat.

    Note that the systemctl command is not available in some Linux distributions, including if you are running Linux on WSL (Windows Subsystem for Linux). This is because Ubuntu WSL does not use the systemd init system, which is what systemctl is designed to manage.

    The following should help you check and restart SQL Services on a Linux host:
    # Show Enabled Services on Linux
    # Check Status of SQL Server Service Linux
    # Stop, Start and Restart SQL Server Services on Linux

    Show Enabled Services on Linux

    To show all enabled services on a Linux system, use the following command:

    systemctl list-unit-files | grep enabled
    
    systemctl list unit files enabled

    If your service is not on the list of enabled services, it will not start automatically on the next system reboot. To enable the SQL Server service with systemctl, use the following command : sudo systemctl enable mssql-server

    Check Status of SQL Server Service on Linux

    The systemctl status mssql-server command is used to check the current status of the SQL Server service on your system. This command will display information about the service, including whether its currently active or not.

    sudo systemctl status mssql-server
    
    systemctl SQL Server Status

    If the SQL Service is active, the output of the command will include the text “active (running)” in green. This indicates that the service is currently running and is available to process requests.

    If the service is not active, the output will include the text “inactive (dead)” in red. This indicates that the service is not currently running, and may need to be started or restarted in order to be used.

    Stop, Start or Restart the SQL Server Services on Linux

    To stop, start, or restart the SQL Server service on Linux, you can use the systemctl command.

    sudo systemctl stop mssql-server
    

    To start the service again, use the following command:

    sudo systemctl start mssql-server
    

    To restart the service, use the following command:

    sudo systemctl restart mssql-server
    systemctl Restart SQL Server

    After running any of these commands, it is always a good idea to check the status of the service to make sure that the desired action was completed successfully. You can do this using the systemctl status mssql-server command as shown in the screenshot.