How to Use a Microsoft SQL Server Database with Yurbi on Docker
The Yurbi Docker package installs with its own PostgreSQL database. This guide explains how to switch a new Docker installation to a Microsoft SQL Server database that you host yourself.
This is a manual procedure for the less common case where Yurbi's own database must live on SQL Server. You do not need it to report on SQL Server data: Yurbi can connect to SQL Server data sources whichever database it uses for itself.
Before you start
Do this on a new installation, before you activate your license, add users or build reports. Nothing is copied from the PostgreSQL database to SQL Server. Data cannot be migrated between the two later, so choose the database you will keep.
SQL Server authentication only. The SQL Server must accept SQL logins (user name and password). Windows authentication is supported only when Yurbi is installed on Windows Server.
SQL Server must support TLS 1.2. Very old, unpatched SQL Server versions that only offer older encryption cannot be used.
The password of the SQL login must be 32 characters or fewer.
Network. The Docker server must be able to reach the SQL Server on its port (1433 by default).
You need:
Yurbi installed with Docker and running. See the Docker install guide.
A database administrator who can create a database and a login on the SQL Server.
This guide assumes the installation folder is /opt/yurbi.
Step 1: Create the database on SQL Server
Your database administrator does this on the SQL Server, for example with SQL Server Management Studio.
Create an empty database named
yurbi.Create a SQL login for Yurbi and make it a member of
db_owneron theyurbidatabase.Download the database script:
https://f002.backblazeb2.com/file/5000fish/yurbi/linux/script.sqlRun the script against the
yurbidatabase. It creates the Yurbi tables and starter data.
Step 2: Test the connection from the Docker server
Confirm that the Yurbi container can reach the SQL Server and log in. Replace the server name and login with your own. You are asked for the password.
cd /opt/yurbisudo docker compose exec yurbi /opt/mssql-tools18/bin/sqlcmd -S sqlserver.example.com,1433 -U yurbi_login -d yurbi -C -Q "select count(*) as tables from sys.tables"
It should print a table count greater than zero. If it reports a connection or login error, resolve that before going further. Common causes are a firewall, a wrong port, or SQL logins not being enabled on the server.
Use the form server,port for the server. If your SQL Server uses a named instance, ask your database administrator for its port number and use that, rather than server\instance.
Step 3: Point Yurbi at SQL Server
The database connection is set in the windowservices.config file, which is stored inside the installation. Copy it out, edit it, and copy it back.
Copy the file out and keep a spare copy:
cd /opt/yurbisudo docker cp yurbi-app:/var/yurbi/config/windowservices.config ./windowservices.configsudo cp windowservices.config windowservices.config.postgres-backupOpen the file in an editor:
sudo nano windowservices.configFind the line that starts with
<Database. It looks like this:<Database Server="postgres:5432" Username="postgres" Password="(a long encrypted value)" Database="yurbi" DatabaseType="Npgsql"/>Replace that one line with the following, using your own server, login and password:
<Database Server="sqlserver.example.com,1433;TrustServerCertificate=True;Encrypt=false" Username="yurbi_login" Password="YourPassword" Database="yurbi" DatabaseType="System.Data.SqlClient"/>Keep
;TrustServerCertificate=True;Encrypt=falseafter the server name exactly as shown.Type the password as plain text. Yurbi encrypts it in the file the first time it starts.
If the password contains
&,<,>or", write them as&,<,>and".Do not change any other line.
Copy the file back and restart Yurbi:
sudo docker cp ./windowservices.config yurbi-app:/var/yurbi/config/windowservices.configsudo docker compose restart yurbiRemove the edited copy, because it contains the password in plain text:
sudo rm ./windowservices.config
Step 4: Check the result
Wait about a minute, then check that the application is healthy:
sudo docker compose psConfirm the password in the file is now encrypted, and that the file points at SQL Server:
sudo docker compose exec yurbi grep "<Database" /var/yurbi/config/windowservices.configYou should see
DatabaseType="System.Data.SqlClient"and a long encrypted value in place of the password you typed.Open Yurbi in your browser and log in with the default administrator account.
Activate your license, then change the administrator password.
If the login fails, look for database errors:
sudo docker compose exec yurbi sh -c 'grep -h ":##:ERROR:##:" /var/yurbi/logs/* | tail -20'
What changes once you use SQL Server
Backups are yours to arrange. The Yurbi upgrade script backs up only the PostgreSQL database that came with the package, which is no longer in use. Make sure your SQL Server backups include the
yurbidatabase, and take one before every Yurbi upgrade.Upgrades work the same way. Run
upgrade.shas described in the Docker install guide. Your connection setting is kept.The PostgreSQL container keeps running. It is no longer used, but leave it in place. The package expects it to be there.
Changing the SQL password later. Repeat step 3 with the new password.
Going back to the built-in database
To return to the PostgreSQL database that came with the package:
cd /opt/yurbisudo docker cp ./windowservices.config.postgres-backup yurbi-app:/var/yurbi/config/windowservices.configsudo docker compose restart yurbi
Anything created while Yurbi was using SQL Server stays in SQL Server and does not appear in the PostgreSQL database.