Skip to content

Slow performance when commiting transaction to SQLite encrypted file #28774

Description

@iplusMario

We are currently testing encrypted SQLite and we are experiencing slow performance (about 500 ms for commiting transaction) when inserting into database.

info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
      Entity Framework Core 6.0.8 initialized 'TestDbContext' using provider 'Microsoft.EntityFrameworkCore.Sqlite:6.0.8' with options: MaxPoolSize=1024
info: 18. 08. 2022 13:49:11.936 CoreEventId.ContextInitialized[10403] (Microsoft.EntityFrameworkCore.Infrastructure)
      Entity Framework Core 6.0.8 initialized 'TestDbContext' using provider 'Microsoft.EntityFrameworkCore.Sqlite:6.0.8' with options: MaxPoolSize=1024
dbug: 18. 08. 2022 13:49:11.987 RelationalEventId.ConnectionOpening[20000] (Microsoft.EntityFrameworkCore.Database.Connection)
      Opening connection to database 'main' on server 'TestDatabase.db'.
dbug: 18. 08. 2022 13:49:12.466 RelationalEventId.ConnectionOpened[20001] (Microsoft.EntityFrameworkCore.Database.Connection)
      Opened connection to database 'main' on server 'P:\C#Projects\EFCoreEncryptionTest\bin\Debug\net6.0\TestDatabase.db'.
dbug: 18. 08. 2022 13:49:12.470 RelationalEventId.ConnectionOpening[20000] (Microsoft.EntityFrameworkCore.Database.Connection)
      Opening connection to database 'main' on server 'TestDatabase.db'.
dbug: 18. 08. 2022 13:49:13.063 RelationalEventId.ConnectionOpened[20001] (Microsoft.EntityFrameworkCore.Database.Connection)
      Opened connection to database 'main' on server 'P:\C#Projects\EFCoreEncryptionTest\bin\Debug\net6.0\TestDatabase.db'.
dbug: 18. 08. 2022 13:49:13.064 RelationalEventId.ConnectionClosing[20002] (Microsoft.EntityFrameworkCore.Database.Connection)
      Closing connection to database 'main' on server 'P:\C#Projects\EFCoreEncryptionTest\bin\Debug\net6.0\TestDatabase.db'.
dbug: 18. 08. 2022 13:49:13.066 RelationalEventId.ConnectionClosed[20003] (Microsoft.EntityFrameworkCore.Database.Connection)
      Closed connection to database 'main' on server 'TestDatabase.db'.
dbug: 18. 08. 2022 13:49:13.070 RelationalEventId.ConnectionOpening[20000] (Microsoft.EntityFrameworkCore.Database.Connection)
      Opening connection to database 'main' on server 'TestDatabase.db'.
dbug: 18. 08. 2022 13:49:13.072 RelationalEventId.ConnectionError[20004] (Microsoft.EntityFrameworkCore.Database.Connection)
      An error occurred using the connection to database 'main' on server 'TestDatabase.db'.
dbug: 18. 08. 2022 13:49:13.073 RelationalEventId.ConnectionOpening[20000] (Microsoft.EntityFrameworkCore.Database.Connection)
      Opening connection to database 'main' on server 'TestDatabase.db'.
dbug: 18. 08. 2022 13:49:13.073 RelationalEventId.ConnectionOpened[20001] (Microsoft.EntityFrameworkCore.Database.Connection)
      Opened connection to database 'main' on server 'P:\C#Projects\EFCoreEncryptionTest\bin\Debug\net6.0\TestDatabase.db'.
dbug: 18. 08. 2022 13:49:13.078 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command)
      Creating DbCommand for 'ExecuteNonQuery'.
dbug: 18. 08. 2022 13:49:13.080 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command)
      Created DbCommand for 'ExecuteNonQuery' (2ms).
