Installing SQL Server on Debian
To run SQL Server on Debian, you must first add Microsoft’s official repository and install the database engine. Start by updating your system and installing dependencies:
sudo apt update && sudo apt upgrade sudo apt install -y curl gnupg apt-transport-https
Next, import Microsoft’s GPG key and add the repository (adjust for your Debian version, e.g., debian/12
for Bookworm):
curl https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor -o /usr/share/keyrings/microsoft-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/microsoft-archive-keyring.gpg] https://packages.microsoft.com/debian/12/prod/ stable main" | sudo tee /etc/apt/sources.list.d/mssql-server.list
Install SQL Server and run the configuration script to set the SA password:
sudo apt update sudo apt install -y mssql-server sudo /opt/mssql/bin/mssql-conf setup
Finally, install command-line tools (sqlcmd
, bcp
) for management:
sudo apt install -y mssql-tools
After installation, verify the service is running:
sudo systemctl status mssql-server
Optimizing Storage Performance
Though SQL Server is not native to Debian, you can improve storage performance for Linux-based deployments (including SQL Server via containers or VMs) with these steps:
ext4
(stable, widely supported) or XFS
(better for large files/high throughput) for SQL Server data directories.deadline
scheduler (default in newer kernels) for balanced latency/throughput or noop
(for hypervisors with hardware RAID) to reduce CPU overhead.SELECT
with specific columns), create indexes on frequently queried columns, and avoid SELECT *
to reduce I/O load.Changing Default Data/Log Directories
By default, SQL Server stores data and logs in /var/opt/mssql/data
. To change this (e.g., to a dedicated disk for better performance):
/home/d/mssql/data
) and set ownership to the mssql
user:sudo mkdir -p /home/d/mssql/data sudo chown mssql:mssql /home/d/mssql/data
mssql-conf
to update the default paths:sudo /opt/mssql/bin/mssql-conf set filelocation.defaultdatadir /home/d/mssql/data sudo /opt/mssql/bin/mssql-conf set filelocation.defaultlogdir /home/d/mssql/logs
sudo systemctl restart mssql-server
This ensures new databases use the specified location without affecting existing ones.
Enabling SSL for Secure Connections
To encrypt data between clients and SQL Server, enable SSL:
mssql.conf
file (located in /var/opt/mssql/mssql.conf
):[network] tls = enabled cert = /path/to/certificate.pem key = /path/to/private.key
sudo systemctl restart mssql-server
For client connections, use a connection string with encrypt=true
and trustServerCertificate=true
(for self-signed certs):
jdbc:sqlserver://your_server_ip:1433;encrypt=true;trustServerCertificate=true;
High Availability Options
For critical workloads, set up high availability using SQL Server Always On Availability Groups (supported on Debian via containers or VMs):
CREATE AVAILABILITY GROUP [YourAGName] WITH (ENCRYPTION ON, LOG_ROTATION_ON_TIMEOUT OFF, MAX_LOG_FILES 2, MAX_LOG_MEMBERS 2, MAX_DATA_FILES 1024);
ALTER AVAILABILITY GROUP [YourAGName] ADD DATABASE [YourDatabaseName]; ALTER AVAILABILITY GROUP [YourAGName] ADD REPLICA ON 'SecondaryNodeIP' WITH (ENDPOINT_URL = 'TCP://SecondaryNodeIP:5022', FAILOVER_MODE = AUTOMATIC, AVAILABILITY_MODE = SYNCHRONOUS_COMMIT);
ALTER AVAILABILITY GROUP [YourAGName] FAILOVER;
This setup ensures automatic failover and minimizes downtime during node failures.