Sql-server – Copy on Write for SQL Server

sql server

I have 20 users that each keep a copy of a database on their local computer (technology other than SQL Server).

Their copy (we call it a sandbox) is updated each morning and their previous changes are throw away.

We are migrating this data to SQL Server and want to maintain the sandbox feature, but we don't want the overhead of installing SQL Server on each of their computers or making 20 separate databases.

Is there a "copy on write" feature that is easy to turn on that will essentially allow each person to only see their changes to the database while still using a common database? I don't want to make big changes to the code to achieve this. If big changes to the code are necessary I will probably go with SQL Server Express and have the database on their local machine.

The users are not technical.

The application that reads the data is an .exe that runs on the users' machine.

We can run what ever version of SQL Server that would support this.

There are enough nuances to the database interaction with the app that I am only going to use SQL Server as trying to switch to e.g. SQLite would find all kinds of problems.

The users need to update the data in sandbox so a read-only solution is not an option.

Best Answer

If the overhead you are concerned about with the local SQL installs is a licensing overhead, and the database is smaller than 10Gb, then you could instead install Express edition which is free (but has the 10Gb limit). If the DB is a little over 10Gb then you could restore to the server, compress enough tables & indexes to make up the difference, then backup and restore that locally.

There is no copy-on-write support in SQL Server itself. If you are running it on Linux you could perhaps try using LVM snapshots to try acheive this:

  1. Drop the existing DBs if present
  2. Drop the LVM snapshots if present from last time
  3. Backup the DB and restore it with the data and log files on the reference LVM volume
  4. Detach (sp_detach_db) the restored copy
  5. Make enough read-write LVM snapshot volumes of the volume now containing the updated DB copy
  6. Attach the DB from each of the snapshots (sp_attach_db)

If your storage subsystem is a SAN with RW-snapshot features than you could potentially use a similar method with that.

I would not recommend this, or other options with 20 copies of the DB on the same instance and drive(s), if the users might pose much load - they will all compete for IO, they will all compete for buffer pool memory, and while the on-disk data is CoW the SQL instance will not know this so will happily hold duplicate copies of unmodified data in memory.