dbug: 18. 08. 2022 13:49:13.082 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command)
      Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
      PRAGMA journal_mode = 'wal';
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (596ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      PRAGMA journal_mode = 'wal';
info: 18. 08. 2022 13:49:13.680 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
      Executed DbCommand (596ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      PRAGMA journal_mode = 'wal';
dbug: 18. 08. 2022 13:49:13.680 RelationalEventId.ConnectionClosing[20002] (Microsoft.EntityFrameworkCore.Database.Connection)
      Closing connection to database 'main' on server 'P:\C#Projects\EFCoreEncryptionTest\bin\Debug\net6.0\TestDatabase.db'.
dbug: 18. 08. 2022 13:49:13.681 RelationalEventId.ConnectionClosed[20003] (Microsoft.EntityFrameworkCore.Database.Connection)
      Closed connection to database 'main' on server 'TestDatabase.db'.
dbug: 18. 08. 2022 13:49:13.733 CoreEventId.DetectChangesStarting[10800] (Microsoft.EntityFrameworkCore.ChangeTracking)
      DetectChanges starting for 'TestDbContext'.
dbug: 18. 08. 2022 13:49:13.734 CoreEventId.DetectChangesCompleted[10801] (Microsoft.EntityFrameworkCore.ChangeTracking)
      DetectChanges completed for 'TestDbContext'.
dbug: 18. 08. 2022 13:49:13.752 RelationalEventId.ConnectionOpening[20000] (Microsoft.EntityFrameworkCore.Database.Connection)
      Opening connection to database 'main' on server 'TestDatabase.db'.
dbug: 18. 08. 2022 13:49:14.214 RelationalEventId.ConnectionOpened[20001] (Microsoft.EntityFrameworkCore.Database.Connection)
      Opened connection to database 'main' on server 'P:\C#Projects\EFCoreEncryptionTest\bin\Debug\net6.0\TestDatabase.db'.
dbug: 18. 08. 2022 13:49:14.216 RelationalEventId.TransactionStarting[20209] (Microsoft.EntityFrameworkCore.Database.Transaction)
      Beginning transaction with isolation level 'Unspecified'.
dbug: 18. 08. 2022 13:49:14.217 RelationalEventId.TransactionStarted[20200] (Microsoft.EntityFrameworkCore.Database.Transaction)
      Began transaction with isolation level 'Serializable'.
dbug: 18. 08. 2022 13:49:14.218 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command)
      Creating DbCommand for 'ExecuteNonQuery'.
dbug: 18. 08. 2022 13:49:14.218 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command)
      Created DbCommand for 'ExecuteNonQuery' (0ms).
dbug: 18. 08. 2022 13:49:14.218 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command)
      Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
      CREATE TABLE "TestModel" (
          "DrawId" INTEGER NOT NULL CONSTRAINT "PK_TestModel" PRIMARY KEY AUTOINCREMENT,
          "ChangeUser" TEXT NULL,
          "ChangeDate" AS (DATETIME()) STORED
      );
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      CREATE TABLE "TestModel" (
          "DrawId" INTEGER NOT NULL CONSTRAINT "PK_TestModel" PRIMARY KEY AUTOINCREMENT,
          "ChangeUser" TEXT NULL,
          "ChangeDate" AS (DATETIME()) STORED
      );
info: 18. 08. 2022 13:49:14.219 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
      Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      CREATE TABLE "TestModel" (
          "DrawId" INTEGER NOT NULL CONSTRAINT "PK_TestModel" PRIMARY KEY AUTOINCREMENT,
          "ChangeUser" TEXT NULL,
          "ChangeDate" AS (DATETIME()) STORED
      );
+ dbug: 18. 08. 2022 13:49:14.221 RelationalEventId.TransactionCommitting[20210] (Microsoft.EntityFrameworkCore.Database.Transaction)
      Committing transaction.
+ dbug: 18. 08. 2022 13:49:14.227 RelationalEventId.TransactionCommitted[20202] (Microsoft.EntityFrameworkCore.Database.Transaction)
      Committed transaction.
dbug: 18. 08. 2022 13:49:14.227 RelationalEventId.TransactionDisposed[20204] (Microsoft.EntityFrameworkCore.Database.Transaction)
      Disposing transaction.
dbug: 18. 08. 2022 13:49:14.228 RelationalEventId.ConnectionClosing[20002] (Microsoft.EntityFrameworkCore.Database.Connection)
      Closing connection to database 'main' on server 'P:\C#Projects\EFCoreEncryptionTest\bin\Debug\net6.0\TestDatabase.db'.
