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 1ef69866c..0b9e66b4d 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 @@ -621,41 +621,8 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings, return False, gone( gettext("The specified table could not be found.")) - # Set value based on - # x: No set, t: true, f: false - res['rows'][0]['autovacuum_enabled'] = 'x' \ - if res['rows'][0]['autovacuum_enabled'] is None else \ - {True: 't', False: 'f'}[res['rows'][0]['autovacuum_enabled']] - - res['rows'][0]['toast_autovacuum_enabled'] = 'x' \ - if res['rows'][0]['toast_autovacuum_enabled'] is None else \ - {True: 't', False: 'f'}[res['rows'][0]['toast_autovacuum_enabled']] - - # Enable custom autovaccum only if one of the options is set - # or autovacuum is set - res['rows'][0]['autovacuum_custom'] = any([ - res['rows'][0]['autovacuum_vacuum_threshold'], - res['rows'][0]['autovacuum_vacuum_scale_factor'], - res['rows'][0]['autovacuum_analyze_threshold'], - res['rows'][0]['autovacuum_analyze_scale_factor'], - res['rows'][0]['autovacuum_vacuum_cost_delay'], - res['rows'][0]['autovacuum_vacuum_cost_limit'], - res['rows'][0]['autovacuum_freeze_min_age'], - res['rows'][0]['autovacuum_freeze_max_age'], - res['rows'][0]['autovacuum_freeze_table_age']]) \ - or res['rows'][0]['autovacuum_enabled'] in ('t', 'f') - - res['rows'][0]['toast_autovacuum'] = any([ - res['rows'][0]['toast_autovacuum_vacuum_threshold'], - res['rows'][0]['toast_autovacuum_vacuum_scale_factor'], - res['rows'][0]['toast_autovacuum_analyze_threshold'], - res['rows'][0]['toast_autovacuum_analyze_scale_factor'], - res['rows'][0]['toast_autovacuum_vacuum_cost_delay'], - res['rows'][0]['toast_autovacuum_vacuum_cost_limit'], - res['rows'][0]['toast_autovacuum_freeze_min_age'], - res['rows'][0]['toast_autovacuum_freeze_max_age'], - res['rows'][0]['toast_autovacuum_freeze_table_age']]) \ - or res['rows'][0]['toast_autovacuum_enabled'] in ('t', 'f') + # Update autovacuum properties + self.update_autovacuum_properties(res) # We will check the threshold set by user before executing # the query because that can cause performance issues diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/__init__.py index 7f77427f5..a174bc28c 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/__init__.py @@ -356,13 +356,7 @@ class PartitionsView(BaseTableView, DataTypeReader, VacuumSettings, JSON of selected table node """ - SQL = render_template("/".join([self.partition_template_path, - 'properties.sql']), - did=did, scid=scid, tid=tid, - ptid=ptid, datlastsysoid=self.datlastsysoid) - status, res = self.conn.execute_dict(SQL) - if not status: - return internal_server_error(errormsg=res) + status, res = self._fetch_properties(did, scid, tid, ptid) if len(res['rows']) == 0: return gone(gettext( @@ -371,6 +365,32 @@ class PartitionsView(BaseTableView, DataTypeReader, VacuumSettings, return super(PartitionsView, self).properties( gid, sid, did, scid, ptid, res) + def _fetch_properties(self, did, scid, tid, ptid=None): + + """ + This function is used to fetch the properties of the specified object + :param did: + :param scid: + :param tid: + :return: + """ + try: + SQL = render_template("/".join([self.partition_template_path, + 'properties.sql']), + did=did, scid=scid, tid=tid, + ptid=ptid, datlastsysoid=self.datlastsysoid) + status, res = self.conn.execute_dict(SQL) + if not status: + return internal_server_error(errormsg=res) + + # Update autovacuum properties + self.update_autovacuum_properties(res) + + except Exception as e: + return False, internal_server_error(errormsg=str(e)) + + return True, res + @BaseTableView.check_precondition def fetch_objects_to_compare(self, sid, did, scid, tid, ptid=None): """ @@ -444,13 +464,7 @@ class PartitionsView(BaseTableView, DataTypeReader, VacuumSettings, """ main_sql = [] - SQL = render_template("/".join([self.partition_template_path, - 'properties.sql']), - did=did, scid=scid, tid=tid, - ptid=ptid, datlastsysoid=self.datlastsysoid) - status, res = self.conn.execute_dict(SQL) - if not status: - return internal_server_error(errormsg=res) + status, res = self._fetch_properties(did, scid, tid, ptid) if len(res['rows']) == 0: return gone(gettext( @@ -627,13 +641,7 @@ class PartitionsView(BaseTableView, DataTypeReader, VacuumSettings, data[k] = v if ptid is not None: - SQL = render_template("/".join([self.partition_template_path, - 'properties.sql']), - did=did, scid=scid, tid=tid, - ptid=ptid, datlastsysoid=self.datlastsysoid) - status, res = self.conn.execute_dict(SQL) - if not status: - return internal_server_error(errormsg=res) + status, res = self._fetch_properties(did, scid, tid, ptid) SQL, name = self.get_sql(did, scid, ptid, data, res) SQL = re.sub('\n{2,}', '\n\n', SQL) @@ -674,13 +682,7 @@ class PartitionsView(BaseTableView, DataTypeReader, VacuumSettings, data[k] = v try: - SQL = render_template("/".join([self.partition_template_path, - 'properties.sql']), - did=did, scid=scid, tid=tid, - ptid=ptid, datlastsysoid=self.datlastsysoid) - status, res = self.conn.execute_dict(SQL) - if not status: - return internal_server_error(errormsg=res) + status, res = self._fetch_properties(did, scid, tid, ptid) return super(PartitionsView, self).update( gid, sid, did, scid, ptid, data, res, parent_id=tid) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/static/js/partition.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/static/js/partition.js index a944c5fff..50d2f0769 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/static/js/partition.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/static/js/partition.js @@ -995,6 +995,16 @@ function( id: 'vacuum_settings_str', label: gettext('Storage settings'), type: 'multiline', group: gettext('Advanced'), mode: ['properties'], }], + sessChanged: function() { + /* If only custom autovacuum option is enabled then check if the options table is also changed. */ + if(_.size(this.sessAttrs) == 2 && this.sessAttrs['autovacuum_custom'] && this.sessAttrs['toast_autovacuum']) { + return this.get('vacuum_table').sessChanged() || this.get('vacuum_toast').sessChanged(); + } + if(_.size(this.sessAttrs) == 1 && (this.sessAttrs['autovacuum_custom'] || this.sessAttrs['toast_autovacuum'])) { + return this.get('vacuum_table').sessChanged() || this.get('vacuum_toast').sessChanged(); + } + return pgBrowser.DataModel.prototype.sessChanged.apply(this); + }, validate: function(keys) { var msg, name = this.get('name'), diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/gpdb/5_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/gpdb/5_plus/properties.sql index c2cfd974a..adeb48b54 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/gpdb/5_plus/properties.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/gpdb/5_plus/properties.sql @@ -30,8 +30,7 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r WHERE i.inhrelid = rel.oid) AS inherited_tables_cnt, false AS relpersistence, substring(array_to_string(rel.reloptions, ',') FROM 'fillfactor=([0-9]*)') AS fillfactor, - (CASE WHEN (substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)') = 'true') - THEN true ELSE false END) AS autovacuum_enabled, + (substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS autovacuum_enabled, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS autovacuum_vacuum_threshold, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.]?[0-9]*)') AS autovacuum_vacuum_scale_factor, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_analyze_threshold=([0-9]*)') AS autovacuum_analyze_threshold, @@ -41,8 +40,7 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS autovacuum_freeze_min_age, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS autovacuum_freeze_max_age, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS autovacuum_freeze_table_age, - (CASE WHEN (substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)') = 'true') - THEN true ELSE false END) AS toast_autovacuum_enabled, + (substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS toast_autovacuum_enabled, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS toast_autovacuum_vacuum_threshold, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.]?[0-9]*)') AS toast_autovacuum_vacuum_scale_factor, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_analyze_threshold=([0-9]*)') AS toast_autovacuum_analyze_threshold, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/pg/10_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/pg/10_plus/create.sql index 365be1d00..966847799 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/pg/10_plus/create.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/pg/10_plus/create.sql @@ -21,24 +21,25 @@ CREATE {% if data.relpersistence %}UNLOGGED {% endif %}TABLE {{conn|qtIdent(data {{ data.partition_value }}{% if data.is_partitioned is defined and data.is_partitioned %} PARTITION BY {{ data.partition_scheme }}{% endif %} -{% if data.fillfactor or data.autovacuum_custom or data.autovacuum_enabled or data.toast_autovacuum or data.toast_autovacuum_enabled or (data.autovacuum_enabled and data.vacuum_table|length > 0) or (data.toast_autovacuum_enabled and data.vacuum_toast|length > 0) %} -{% set add_comma = false%} +{% if data.fillfactor or data.autovacuum_custom or data.autovacuum_enabled in ('t', 'f') or data.toast_autovacuum or data.toast_autovacuum_enabled in ('t', 'f') or (data.autovacuum_enabled in ('t', 'f') and data.vacuum_table|length > 0) or (data.toast_autovacuum_enabled in ('t', 'f') and data.vacuum_toast|length > 0) %} +{% set ns = namespace(add_comma=false) %} WITH ( -{% if data.fillfactor %}{% set add_comma = true%} - FILLFACTOR = {{ data.fillfactor }}{% endif %}{% if data.autovacuum_custom %} -{% if add_comma %}, +{% if data.fillfactor %}{% set ns.add_comma = true%} + FILLFACTOR = {{ data.fillfactor }}{% endif %}{% if data.autovacuum_enabled in ('t', 'f') %} +{% if ns.add_comma %}, {% endif %} - autovacuum_enabled = {% if data.autovacuum_enabled %}TRUE{% else %}FALSE{% endif %}{% set add_comma = true%}{% endif %}{% if data.toast_autovacuum %} -{% if add_comma %}, + autovacuum_enabled = {% if data.autovacuum_enabled == 't' %}TRUE{% else %}FALSE{% endif %}{% set ns.add_comma = true%}{% endif %}{% if data.toast_autovacuum_enabled in ('t', 'f') %} +{% if ns.add_comma %}, {% endif %} - toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled %}TRUE{% else %}FALSE{% endif %} -{% endif %}{% if data.autovacuum_enabled and data.vacuum_table|length > 0 %} -{% for opt in data.vacuum_table %}{% if opt.name and opt.value %} -, - {{opt.name}} = {{opt.value}}{% endif %} -{% endfor %}{% endif %}{% if data.toast_autovacuum_enabled and data.vacuum_toast|length > 0 %} -{% for opt in data.vacuum_toast %}{% if opt.name and opt.value %} + toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}TRUE{% else %}FALSE{% endif %}{% set ns.add_comma = true%}{% endif %} +{% if data.autovacuum_custom and data.vacuum_table|length > 0 %} +{% for opt in data.vacuum_table %}{% if opt.name and opt.value is defined %} +{% if ns.add_comma %}, +{% endif %} + {{opt.name}} = {{opt.value}}{% endif %}{% if opt.name and opt.value is defined %}{% set ns.add_comma = true%}{% endif %} +{% endfor %}{% endif %}{% if data.toast_autovacuum and data.vacuum_toast|length > 0 %} +{% for opt in data.vacuum_toast %}{% if opt.name and opt.value is defined %} , toast.{{opt.name}} = {{opt.value}}{% endif %} {% endfor %}{% endif %} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/pg/10_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/pg/10_plus/properties.sql index 48e6248d1..eed03bbaa 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/pg/10_plus/properties.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/pg/10_plus/properties.sql @@ -27,8 +27,7 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r WHERE i.inhrelid = rel.oid) AS inherited_tables_cnt, (CASE WHEN rel.relpersistence = 'u' THEN true ELSE false END) AS relpersistence, substring(array_to_string(rel.reloptions, ',') FROM 'fillfactor=([0-9]*)') AS fillfactor, - (CASE WHEN (substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)') = 'true') - THEN true ELSE false END) AS autovacuum_enabled, + (substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS autovacuum_enabled, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS autovacuum_vacuum_threshold, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.]?[0-9]*)') AS autovacuum_vacuum_scale_factor, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_analyze_threshold=([0-9]*)') AS autovacuum_analyze_threshold, @@ -38,8 +37,7 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS autovacuum_freeze_min_age, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS autovacuum_freeze_max_age, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS autovacuum_freeze_table_age, - (CASE WHEN (substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)') = 'true') - THEN true ELSE false END) AS toast_autovacuum_enabled, + (substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS toast_autovacuum_enabled, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS toast_autovacuum_vacuum_threshold, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.]?[0-9]*)') AS toast_autovacuum_vacuum_scale_factor, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_analyze_threshold=([0-9]*)') AS toast_autovacuum_analyze_threshold, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/pg/12_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/pg/12_plus/properties.sql index c2c8e4274..9de83f353 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/pg/12_plus/properties.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/pg/12_plus/properties.sql @@ -27,8 +27,7 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r WHERE i.inhrelid = rel.oid) AS inherited_tables_cnt, (CASE WHEN rel.relpersistence = 'u' THEN true ELSE false END) AS relpersistence, substring(array_to_string(rel.reloptions, ',') FROM 'fillfactor=([0-9]*)') AS fillfactor, - (CASE WHEN (substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)') = 'true') - THEN true ELSE false END) AS autovacuum_enabled, + (substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS autovacuum_enabled, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS autovacuum_vacuum_threshold, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.]?[0-9]*)') AS autovacuum_vacuum_scale_factor, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_analyze_threshold=([0-9]*)') AS autovacuum_analyze_threshold, @@ -38,8 +37,7 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS autovacuum_freeze_min_age, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS autovacuum_freeze_max_age, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS autovacuum_freeze_table_age, - (CASE WHEN (substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)') = 'true') - THEN true ELSE false END) AS toast_autovacuum_enabled, + (substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS toast_autovacuum_enabled, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS toast_autovacuum_vacuum_threshold, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.]?[0-9]*)') AS toast_autovacuum_vacuum_scale_factor, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_analyze_threshold=([0-9]*)') AS toast_autovacuum_analyze_threshold, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/ppas/10_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/ppas/10_plus/create.sql index 279ff99ab..725ed5242 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/ppas/10_plus/create.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/ppas/10_plus/create.sql @@ -21,23 +21,24 @@ CREATE {% if data.relpersistence %}UNLOGGED {% endif %}TABLE {{conn|qtIdent(data PARTITION BY {{ data.partition_scheme }}{% endif %} {% if data.fillfactor or data.autovacuum_custom or data.autovacuum_enabled or data.toast_autovacuum or data.toast_autovacuum_enabled or (data.autovacuum_enabled and data.vacuum_table|length > 0) or (data.toast_autovacuum_enabled and data.vacuum_toast|length > 0) %} -{% set add_comma = false%} +{% set ns = namespace(add_comma=false) %} WITH ( -{% if data.fillfactor %}{% set add_comma = true%} - FILLFACTOR = {{ data.fillfactor }}{% endif %}{% if data.autovacuum_custom %} -{% if add_comma %}, +{% if data.fillfactor %}{% set ns.add_comma = true%} + FILLFACTOR = {{ data.fillfactor }}{% endif %}{% if data.autovacuum_enabled in ('t', 'f') %} +{% if ns.add_comma %}, {% endif %} - autovacuum_enabled = {% if data.autovacuum_enabled %}TRUE{% else %}FALSE{% endif %}{% set add_comma = true%}{% endif %}{% if data.toast_autovacuum %} -{% if add_comma %}, + autovacuum_enabled = {% if data.autovacuum_enabled == 't' %}TRUE{% else %}FALSE{% endif %}{% set ns.add_comma = true%}{% endif %}{% if data.toast_autovacuum_enabled in ('t', 'f') %} +{% if ns.add_comma %}, {% endif %} - toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled %}TRUE{% else %}FALSE{% endif %} -{% endif %}{% if data.autovacuum_enabled and data.vacuum_table|length > 0 %} -{% for opt in data.vacuum_table %}{% if opt.name and opt.value %} -, - {{opt.name}} = {{opt.value}}{% endif %} -{% endfor %}{% endif %}{% if data.toast_autovacuum_enabled and data.vacuum_toast|length > 0 %} -{% for opt in data.vacuum_toast %}{% if opt.name and opt.value %} + toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}TRUE{% else %}FALSE{% endif %}{% set ns.add_comma = true%}{% endif %} +{% if data.autovacuum_custom and data.vacuum_table|length > 0 %} +{% for opt in data.vacuum_table %}{% if opt.name and opt.value is defined %} +{% if ns.add_comma %}, +{% endif %} + {{opt.name}} = {{opt.value}}{% endif %}{% if opt.name and opt.value is defined %}{% set ns.add_comma = true%}{% endif %} +{% endfor %}{% endif %}{% if data.toast_autovacuum and data.vacuum_toast|length > 0 %} +{% for opt in data.vacuum_toast %}{% if opt.name and opt.value is defined %} , toast.{{opt.name}} = {{opt.value}}{% endif %} {% endfor %}{% endif %} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/ppas/10_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/ppas/10_plus/properties.sql index 48e6248d1..eed03bbaa 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/ppas/10_plus/properties.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/ppas/10_plus/properties.sql @@ -27,8 +27,7 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r WHERE i.inhrelid = rel.oid) AS inherited_tables_cnt, (CASE WHEN rel.relpersistence = 'u' THEN true ELSE false END) AS relpersistence, substring(array_to_string(rel.reloptions, ',') FROM 'fillfactor=([0-9]*)') AS fillfactor, - (CASE WHEN (substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)') = 'true') - THEN true ELSE false END) AS autovacuum_enabled, + (substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS autovacuum_enabled, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS autovacuum_vacuum_threshold, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.]?[0-9]*)') AS autovacuum_vacuum_scale_factor, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_analyze_threshold=([0-9]*)') AS autovacuum_analyze_threshold, @@ -38,8 +37,7 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS autovacuum_freeze_min_age, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS autovacuum_freeze_max_age, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS autovacuum_freeze_table_age, - (CASE WHEN (substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)') = 'true') - THEN true ELSE false END) AS toast_autovacuum_enabled, + (substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS toast_autovacuum_enabled, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS toast_autovacuum_vacuum_threshold, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.]?[0-9]*)') AS toast_autovacuum_vacuum_scale_factor, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_analyze_threshold=([0-9]*)') AS toast_autovacuum_analyze_threshold, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/ppas/12_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/ppas/12_plus/properties.sql index c2c8e4274..9de83f353 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/ppas/12_plus/properties.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/ppas/12_plus/properties.sql @@ -27,8 +27,7 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r WHERE i.inhrelid = rel.oid) AS inherited_tables_cnt, (CASE WHEN rel.relpersistence = 'u' THEN true ELSE false END) AS relpersistence, substring(array_to_string(rel.reloptions, ',') FROM 'fillfactor=([0-9]*)') AS fillfactor, - (CASE WHEN (substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)') = 'true') - THEN true ELSE false END) AS autovacuum_enabled, + (substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS autovacuum_enabled, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS autovacuum_vacuum_threshold, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.]?[0-9]*)') AS autovacuum_vacuum_scale_factor, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_analyze_threshold=([0-9]*)') AS autovacuum_analyze_threshold, @@ -38,8 +37,7 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS autovacuum_freeze_min_age, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS autovacuum_freeze_max_age, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS autovacuum_freeze_table_age, - (CASE WHEN (substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)') = 'true') - THEN true ELSE false END) AS toast_autovacuum_enabled, + (substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS toast_autovacuum_enabled, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS toast_autovacuum_vacuum_threshold, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.]?[0-9]*)') AS toast_autovacuum_vacuum_scale_factor, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_analyze_threshold=([0-9]*)') AS toast_autovacuum_analyze_threshold, 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 40c9a453b..fc902aec2 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 @@ -1584,3 +1584,49 @@ class BaseTableView(PGChildNodeView, BasePartitionTable): if len(reset_values) > 0: data[vacuum_key]['reset_values'] = reset_values + + def update_autovacuum_properties(self, res): + """ + This function sets the appropriate value for autovacuum_enabled and + autovacuum_custom for table & toast table both. + :param res: + :return: + """ + # Set value based on + # x: No set, t: true, f: false + if res is not None and res['rows'] is not None \ + and res['rows'][0] is not None: + res['rows'][0]['autovacuum_enabled'] = 'x' \ + if res['rows'][0]['autovacuum_enabled'] is None else \ + {True: 't', False: 'f'}[res['rows'][0]['autovacuum_enabled']] + + res['rows'][0]['toast_autovacuum_enabled'] = 'x' \ + if res['rows'][0]['toast_autovacuum_enabled'] is None else \ + {True: 't', False: 'f'}[ + res['rows'][0]['toast_autovacuum_enabled']] + + # Enable custom autovaccum only if one of the options is set + # or autovacuum is set + res['rows'][0]['autovacuum_custom'] = any([ + res['rows'][0]['autovacuum_vacuum_threshold'], + res['rows'][0]['autovacuum_vacuum_scale_factor'], + res['rows'][0]['autovacuum_analyze_threshold'], + res['rows'][0]['autovacuum_analyze_scale_factor'], + res['rows'][0]['autovacuum_vacuum_cost_delay'], + res['rows'][0]['autovacuum_vacuum_cost_limit'], + res['rows'][0]['autovacuum_freeze_min_age'], + res['rows'][0]['autovacuum_freeze_max_age'], + res['rows'][0]['autovacuum_freeze_table_age']]) or \ + res['rows'][0]['autovacuum_enabled'] in ('t', 'f') + + res['rows'][0]['toast_autovacuum'] = any([ + res['rows'][0]['toast_autovacuum_vacuum_threshold'], + res['rows'][0]['toast_autovacuum_vacuum_scale_factor'], + res['rows'][0]['toast_autovacuum_analyze_threshold'], + res['rows'][0]['toast_autovacuum_analyze_scale_factor'], + res['rows'][0]['toast_autovacuum_vacuum_cost_delay'], + res['rows'][0]['toast_autovacuum_vacuum_cost_limit'], + res['rows'][0]['toast_autovacuum_freeze_min_age'], + res['rows'][0]['toast_autovacuum_freeze_max_age'], + res['rows'][0]['toast_autovacuum_freeze_table_age']]) or \ + res['rows'][0]['toast_autovacuum_enabled'] in ('t', 'f')