单个SQL Server表上的死锁(deadlock on a single SQL Server table)
我正在使用SQL Server 2008 Enterprise。 并使用ADO.Net + C#+。Net 3.5 + ASP.Net作为客户端访问数据库。 当我访问SQL Server 2008表时,我总是从我的C#+ ADO.Net代码调用存储过程。
我在表FooTable上有3个操作。 并且多个连接将按顺序同时执行它们,即执行delete,execute insert然后执行select。 每个语句(删除/插入/选择)都是单存储过程中的单独的单个事务。
我的问题是删除语句是否可能发生死锁? 我的猜测是,如果多个连接在相同的Param1值上运行,是否可能发生死锁?
BTW:对于下面的语句,Param1是表FooTable的列,Param1是另一个表的外键(指另一个表的另一个主键聚簇索引列)。 对于表FooTable,Param1本身没有索引。 FooTable有另一列用作聚簇主键,但不是Param1列。
create PROCEDURE [dbo].[FooProc] ( @Param1 int ,@Param2 int ,@Param3 int ) AS DELETE FooTable WHERE Param1 = @Param1 INSERT INTO FooTable ( Param1 ,Param2 ,Param3 ) VALUES ( @Param1 ,@Param2 ,@Param3 ) DECLARE @ID bigint SET @ID = ISNULL(@@Identity,-1) IF @ID > 0 BEGIN SELECT IdentityStr FROM FooTable WHERE ID = @ID END
以下是活动监视器表的外观,
ProcessID System Process Login Database Status Opened transaction Command Application Wait Time Wait Type CPU 52 No Foo suspended 0 DELETE .Net SqlClient Data Provider 4882 LCK_M_U 0 53 No George Foo suspended 2 DELETE .Net SqlClient Data Provider 12332 LCK_M_U 0 54 No George Foo suspended 2 DELETE .Net SqlClient Data Provider 6505 LCK_M_U 0 (a lot of rows like the row for process ID 54)
I am using SQL Server 2008 Enterprise. And using ADO.Net + C# + .Net 3.5 + ASP.Net as client to access database. When I access SQL Server 2008 tables, I always invoke stored procedure from my C# + ADO.Net code.
I have 3 operations on table FooTable. And Multiple connections will execute them at the same time in sequences, i.e. executes delete, the execute insert and then execute select. Each statement (delete/insert/select) is of a separate individual transaction in the single store procedure.
My question is whether it is possible that deadlock will occur on delete statement? My guess is whether it is possible that deadlock occurs if multiple connections are operating on the same Param1 value?
BTW: For the statements below, Param1 is a column of table FooTable, Param1 is a foreign key of another table (refers to another primary key clustered index column of the other table). There is no index on Param1 itself for table FooTable. FooTable has another column which is used as clustered primary key, but not Param1 column.
create PROCEDURE [dbo].[FooProc] ( @Param1 int ,@Param2 int ,@Param3 int ) AS DELETE FooTable WHERE Param1 = @Param1 INSERT INTO FooTable ( Param1 ,Param2 ,Param3 ) VALUES ( @Param1 ,@Param2 ,@Param3 ) DECLARE @ID bigint SET @ID = ISNULL(@@Identity,-1) IF @ID > 0 BEGIN SELECT IdentityStr FROM FooTable WHERE ID = @ID END
Here is what the activity monitor table looks like,
ProcessID System Process Login Database Status Opened transaction Command Application Wait Time Wait Type CPU 52 No Foo suspended 0 DELETE .Net SqlClient Data Provider 4882 LCK_M_U 0 53 No George Foo suspended 2 DELETE .Net SqlClient Data Provider 12332 LCK_M_U 0 54 No George Foo suspended 2 DELETE .Net SqlClient Data Provider 6505 LCK_M_U 0 (a lot of rows like the row for process ID 54)
原文:https://stackoverflow.com/questions/3075885
最满意答案
对于任何可能不知道如何的人。
response = client.add_permission( FunctionName='<YOUR_FUNCTION_NAME>', StatementId='AlexaFunctionPermission', Action='lambda:InvokeFunction', Principal='alexa-appkit.amazon.com',)
For anyone who may not know how.
response = client.add_permission( FunctionName='<YOUR_FUNCTION_NAME>', StatementId='AlexaFunctionPermission', Action='lambda:InvokeFunction', Principal='alexa-appkit.amazon.com',)
相关问答
更多-
AWS:通过boto3(Python2)发布Lambda函数的SNS消息(AWS: Publish SNS message for Lambda function via boto3 (Python2))[2023-08-08]
您需要将default密钥添加到您的消息负载中,并指定MessageStructure : import json import boto3 message = {"foo": "bar"} client = boto3.client('sns') response = client.publish( TargetArn=arn, Message=json.dumps({'default': json.dumps(message)}), MessageStructure='json ... -
这是我通过python导入SNS的方法: import boto sns = boto.connect_sns() 要么 import boto3 client = boto3.client('sns') This is how I import SNS via python: import boto sns = boto.connect_sns() OR import boto3 client = boto3.client('sns')
-
最近有一个定制化进入了Boto3,这有助于(除其他外)。 它目前在低级别的S3客户端上公开,可以这样使用: s3_client = boto3.client('s3') open('hello.txt').write('Hello, world!') # Upload the file to S3 s3_client.upload_file('hello.txt', 'MyBucket', 'hello-remote.txt') # Download the file from S3 s3_client ...
-
有没有办法通过AWS Lambda修改EBS卷?(Is there a way to modify an EBS volume through AWS Lambda ? (Boto3))[2022-05-15]
boto3 AWS SDK for Python有一个modify_volume()函数 ,可以修改卷大小,卷类型和IOPS容量: response = client.modify_volume( DryRun=True|False, VolumeId='string', Size=123, VolumeType='standard'|'io1'|'gp2'|'sc1'|'st1', Iops=123 ) 这可以从用Python编写的AWS Lambda函数调用。 ... -
函数ec2.snapshots.all不会迭代boto3 lambda(Function ec2.snapshots.all not iterate boto3 lambda)[2022-03-20]
我怀疑它列出了所有公开可用的快照,这可能相当多。 最好将其限制为您所有者的快照。 describe-snapshots()函数带有一个可以缩小返回值的OwnerIds参数。 下面是一个来自boto3快照文档的示例,演示了如何在snapshots迭代器上使用过滤器: snapshot_iterator = ec2.snapshots.filter( DryRun=True|False, SnapshotIds=[ 'string', ], OwnerIds=[ ... -
对于任何可能不知道如何的人。 response = client.add_permission( FunctionName='
', StatementId='AlexaFunctionPermission', Action='lambda:InvokeFunction', Principal='alexa-appkit.amazon.com',) For anyone who may not know how. response = ... -
根据CopySnapshot - Amazon Elastic Compute Cloud : CopySnapshot将快照副本发送到您发送HTTP请求到的区域端点 ,例如ec2.us-east-1.amazonaws.com (在AWS CLI中,这是通过--region参数或默认区域您的AWS配置文件)。 因此,应该将copy_snapshot()命令发送到us-east-1 ,并将Source Region设置为us-east-2 。 如果你想移动最近的快照,你可以运行: import boto3 ...
-
没有称为root的 IAM用户。 根用户实际上与AWS账户相关联。 它完全独立于IAM,它允许创建个人用户。 您不能禁用与root用户关联的访问密钥,但可以从根用户中删除访问密钥 。 delete-access-key文档不太清楚,但它确实引用了能够通过API调用删除密钥。 如果我正确读取它, 则可以删除根键 - 但只能以root用户身份调用该函数 。 这在Lambda函数中是不可能的。 最好的行动方案可能是通过管理控制台删除根密钥 ,然后尝试找到一种方法来监控它(但我怀疑没有可以提供此信息的调用)。 幸运 ...
-
默认情况下,仅描述正在运行的实例,除非另有说明。 实例可能需要几分钟才能进入运行状态。 您的程序将永远不会睡眠,因为它在前一步骤中失败,其中状态实际上未在第一次迭代中返回。 使用“IncludeAllInstances”这是一个布尔请求参数,当为true时,包括所有实例的运行状况。 如果为false,则仅包括运行实例的运行状况。 默认值为false By default, only running instances are described, unless specified otherwise. It ...
-
您假设所有实例都至少有一个标记。 在您的情况下,有些实例没有标记导致您的代码失败。 相反,您可以在迭代tags之前检查标记是否存在。 for instance in instances: if instance.tags: for tag in instance.tags: 上面的代码将忽略没有定义标记的实例。 您可以修改代码以满足您的需求。 要验证这一点,您还可以在打印instance-id和instance-type时打印标记。 for instance in instances: p ...