dbug: 18. 08. 2022 13:49:14.228 RelationalEventId.ConnectionClosed[20003] (Microsoft.EntityFrameworkCore.Database.Connection)
      Closed connection to database 'main' on server 'TestDatabase.db'.
dbug: 18. 08. 2022 13:49:14.251 CoreEventId.ValueGenerated[10808] (Microsoft.EntityFrameworkCore.ChangeTracking)
      'TestDbContext' generated a temporary value for the property 'DrawId.TestModel'. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see key values.
dbug: 18. 08. 2022 13:49:14.280 CoreEventId.StartedTracking[10806] (Microsoft.EntityFrameworkCore.ChangeTracking)
      Context 'TestDbContext' started tracking 'TestModel' entity. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see key values.
dbug: 18. 08. 2022 13:49:14.284 CoreEventId.SaveChangesStarting[10004] (Microsoft.EntityFrameworkCore.Update)
      SaveChanges starting for 'TestDbContext'.
dbug: 18. 08. 2022 13:49:14.284 CoreEventId.DetectChangesStarting[10800] (Microsoft.EntityFrameworkCore.ChangeTracking)
      DetectChanges starting for 'TestDbContext'.
dbug: 18. 08. 2022 13:49:14.288 CoreEventId.DetectChangesCompleted[10801] (Microsoft.EntityFrameworkCore.ChangeTracking)
      DetectChanges completed for 'TestDbContext'.
dbug: 18. 08. 2022 13:49:14.300 RelationalEventId.ConnectionOpening[20000] (Microsoft.EntityFrameworkCore.Database.Connection)
      Opening connection to database 'main' on server 'TestDatabase.db'.
dbug: 18. 08. 2022 13:49:14.301 RelationalEventId.ConnectionOpened[20001] (Microsoft.EntityFrameworkCore.Database.Connection)
      Opened connection to database 'main' on server 'P:\C#Projects\EFCoreEncryptionTest\bin\Debug\net6.0\TestDatabase.db'.
dbug: 18. 08. 2022 13:49:14.302 RelationalEventId.TransactionStarting[20209] (Microsoft.EntityFrameworkCore.Database.Transaction)
      Beginning transaction with isolation level 'Unspecified'.
dbug: 18. 08. 2022 13:49:14.304 RelationalEventId.TransactionStarted[20200] (Microsoft.EntityFrameworkCore.Database.Transaction)
      Began transaction with isolation level 'Serializable'.
dbug: 18. 08. 2022 13:49:14.332 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command)
      Creating DbCommand for 'ExecuteReader'.
dbug: 18. 08. 2022 13:49:14.332 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command)
      Created DbCommand for 'ExecuteReader' (0ms).
dbug: 18. 08. 2022 13:49:14.337 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command)
      Executing DbCommand [Parameters=[@p0='?'], CommandType='Text', CommandTimeout='30']
      INSERT INTO "TestModel" ("ChangeUser")
      VALUES (@p0);
      SELECT "DrawId", "ChangeDate"
      FROM "TestModel"
      WHERE changes() = 1 AND "rowid" = last_insert_rowid();
info: 18. 08. 2022 13:49:14.339 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
      Executed DbCommand (4ms) [Parameters=[@p0='?'], CommandType='Text', CommandTimeout='30']
      INSERT INTO "TestModel" ("ChangeUser")
      VALUES (@p0);
      SELECT "DrawId", "ChangeDate"
      FROM "TestModel"
      WHERE changes() = 1 AND "rowid" = last_insert_rowid();
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (4ms) [Parameters=[@p0='?'], CommandType='Text', CommandTimeout='30']
      INSERT INTO "TestModel" ("ChangeUser")
      VALUES (@p0);
      SELECT "DrawId", "ChangeDate"
      FROM "TestModel"
      WHERE changes() = 1 AND "rowid" = last_insert_rowid();
dbug: 18. 08. 2022 13:49:14.364 CoreEventId.ForeignKeyChangeDetected[10803] (Microsoft.EntityFrameworkCore.ChangeTracking)
      The foreign key property 'TestModel.DrawId' was detected as changed. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see property values.
