diff --git a/docs/en_US/release_notes_6_2.rst b/docs/en_US/release_notes_6_2.rst index 99ed9aef1..783f924cc 100644 --- a/docs/en_US/release_notes_6_2.rst +++ b/docs/en_US/release_notes_6_2.rst @@ -18,6 +18,7 @@ Housekeeping Bug fixes ********* +| `Issue #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 `_ - Ensure that columns should be merged if the newly added column is present in the parent table. | `Issue #6859 `_ - Fixed an issue where properties panel is not updated when any object is added from the browser tree. | `Issue #6949 `_ - Ensure that dialog should be opened when clicking on Reassign/Drop owned menu. diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py index 2891d2181..cecd7ad27 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py @@ -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) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.js index 60621c21f..33d46b162 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.js @@ -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); diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/default/get_application_name.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/default/get_application_name.sql new file mode 100644 index 000000000..7f97337e1 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/default/get_application_name.sql @@ -0,0 +1,8 @@ +SELECT + usename, + application_name +FROM + pg_catalog.pg_stat_activity +WHERE + pid = {{ pid }} +ORDER BY pid diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/default/locks.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/default/locks.sql new file mode 100644 index 000000000..b74f59ebd --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/default/locks.sql @@ -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 diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py index 9f370a951..aca27fd00 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py @@ -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 diff --git a/web/pgadmin/browser/static/js/node.js b/web/pgadmin/browser/static/js/node.js index bd094dcfa..d9f887a39 100644 --- a/web/pgadmin/browser/static/js/node.js +++ b/web/pgadmin/browser/static/js/node.js @@ -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