I need to know the list of tables on which there a

2019-07-30 13:39发布

问题:

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.