dbug: 18. 08. 2022 13:49:14.371 RelationalEventId.DataReaderDisposing[20300] (Microsoft.EntityFrameworkCore.Database.Command)
      A data reader was disposed.
- dbug: 18. 08. 2022 13:49:14.373 RelationalEventId.TransactionCommitting[20210] (Microsoft.EntityFrameworkCore.Database.Transaction)
      Committing transaction.
- dbug: 18. 08. 2022 13:49:14.834 RelationalEventId.TransactionCommitted[20202] (Microsoft.EntityFrameworkCore.Database.Transaction)
      Committed transaction.
dbug: 18. 08. 2022 13:49:14.836 RelationalEventId.ConnectionClosing[20002] (Microsoft.EntityFrameworkCore.Database.Connection)
      Closing connection to database 'main' on server 'P:\C#Projects\EFCoreEncryptionTest\bin\Debug\net6.0\TestDatabase.db'.
dbug: 18. 08. 2022 13:49:14.837 RelationalEventId.ConnectionClosed[20003] (Microsoft.EntityFrameworkCore.Database.Connection)
      Closed connection to database 'main' on server 'TestDatabase.db'.
dbug: 18. 08. 2022 13:49:14.840 RelationalEventId.TransactionDisposed[20204] (Microsoft.EntityFrameworkCore.Database.Transaction)
      Disposing transaction.
dbug: 18. 08. 2022 13:49:14.846 CoreEventId.StateChanged[10807] (Microsoft.EntityFrameworkCore.ChangeTracking)
      An entity of type 'TestModel' tracked by 'TestDbContext' changed state from 'Added' to 'Unchanged'. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see key values.
dbug: 18. 08. 2022 13:49:14.847 CoreEventId.SaveChangesCompleted[10005] (Microsoft.EntityFrameworkCore.Update)
      SaveChanges completed for 'TestDbContext' with 1 entities written to the database.
dbug: 18. 08. 2022 13:49:54.918 CoreEventId.ValueGenerated[10808] (Microsoft.EntityFrameworkCore.ChangeTracking)
      'TestDbContext' generated a temporary value for the property 'DrawId.TestModel'. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see key values.
dbug: 18. 08. 2022 13:49:54.925 CoreEventId.StartedTracking[10806] (Microsoft.EntityFrameworkCore.ChangeTracking)
      Context 'TestDbContext' started tracking 'TestModel' entity. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see key values.
dbug: 18. 08. 2022 13:49:54.927 CoreEventId.SaveChangesStarting[10004] (Microsoft.EntityFrameworkCore.Update)
      SaveChanges starting for 'TestDbContext'.
dbug: 18. 08. 2022 13:49:54.928 CoreEventId.DetectChangesStarting[10800] (Microsoft.EntityFrameworkCore.ChangeTracking)
      DetectChanges starting for 'TestDbContext'.
dbug: 18. 08. 2022 13:49:54.930 CoreEventId.DetectChangesCompleted[10801] (Microsoft.EntityFrameworkCore.ChangeTracking)
      DetectChanges completed for 'TestDbContext'.
dbug: 18. 08. 2022 13:49:54.931 RelationalEventId.ConnectionOpening[20000] (Microsoft.EntityFrameworkCore.Database.Connection)
      Opening connection to database 'main' on server 'TestDatabase.db'.
dbug: 18. 08. 2022 13:49:54.931 RelationalEventId.ConnectionOpened[20001] (Microsoft.EntityFrameworkCore.Database.Connection)
      Opened connection to database 'main' on server 'P:\C#Projects\EFCoreEncryptionTest\bin\Debug\net6.0\TestDatabase.db'.
dbug: 18. 08. 2022 13:49:54.932 RelationalEventId.TransactionStarting[20209] (Microsoft.EntityFrameworkCore.Database.Transaction)
      Beginning transaction with isolation level 'Unspecified'.
dbug: 18. 08. 2022 13:49:54.932 RelationalEventId.TransactionStarted[20200] (Microsoft.EntityFrameworkCore.Database.Transaction)
      Began transaction with isolation level 'Serializable'.
