public inbox for [email protected]
help / color / mirror / Atom feedFrom: Pradip Parkale <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin][RM5427]: pgAdmin is freezing
Date: Wed, 27 Oct 2021 10:10:13 +0530
Message-ID: <CAJ9T6Su5Eqt+gVxvwiYYHm0ANpJERduW1gr3eyY6NdKvUAZCaA@mail.gmail.com> (raw)
Hi Hackers,
Please find the attached patch for #5427 pgAdmin is freezing.
--
Thanks & Regards,
Pradip Parkale
Software Engineer | EnterpriseDB Corporation
Attachments:
[application/octet-stream] RM5427.patch (6.6K, 3-RM5427.patch)
download | inline diff:
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
view thread (4+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: [pgAdmin][RM5427]: pgAdmin is freezing
In-Reply-To: <CAJ9T6Su5Eqt+gVxvwiYYHm0ANpJERduW1gr3eyY6NdKvUAZCaA@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox