Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

I have a simple table that is pretty much static in our application in that the application does not directly write or update any records in it. I want to modify the size of a field to this table but I get an error stating "User DBA has the row in table billing locked". When I look at the locks in the DB, there is a lock showing on this table. The lock is a Shared Schema lock with a Lock duration of Transaction. My question is - why would this lock appear on this table if I never issue and UPDATE or INSERT? I do have some code that will query this table but I close the cursor. I don't see why I would need to issue a COMMIT on a read cursor. Is there anyway around this or am I doing something wrong. Using SQL ANYWHERE 12 (12.0.1.3773). Any help is greatly appreciated !!!!

asked 18 Mar '15, 09:21

barry123's gravatar image

barry123
181458
accept rate: 0%


Operations like ALTER TABLE need absolute, complete, exclusive access to the table. Operations like SELECT obtain a schema lock on the table that prevent other connections from gaining exclusive locks... in this case, to prevent the other connection from messing up the schema while this connection is working with the table... hence the name "schema lock".

This is standard behavior for SQL Anywhere, and you solve it by issuing a COMMIT on the connection that did the SELECT... or in the case of Sybase Central, which is the biggest offender for holding schema locks on everything in sight, you just shut it down while doing your ALTER.

Another approach (sometimes used in production environments) is to let the ALTER TABLE sit there blocked until all other connections let go (perhaps overnight). In this case the ALTER TABLE connection has to set the blocking option to ON. That's the default: sit and wait, rather than raise the exception you saw, which leads me to believe you saw that message in Sybase Central which (I think) sets blocking to OFF so it will immediately choke when faced with a lock that blocks it from proceeding. In a production environment, you typically want blocking set on (the default) so that application connections will wait momentarily while other connections quickly update and commit stuff, rather than have connections failing all over the place when users collide.

permanent link

answered 18 Mar '15, 09:44

Breck%20Carter's gravatar image

Breck Carter
32.5k5417261050
accept rate: 20%

edited 18 Mar '15, 09:45

2

Just to add:

I don't see why I would need to issue a COMMIT on a read cursor.

Besides schema locks, there may be further reasons to commit read operations soon, depending on the chosen isolation level - e.g. with isolation level 2 or 3, even closed cursors leave read locks open until the transaction completes...

(18 Mar '15, 10:13) Volker Barth
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×21

question asked: 18 Mar '15, 09:21

question was seen: 2,494 times

last updated: 18 Mar '15, 10:13