locking database table while deleting records - understanding "Read Committed" transaction isolation in postgresql -


i have web app provide feature delete widget belong user. logic have right delete looks this:

local delete_widget = function(widgetid, user)    local retval = ""                 sql = "delete widgets widgetid="..widgetid          cur, err = assert(con:execute(sql))          if not err                sql = "select * widgets widgetid = ".. widgetid                listofwidgets = executesqlandreturntable(sql)                if #listofwidgets == 0                     retval = "deleted widget"                else                     retval = "unable delete widget"                end          else                retval = "unable delete widget"          end     return retval end 

what i'm wondering if should change transaction. right now, if deletion attempt fails whatever reason, i'm not doing anything. select see if still exists , if does, throw error.

i'm wondering if should full begin transaction/commit / rollback if select statement finds widget still exists, rollback delete sql statement.

but have following questions:

  1. how use pgadmin3 check current value transaction isolation level?

  2. if leave default - according i've read "read committed" - lock widgets table while i'm finished both delete , select commands, correct? mean no 1 else can select widgets table until transaction complete, right? doesn't sound thing, given have hundreds of users.

any comments / suggestions appreciated.

  1. don't know.
  2. modern databases allow acquire locks on row levels, without locking entire tables, highly inneficient. in instance, row level locks acquired until transaction complete. means other users able select table, rows not locked transaction.

i don't know why issue select after delete row. delete should either successful or query return error (due lock time out, example). there's no need check again.

so in instance starting transaction not necessary, delete acquires write lock on row implicitly. unless autocommit turned off, you'd have commit anyway.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -