Fixed pgAdmin freezing issue by providing the error message for the operation

that can't perform due to lock on the particular table. Fixes #5427
This commit is contained in:
Pradip Parkale 2021-10-27 10:51:52 +05:30 committed by Akshay Joshi
parent 711ea3bfa1
commit 35b1e1d0d2
7 changed files with 83 additions and 1 deletions

View File

@ -18,6 +18,7 @@ Housekeeping
Bug fixes
*********
| `Issue #5427 <https://redmine.postgresql.org/issues/5427>`_ - Fixed pgAdmin freezing issue by providing the error message for the operation that can't perform due to lock on the particular table.
| `Issue #6780 <https://redmine.postgresql.org/issues/6780>`_ - Ensure that columns should be merged if the newly added column is present in the parent table.
| `Issue #6859 <https://redmine.postgresql.org/issues/6859>`_ - Fixed an issue where properties panel is not updated when any object is added from the browser tree.
| `Issue #6949 <https://redmine.postgresql.org/issues/6949>`_ - Ensure that dialog should be opened when clicking on Reassign/Drop owned menu.

View File

@ -1070,6 +1070,10 @@ class TableView(BaseTableView, DataTypeReader, SchemaDiffTableCompare):
)
)
lock_on_table = self.get_table_locks(did, res['rows'][0])
if lock_on_table != '':
return lock_on_table
status, res = super(TableView, self).delete(gid, sid, did,
scid, tid, res)

View File

@ -205,6 +205,9 @@ define('pgadmin.node.table', [
t.select(i);
}, 10);
}
if (res.success == 2) {
Alertify.error(res.info, 0);
}
})
.fail(function(xhr, status, error) {
Alertify.pgRespErrorNotify(xhr, error);

View File

@ -0,0 +1,8 @@
SELECT
usename,
application_name
FROM
pg_catalog.pg_stat_activity
WHERE
pid = {{ pid }}
ORDER BY pid

View File

@ -0,0 +1,23 @@
SELECT
pid,
locktype,
datname,
relation::regclass,
page,
tuple,
virtualxid
transactionid,
classid::regclass,
objid,
objsubid,
virtualtransaction,
mode,
granted,
fastpath
FROM
pg_catalog.pg_locks l
LEFT OUTER JOIN pg_catalog.pg_database d ON (l.database = d.oid)
{% if did %}WHERE
datname = (SELECT datname FROM pg_catalog.pg_database WHERE oid = {{ did }}){% endif %}
ORDER BY
pid, locktype

View File

@ -49,6 +49,7 @@ from pgadmin.utils.preferences import Preferences
from pgadmin.browser.server_groups.servers.databases.schemas.utils \
import VacuumSettings
from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry
from pgadmin.dashboard import locks
class BaseTableView(PGChildNodeView, BasePartitionTable, VacuumSettings):
@ -1952,6 +1953,10 @@ class BaseTableView(PGChildNodeView, BasePartitionTable, VacuumSettings):
data = res['rows'][0]
lock_on_table = self.get_table_locks(did, data)
if lock_on_table != '':
return lock_on_table
sql = render_template("/".join([self.table_template_path,
'truncate.sql']),
data=data, cascade=is_cascade,
@ -2004,6 +2009,41 @@ class BaseTableView(PGChildNodeView, BasePartitionTable, VacuumSettings):
'scid': scid
}
def get_table_locks(self, did, data):
"""
This function returns the lock details if there is any on table
:param did:
:param data:
:return:
"""
sql = render_template(
"/".join([self.table_template_path, 'locks.sql']), did=did
)
status, lock_table_result = self.conn.execute_dict(sql)
for row in lock_table_result['rows']:
if row['relation'].strip('\"') == data['name']:
sql = render_template(
"/".join([self.table_template_path,
'get_application_name.sql']), pid=row['pid']
)
status, res = self.conn.execute_dict(sql)
application_name = res['rows'][0]['application_name']
return make_json_response(
success=2,
info=gettext(
"The table is currently locked and the "
"operation cannot be completed. "
"Please try again later. "
"\r\nBlocking Process ID : {0} "
"Application Name : {1}").format(row['pid'],
application_name)
)
return ''
def get_schema_and_table_name(self, tid):
"""
This function will fetch the schema qualified name of the

View File

@ -838,6 +838,10 @@ define('pgadmin.browser.node', [
type: 'DELETE',
})
.done(function(res) {
if(res.success == 2){
Alertify.error(res.info, 0);
return;
}
if (res.success == 0) {
pgBrowser.report_error(res.errormsg, res.info);
} else {
@ -867,7 +871,6 @@ define('pgadmin.browser.node', [
}
pgBrowser.report_error(
gettext('Error dropping/removing %s: "%s"', obj.label, objName), errmsg);
});
},
null