Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

SQL Server Error 1238: Fix Lock Partition Issue

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

SQL Server error 1238 (“Could not extend all lock partitions”) means the instance has run out of lock memory because the lock manager cannot grow its lock partition structures. The fix is to reduce lock pressure, give SQL Server more memory, or increase the lock memory limit, then restart the service so the lock manager rebuilds cleanly. Start by checking the error log and current memory settings, then work through the steps below.

What You'll Need

  • Administrative access to the SQL Server instance (sysadmin or equivalent).
  • Permission to restart the SQL Server service (Windows service console or SQL Server Configuration Manager).
  • A maintenance window, because some fixes require a service restart.
  • Access to the SQL Server error log and Windows Event Viewer.
  • Optional: a monitoring tool or query to check memory usage and lock counts before and after changes.

Step-by-Step

  1. Confirm the error and capture context. Open SQL Server Management Studio (SSMS), connect to the instance, and run EXEC sp_readerrorlog; to view the current error log. Look for messages around the time of the failure: error 1238, memory-related warnings (e.g., “memory pressure”), or lock escalation notices. Also check Windows Event Viewer > Windows Logs > Application for corresponding entries. Note the database, query, or job that was running when the error occurred.
  2. Check available memory and SQL Server’s memory configuration. In SSMS, run EXEC sp_configure 'max server memory (MB)'; and EXEC sp_configure 'min server memory (MB)';. If max server memory is set too low or left at the default (which can be very high on large servers), adjust it. A common starting point is to leave 4–8 GB for the operating system, then set max server memory to the remainder. For example, on a 32 GB server, set max server memory to 24–28 GB. Use EXEC sp_configure 'max server memory (MB)', 24576; RECONFIGURE; (adjust the number to your server).
  3. Reduce lock pressure from queries. Identify long-running transactions and queries that take many row or page locks. Use Activity Monitor in SSMS or query sys.dm_tran_locks and sys.dm_exec_requests to find blocking and high lock counts. Rewrite large batch operations to commit in smaller chunks, add appropriate indexes to reduce scan locks, and consider enabling READ_COMMITTED_SNAPSHOT for the database if your application can tolerate it (this changes locking behavior; test first). Avoid unnecessary table hints like HOLDLOCK or TABLOCK in application code.
  4. Increase the lock memory limit if needed. SQL Server has an internal limit on lock memory. You can raise it with the startup parameter -T1232 (trace flag) or by adjusting the “locks” configuration option if available in your version. The safer, supported approach is to increase available memory and reduce lock usage first. If you must use a trace flag, add it via SQL Server Configuration Manager > SQL Server Services > right-click the instance > Properties > Startup Parameters, then restart the service. Document the change.
  5. Restart the SQL Server service. After changing memory settings or startup parameters, restart the SQL Server service (SQL Server Configuration Manager > SQL Server Services > right-click SQL Server (MSSQLSERVER) > Restart). This clears the lock manager state and applies the new settings. Plan for downtime.
  6. Verify the fix. Reconnect and run a representative workload or the query that previously failed. Monitor the error log and sys.dm_os_ring_buffers for memory pressure. Check that error 1238 no longer appears. Keep an eye on lock counts and memory usage for a few days.

Common Mistakes

  • Setting max server memory too low, which starves the buffer pool and can cause other memory errors.
  • Ignoring the operating system’s memory needs; SQL Server will happily consume all available memory if not capped.
  • Using trace flag 1232 without understanding the implications; it can mask underlying memory pressure.
  • Restarting the service without a maintenance window, causing unexpected downtime.
  • Overlooking application-level causes such as long transactions or missing indexes.

Tips

  • Use the “Lock Pages in Memory” privilege only after consulting Microsoft guidance; it can help with memory pressure but is not a cure-all.
  • Regularly review the error log for memory-related warnings before they become errors.
  • Consider using Resource Governor to limit memory for less critical workloads.
  • Keep statistics and indexes maintained to reduce lock escalation.
  • Test configuration changes on a non-production instance first.

Troubleshooting

If error 1238 persists after the steps above, check for memory leaks or third-party components. Run DBCC MEMORYSTATUS; to see detailed memory usage. Look for large numbers of locks held by a single session; use sys.dm_tran_locks grouped by request_session_id. If a specific query is the culprit, examine its execution plan for table scans or missing indexes. If the server is virtualized, ensure the host has enough memory and that dynamic memory is not starving the VM. In extreme cases, consider increasing the server’s physical memory or moving to a larger instance. If you are unsure about trace flags, consult Microsoft support or a qualified DBA.

Frequently Asked Questions

What causes SQL Server error 1238?

It occurs when SQL Server cannot allocate more memory for lock structures, usually due to memory pressure, a low max server memory setting, or excessive locking from queries.

Can I fix it without restarting SQL Server?

Sometimes reducing lock pressure or increasing max server memory and running RECONFIGURE helps, but a restart is often needed to fully reset the lock manager.

Is trace flag 1232 safe to use?

It increases the lock memory limit but can mask underlying issues. Use it only as a temporary measure and with guidance from Microsoft or an experienced DBA.

How do I monitor lock memory usage?

Query sys.dm_os_performance_counters for “Lock Memory (KB)” and “Lock Blocks” counters, and check the error log for memory warnings.

Will increasing max server memory always fix error 1238?

Not always. If the workload generates excessive locks, you also need to optimize queries and transactions to reduce lock pressure.

Does this error affect all databases on the instance?

Yes, because lock memory is instance-wide. A single heavy query can impact all databases on that SQL Server instance.