dbug: 18. 08. 2022 13:49:54.933 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command)
      Creating DbCommand for 'ExecuteReader'.
dbug: 18. 08. 2022 13:49:54.934 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command)
      Created DbCommand for 'ExecuteReader' (0ms).
dbug: 18. 08. 2022 13:49:54.935 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command)
      Executing DbCommand [Parameters=[@p0='?'], CommandType='Text', CommandTimeout='30']
      INSERT INTO "TestModel" ("ChangeUser")
      VALUES (@p0);
      SELECT "DrawId", "ChangeDate"
      FROM "TestModel"
      WHERE changes() = 1 AND "rowid" = last_insert_rowid();
info: 18. 08. 2022 13:49:54.936 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
      Executed DbCommand (2ms) [Parameters=[@p0='?'], CommandType='Text', CommandTimeout='30']
      INSERT INTO "TestModel" ("ChangeUser")
      VALUES (@p0);
      SELECT "DrawId", "ChangeDate"
      FROM "TestModel"
      WHERE changes() = 1 AND "rowid" = last_insert_rowid();
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (2ms) [Parameters=[@p0='?'], CommandType='Text', CommandTimeout='30']
      INSERT INTO "TestModel" ("ChangeUser")
      VALUES (@p0);
      SELECT "DrawId", "ChangeDate"
      FROM "TestModel"
      WHERE changes() = 1 AND "rowid" = last_insert_rowid();
dbug: 18. 08. 2022 13:49:54.940 CoreEventId.ForeignKeyChangeDetected[10803] (Microsoft.EntityFrameworkCore.ChangeTracking)
      The foreign key property 'TestModel.DrawId' was detected as changed. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see property values.
dbug: 18. 08. 2022 13:49:54.951 RelationalEventId.DataReaderDisposing[20300] (Microsoft.EntityFrameworkCore.Database.Command)
      A data reader was disposed.
- dbug: 18. 08. 2022 13:49:54.952 RelationalEventId.TransactionCommitting[20210] - -(Microsoft.EntityFrameworkCore.Database.Transaction)
      Committing transaction.
- dbug: 18. 08. 2022 13:49:55.457 RelationalEventId.TransactionCommitted[20202] (Microsoft.EntityFrameworkCore.Database.Transaction)
      Committed transaction.
dbug: 18. 08. 2022 13:49:55.457 RelationalEventId.ConnectionClosing[20002] (Microsoft.EntityFrameworkCore.Database.Connection)
      Closing connection to database 'main' on server 'P:\C#Projects\EFCoreEncryptionTest\bin\Debug\net6.0\TestDatabase.db'.
dbug: 18. 08. 2022 13:49:55.459 RelationalEventId.ConnectionClosed[20003] (Microsoft.EntityFrameworkCore.Database.Connection)
      Closed connection to database 'main' on server 'TestDatabase.db'.
dbug: 18. 08. 2022 13:49:55.463 RelationalEventId.TransactionDisposed[20204] (Microsoft.EntityFrameworkCore.Database.Transaction)
      Disposing transaction.
dbug: 18. 08. 2022 13:49:55.463 CoreEventId.StateChanged[10807] (Microsoft.EntityFrameworkCore.ChangeTracking)
      An entity of type 'TestModel' tracked by 'TestDbContext' changed state from 'Added' to 'Unchanged'. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see key values.
dbug: 18. 08. 2022 13:49:55.465 CoreEventId.SaveChangesCompleted[10005] (Microsoft.EntityFrameworkCore.Update)
      SaveChanges completed for 'TestDbContext' with 1 entities written to the database.

P:\C#Projects\EFCoreEncryptionTest\bin\Debug\net6.0\EFCoreEncryptionTest.exe (process 49672) exited with code -1.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.

Press any key to close this window . . .

Include provider and version information

Include provider and version information
EF Core version: 6.0
Database provider: Microsoft.EntityFrameworkCore.Sqlite.Core 6.0.8 and SQLitePCLRaw.bundle_e_sqlcipher 2.1.0
Target framework: NET Core 6.0
Operating system: Windows 10
IDE: Visual Studio 2022

Simple test project
EFCoreEncryptionTest.zip

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions