Launching SQL Server on Linux in Single User Mode
There was a question this morning on the SQL Server Community Slack channel from SvenLowry about how to launch SQL Server on Linux in Single User Mode. Well you’ve heard everyone say, it’s just SQL Server…and that’s certainly true and this is another example of that idea.
The command line parameters from the sqlservr binary are passed through into the SQLPAL managed Win32 SQL Process. So let’s check out how to do this together…
First, you’ll want to switch to the user mssql and you can do that with this command
bash-4.2$ sudo su mssql –
What’s happening here is we’re using sudo to switch our user’s security context to the user mssql. This is the account that SQL Server normally runs under. That last dash there is to load the mssql user’s shell, rather than ours.
Next, we need to launch the /opt/mssql/bin/sqlservr binary with the -m parameter
bash-4.2$ /opt/mssql/bin/sqlservr -m
Here’s the output from the console while SQL Server is starting up.
2017-11-09 12:53:18.70 Server Microsoft SQL Server 2017 (RTM-CU1) (KB4038634) – 14.0.3006.16 (X64)
<p style="margin: 0px; font-stretch: normal; font-size: 18px; line-height: normal; font-family: 'Andale Mono'; color: #28fe14; background-color: rgba(0, 0, 0, 0.901961);">
<span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;">Oct 19 2017 02:42:29 </span>
</p>
<p style="margin: 0px; font-stretch: normal; font-size: 18px; line-height: normal; font-family: 'Andale Mono'; color: #28fe14; background-color: rgba(0, 0, 0, 0.901961);">
<span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;">Copyright (C) 2017 Microsoft Corporation</span>
</p>
<p style="margin: 0px; font-stretch: normal; font-size: 18px; line-height: normal; font-family: 'Andale Mono'; color: #28fe14; background-color: rgba(0, 0, 0, 0.901961);">
<span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;">Developer Edition (64-bit) on Linux (CentOS Linux 7 (Core))</span>
</p>
<p style="margin: 0px; font-stretch: normal; font-size: 18px; line-height: normal; font-family: 'Andale Mono'; color: #28fe14; background-color: rgba(0, 0, 0, 0.901961);">
<span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;">2017-11-09 12:53:18.70 Server UTC adjustment: -6:00</span>
</p>
<p style="margin: 0px; font-stretch: normal; font-size: 18px; line-height: normal; font-family: 'Andale Mono'; color: #28fe14; background-color: rgba(0, 0, 0, 0.901961);">
<span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;">2017-11-09 12:53:18.70 Server (c) Microsoft Corporation.</span>
</p>
<p style="margin: 0px; font-stretch: normal; font-size: 18px; line-height: normal; font-family: 'Andale Mono'; color: #28fe14; background-color: rgba(0, 0, 0, 0.901961);">
<span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;">2017-11-09 12:53:18.70 Server All rights reserved.</span>
</p>
<p style="margin: 0px; font-stretch: normal; font-size: 18px; line-height: normal; font-family: 'Andale Mono'; color: #28fe14; background-color: rgba(0, 0, 0, 0.901961);">
<span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;">2017-11-09 12:53:18.70 Server Server process ID is 4120.</span>
</p>
<p style="margin: 0px; font-stretch: normal; font-size: 18px; line-height: normal; font-family: 'Andale Mono'; color: #28fe14; background-color: rgba(0, 0, 0, 0.901961);">
<span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;">2017-11-09 12:53:18.70 Server Logging SQL Server messages in file ‘/var/opt/mssql/log/errorlog’.</span>
</p>
<p style="margin: 0px; font-stretch: normal; font-size: 18px; line-height: normal; font-family: 'Andale Mono'; color: #28fe14; background-color: rgba(0, 0, 0, 0.901961);">
<span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;">2017-11-09 12:53:18.70 Server Registry startup parameters: </span>
</p>
<p style="margin: 0px; font-stretch: normal; font-size: 18px; line-height: normal; font-family: 'Andale Mono'; color: #28fe14; background-color: rgba(0, 0, 0, 0.901961);">
<span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;"> -d /var/opt/mssql/data/master.mdf</span>
</p>
<p style="margin: 0px; font-stretch: normal; font-size: 18px; line-height: normal; font-family: 'Andale Mono'; color: #28fe14; background-color: rgba(0, 0, 0, 0.901961);">
<span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;"> -l /var/opt/mssql/data/mastlog.ldf</span>
</p>
<p style="margin: 0px; font-stretch: normal; font-size: 18px; line-height: normal; font-family: 'Andale Mono'; color: #28fe14; background-color: rgba(0, 0, 0, 0.901961);">
<span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;"> -e /var/opt/mssql/log/errorlog</span>
</p>
<p style="margin: 0px; font-stretch: normal; font-size: 18px; line-height: normal; font-family: 'Andale Mono'; color: #28fe14; background-color: rgba(0, 0, 0, 0.901961);">
<span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;"><strong>2017-11-09 12:53:18.70 Server Command Line Startup Parameters:</strong></span>
</p>
<p style="margin: 0px; font-stretch: normal; font-size: 18px; line-height: normal; font-family: 'Andale Mono'; color: #28fe14; background-color: rgba(0, 0, 0, 0.901961);">
<span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;"><strong> -m</strong></span>
</p>
<p style="margin: 0px; font-stretch: normal; font-size: 18px; line-height: normal; font-family: 'Andale Mono'; color: #28fe14; background-color: rgba(0, 0, 0, 0.901961);">
<span style="font-size: 12px;">Output omitted…</span>
</p>
<p style="margin: 0px; font-stretch: normal; font-size: 18px; line-height: normal; font-family: 'Andale Mono'; color: #28fe14; background-color: rgba(0, 0, 0, 0.901961);">
<span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;"><strong>2017-11-09 12:53:19.50 spid4s SQL Server started in single-user mode. This an informational message only. No user action is required.</strong></span>
</p>
<p style="margin: 0px; font-stretch: normal; font-size: 18px; line-height: normal; font-family: 'Andale Mono'; color: #28fe14; background-color: rgba(0, 0, 0, 0.901961);">
<span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;">Output omitted…</span>
</p>
<p style="margin: 0px; font-stretch: normal; font-size: 18px; line-height: normal; font-family: 'Andale Mono'; color: #28fe14; background-color: rgba(0, 0, 0, 0.901961);">
<span style="font-size: 12px;"><strong style="font-size: 12px;">2017-11-09 12:53:19.90 spid4s Always On Availability Groups was not started because the SQL Server instance is running in single-user mode. This is an informational message. No user action is required.</strong></span>
</p>
<p style="margin: 0px; font-stretch: normal; font-size: 18px; line-height: normal; font-family: 'Andale Mono'; color: #28fe14; background-color: rgba(0, 0, 0, 0.901961);">
<span style="font-family: 'Andale Mono'; font-size: 12px;">Output omitted…</span>
</p>
<p style="margin: 0px; font-stretch: normal; font-size: 18px; line-height: normal; font-family: 'Andale Mono'; color: #28fe14; background-color: rgba(0, 0, 0, 0.901961);">
<span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;">2017-11-09 12:53:20.62 spid4s Recovery is complete. This is an informational message only. No user action is required.</span>
</p>
<div>
<span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;"><br /></span>
</div>
<div>
From here, you can go about what ever task it is you needed single user mode for.
</div>