Table Locks
Hi,
Is there a way to explicitly lock a table in Vertica before writing to it? The intent is to limit the write to one session at a time. I know about select for update, but what if the record does not even exist..
Also if you can explain how Serializable isloation level affects other sessions if at all it does (which I believe it does not) and what is the real use of it.
Thanks
Is there a way to explicitly lock a table in Vertica before writing to it? The intent is to limit the write to one session at a time. I know about select for update, but what if the record does not even exist..
Also if you can explain how Serializable isloation level affects other sessions if at all it does (which I believe it does not) and what is the real use of it.
Thanks
0
Comments
For explicitly lock you can run LOCK TABLE <table_name> on your session no one else on other session will be ab write to this table until to explicitly run commit or rollback .
Serializable will provide your constant view for all the duration of the transaction , for example , if during the transaction you access several time to the same table record , it promise you that you always see the same data .
Other session will not be able to update the table that you access .
Had to post this as I could not find Lock Table thing in the documentation (Sql ref and programming manual).
EDIT:: I tested it in another Database and it seems to be working fine. Any idea what will lead to this difference in the behaviour ?
This is not normal behave , the normal behave is that once you able to take an exclusive lock on a table on the session you are the owner of it . The only option is see it is that you have some kind of auto commit on the session which release your lock and someone else on other session take it , so you become lock .
## DB 1 Session 1::
Lock Table myschema.mytable;
Lock Table
Insert into myschema.mytable values (1, 'ABC') ;
<Session goes into wait.... >
## DB 1 Session 2::
Insert into myschema.mytable values (1, 'ABC') ;
<Session goes into wait.... >
## Back in DB 1 Session 1::
(still waiting..... )
ctrl + C ++++++++++++ +++++++++++ +++++++++ ++++++++
## DB 2 : Session 1
Lock Table myschema.mytable;
Lock Table
Insert into myschema.mytable values (1, 'ABC') ;
OUTPUT
--------
1
<Data inserted .. no problem>
## DB 2 : Session 2
Insert into myschema.mytable values (1, 'ABC') ;
<goes into wait>
-----------------------------
So having said that, this amazes me why DB1 shows a different behaviour, is there a system property or something that I can check ?
Please run you test after you have at list 1 records on your table
Will creating a projection explicitly help ?
Let's say I am creating the table for first time and have to lock it before any row gets into it, to ensure sequential inserts; how can this be achieved then.
One way would be to have a dummy row in there and other which I am not sure if is correct, will be to create a projection. Is that right ?