public inbox for [email protected]  
help / color / mirror / Atom feed
[pgAdmin][RM5427]: pgAdmin is freezing
4+ messages / 2 participants
[nested] [flat]

* [pgAdmin][RM5427]: pgAdmin is freezing
@ 2021-10-27 04:40  Pradip Parkale <[email protected]>
  0 siblings, 1 reply; 4+ messages in thread

From: Pradip Parkale @ 2021-10-27 04:40 UTC (permalink / raw)
  To: pgadmin-hackers

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


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [pgAdmin][RM5427]: pgAdmin is freezing
@ 2021-10-27 05:36  Akshay Joshi <[email protected]>
  parent: Pradip Parkale <[email protected]>
  0 siblings, 1 reply; 4+ messages in thread

From: Akshay Joshi @ 2021-10-27 05:36 UTC (permalink / raw)
  To: Pradip Parkale <[email protected]>; +Cc: pgadmin-hackers

Thanks, the patch applied.

On Wed, Oct 27, 2021 at 10:10 AM Pradip Parkale <
[email protected]> wrote:

> Hi Hackers,
>
> Please find the attached patch for #5427 pgAdmin is freezing.
>
>
> --
> Thanks & Regards,
> Pradip Parkale
> Software Engineer | EnterpriseDB Corporation
>


-- 
*Thanks & Regards*
*Akshay Joshi*
*pgAdmin Hacker | Principal Software Architect*
*EDB Postgres <http://edbpostgres.com>*

*Mobile: +91 976-788-8246*


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [pgAdmin][RM5427]: pgAdmin is freezing
@ 2021-11-08 08:49  Pradip Parkale <[email protected]>
  parent: Akshay Joshi <[email protected]>
  0 siblings, 1 reply; 4+ messages in thread

From: Pradip Parkale @ 2021-11-08 08:49 UTC (permalink / raw)
  To: Akshay Joshi <[email protected]>; +Cc: pgadmin-hackers

Hi Akshay,

Please find the attached patch.

On Wed, Oct 27, 2021 at 11:06 AM Akshay Joshi <[email protected]>
wrote:

> Thanks, the patch applied.
>
> On Wed, Oct 27, 2021 at 10:10 AM Pradip Parkale <
> [email protected]> wrote:
>
>> Hi Hackers,
>>
>> Please find the attached patch for #5427 pgAdmin is freezing.
>>
>>
>> --
>> Thanks & Regards,
>> Pradip Parkale
>> Software Engineer | EnterpriseDB Corporation
>>
>
>
> --
> *Thanks & Regards*
> *Akshay Joshi*
> *pgAdmin Hacker | Principal Software Architect*
> *EDB Postgres <http://edbpostgres.com>*
>
> *Mobile: +91 976-788-8246*
>


-- 
Thanks & Regards,
Pradip Parkale
Software Engineer | EnterpriseDB Corporation


Attachments:

  [application/octet-stream] RM5427.patch (1.2K, 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 cecd7ad27..2dcb6ca3c 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
@@ -29,6 +29,7 @@ from pgadmin.browser.server_groups.servers.databases.schemas.tables.\
     columns import utils as column_utils
 from pgadmin.browser.server_groups.servers.databases.schemas.tables.\
     constraints.exclusion_constraint import utils as exclusion_utils
+from pgadmin.utils.exception import ExecuteError
 
 
 class TableModule(SchemaChildModule):
@@ -1024,6 +1025,11 @@ class TableView(BaseTableView, DataTypeReader, SchemaDiffTableCompare):
             if not status:
                 return res
 
+            lock_on_table = self.get_table_locks(did, res['rows'][0])
+            if lock_on_table != '':
+                return ExecuteError(
+                    error_msg=str(lock_on_table.json['info']))
+
             return super(TableView, self).update(
                 gid, sid, did, scid, tid, data=data, res=res)
         except Exception as e:


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [pgAdmin][RM5427]: pgAdmin is freezing
@ 2021-11-10 06:27  Akshay Joshi <[email protected]>
  parent: Pradip Parkale <[email protected]>
  0 siblings, 0 replies; 4+ messages in thread

From: Akshay Joshi @ 2021-11-10 06:27 UTC (permalink / raw)
  To: Pradip Parkale <[email protected]>; +Cc: pgadmin-hackers

Thanks, the patch applied.

On Mon, Nov 8, 2021 at 2:20 PM Pradip Parkale <
[email protected]> wrote:

> Hi Akshay,
>
> Please find the attached patch.
>
> On Wed, Oct 27, 2021 at 11:06 AM Akshay Joshi <
> [email protected]> wrote:
>
>> Thanks, the patch applied.
>>
>> On Wed, Oct 27, 2021 at 10:10 AM Pradip Parkale <
>> [email protected]> wrote:
>>
>>> Hi Hackers,
>>>
>>> Please find the attached patch for #5427 pgAdmin is freezing.
>>>
>>>
>>> --
>>> Thanks & Regards,
>>> Pradip Parkale
>>> Software Engineer | EnterpriseDB Corporation
>>>
>>
>>
>> --
>> *Thanks & Regards*
>> *Akshay Joshi*
>> *pgAdmin Hacker | Principal Software Architect*
>> *EDB Postgres <http://edbpostgres.com>*
>>
>> *Mobile: +91 976-788-8246*
>>
>
>
> --
> Thanks & Regards,
> Pradip Parkale
> Software Engineer | EnterpriseDB Corporation
>


-- 
*Thanks & Regards*
*Akshay Joshi*
*pgAdmin Hacker | Principal Software Architect*
*EDB Postgres <http://edbpostgres.com>*

*Mobile: +91 976-788-8246*


^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2021-11-10 06:27 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-10-27 04:40 [pgAdmin][RM5427]: pgAdmin is freezing Pradip Parkale <[email protected]>
2021-10-27 05:36 ` Akshay Joshi <[email protected]>
2021-11-08 08:49   ` Pradip Parkale <[email protected]>
2021-11-10 06:27     ` Akshay Joshi <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox