SQL 服务器数据库引擎的实例此时无法获取 LOCK 资源,无法释放更多资源
The instance of the SQL Server Database Engine cannot obtain a LOCK resource at this time, cannot free up more resiources
我正在尝试 运行 一个存储过程。在 SP 中,我创建了两个 table 变量(通过使用 3 个 CTE)。然后加入两个 table 并插入一个现有的 table。我一直收到错误无法获得锁定资源。有什么办法可以解决这个问题吗?这是我写SP的方式吗?
ALTER PROCEDURE [dbo].[CreateDailyAttribution]
-- Add the parameters for the stored procedure here
@day1 varchar(10)
,@day2 varchar(10)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @tableUnrealized as table
(
POFFIC varchar(3)
,PACCT varchar(5)
--,PATYPE varchar(3)
,PSDSC1 varchar(100)
,ShortDesc varchar(100)
,ChangeInOTE decimal(18,0)
,tMinus1_Qty integer
,tMinus2_Qty integer
,Sector varchar(50)
);
DECLARE @tableRealized as table
(
POFFIC varchar(3)
,PACCT varchar(5)
--,PATYPE varchar(3)
,PSDSC1 varchar(100)
,ShortDesc varchar(100)
,Realized decimal(18,0)
,Sector varchar(50)
);
您收到的错误表明服务器没有足够的内存,可能是因为没有足够的物理内存可用,没有足够的内存可供服务器使用,或者其他进程使用了太多内存SQL 没有足够的喘息空间。
您的查询看起来可能会使用大量内存 - 可能会对其进行调整(一件简单的事情可能是使用 #temp tables 而不是 @table 变量和看看这是否减轻了一些内存压力(#temp tables 将进入 tempdb 并命中磁盘,而 table 变量可能存储在内存中)。虽然不了解更多信息,但真的很难说您的数据和对查询的更深入分析。
MSDN 对此错误有一些额外的建议:
Explanation
SQL Server cannot obtain a lock resource. This can be caused by either of the following reasons:
- SQL Server cannot allocate more memory from the operating system, either because other processes are using it, or because the server is operating with the max server memory option configured.
- The lock manager will not use more than 60 percent of the memory available to SQL Server.
User Action
If you suspect that SQL Server cannot allocate sufficient memory, try the following:
- If applications besides SQL Server are consuming resources, try stopping these applications or consider running them on a separate server. This will remove release memory from other processes for SQL Server.
- If you have configured max server memory, increase max server memory setting.
If you suspect that the lock manager has used the maximum amount of available memory identify the transaction that is holding the most locks and terminate it.
The following script will identify the transaction with the most locks:
SELECT request_session_id, COUNT (*) num_locks
FROM sys.dm_tran_locks
GROUP BY request_session_id
ORDER BY count (*) DESC
Take the highest session id, and terminate it using the KILL command.
我正在尝试 运行 一个存储过程。在 SP 中,我创建了两个 table 变量(通过使用 3 个 CTE)。然后加入两个 table 并插入一个现有的 table。我一直收到错误无法获得锁定资源。有什么办法可以解决这个问题吗?这是我写SP的方式吗?
ALTER PROCEDURE [dbo].[CreateDailyAttribution]
-- Add the parameters for the stored procedure here
@day1 varchar(10)
,@day2 varchar(10)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @tableUnrealized as table
(
POFFIC varchar(3)
,PACCT varchar(5)
--,PATYPE varchar(3)
,PSDSC1 varchar(100)
,ShortDesc varchar(100)
,ChangeInOTE decimal(18,0)
,tMinus1_Qty integer
,tMinus2_Qty integer
,Sector varchar(50)
);
DECLARE @tableRealized as table
(
POFFIC varchar(3)
,PACCT varchar(5)
--,PATYPE varchar(3)
,PSDSC1 varchar(100)
,ShortDesc varchar(100)
,Realized decimal(18,0)
,Sector varchar(50)
);
您收到的错误表明服务器没有足够的内存,可能是因为没有足够的物理内存可用,没有足够的内存可供服务器使用,或者其他进程使用了太多内存SQL 没有足够的喘息空间。
您的查询看起来可能会使用大量内存 - 可能会对其进行调整(一件简单的事情可能是使用 #temp tables 而不是 @table 变量和看看这是否减轻了一些内存压力(#temp tables 将进入 tempdb 并命中磁盘,而 table 变量可能存储在内存中)。虽然不了解更多信息,但真的很难说您的数据和对查询的更深入分析。
MSDN 对此错误有一些额外的建议:
Explanation
SQL Server cannot obtain a lock resource. This can be caused by either of the following reasons:
- SQL Server cannot allocate more memory from the operating system, either because other processes are using it, or because the server is operating with the max server memory option configured.
- The lock manager will not use more than 60 percent of the memory available to SQL Server.
User Action
If you suspect that SQL Server cannot allocate sufficient memory, try the following:
- If applications besides SQL Server are consuming resources, try stopping these applications or consider running them on a separate server. This will remove release memory from other processes for SQL Server.
- If you have configured max server memory, increase max server memory setting.
If you suspect that the lock manager has used the maximum amount of available memory identify the transaction that is holding the most locks and terminate it.
The following script will identify the transaction with the most locks:
SELECT request_session_id, COUNT (*) num_locks
FROM sys.dm_tran_locks
GROUP BY request_session_id
ORDER BY count (*) DESC
Take the highest session id, and terminate it using the KILL command.