{"id":1865,"date":"2021-09-01T18:42:38","date_gmt":"2021-09-02T01:42:38","guid":{"rendered":"https:\/\/jim-zimmerman.com\/?p=1865"},"modified":"2021-09-01T18:42:38","modified_gmt":"2021-09-02T01:42:38","slug":"mssql-2017-on-ubuntu-configuration-modifications","status":"publish","type":"post","link":"https:\/\/jim-zimmerman.com\/?p=1865","title":{"rendered":"MSSQL 2017 on Ubuntu Configuration Modifications"},"content":{"rendered":"<p>This will address a few basic MSSQL configuration changes when running MSSQL on a linux platform.  <\/p>\n<p>The first one involves changing the default database and log locations:<br \/>\nTo set the default directories:<\/p>\n<blockquote><p>sudo \/opt\/mssql\/bin\/mssql-conf set filelocation.defaultdatadir \/{SOMENEWDATADIRECTORY}<br \/>\nsudo \/opt\/mssql\/bin\/mssql-conf set filelocation.defaultlogdir \/{SOMENEWLOGDIRECTORY}<br \/>\nsudo \/opt\/mssql\/bin\/mssql-conf set filelocation.defaultbackupdir \/{SOMENEWBACKUPDIRECTORY}<br \/>\nsudo systmectl restart mssql-server<\/p><\/blockquote>\n<p>For example:<\/p>\n<blockquote><p>sudo \/opt\/mssql\/bin\/mssql-conf set filelocation.defaultdatadir \/Data<br \/>\nsudo \/opt\/mssql\/bin\/mssql-conf set filelocation.defaultlogdir \/Logs<br \/>\nsudo \/opt\/mssql\/bin\/mssql-conf set filelocation.defaultbackupdir \/Backup<br \/>\nsudo systmectl restart mssql-server<\/p><\/blockquote>\n<p>Next up is enabling the SQL Agent:<br \/>\nEnable the SQL Agent:<\/p>\n<blockquote><p>\/opt\/mssql\/bin\/mssql-conf set sqlagent.enabled true<br \/>\nsudo systemctl restart mssql-server<\/p><\/blockquote>\n<p>Lastly is moving the default databases to a new location.  For instance to the default directories you configured above.  This is a bit more involved, so you have to pay attention to the details.  Unless otherwise specified these are run from the linux command line.<\/p>\n<p>First, you need to ensure that the new directory locations are owned by mssql, and group access is allowed for mssql group as well.<\/p>\n<blockquote><p>sudo chown mssql.mssql \/Data<br \/>\nsudo chown mssql.mssql \/Logs<br \/>\nsudo chown mssql.mssql \/Backup <\/p><\/blockquote>\n<p>Determine where the tempdb data and logs files are currently:<br \/>\nAccess the SQL server and update the tempdb location:<\/p>\n<blockquote><p>sqlcmd -S localhost -U SA -P {PASSWORD}<br \/>\n> SELECT name, physical_name AS CurrentLocation  FROM sys.master_files  WHERE database_id = DB_ID(N&#8217;tempdb&#8217;);<br \/>\n> GO  <\/p>\n<p>> USE master;<br \/>\n> GO<br \/>\n> ALTER DATABASE tempdb<br \/>\n> MODIFY FILE (NAME = tempdev, FILENAME = &#8216;\/Data\/tempdb.mdf&#8217;);<br \/>\n> GO<br \/>\n> ALTER DATABASE tempdb<br \/>\n> MODIFY FILE (NAME = templog, FILENAME = &#8216;\/Logs\/templog.ldf&#8217;);<br \/>\n> GO  <\/p><\/blockquote>\n<p>Restart the MSSQL server:<\/p>\n<blockquote><p>sudo systemctl restart mssql-server.service<\/p><\/blockquote>\n<p>You can make subdirectories for each database if you want as well.  You just have to make certain that the ownership is correct.<\/p>\n<blockquote><p>sudo mkdir \/Data\/msdb<br \/>\nsudo mkdir \/Logs\/msdb<br \/>\nsudo chown -R mssql.mssql \/Data\/<br \/>\nsudo chown -R mssql.mssql \/Logs\/<\/p><\/blockquote>\n<p>Access the SQL server:<\/p>\n<blockquote><p>sqlcmd -S localhost -U SA -P {PASSWORD}<\/p><\/blockquote>\n<p>Determine where the msdb data and logs files are currently:<\/p>\n<blockquote><p>> SELECT name, physical_name AS CurrentLocation FROM sys.master_files WHERE database_id = DB_ID(N&#8217;msdb&#8217;);<br \/>\n> GO<\/p><\/blockquote>\n<p>Continuing from the SQL server:<br \/>\nMove msdb:<\/p>\n<blockquote><p>> USER master<br \/>\n> GO<br \/>\n> ALTER DATABASE msdb<br \/>\n> MODIFY FILE (NAME = MSDBData, FILENAME = &#8216;\/Data\/msdb\/MSDBData.mdf&#8217;);<br \/>\n> GO<br \/>\n> ALTER DATABASE msdb<br \/>\n> MODIFY FILE (NAME = MSDBLog, FILENAME = &#8216;\/Logs\/msdb\/MSDBLog.ldf&#8217;);<br \/>\n> GO<\/p><\/blockquote>\n<p>Move the existing database files to their new locations:<\/p>\n<blockquote><p>sudo sudo cd \/var\/opt\/mssql\/data\/<br \/>\nsudo systemctl stop mssql-server.service<br \/>\nsudo mv msdbdata.mdf \/Data\/msdb\/<br \/>\nsudo mv msdblog.ldf \/Logs\/msdb\/<br \/>\nsudo systemctl restart mssql-server.service<br \/>\nsudo systemctl status  mssql-server.service<\/p><\/blockquote>\n<p>Access the SQL server:<\/p>\n<blockquote><p>sqlcmd -S localhost -U SA -P {PASSWORD}<\/p><\/blockquote>\n<p>Determine where the model data and logs files are currently:<\/p>\n<blockquote><p>> SELECT name, physical_name AS CurrentLocation FROM sys.master_files where database_id = DB_ID(N&#8217;model&#8217;)<br \/>\n> GO<\/p><\/blockquote>\n<p>Continuing from the SQL server:<br \/>\nMove model:<\/p>\n<blockquote><p>> USE master<br \/>\n> ALTER DATABASE model<br \/>\n> MODIFY file (NAME = modeldev, FILENAME = &#8216;\/Data\/model\/model.mdf&#8217;)<br \/>\n> GO<br \/>\n> ALTER DATABASE model<br \/>\n> MODIFY file (NAME = modellog, FILENAME = &#8216;\/Logs\/model\/modellog.ldf&#8217;)<br \/>\n> GO<\/p><\/blockquote>\n<p>Move the existing database files to their new locations:<\/p>\n<blockquote><p>sudo sudo cd \/var\/opt\/mssql\/data\/<br \/>\nsudo systemctl stop mssql-server.service<br \/>\nsudo mkdir \/Data\/model<br \/>\nsudo mkdir \/Logs\/model<br \/>\nsudo chown mssql.mssql \/Data<br \/>\nsudo chown mssql.mssql \/Logs<br \/>\nsudo mv msdbdata.mdf \/Data\/model\/<br \/>\nsudo mv msdblog.ldf \/Logs\/model\/<br \/>\nsudo systemctl restart mssql-server.service<br \/>\nsudo systemctl status  mssql-server.service<\/p><\/blockquote>\n<p>Access the SQL server:<\/p>\n<blockquote><p>sqlcmd -S localhost -U SA -P {PASSWORD}<\/p><\/blockquote>\n<p>Determine where the master data and log files are currently:<\/p>\n<blockquote><p>> SELECT name, physical_name AS CurrentLocation FROM sys.master_files where database_id = DB_ID(N&#8217;master&#8217;)<br \/>\n> GO<\/p><\/blockquote>\n<p>The master database is a little different than the others.  You set the configuration after stopping the mssql-server process and moving the files.<\/p>\n<blockquote><p>sudo cd \/var\/opt\/mssql\/data<br \/>\nsudo mkdir \/Data\/master<br \/>\nsudo mkdir \/Logs\/master<br \/>\nsudo chown -R mssql.mssql \/Data<br \/>\nsudo chown -R mssql.mssql \/Logs<br \/>\nsudo mv master.mdf \/Data\/master<br \/>\nsudo mv master.mdf \/Logs\/master<br \/>\nsudo \/opt\/mssql\/bin\/mssql-conf set filelocation.masterdatafile \/Data\/master\/master.mdf<br \/>\nsudo \/opt\/mssql\/bin\/mssql-conf set filelocation.masterlogfile  \/Logs\/master\/mastlog.ldf<br \/>\nsudo systemctl stop mssql-server<br \/>\nsudo systemctl start mssql-server<br \/>\nsudo systemctl status mssql-server<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>This will address a few basic MSSQL configuration changes when running MSSQL on a linux platform. The first one involves changing the default database and log locations: To set the default directories: sudo \/opt\/mssql\/bin\/mssql-conf set filelocation.defaultdatadir \/{SOMENEWDATADIRECTORY} sudo \/opt\/mssql\/bin\/mssql-conf set filelocation.defaultlogdir \/{SOMENEWLOGDIRECTORY} sudo \/opt\/mssql\/bin\/mssql-conf set filelocation.defaultbackupdir \/{SOMENEWBACKUPDIRECTORY} sudo systmectl restart mssql-server For example: sudo \/opt\/mssql\/bin\/mssql-conf [&#038;hellip<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[48,218,132],"class_list":["post-1865","post","type-post","status-publish","format-standard","hentry","category-documentation","tag-linux","tag-mssql","tag-ubuntu"],"share_on_mastodon":{"url":"","error":""},"_links":{"self":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts\/1865","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1865"}],"version-history":[{"count":5,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts\/1865\/revisions"}],"predecessor-version":[{"id":1870,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts\/1865\/revisions\/1870"}],"wp:attachment":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1865"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1865"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}