M1 칩으로 MSSQL 개발환경 갖춰보기

M1 칩 맥북에서 Azure Data Studio를 사용하여 MSSQL 개발 환경을 구축하는 과정에서 발생한 문제점과 해결 방법을 공유합니다.

새로운 맥북을 구매했다. 다들 M1 칩으로 옮겨가면서 한 번씩 헤맨 기록들이 블로그에 있던데, 나는 별다른 이상이 없어서 안심하고 있었다. 하지만 마지막 설정으로 MSSQL 개발환경을 맞추다가, 나에게도 문제가 발생했다.

MSSQL 개발환경으로 Azure Data Studio 를 사용하고 있다.

기존에는 mcr.microsoft.com/mssql/server:2019-latest 도커 이미지를 이용하고 있었는데, M1 아키텍처에서는 더이상 지원하지 않았다.

/opt/mssql/bin/sqlservr: Invalid mapping of address 0x400976b000 in reserved address space below 0x400000000000. Possible causes:
1) the process (itself, or via a wrapper) starts-up its own running environment sets the stack size limit to unlimited via syscall setrlimit(2);
2) the process (itself, or via a wrapper) adjusts its own execution domain and flag the system its legacy personality via syscall personality(2);
3) sysadmin deliberately sets the system to run on legacy VA layout mode by adjusting a sysctl knob vm.legacy_va_layout.

SQL Server 의 아키텍처 자체가 M1 과 호환되지 않게 설계되었기 때문에, 기존 이미지로는 이용할 수 없었다. Azure SQL Edge 는 M1 아키텍처와도 호환이 되어서, 어쩔 수 없이 Azure 를 사용해야 했다.

# Docker
alias dockermssqlboot="docker run --cap-add SYS_PTRACE -e 'ACCEPT_EULA=1' \
 -e 'MSSQL_SA_PASSWORD=password' \
 -p 1433:1433 --name 'mssql' \
 -v /Users/heej/data/docker/mssql:/var/opt/mssql \
 -d mcr.microsoft.com/azure-sql-edge"

설치까지 제대로 되어서 안심하고 있었는데, DB Restore 기능을 사용하면 자꾸 다음과 같은 에러가 떴다.

Msg 3634, Level 16, State 1, Line 7 The operating system returned the error '2(The system cannot find the file specified.)' while attempting 'RestoreContainer::ValidateTargetForCreation' on '/var/opt/mssql/data/AdventureWorks2017.mdf'. Msg 3156, Level 16, State 5, Line 7 File 'AdventureWorks2017' cannot be restored to '/var/opt/mssql/data/AdventureWorks2017.mdf'. Use WITH MOVE to identify a valid location for the file. Msg 3634, Level 16, State 1, Line 7 The operating system returned the error '2(The system cannot find the file specified.)' while attempting 'RestoreContainer::ValidateTargetForCreation' on '/var/opt/mssql/log/AdventureWorks2017_log.ldf'. Msg 3156, Level 16, State 5, Line 7 File 'AdventureWorks2017_log' cannot be restored to '/var/opt/mssql/log/AdventureWorks2017_log.ldf'. Use WITH MOVE to identify a valid location for the file. Msg 3119, Level 16, State 1, Line 7 Problems were identified while planning for the RESTORE statement. Previous messages provide details. Msg 3013, Level 16, State 1, Line 7 RESTORE DATABASE is terminating abnormally.

이 에러로 인해 한참동안 시간을 썼는데, 결과적으로는 Azure Data Studio 가 Docker 에 지니는 권한 문제인 것 같다. 검색해 보았더니, 많은 사람들이 같은 이슈를 겪고 있으며 괴이한 해결책을 찾을 수 있었다.

USE [master]
BACKUP LOG [dbAdmin] TO  DISK = N'/var/opt/mssql/data/dbAdmin_LogBackup_2021-09-27_05-20-22.bak' WITH NOFORMAT, NOINIT,  NAME = N'dbAdmin_LogBackup_2021-09-27_05-20-22', NOSKIP, NOREWIND, NOUNLOAD,  NORECOVERY ,  STATS = 5
RESTORE DATABASE [dbAdmin] FROM  DISK = N'/var/opt/mssql/backup/dbAdmin_backup_2021_01_13_010001_4695028.bak' WITH  FILE = 1,  MOVE N'dbAdmin' TO N'/var/opt/mssql/data/dbAdmin.mdf',  MOVE N'dbAdmin_log' TO N'/var/opt/mssql/data/dbAdmin_0.ldf',  NOUNLOAD,  REPLACE,  STATS = 5

Migration 하는 SQL Script 를 생성해 본 후, SQL script 에서 생성하려는 파일을 미리 생성해 주면 된다. 도커 컨테이너 내부에서

touch /var/opt/mssql/data/dbname.mdf
touch /var/opt/mssql/data/dbname_0.ldf

다음과 같이 파일을 생성해 준 후, Restore with Replace 옵션을 통해서 생성하면, 정상적으로 Migration 작업이 이루어진다..다음과 같이 파일을 생성해 준 후, Restore with Replace 옵션을 통해서 생성하면, 정상적으로 Migration 작업이 이루어진다..다음과 같이 파일을 생성해 준 후, Restore with Replace 옵션을 통해서 생성하면, 정상적으로 Migration 작업이 이루어진다..다음과 같이 파일을 생성해 준 후, Restore with Replace 옵션을 통해서 생성하면, 정상적으로 Migration 작업이 이루어진다..


이것도 읽어보세요