I need to know the list of tables on which there are locks currently

淺唱寂寞╮ 提交于 2019-12-11 04:27:13

问题


select 
  A.table_id, 
  last_update, 
  last_commit, 
  lock_owner_pid, 
  lock_status,
  B.table
from stv_locks as A left outer join svv_table_info as B on A.table_id = B.table_id
order by last_update asc

I used the query above, but am getting null in a name for some table_ids. what are these?


回答1:


select distinct(id) table_id
,trim(datname)   db_name
,trim(nspname)   schema_name
,trim(relname)   table_name
from stv_locks
join stv_tbl_perm on stv_locks.table_id = stv_tbl_perm.id
join pg_class on pg_class.oid = stv_tbl_perm.id
join pg_namespace on pg_namespace.oid = relnamespace
join pg_database on pg_database.oid = stv_tbl_perm.db_id;


This should work. You can add other columns based on your use case!
If I’ve made a bad assumption please comment and I’ll refocus my answer.



来源:https://stackoverflow.com/questions/42730718/i-need-to-know-the-list-of-tables-on-which-there-are-locks-currently

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!