diff --git a/docs/en_US/images/materialized_view_parameter.png b/docs/en_US/images/materialized_view_parameter.png old mode 100755 new mode 100644 index ae8d7cd8a..e5794299c Binary files a/docs/en_US/images/materialized_view_parameter.png and b/docs/en_US/images/materialized_view_parameter.png differ diff --git a/docs/en_US/images/table_parameter.png b/docs/en_US/images/table_parameter.png old mode 100755 new mode 100644 index 6ad16c10f..b8399f6a0 Binary files a/docs/en_US/images/table_parameter.png and b/docs/en_US/images/table_parameter.png differ diff --git a/docs/en_US/materialized_view_dialog.rst b/docs/en_US/materialized_view_dialog.rst index 534e86b73..c13e3fb63 100644 --- a/docs/en_US/materialized_view_dialog.rst +++ b/docs/en_US/materialized_view_dialog.rst @@ -67,9 +67,10 @@ thresholds; use the *Table* tab and the *Toast Table* tab to customize values for the table and the associated toast table. To change the default values: * Move the *Custom auto-vacuum?* switch to the *Yes* position to perform custom - maintenance on the materialized view. -* Move the *Enabled?* switch to the *Yes* position to select values in the - *Vacuum table*. Provide values for each row in the *Value* column. + maintenance on the materialized view and to select values in the + *Vacuum table*. The *Vacuum Table* provides default values for maintenance + operations. +* Changing *Autovacuum enabled?* to *Not set* will reset autovacuum_enabled. Click the *Security* tab to continue. diff --git a/docs/en_US/release_notes_4_22.rst b/docs/en_US/release_notes_4_22.rst index ffcfe6bcf..3e2772ce8 100644 --- a/docs/en_US/release_notes_4_22.rst +++ b/docs/en_US/release_notes_4_22.rst @@ -26,6 +26,7 @@ Bug fixes | `Issue #4279 `_ - Ensure that file browse "home" button should point to $HOME rather than /. | `Issue #4840 `_ - Ensure that 'With OID' option should be disabled while taking backup of database server version 12 and above. | `Issue #5001 `_ - Fixed invalid literal issue when removing the connection limit for the existing role. +| `Issue #5398 `_ - Fixed generated SQL issue for auto vacuum options. | `Issue #5422 `_ - Ensure that the dependencies tab shows correct information for Synonyms. | `Issue #5434 `_ - Fixed an issue where the newly added table is not alphabetically added to the tree. | `Issue #5440 `_ - Fixed list sorting issue in the schema diff tool. diff --git a/docs/en_US/table_dialog.rst b/docs/en_US/table_dialog.rst index abb009649..02401da33 100644 --- a/docs/en_US/table_dialog.rst +++ b/docs/en_US/table_dialog.rst @@ -485,10 +485,10 @@ thresholds; use the *Table* tab and the *Toast Table* tab to customize values for the table and the associated toast table: * Move the *Custom auto-vacuum?* switch to the *Yes* position to perform custom - maintenance on the table. -* Move the *Enabled?* switch to the *Yes* position to select values in the + maintenance on the table and to select values in the *Vacuum table*. The *Vacuum Table* provides default values for maintenance operations. +* Changing *Autovacuum enabled?* to *Not set* will reset autovacuum_enabled. Provide a custom value in the *Value* column for each metric listed in the *Label* column. diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/static/js/schema.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/static/js/schema.js index 084e4cd9e..f606e384f 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/static/js/schema.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/static/js/schema.js @@ -88,7 +88,9 @@ define('pgadmin.node.schema', [ var gridHeader = _.template([ '
', - ' <%-label%>', + '<% if (label && label != "") %> {', + ' <%-label%>', + '}', '
'].join('\n')), gridBody = $('
').append( gridHeader(attributes) @@ -151,7 +153,8 @@ define('pgadmin.node.schema', [ },{ id: 'autovacuum_custom', label: gettext('Custom auto-vacuum?'), group: gettext('Table'), mode: ['edit', 'create'], - type: 'switch', + type: 'switch', controlLabelClassName: 'control-label pg-el-sm-4 pg-el-12', + controlsClassName: 'pgadmin-controls pg-el-sm-8 pg-el-12', disabled: function(m) { // If table is partitioned table then disabled it. if (m.top && m.top.get('is_partitioned')) { @@ -169,45 +172,29 @@ define('pgadmin.node.schema', [ return true; }, },{ - id: 'autovacuum_enabled', label: gettext('Enabled?'), + id: 'autovacuum_enabled', label: gettext('Autovacuum Enabled?'), group: gettext('Table'), mode: ['edit', 'create'], - type: 'switch', + type: 'radioModern', controlLabelClassName: 'control-label pg-el-sm-4 pg-el-12', + controlsClassName: 'pgadmin-controls pg-el-sm-8 pg-el-12', + options: [ + {'label': gettext('Not set'), 'value': 'x'}, + {'label': gettext('Yes'), 'value': 't'}, + {'label': gettext('No'), 'value': 'f'}, + ], deps: ['autovacuum_custom'], disabled: function(m) { if(!m.top.inSchema.apply(this, [m]) && m.get('autovacuum_custom') == true) { - // If reloptions is null then set the autovacuum_enabled to true. - if (!_.isUndefined(m.get('reloptions')) && - _.isNull(m.get('reloptions'))) { - setTimeout(function() { - m.set('autovacuum_enabled', true); - }, 10); - } return false; } // We also need to unset rest of all setTimeout(function() { - m.set('autovacuum_enabled', false); + m.set('autovacuum_enabled', 'x'); }, 10); return true; }, - control: Backform.SwitchControl.extend({ - onChange: function() { - Backform.SwitchControl.prototype.onChange.apply(this, arguments); - let m = this.model; - // If value of autovacuum_enabled is false and reloptions is null - // then we should set the value of autovacuum_custom to false, as - // there is no query to run. - if (!m.get('autovacuum_enabled') && !_.isUndefined(m.get('reloptions')) - && _.isNull(m.get('reloptions'))) { - setTimeout(function() { - m.set('autovacuum_custom', false); - }, 10); - } - }, - }), },{ id: 'vacuum_table', label: '', model: Backform.VacuumTableModel, editable: false, type: 'collection', @@ -224,7 +211,7 @@ define('pgadmin.node.schema', [ name: 'value', label: gettext('Value'), cellHeaderClasses:'width_percent_30', cellFunction: Backform.cellFunction, editable: function(m) { - return m.handler.get('autovacuum_enabled'); + return m.handler.get('autovacuum_custom'); }, headerCell: Backgrid.Extension.CustomHeaderCell, }, { @@ -235,13 +222,14 @@ define('pgadmin.node.schema', [ }, ], }), - deps: ['autovacuum_enabled'], + deps: ['autovacuum_custom'], },{ id: 'spacer_ctrl', group: gettext('TOAST table'), mode: ['edit', 'create'], type: 'spacer', },{ id: 'toast_autovacuum', label: gettext('Custom auto-vacuum?'), group: gettext('TOAST table'), mode: ['edit', 'create'], - type: 'switch', + type: 'switch', controlLabelClassName: 'control-label pg-el-sm-4 pg-el-12', + controlsClassName: 'pgadmin-controls pg-el-sm-8 pg-el-12', disabled: function(m) { // We need to check additional condition to toggle enable/disable // for table auto-vacuum @@ -255,50 +243,32 @@ define('pgadmin.node.schema', [ return true; }, },{ - id: 'toast_autovacuum_enabled', label: gettext('Enabled?'), + id: 'toast_autovacuum_enabled', label: gettext('Autovacuum Enabled?'), group: gettext('TOAST table'), mode: ['edit', 'create'], - type: 'switch', + type: 'radioModern', controlLabelClassName: 'control-label pg-el-sm-4 pg-el-12', + controlsClassName: 'pgadmin-controls pg-el-sm-8 pg-el-12', + options: [ + {'label': gettext('Not set'), 'value': 'x'}, + {'label': gettext('Yes'), 'value': 't'}, + {'label': gettext('No'), 'value': 'f'}, + ], deps:['toast_autovacuum'], disabled: function(m) { // If in schema & in create mode then enable it if(!m.top.inSchema.apply(this, [m]) && m.get('toast_autovacuum') === true) { - // If reloptions is null then set the autovacuum_enabled to true. - if (!_.isUndefined(m.get('toast_reloptions')) && - _.isNull(m.get('toast_reloptions'))) { - setTimeout(function() { - m.set('toast_autovacuum_enabled', true); - }, 10); - } - return false; } if (m.isNew() || m.get('hastoasttable')) { // we also need to unset rest of all setTimeout(function() { - m.set('toast_autovacuum_enabled', false); + m.set('toast_autovacuum_enabled', 'x'); }, 10); } return true; }, - control: Backform.SwitchControl.extend({ - onChange: function() { - Backform.SwitchControl.prototype.onChange.apply(this, arguments); - - let m = this.model; - // If value of autovacuum_enabled is false and reloptions is null - // then we should set the value of autovacuum_custom to false, as - // there is no query to run. - if (!m.get('toast_autovacuum_enabled') && !_.isUndefined(m.get('toast_reloptions')) - && _.isNull(m.get('toast_reloptions'))) { - setTimeout(function() { - m.set('toast_autovacuum', false); - }, 10); - } - }, - }), },{ id: 'vacuum_toast', label: '', model: Backform.VacuumTableModel, type: 'collection', editable: function(m) { @@ -318,7 +288,7 @@ define('pgadmin.node.schema', [ cellHeaderClasses:'width_percent_30', headerCell: Backgrid.Extension.CustomHeaderCell, cellFunction: Backform.cellFunction, editable: function(m) { - return m.handler.get('toast_autovacuum_enabled'); + return m.handler.get('toast_autovacuum'); }, }, { @@ -329,7 +299,7 @@ define('pgadmin.node.schema', [ }, ], }), - deps: ['toast_autovacuum_enabled'], + deps: ['toast_autovacuum'], }]; // Extend the browser's collection class for schema collection 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 03073e277..68b945c56 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 @@ -619,6 +619,42 @@ 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') + # We will check the threshold set by user before executing # the query because that can cause performance issues # with large result set @@ -943,6 +979,11 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings, data['partition_scheme'] = self.get_partition_scheme(data) partitions_sql = self.get_partitions_sql(data) + # Update the vacuum table settings. + BaseTableView.update_vacuum_settings(self, 'vacuum_table', data) + # Update the vacuum toast table settings. + BaseTableView.update_vacuum_settings(self, 'vacuum_toast', data) + SQL = render_template( "/".join([self.table_template_path, 'create.sql']), data=data, conn=self.conn @@ -1023,14 +1064,9 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings, data[k] = v try: - SQL = render_template( - "/".join([self.table_template_path, 'properties.sql']), - did=did, scid=scid, tid=tid, - datlastsysoid=self.datlastsysoid - ) - status, res = self.conn.execute_dict(SQL) + status, res = self._fetch_properties(did, scid, tid) if not status: - return internal_server_error(errormsg=res) + return res return super(TableView, self).update( gid, sid, did, scid, tid, data, res) @@ -1266,14 +1302,9 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings, res = None if tid is not None: - SQL = render_template( - "/".join([self.table_template_path, 'properties.sql']), - did=did, scid=scid, tid=tid, - datlastsysoid=self.datlastsysoid - ) - status, res = self.conn.execute_dict(SQL) + status, res = self._fetch_properties(did, scid, tid) if not status: - return internal_server_error(errormsg=SQL) + return res SQL, name = self.get_sql(did, scid, tid, data, res) SQL = re.sub('\n{2,}', '\n\n', SQL) @@ -1335,17 +1366,9 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings, """ main_sql = [] - SQL = render_template( - "/".join([self.table_template_path, 'properties.sql']), - did=did, scid=scid, tid=tid, - datlastsysoid=self.datlastsysoid - ) - status, res = self.conn.execute_dict(SQL) + status, res = self._fetch_properties(did, scid, tid) if not status: - return internal_server_error(errormsg=res) - - if len(res['rows']) == 0: - return gone(gettext("The specified table could not be found.")) + return res data = res['rows'][0] 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 9ce744cfa..68b2209a8 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 @@ -330,8 +330,8 @@ function( is_sys_table: undefined, coll_inherits: [], hastoasttable: true, - toast_autovacuum_enabled: false, - autovacuum_enabled: false, + toast_autovacuum_enabled: 'x', + autovacuum_enabled: 'x', primary_key: [], partitions: [], partition_type: 'range', 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 d65957132..0e73de872 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 @@ -300,8 +300,8 @@ define('pgadmin.node.table', [ is_sys_table: undefined, coll_inherits: [], hastoasttable: true, - toast_autovacuum_enabled: false, - autovacuum_enabled: false, + toast_autovacuum_enabled: 'x', + autovacuum_enabled: 'x', primary_key: [], partitions: [], partition_type: 'range', @@ -1149,6 +1149,16 @@ define('pgadmin.node.table', [ id: 'vacuum_settings_str', label: gettext('Storage settings'), type: 'multiline', group: 'advanced', mode: ['properties'], }], + sessChanged: function() { + /* If only custom autovacuum option is enabled the 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() { 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 bc7ce83b4..c2cfd974a 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 @@ -58,8 +58,6 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r typ.typrelid AS typoid, (CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, -- Added for pgAdmin4 - (CASE WHEN array_length(rel.reloptions, 1) > 0 THEN true ELSE false END) AS autovacuum_custom, - (CASE WHEN array_length(tst.reloptions, 1) > 0 AND rel.reltoastrelid != 0 THEN true ELSE false END) AS toast_autovacuum, NULL AS seclabels, (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table, -- Added for partition table 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 4bf44a156..48e6248d1 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 @@ -49,15 +49,9 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS toast_autovacuum_freeze_min_age, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS toast_autovacuum_freeze_max_age, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age, - array_to_string(rel.reloptions, ',') AS table_vacuum_settings_str, - array_to_string(tst.reloptions, ',') AS toast_table_vacuum_settings_str, rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, rel.reloftype, typ.typname, typ.typrelid AS typoid, (CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, - -- Added for pgAdmin4 - (CASE WHEN array_length(rel.reloptions, 1) > 0 THEN true ELSE false END) AS autovacuum_custom, - (CASE WHEN array_length(tst.reloptions, 1) > 0 AND rel.reltoastrelid != 0 THEN true ELSE false END) AS toast_autovacuum, - (SELECT array_agg(provider || '=' || label) FROM pg_seclabels sl1 WHERE sl1.objoid=rel.oid AND sl1.objsubid=0) AS seclabels, (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table, -- Added for partition table 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 40a257b5b..c2c8e4274 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 @@ -49,15 +49,9 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS toast_autovacuum_freeze_min_age, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS toast_autovacuum_freeze_max_age, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age, - array_to_string(rel.reloptions, ',') AS table_vacuum_settings_str, - array_to_string(tst.reloptions, ',') AS toast_table_vacuum_settings_str, rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, rel.reloftype, typ.typname, typ.typrelid AS typoid, (CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, - -- Added for pgAdmin4 - (CASE WHEN array_length(rel.reloptions, 1) > 0 THEN true ELSE false END) AS autovacuum_custom, - (CASE WHEN array_length(tst.reloptions, 1) > 0 AND rel.reltoastrelid != 0 THEN true ELSE false END) AS toast_autovacuum, - (SELECT array_agg(provider || '=' || label) FROM pg_seclabels sl1 WHERE sl1.objoid=rel.oid AND sl1.objsubid=0) AS seclabels, (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table, -- Added for partition table 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 4bf44a156..48e6248d1 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 @@ -49,15 +49,9 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS toast_autovacuum_freeze_min_age, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS toast_autovacuum_freeze_max_age, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age, - array_to_string(rel.reloptions, ',') AS table_vacuum_settings_str, - array_to_string(tst.reloptions, ',') AS toast_table_vacuum_settings_str, rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, rel.reloftype, typ.typname, typ.typrelid AS typoid, (CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, - -- Added for pgAdmin4 - (CASE WHEN array_length(rel.reloptions, 1) > 0 THEN true ELSE false END) AS autovacuum_custom, - (CASE WHEN array_length(tst.reloptions, 1) > 0 AND rel.reltoastrelid != 0 THEN true ELSE false END) AS toast_autovacuum, - (SELECT array_agg(provider || '=' || label) FROM pg_seclabels sl1 WHERE sl1.objoid=rel.oid AND sl1.objsubid=0) AS seclabels, (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table, -- Added for partition table 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 40a257b5b..c2c8e4274 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 @@ -49,15 +49,9 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS toast_autovacuum_freeze_min_age, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS toast_autovacuum_freeze_max_age, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age, - array_to_string(rel.reloptions, ',') AS table_vacuum_settings_str, - array_to_string(tst.reloptions, ',') AS toast_table_vacuum_settings_str, rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, rel.reloftype, typ.typname, typ.typrelid AS typoid, (CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, - -- Added for pgAdmin4 - (CASE WHEN array_length(rel.reloptions, 1) > 0 THEN true ELSE false END) AS autovacuum_custom, - (CASE WHEN array_length(tst.reloptions, 1) > 0 AND rel.reltoastrelid != 0 THEN true ELSE false END) AS toast_autovacuum, - (SELECT array_agg(provider || '=' || label) FROM pg_seclabels sl1 WHERE sl1.objoid=rel.oid AND sl1.objsubid=0) AS seclabels, (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table, -- Added for partition table diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/10_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/10_plus/create.sql index dafc87aa2..0e0fdd263 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/10_plus/create.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/10_plus/create.sql @@ -78,15 +78,15 @@ CACHE {{c.seqcache|int}} {% endif %} WITH ( OIDS = {% if data.relhasoids %}TRUE{% else %}FALSE{% endif %}{% if data.fillfactor %}, FILLFACTOR = {{ data.fillfactor }}{% endif %}{% if data.parallel_workers is defined and data.parallel_workers != '' and data.parallel_workers != None %}, - parallel_workers = {{ data.parallel_workers }}{% endif %}{% if data.autovacuum_custom %}, - autovacuum_enabled = {% if data.autovacuum_enabled %}TRUE{% else %}FALSE{% endif %}{% endif %}{% if data.toast_autovacuum %}, - 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 %} + parallel_workers = {{ data.parallel_workers }}{% endif %}{% if data.autovacuum_enabled in ('t', 'f') %}, + autovacuum_enabled = {% if data.autovacuum_enabled == 't' %}TRUE{% else %}FALSE{% endif %}{% endif %}{% if data.toast_autovacuum_enabled in ('t', 'f') %}, + toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}TRUE{% else %}FALSE{% endif %} +{% 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 %} , {{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 %} +{% 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/tables/sql/10_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/10_plus/properties.sql index 5707f46d1..7c3a67c9a 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/10_plus/properties.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/10_plus/properties.sql @@ -28,8 +28,7 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r (CASE WHEN rel.relpersistence = 'u' THEN true ELSE false END) AS relpersistence, substring(array_to_string(rel.reloptions, ',') FROM 'fillfactor=([0-9]*)') AS fillfactor, substring(array_to_string(rel.reloptions, ',') FROM 'parallel_workers=([0-9]*)') AS parallel_workers, - (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, @@ -39,8 +38,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, @@ -50,16 +48,10 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS toast_autovacuum_freeze_min_age, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS toast_autovacuum_freeze_max_age, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age, - array_to_string(rel.reloptions, ',') AS table_vacuum_settings_str, - array_to_string(tst.reloptions, ',') AS toast_table_vacuum_settings_str, rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, rel.reloftype, CASE WHEN typ.typname IS NOT NULL THEN (select quote_ident(nspname) FROM pg_namespace WHERE oid = {{scid}}::oid )||'.'||quote_ident(typ.typname) ELSE typ.typname END AS typname, typ.typrelid AS typoid, (CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, - -- Added for pgAdmin4 - (array_to_string(rel.reloptions, ',') like '%autovacuum%') AS autovacuum_custom, - (CASE WHEN array_length(tst.reloptions, 1) > 0 AND rel.reltoastrelid != 0 THEN true ELSE false END) AS toast_autovacuum, - (SELECT array_agg(provider || '=' || label) FROM pg_seclabels sl1 WHERE sl1.objoid=rel.oid AND sl1.objsubid=0) AS seclabels, (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table -- Added for partition table diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/11_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/11_plus/create.sql index caec8f520..73717cd2d 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/11_plus/create.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/11_plus/create.sql @@ -79,15 +79,15 @@ WITH ( OIDS = {% if data.relhasoids %}TRUE{% else %}FALSE{% endif %}{% if data.fillfactor %}, FILLFACTOR = {{ data.fillfactor }}{% endif %}{% if data.parallel_workers is defined and data.parallel_workers != '' and data.parallel_workers != None %}, parallel_workers = {{ data.parallel_workers }}{% endif %}{% if data.toast_tuple_target is defined and data.toast_tuple_target != '' and data.toast_tuple_target != None %}, - toast_tuple_target = {{ data.toast_tuple_target }}{% endif %}{% if data.autovacuum_custom %}, - autovacuum_enabled = {% if data.autovacuum_enabled %}TRUE{% else %}FALSE{% endif %}{% endif %}{% if data.toast_autovacuum %}, - 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 %} + toast_tuple_target = {{ data.toast_tuple_target }}{% endif %}{% if data.autovacuum_enabled in ('t', 'f') %}, + autovacuum_enabled = {% if data.autovacuum_enabled == 't' %}TRUE{% else %}FALSE{% endif %}{% endif %}{% if data.toast_autovacuum_enabled in ('t', 'f') %}, + toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}TRUE{% else %}FALSE{% endif %} +{% 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 %} , {{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 %} +{% 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/tables/sql/11_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/11_plus/properties.sql index 1d7e596b8..f874f52ac 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/11_plus/properties.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/11_plus/properties.sql @@ -29,8 +29,7 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r substring(array_to_string(rel.reloptions, ',') FROM 'fillfactor=([0-9]*)') AS fillfactor, substring(array_to_string(rel.reloptions, ',') FROM 'parallel_workers=([0-9]*)') AS parallel_workers, substring(array_to_string(rel.reloptions, ',') FROM 'toast_tuple_target=([0-9]*)') AS toast_tuple_target, - (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, @@ -40,8 +39,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, @@ -51,16 +49,10 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS toast_autovacuum_freeze_min_age, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS toast_autovacuum_freeze_max_age, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age, - array_to_string(rel.reloptions, ',') AS table_vacuum_settings_str, - array_to_string(tst.reloptions, ',') AS toast_table_vacuum_settings_str, rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, rel.reloftype, CASE WHEN typ.typname IS NOT NULL THEN (select quote_ident(nspname) FROM pg_namespace WHERE oid = {{scid}}::oid )||'.'||quote_ident(typ.typname) ELSE typ.typname END AS typname, typ.typrelid AS typoid, (CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, - -- Added for pgAdmin4 - (array_to_string(rel.reloptions, ',') like '%autovacuum%') AS autovacuum_custom, - (CASE WHEN array_length(tst.reloptions, 1) > 0 AND rel.reltoastrelid != 0 THEN true ELSE false END) AS toast_autovacuum, - (SELECT array_agg(provider || '=' || label) FROM pg_seclabels sl1 WHERE sl1.objoid=rel.oid AND sl1.objsubid=0) AS seclabels, (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table -- Added for partition table diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/11_plus/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/11_plus/update.sql index 0f27dbed2..d5b9d367c 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/11_plus/update.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/11_plus/update.sql @@ -115,14 +115,14 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} RESET ( autovacuum_freeze_table_age ); {% else %} -{% if data.autovacuum_enabled is defined or has_vacuum_set %} +{% if (data.autovacuum_enabled in ('t', 'f') and data.autovacuum_enabled != o_data.autovacuum_enabled) or has_vacuum_set %} ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET ( -{% if data.autovacuum_enabled is defined and data.autovacuum_enabled != o_data.autovacuum_enabled %} - autovacuum_enabled = {% if data.autovacuum_enabled %}true{% else %}false{% endif %}{% if has_vacuum_set %}, +{% if data.autovacuum_enabled in ('t', 'f') and data.autovacuum_enabled != o_data.autovacuum_enabled %} + autovacuum_enabled = {% if data.autovacuum_enabled == 't' %}true{% else %}false{% endif %}{% if has_vacuum_set %}, {% endif %} {% endif %} {% if has_vacuum_set %} -{% for opt in data.vacuum_table.set_values %}{% if opt.name and opt.value %} +{% for opt in data.vacuum_table.set_values %}{% if opt.name and opt.value is defined %} {{opt.name}} = {{opt.value}}{% if not loop.last %}, {% endif %} {% endif %} @@ -131,13 +131,19 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET ( ); {% endif %} -{% if has_vacuum_reset %} +{% if (data.autovacuum_enabled == 'x' and data.autovacuum_enabled != o_data.autovacuum_enabled) or has_vacuum_reset %} ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} RESET ( +{% if data.autovacuum_enabled =='x' and data.autovacuum_enabled != o_data.autovacuum_enabled %} + autovacuum_enabled{% if has_vacuum_reset %}, +{% endif %} +{% endif %} +{% if has_vacuum_reset %} {% for opt in data.vacuum_table.reset_values %}{% if opt.name %} {{opt.name}}{% if not loop.last %}, {% endif %} {% endif %} {% endfor %} +{% endif %} ); {% endif %} @@ -165,14 +171,14 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} RESET ( toast.autovacuum_analyze_scale_factor ); {% else %} -{% if data.toast_autovacuum_enabled is defined or has_vacuum_toast_set %} +{% if (data.toast_autovacuum_enabled in ('t', 'f') and data.toast_autovacuum_enabled != o_data.toast_autovacuum_enabled) or has_vacuum_toast_set %} ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET ( -{% if data.toast_autovacuum_enabled is defined and data.toast_autovacuum_enabled != o_data.toast_autovacuum_enabled %} - toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled %}true{% else %}false{% endif %}{% if has_vacuum_toast_set %}, +{% if data.toast_autovacuum_enabled in ('t', 'f') and data.toast_autovacuum_enabled != o_data.toast_autovacuum_enabled %} + toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}true{% else %}false{% endif %}{% if has_vacuum_toast_set %}, {% endif %} {% endif %} {% if has_vacuum_toast_set %} -{% for opt in data.vacuum_toast.set_values %}{% if opt.name and opt.value %} +{% for opt in data.vacuum_toast.set_values %}{% if opt.name and opt.value is defined %} toast.{{opt.name}} = {{opt.value}}{% if not loop.last %}, {% endif %} {% endif %} @@ -181,13 +187,19 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET ( ); {% endif %} -{% if has_vacuum_toast_reset %} +{% if (data.toast_autovacuum_enabled == 'x' and data.toast_autovacuum_enabled != o_data.toast_autovacuum_enabled) or has_vacuum_toast_reset %} ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} RESET ( +{% if data.toast_autovacuum_enabled == 'x' and data.toast_autovacuum_enabled != o_data.toast_autovacuum_enabled %} + toast.autovacuum_enabled{% if has_vacuum_toast_reset %}, +{% endif %} +{% endif %} +{% if has_vacuum_toast_reset %} {% for opt in data.vacuum_toast.reset_values %}{% if opt.name %} toast.{{opt.name}}{% if not loop.last %}, {% endif %} {% endif %} {% endfor %} +{% endif %} ); {% endif %} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/12_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/12_plus/create.sql index 486bc3091..79d5d74b6 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/12_plus/create.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/12_plus/create.sql @@ -17,7 +17,7 @@ {% set empty_bracket = "\n(\n)"%} {% endif %} {% set with_clause = false%} -{% if data.fillfactor or data.parallel_workers or data.toast_tuple_target 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) %} +{% if data.fillfactor or data.parallel_workers or data.toast_tuple_target or data.autovacuum_custom or data.autovacuum_enabled in ('t', 'f') or data.toast_autovacuum or data.toast_autovacuum_enabled in ('t', 'f') %} {% set with_clause = true%} {% endif %} CREATE {% if data.relpersistence %}UNLOGGED {% endif %}TABLE {{conn|qtIdent(data.schema, data.name)}}{{empty_bracket}} @@ -83,30 +83,31 @@ CACHE {{c.seqcache|int}} {% endif %} {% endif %} {% if with_clause %} -{% set add_comma = false%} +{% set ns = namespace(add_comma=false) %} WITH ( -{% if data.fillfactor %}{% set add_comma = true%} +{% if data.fillfactor %}{% set ns.add_comma = true%} FILLFACTOR = {{ data.fillfactor }}{% endif %}{% if data.parallel_workers %} -{% if add_comma %}, +{% if ns.add_comma %}, {% endif %} - parallel_workers = {{ data.parallel_workers }}{% set add_comma = true%}{% endif %}{% if data.toast_tuple_target %} -{% if add_comma %}, + parallel_workers = {{ data.parallel_workers }}{% set ns.add_comma = true%}{% endif %}{% if data.toast_tuple_target %} +{% if ns.add_comma %}, {% endif %} - toast_tuple_target = {{ data.toast_tuple_target }}{% set add_comma = true%}{% endif %}{% if data.autovacuum_custom %} -{% if add_comma %}, + toast_tuple_target = {{ data.toast_tuple_target }}{% set ns.add_comma = true%}{% 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.{{opt.name}} = {{opt.value}}{% endif %} + toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}TRUE{% else %}FALSE{% endif %}{% set ns.add_comma = true%}{% endif %}{% if data.autovacuum_custom %} +{% for opt in data.vacuum_table %}{% if opt.name and opt.value is defined %} +{% if ns.add_comma %}, +{% endif %} + {{opt.name}} = {{opt.value}}{% set ns.add_comma = true%}{% endif %} +{% endfor %}{% endif %}{% if data.toast_autovacuum %} +{% for opt in data.vacuum_toast %}{% if opt.name and opt.value is defined %} +{% if ns.add_comma %}, +{% endif %} + toast.{{opt.name}} = {{opt.value}}{% set ns.add_comma = true%}{% endif %} {% endfor %}{% endif %} {% if data.spcname %}){% else %});{% endif %} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/12_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/12_plus/properties.sql index d283cef22..1a7aec47e 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/12_plus/properties.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/12_plus/properties.sql @@ -29,8 +29,7 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r substring(array_to_string(rel.reloptions, ',') FROM 'fillfactor=([0-9]*)') AS fillfactor, substring(array_to_string(rel.reloptions, ',') FROM 'parallel_workers=([0-9]*)') AS parallel_workers, substring(array_to_string(rel.reloptions, ',') FROM 'toast_tuple_target=([0-9]*)') AS toast_tuple_target, - (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, @@ -40,8 +39,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, @@ -51,16 +49,10 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS toast_autovacuum_freeze_min_age, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS toast_autovacuum_freeze_max_age, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age, - array_to_string(rel.reloptions, ',') AS table_vacuum_settings_str, - array_to_string(tst.reloptions, ',') AS toast_table_vacuum_settings_str, rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, rel.reloftype, CASE WHEN typ.typname IS NOT NULL THEN (select quote_ident(nspname) FROM pg_namespace WHERE oid = {{scid}}::oid )||'.'||quote_ident(typ.typname) ELSE typ.typname END AS typname, typ.typrelid AS typoid, (CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, - -- Added for pgAdmin4 - (array_to_string(rel.reloptions, ',') like '%autovacuum%') AS autovacuum_custom, - (CASE WHEN array_length(tst.reloptions, 1) > 0 AND rel.reltoastrelid != 0 THEN true ELSE false END) AS toast_autovacuum, - (SELECT array_agg(provider || '=' || label) FROM pg_seclabels sl1 WHERE sl1.objoid=rel.oid AND sl1.objsubid=0) AS seclabels, (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table -- Added for partition table diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/12_plus/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/12_plus/update.sql index e2415ad2a..b8b4da665 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/12_plus/update.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/12_plus/update.sql @@ -51,7 +51,7 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} {% endif %} {#####################################################} -{## change fillfactore settings ##} +{## change fillfactor settings ##} {#####################################################} {% if data.fillfactor and data.fillfactor != o_data.fillfactor %} ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} @@ -107,14 +107,14 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} RESET ( autovacuum_freeze_table_age ); {% else %} -{% if data.autovacuum_enabled is defined or has_vacuum_set %} +{% if (data.autovacuum_enabled in ('t', 'f') and data.autovacuum_enabled != o_data.autovacuum_enabled) or has_vacuum_set %} ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET ( -{% if data.autovacuum_enabled is defined and data.autovacuum_enabled != o_data.autovacuum_enabled %} - autovacuum_enabled = {% if data.autovacuum_enabled %}true{% else %}false{% endif %}{% if has_vacuum_set %}, +{% if data.autovacuum_enabled in ('t', 'f') and data.autovacuum_enabled != o_data.autovacuum_enabled %} + autovacuum_enabled = {% if data.autovacuum_enabled == 't' %}true{% else %}false{% endif %}{% if has_vacuum_set %}, {% endif %} {% endif %} {% if has_vacuum_set %} -{% for opt in data.vacuum_table.set_values %}{% if opt.name and opt.value %} +{% for opt in data.vacuum_table.set_values %}{% if opt.name and opt.value is defined %} {{opt.name}} = {{opt.value}}{% if not loop.last %}, {% endif %} {% endif %} @@ -123,13 +123,19 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET ( ); {% endif %} -{% if has_vacuum_reset %} +{% if (data.autovacuum_enabled == 'x' and data.autovacuum_enabled != o_data.autovacuum_enabled) or has_vacuum_reset %} ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} RESET ( +{% if data.autovacuum_enabled =='x' and data.autovacuum_enabled != o_data.autovacuum_enabled %} + autovacuum_enabled{% if has_vacuum_reset %}, +{% endif %} +{% endif %} +{% if has_vacuum_reset %} {% for opt in data.vacuum_table.reset_values %}{% if opt.name %} {{opt.name}}{% if not loop.last %}, {% endif %} {% endif %} {% endfor %} +{% endif %} ); {% endif %} @@ -157,14 +163,14 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} RESET ( toast.autovacuum_analyze_scale_factor ); {% else %} -{% if data.toast_autovacuum_enabled is defined or has_vacuum_toast_set %} +{% if (data.toast_autovacuum_enabled in ('t', 'f') and data.toast_autovacuum_enabled != o_data.toast_autovacuum_enabled) or has_vacuum_toast_set %} ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET ( -{% if data.toast_autovacuum_enabled is defined and data.toast_autovacuum_enabled != o_data.toast_autovacuum_enabled %} - toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled %}true{% else %}false{% endif %}{% if has_vacuum_toast_set %}, +{% if data.toast_autovacuum_enabled in ('t', 'f') and data.toast_autovacuum_enabled != o_data.toast_autovacuum_enabled %} + toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}true{% else %}false{% endif %}{% if has_vacuum_toast_set %}, {% endif %} {% endif %} {% if has_vacuum_toast_set %} -{% for opt in data.vacuum_toast.set_values %}{% if opt.name and opt.value %} +{% for opt in data.vacuum_toast.set_values %}{% if opt.name and opt.value is defined %} toast.{{opt.name}} = {{opt.value}}{% if not loop.last %}, {% endif %} {% endif %} @@ -173,13 +179,19 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET ( ); {% endif %} -{% if has_vacuum_toast_reset %} +{% if (data.toast_autovacuum_enabled == 'x' and data.toast_autovacuum_enabled != o_data.toast_autovacuum_enabled) or has_vacuum_toast_reset %} ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} RESET ( +{% if data.toast_autovacuum_enabled == 'x' and data.toast_autovacuum_enabled != o_data.toast_autovacuum_enabled %} + toast.autovacuum_enabled{% if has_vacuum_toast_reset %}, +{% endif %} +{% endif %} +{% if has_vacuum_toast_reset %} {% for opt in data.vacuum_toast.reset_values %}{% if opt.name %} toast.{{opt.name}}{% if not loop.last %}, {% endif %} {% endif %} {% endfor %} +{% endif %} ); {% endif %} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/9.1_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/9.1_plus/properties.sql index eaa5c1056..ef3bcfd9a 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/9.1_plus/properties.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/9.1_plus/properties.sql @@ -26,8 +26,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, @@ -37,8 +36,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, @@ -48,16 +46,10 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS toast_autovacuum_freeze_min_age, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS toast_autovacuum_freeze_max_age, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age, - array_to_string(rel.reloptions, ',') AS table_vacuum_settings_str, - array_to_string(tst.reloptions, ',') AS toast_table_vacuum_settings_str, rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, rel.reloftype, CASE WHEN typ.typname IS NOT NULL THEN (select quote_ident(nspname) FROM pg_namespace WHERE oid = {{scid}}::oid )||'.'||quote_ident(typ.typname) ELSE typ.typname END AS typname, typ.typrelid AS typoid, (CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, - -- Added for pgAdmin4 - (CASE WHEN array_length(rel.reloptions, 1) > 0 THEN true ELSE false END) AS autovacuum_custom, - (CASE WHEN array_length(tst.reloptions, 1) > 0 AND rel.reltoastrelid != 0 THEN true ELSE false END) AS toast_autovacuum, - (SELECT array_agg(provider || '=' || label) FROM pg_seclabels sl1 WHERE sl1.objoid=rel.oid AND sl1.objsubid=0) AS seclabels, (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table FROM pg_class rel diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/9.6_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/9.6_plus/create.sql index 87df7a386..9f32fb855 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/9.6_plus/create.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/9.6_plus/create.sql @@ -66,15 +66,15 @@ CREATE {% if data.relpersistence %}UNLOGGED {% endif %}TABLE {{conn|qtIdent(data WITH ( OIDS = {% if data.relhasoids %}TRUE{% else %}FALSE{% endif %}{% if data.fillfactor %}, FILLFACTOR = {{ data.fillfactor }}{% endif %}{% if data.parallel_workers is defined and data.parallel_workers != '' and data.parallel_workers != None %}, - parallel_workers = {{ data.parallel_workers }}{% endif %}{% if data.autovacuum_custom %}, - autovacuum_enabled = {% if data.autovacuum_enabled %}TRUE{% else %}FALSE{% endif %}{% endif %}{% if data.toast_autovacuum %}, - 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 %} + parallel_workers = {{ data.parallel_workers }}{% endif %}{% if data.autovacuum_enabled in ('t', 'f') %}, + autovacuum_enabled = {% if data.autovacuum_enabled == 't' %}TRUE{% else %}FALSE{% endif %}{% endif %}{% if data.toast_autovacuum_enabled in ('t', 'f') %}, + toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}TRUE{% else %}FALSE{% endif %} +{% 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 %} , {{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 %} +{% 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/tables/sql/9.6_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/9.6_plus/properties.sql index b43658d14..444fe27c0 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/9.6_plus/properties.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/9.6_plus/properties.sql @@ -27,8 +27,7 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r (CASE WHEN rel.relpersistence = 'u' THEN true ELSE false END) AS relpersistence, substring(array_to_string(rel.reloptions, ',') FROM 'fillfactor=([0-9]*)') AS fillfactor, substring(array_to_string(rel.reloptions, ',') FROM 'parallel_workers=([0-9]*)') AS parallel_workers, - (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, @@ -49,16 +47,10 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS toast_autovacuum_freeze_min_age, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS toast_autovacuum_freeze_max_age, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age, - array_to_string(rel.reloptions, ',') AS table_vacuum_settings_str, - array_to_string(tst.reloptions, ',') AS toast_table_vacuum_settings_str, rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, rel.reloftype, CASE WHEN typ.typname IS NOT NULL THEN (select quote_ident(nspname) FROM pg_namespace WHERE oid = {{scid}}::oid )||'.'||quote_ident(typ.typname) ELSE typ.typname END AS typname, typ.typrelid AS typoid, (CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, - -- Added for pgAdmin4 - (array_to_string(rel.reloptions, ',') like '%autovacuum%') AS autovacuum_custom, - (CASE WHEN array_length(tst.reloptions, 1) > 0 AND rel.reltoastrelid != 0 THEN true ELSE false END) AS toast_autovacuum, - (SELECT array_agg(provider || '=' || label) FROM pg_seclabels sl1 WHERE sl1.objoid=rel.oid AND sl1.objsubid=0) AS seclabels, (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table FROM pg_class rel diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/9.6_plus/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/9.6_plus/update.sql index 98e9ebf4b..fc44fe8bc 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/9.6_plus/update.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/9.6_plus/update.sql @@ -103,14 +103,14 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} RESET ( autovacuum_freeze_table_age ); {% else %} -{% if data.autovacuum_enabled is defined or has_vacuum_set %} +{% if (data.autovacuum_enabled in ('t', 'f') and data.autovacuum_enabled != o_data.autovacuum_enabled) or has_vacuum_set %} ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET ( -{% if data.autovacuum_enabled is defined and data.autovacuum_enabled != o_data.autovacuum_enabled %} - autovacuum_enabled = {% if data.autovacuum_enabled %}true{% else %}false{% endif %}{% if has_vacuum_set %}, +{% if data.autovacuum_enabled in ('t', 'f') and data.autovacuum_enabled != o_data.autovacuum_enabled %} + autovacuum_enabled = {% if data.autovacuum_enabled == 't' %}true{% else %}false{% endif %}{% if has_vacuum_set %}, {% endif %} {% endif %} {% if has_vacuum_set %} -{% for opt in data.vacuum_table.set_values %}{% if opt.name and opt.value %} +{% for opt in data.vacuum_table.set_values %}{% if opt.name and opt.value is defined %} {{opt.name}} = {{opt.value}}{% if not loop.last %}, {% endif %} {% endif %} @@ -119,13 +119,19 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET ( ); {% endif %} -{% if has_vacuum_reset %} +{% if (data.autovacuum_enabled == 'x' and data.autovacuum_enabled != o_data.autovacuum_enabled) or has_vacuum_reset %} ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} RESET ( +{% if data.autovacuum_enabled =='x' and data.autovacuum_enabled != o_data.autovacuum_enabled %} + autovacuum_enabled{% if has_vacuum_reset %}, +{% endif %} +{% endif %} +{% if has_vacuum_reset %} {% for opt in data.vacuum_table.reset_values %}{% if opt.name %} {{opt.name}}{% if not loop.last %}, {% endif %} {% endif %} {% endfor %} +{% endif %} ); {% endif %} @@ -153,14 +159,14 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} RESET ( toast.autovacuum_analyze_scale_factor ); {% else %} -{% if data.toast_autovacuum_enabled is defined or has_vacuum_toast_set %} +{% if (data.toast_autovacuum_enabled in ('t', 'f') and data.toast_autovacuum_enabled != o_data.toast_autovacuum_enabled) or has_vacuum_toast_set %} ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET ( -{% if data.toast_autovacuum_enabled is defined and data.toast_autovacuum_enabled != o_data.toast_autovacuum_enabled %} - toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled %}true{% else %}false{% endif %}{% if has_vacuum_toast_set %}, +{% if data.toast_autovacuum_enabled in ('t', 'f') and data.toast_autovacuum_enabled != o_data.toast_autovacuum_enabled %} + toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}true{% else %}false{% endif %}{% if has_vacuum_toast_set %}, {% endif %} {% endif %} {% if has_vacuum_toast_set %} -{% for opt in data.vacuum_toast.set_values %}{% if opt.name and opt.value %} +{% for opt in data.vacuum_toast.set_values %}{% if opt.name and opt.value is defined %} toast.{{opt.name}} = {{opt.value}}{% if not loop.last %}, {% endif %} {% endif %} @@ -169,13 +175,19 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET ( ); {% endif %} -{% if has_vacuum_toast_reset %} +{% if (data.toast_autovacuum_enabled == 'x' and data.toast_autovacuum_enabled != o_data.toast_autovacuum_enabled) or has_vacuum_toast_reset %} ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} RESET ( +{% if data.toast_autovacuum_enabled == 'x' and data.toast_autovacuum_enabled != o_data.toast_autovacuum_enabled %} + toast.autovacuum_enabled{% if has_vacuum_toast_reset %}, +{% endif %} +{% endif %} +{% if has_vacuum_toast_reset %} {% for opt in data.vacuum_toast.reset_values %}{% if opt.name %} toast.{{opt.name}}{% if not loop.last %}, {% endif %} {% endif %} {% endfor %} +{% endif %} ); {% endif %} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/default/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/default/create.sql index 25b243041..9553d99bb 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/default/create.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/default/create.sql @@ -65,15 +65,15 @@ CREATE {% if data.relpersistence %}UNLOGGED {% endif %}TABLE {{conn|qtIdent(data {% endif %} WITH ( OIDS = {% if data.relhasoids %}TRUE{% else %}FALSE{% endif %}{% if data.fillfactor %}, - FILLFACTOR = {{ data.fillfactor }}{% endif %}{% if data.autovacuum_custom %}, - autovacuum_enabled = {% if data.autovacuum_enabled %}TRUE{% else %}FALSE{% endif %}{% endif %}{% if data.toast_autovacuum %}, - 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 %} + FILLFACTOR = {{ data.fillfactor }}{% endif %}{% if data.autovacuum_enabled in ('t', 'f') %}, + autovacuum_enabled = {% if data.autovacuum_enabled == 't' %}TRUE{% else %}FALSE{% endif %}{% endif %}{% if data.toast_autovacuum_enabled in ('t', 'f') %}, + toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}TRUE{% else %}FALSE{% endif %} +{% 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 %} , {{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 %} +{% 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/tables/sql/default/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/default/properties.sql index 9bb7bc8b7..b5c3c2527 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/default/properties.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/default/properties.sql @@ -29,8 +29,7 @@ FROM ( 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, @@ -40,8 +39,7 @@ FROM ( 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, @@ -51,15 +49,9 @@ FROM ( substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS toast_autovacuum_freeze_min_age, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS toast_autovacuum_freeze_max_age, substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age, - array_to_string(rel.reloptions, ',') AS table_vacuum_settings_str, - array_to_string(tst.reloptions, ',') AS toast_table_vacuum_settings_str, rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, NULL AS reloftype, NULL AS typname, typ.typrelid AS typoid, (CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, - -- Added for pgAdmin4 - (array_to_string(rel.reloptions, ',') like '%autovacuum%') AS autovacuum_custom, - (CASE WHEN array_length(tst.reloptions, 1) > 0 AND rel.reltoastrelid != 0 THEN true ELSE false END) AS toast_autovacuum, - ARRAY[]::varchar[] AS seclabels, (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/default/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/default/update.sql index 36eb180db..09817343f 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/default/update.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/default/update.sql @@ -59,7 +59,7 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} {% endif %} {#####################################################} -{## change fillfactore settings ##} +{## change fillfactor settings ##} {#####################################################} {% if data.fillfactor and data.fillfactor != o_data.fillfactor %} ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} @@ -92,14 +92,14 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} RESET ( autovacuum_freeze_table_age ); {% else %} -{% if data.autovacuum_enabled is defined or has_vacuum_set %} +{% if (data.autovacuum_enabled in ('t', 'f') and data.autovacuum_enabled != o_data.autovacuum_enabled) or has_vacuum_set %} ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET ( -{% if data.autovacuum_enabled is defined and data.autovacuum_enabled != o_data.autovacuum_enabled %} - autovacuum_enabled = {% if data.autovacuum_enabled %}true{% else %}false{% endif %}{% if has_vacuum_set %}, +{% if data.autovacuum_enabled in ('t', 'f') and data.autovacuum_enabled != o_data.autovacuum_enabled %} + autovacuum_enabled = {% if data.autovacuum_enabled == 't' %}true{% else %}false{% endif %}{% if has_vacuum_set %}, {% endif %} {% endif %} {% if has_vacuum_set %} -{% for opt in data.vacuum_table.set_values %}{% if opt.name and opt.value %} +{% for opt in data.vacuum_table.set_values %}{% if opt.name and opt.value is defined %} {{opt.name}} = {{opt.value}}{% if not loop.last %}, {% endif %} {% endif %} @@ -108,13 +108,19 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET ( ); {% endif %} -{% if has_vacuum_reset %} +{% if (data.autovacuum_enabled == 'x' and data.autovacuum_enabled != o_data.autovacuum_enabled) or has_vacuum_reset %} ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} RESET ( +{% if data.autovacuum_enabled =='x' and data.autovacuum_enabled != o_data.autovacuum_enabled %} + autovacuum_enabled{% if has_vacuum_reset %}, +{% endif %} +{% endif %} +{% if has_vacuum_reset %} {% for opt in data.vacuum_table.reset_values %}{% if opt.name %} {{opt.name}}{% if not loop.last %}, {% endif %} {% endif %} {% endfor %} +{% endif %} ); {% endif %} @@ -142,14 +148,14 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} RESET ( toast.autovacuum_analyze_scale_factor ); {% else %} -{% if data.toast_autovacuum_enabled is defined or has_vacuum_toast_set %} +{% if (data.toast_autovacuum_enabled in ('t', 'f') and data.toast_autovacuum_enabled != o_data.toast_autovacuum_enabled) or has_vacuum_toast_set %} ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET ( -{% if data.toast_autovacuum_enabled is defined and data.toast_autovacuum_enabled != o_data.toast_autovacuum_enabled %} - toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled %}true{% else %}false{% endif %}{% if has_vacuum_toast_set %}, +{% if data.toast_autovacuum_enabled in ('t', 'f') and data.toast_autovacuum_enabled != o_data.toast_autovacuum_enabled %} + toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}true{% else %}false{% endif %}{% if has_vacuum_toast_set %}, {% endif %} {% endif %} {% if has_vacuum_toast_set %} -{% for opt in data.vacuum_toast.set_values %}{% if opt.name and opt.value %} +{% for opt in data.vacuum_toast.set_values %}{% if opt.name and opt.value is defined %} toast.{{opt.name}} = {{opt.value}}{% if not loop.last %}, {% endif %} {% endif %} @@ -158,13 +164,19 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET ( ); {% endif %} -{% if has_vacuum_toast_reset %} +{% if (data.toast_autovacuum_enabled == 'x' and data.toast_autovacuum_enabled != o_data.toast_autovacuum_enabled) or has_vacuum_toast_reset %} ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} RESET ( +{% if data.toast_autovacuum_enabled == 'x' and data.toast_autovacuum_enabled != o_data.toast_autovacuum_enabled %} + toast.autovacuum_enabled{% if has_vacuum_toast_reset %}, +{% endif %} +{% endif %} +{% if has_vacuum_toast_reset %} {% for opt in data.vacuum_toast.reset_values %}{% if opt.name %} toast.{{opt.name}}{% if not loop.last %}, {% endif %} {% endif %} {% endfor %} +{% endif %} ); {% endif %} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_5.0_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_5.0_plus/properties.sql index 356a94f15..738608c54 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_5.0_plus/properties.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_5.0_plus/properties.sql @@ -62,10 +62,6 @@ FROM ( rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, NULL AS reloftype, typ.typname AS typname, typ.typrelid AS typoid, (CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, - -- Added for pgAdmin4 - (CASE WHEN array_length(rel.reloptions, 1) > 0 THEN true ELSE false END) AS autovacuum_custom, - (CASE WHEN array_length(tst.reloptions, 1) > 0 AND rel.reltoastrelid != 0 THEN true ELSE false END) AS toast_autovacuum, - ARRAY[]::varchar[] AS seclabels, (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_table_parameters.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_table_parameters.py index bbed26998..4bd59f5c1 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_table_parameters.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_table_parameters.py @@ -25,25 +25,104 @@ class TableUpdateParameterTestCase(BaseTestGenerator): """This class will add new collation under schema node.""" scenarios = [ # Fetching default URL for table node. - ('Enable custom auto vacuum and set the parameters for table', - dict(url='/browser/table/obj/', type='set_vacuum_parameters') + ('Enable custom auto vacuum and set the parameters for table ' + 'without autovacuum_enabled', + dict(url='/browser/table/obj/', + api_data={ + 'autovacuum_custom': True, + 'vacuum_table': { + 'changed': [ + {'name': 'autovacuum_vacuum_cost_delay', + 'value': 20}, + {'name': 'autovacuum_vacuum_threshold', + 'value': 20} + ] + }} + ) ), - ('Disable auto vacuum and reset the parameters for table', - dict(url='/browser/table/obj/', type='reset_vacuum_parameters') + ('Change a parameter to zero value ' + 'without autovacuum_enabled', + dict(url='/browser/table/obj/', + api_data={ + 'vacuum_table': { + 'changed': [ + {'name': 'autovacuum_vacuum_cost_delay', + 'value': 0} + ] + }} + ) ), - ('Disable custom auto vacuum and reset all the parameters for table', - dict(url='/browser/table/obj/', type='reset_all_vacuum_parameters') + ('Enable autovacuum_enabled', + dict(url='/browser/table/obj/', + api_data={'autovacuum_enabled': 't'} + ) ), - ('Enable custom auto vacuum and set the toast parameters for table', - dict(url='/browser/table/obj/', type='set_toast_parameters') + ('Reset individual parameters for table', + dict(url='/browser/table/obj/', + api_data={ + 'autovacuum_enabled': 'x', + 'vacuum_table': { + 'changed': [ + {'name': 'autovacuum_vacuum_cost_delay', + 'value': None}, + ] + }} + ) ), - ('Disable auto vacuum and reset the toast parameters for table', - dict(url='/browser/table/obj/', type='reset_toast_parameters') + ('Reset custom auto vacuum', + dict(url='/browser/table/obj/', + api_data={'autovacuum_custom': False} + ) + ), + ('Enable toast custom auto vacuum and set the parameters for table ' + 'without autovacuum_enabled', + dict(url='/browser/table/obj/', + api_data={ + 'toast_autovacuum': True, + 'vacuum_toast': { + 'changed': [ + {'name': 'autovacuum_vacuum_cost_delay', + 'value': 20}, + {'name': 'autovacuum_vacuum_threshold', + 'value': 20} + ] + }} + ) + ), + ('Change a toast parameter to zero value ' + 'without autovacuum_enabled', + dict(url='/browser/table/obj/', + api_data={ + 'vacuum_toast': { + 'changed': [ + {'name': 'autovacuum_vacuum_cost_delay', + 'value': 0} + ] + }} + ) + ), + ('Enable toast.autovacuum_enabled', + dict(url='/browser/table/obj/', + api_data={'toast_autovacuum_enabled': 't'} + ) + ), + ('Reset individual toast parameters for table', + dict(url='/browser/table/obj/', + api_data={ + 'toast_autovacuum_enabled': 'x', + 'vacuum_toast': { + 'changed': [ + {'name': 'autovacuum_vacuum_cost_delay', + 'value': None}, + ] + }} + ) + ), + ('Reset auto vacuum', + dict(url='/browser/table/obj/', + api_data={'toast_autovacuum': False} + ) ), - ('Disable custom auto vacuum and reset all the toast ' - 'parameters for table', - dict(url='/browser/table/obj/', type='reset_all_toast_parameters') - ) ] @classmethod @@ -77,50 +156,8 @@ class TableUpdateParameterTestCase(BaseTestGenerator): if not table_response: raise Exception("Could not find the table to update.") - data = None - if self.type == 'set_vacuum_parameters': - data = dict({'oid': self.table_id, - 'autovacuum_custom': True, - 'autovacuum_enabled': True, - 'vacuum_table': dict({'changed': [ - {'name': 'autovacuum_vacuum_cost_delay', - 'value': 20}, - {'name': 'autovacuum_vacuum_threshold', - 'value': 20} - ]})}) - elif self.type == 'reset_vacuum_parameters': - data = dict({'oid': self.table_id, - 'autovacuum_enabled': False, - 'vacuum_table': dict({'changed': [ - {'name': 'autovacuum_vacuum_cost_delay', - 'value': None}, - {'name': 'autovacuum_vacuum_threshold', - 'value': None} - ]})}) - elif self.type == 'reset_all_vacuum_parameters': - data = dict({'oid': self.table_id, 'autovacuum_custom': False}) - elif self.type == 'set_toast_parameters': - data = dict({'oid': self.table_id, - 'autovacuum_custom': True, - 'autovacuum_enabled': True, - 'vacuum_toast': dict({'changed': [ - {'name': 'autovacuum_vacuum_cost_delay', - 'value': 20}, - {'name': 'autovacuum_vacuum_threshold', - 'value': 20} - ]})}) - elif self.type == 'reset_toast_parameters': - data = dict({'oid': self.table_id, - 'autovacuum_enabled': False, - 'vacuum_toast': dict({'changed': [ - {'name': 'autovacuum_vacuum_cost_delay', - 'value': None}, - {'name': 'autovacuum_vacuum_threshold', - 'value': None} - ]})}) - elif self.type == 'reset_all_toast_parameters': - data = dict({'oid': self.table_id, 'autovacuum_custom': False}) - + data = self.api_data + data['oid'] = self.table_id response = self.tester.put(self.url + str(utils.SERVER_GROUP) + '/' + str(self.server_id) + '/' + str(self.db_id) + '/' + 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 c552006ab..6a442bfd6 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 @@ -1029,6 +1029,11 @@ class BaseTableView(PGChildNodeView, BasePartitionTable): data['partition_scheme'] = self.get_partition_scheme(data) partitions_sql = self.get_partitions_sql(data) + # Update the vacuum table settings. + self.update_vacuum_settings('vacuum_table', data) + # Update the vacuum toast table settings. + self.update_vacuum_settings('vacuum_toast', data) + SQL = render_template("/".join([self.table_template_path, 'create.sql']), data=data, conn=self.conn) @@ -1191,21 +1196,20 @@ class BaseTableView(PGChildNodeView, BasePartitionTable): """ data = res['rows'][0] - data['vacuum_settings_str'] = "" + data['vacuum_settings_str'] = '' - if data['table_vacuum_settings_str'] is not None: - data['vacuum_settings_str'] += data[ - 'table_vacuum_settings_str'].replace(',', '\n') + if data['reloptions'] is not None: + data['vacuum_settings_str'] += '\n'.join(data['reloptions']) + + if data['toast_reloptions'] is not None: + data['vacuum_settings_str'] += '\n' \ + if data['vacuum_settings_str'] != '' else '' + data['vacuum_settings_str'] += '\n'.\ + join(map(lambda o: 'toast.' + o, data['toast_reloptions'])) - if data['toast_table_vacuum_settings_str'] is not None: - data['vacuum_settings_str'] += '\n' + '\n'.join( - ['toast_' + setting for setting in data[ - 'toast_table_vacuum_settings_str' - ].split(',')] - ) data['vacuum_settings_str'] = data[ 'vacuum_settings_str' - ].replace("=", " = ") + ].replace('=', ' = ') data = self._formatter(did, scid, tid, data) @@ -1496,7 +1500,7 @@ class BaseTableView(PGChildNodeView, BasePartitionTable): return schema_name, table_name - def update_vacuum_settings(self, vacuum_key, old_data, data): + def update_vacuum_settings(self, vacuum_key, old_data, data=None): """ This function iterate the vacuum and vacuum toast table and create two new dictionaries. One for set parameter and another for reset. @@ -1507,8 +1511,14 @@ class BaseTableView(PGChildNodeView, BasePartitionTable): :return: """ + # When creating a table old_data is the actual data + if data is None: + if vacuum_key in old_data: + for opt in old_data[vacuum_key]: + if 'value' in opt and opt['value'] is None: + opt.pop('value') # Iterate vacuum table - if vacuum_key in data and 'changed' in data[vacuum_key] \ + elif vacuum_key in data and 'changed' in data[vacuum_key] \ and vacuum_key in old_data: set_values = [] reset_values = [] diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py index be3c43c52..f7b8e701b 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py @@ -10,6 +10,7 @@ """Schema collection node helper class""" import json +import copy from flask import render_template @@ -575,8 +576,8 @@ class VacuumSettings: * type - table/toast vacuum type """ - vacuum_settings_tmp = self.fetch_default_vacuum_settings( - conn, self.manager.sid, type) + vacuum_settings_tmp = copy.deepcopy(self.fetch_default_vacuum_settings( + conn, self.manager.sid, type)) for row in vacuum_settings_tmp: row_name = row['name'] @@ -585,6 +586,7 @@ class VacuumSettings: if row_name in result and result[row_name] is not None: if row['column_type'] == 'number': value = float(result[row_name]) + value = int(value) if value % 1 == 0 else value else: value = int(result[row_name]) row['value'] = value diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/__init__.py index c64de73bd..60ff902bf 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/__init__.py @@ -1619,27 +1619,17 @@ class MViewNode(ViewNode, VacuumSettings): This function will generate sql from model data """ if vid is not None: - SQL = render_template("/".join( - [self.template_path, 'sql/properties.sql']), - did=did, - vid=vid, - datlastsysoid=self.datlastsysoid - ) - status, res = self.conn.execute_dict(SQL) - if not status: - return None, internal_server_error(errormsg=res) - if len(res['rows']) == 0: - return None, gone( - gettext( - "Could not find the materialized view on the server.") - ) + status, res = self._fetch_properties(did, None, vid) - old_data = res['rows'][0] + if not status: + return res + + old_data = res if 'name' not in data: - data['name'] = res['rows'][0]['name'] + data['name'] = res['name'] if 'schema' not in data: - data['schema'] = res['rows'][0]['schema'] + data['schema'] = res['schema'] # merge vacuum lists into one data['vacuum_data'] = {} @@ -1660,26 +1650,6 @@ class MViewNode(ViewNode, VacuumSettings): item['value']))): data['vacuum_data']['changed'].append(item) - if ( - 'autovacuum_enabled' in data and - old_data['autovacuum_enabled'] is not None - ): - if ( - data['autovacuum_enabled'] != - old_data['autovacuum_enabled'] - ): - data['vacuum_data']['changed'].append( - {'name': 'autovacuum_enabled', - 'value': data['autovacuum_enabled']}) - elif ( - 'autovacuum_enabled' in data and - 'autovacuum_custom' in data and - old_data['autovacuum_enabled'] is None and data[ - 'autovacuum_custom']): - data['vacuum_data']['changed'].append( - {'name': 'autovacuum_enabled', - 'value': data['autovacuum_enabled']}) - # toast autovacuum: separate list of changed and reset data if 'vacuum_toast' in data: if 'changed' in data['vacuum_toast']: @@ -1696,27 +1666,6 @@ class MViewNode(ViewNode, VacuumSettings): item['value']))): data['vacuum_data']['changed'].append(item) - if ( - 'toast_autovacuum_enabled' in data and - old_data['toast_autovacuum_enabled'] is not None - ): - if ( - data['toast_autovacuum_enabled'] != - old_data['toast_autovacuum_enabled'] - ): - data['vacuum_data']['changed'].append( - {'name': 'toast.autovacuum_enabled', - 'value': data['toast_autovacuum_enabled']}) - elif ( - 'toast_autovacuum_enabled' in data and - 'toast_autovacuum' in data and - old_data['toast_autovacuum_enabled'] is None and - data['toast_autovacuum'] - ): - data['vacuum_data']['changed'].append( - {'name': 'toast.autovacuum_enabled', - 'value': data['toast_autovacuum_enabled']}) - acls = [] try: acls = render_template( @@ -1762,32 +1711,15 @@ class MViewNode(ViewNode, VacuumSettings): data['schema'] = self._get_schema(data['schema']) # merge vacuum lists into one - vacuum_table = [item for item in data['vacuum_table'] + vacuum_table = [item for item in data.get('vacuum_table', []) if 'value' in item.keys() and item['value'] is not None] vacuum_toast = [ {'name': 'toast.' + item['name'], 'value': item['value']} - for item in data['vacuum_toast'] + for item in data.get('vacuum_toast', []) if 'value' in item.keys() and item['value'] is not None] - # add table_enabled & toast_enabled settings - if 'autovacuum_custom' in data and data['autovacuum_custom']: - vacuum_table.append( - { - 'name': 'autovacuum_enabled', - 'value': str(data['autovacuum_enabled']) - } - ) - if 'toast_autovacuum' in data and data['toast_autovacuum']: - vacuum_table.append( - { - 'name': 'toast.autovacuum_enabled', - 'value': str(data['toast_autovacuum_enabled']) - } - ) - - # add vacuum_toast dict to vacuum_data only if - # table & toast's custom autovacuum is enabled + # add vacuum_toast dict to vacuum_data data['vacuum_data'] = [] if ( 'autovacuum_custom' in data and @@ -1838,22 +1770,10 @@ class MViewNode(ViewNode, VacuumSettings): display_comments = False SQL_data = '' - SQL = render_template("/".join( - [self.template_path, 'sql/properties.sql']), - did=did, - vid=vid, - datlastsysoid=self.datlastsysoid - ) + status, result = self._fetch_properties(did, scid, vid) - status, res = self.conn.execute_dict(SQL) if not status: - return internal_server_error(errormsg=res) - if len(res['rows']) == 0: - return gone( - gettext("Could not find the materialized view on the server.") - ) - - result = res['rows'][0] + return result if diff_schema: result['definition'] = result['definition'].replace( @@ -1861,16 +1781,6 @@ class MViewNode(ViewNode, VacuumSettings): diff_schema) result['schema'] = diff_schema - # sending result to formtter - frmtd_reslt = self.formatter(result) - - # merging formated result with main result again - result.update(frmtd_reslt) - result['vacuum_table'] = self.parse_vacuum_data( - self.conn, result, 'table') - result['vacuum_toast'] = self.parse_vacuum_data( - self.conn, result, 'toast') - # merge vacuum lists into one vacuum_table = [item for item in result['vacuum_table'] if @@ -1880,43 +1790,7 @@ class MViewNode(ViewNode, VacuumSettings): for item in result['vacuum_toast'] if 'value' in item.keys() and item['value'] is not None] - if 'autovacuum_custom' in result and result['autovacuum_custom']: - vacuum_table.append( - { - 'name': 'autovacuum_enabled', - 'value': str(result['autovacuum_enabled']) - } - ) - if 'toast_autovacuum' in result and result['toast_autovacuum']: - vacuum_table.append( - { - 'name': 'toast.autovacuum_enabled', - 'value': str(result['toast_autovacuum_enabled']) - } - ) - - # add vacuum_toast dict to vacuum_data only if - # toast's autovacuum is enabled - if ( - 'toast_autovacuum_enabled' in result and - result['toast_autovacuum_enabled'] is True - ): - result['vacuum_data'] = vacuum_table + vacuum_toast - else: - result['vacuum_data'] = vacuum_table - - # Fetch all privileges for view - SQL = render_template("/".join( - [self.template_path, 'sql/acl.sql']), vid=vid) - status, dataclres = self.conn.execute_dict(SQL) - if not status: - return internal_server_error(errormsg=res) - - for row in dataclres['rows']: - priv = parse_priv_from_db(row) - res['rows'][0].setdefault(row['deftype'], []).append(priv) - - result.update(res['rows'][0]) + result['vacuum_data'] = vacuum_table + vacuum_toast acls = [] try: @@ -1996,6 +1870,7 @@ class MViewNode(ViewNode, VacuumSettings): and render in the properties tab """ status, res = self._fetch_properties(did, scid, vid) + if not status: return res @@ -2023,6 +1898,59 @@ class MViewNode(ViewNode, VacuumSettings): return False, gone( gettext("""Could not find the materialized view.""")) + # 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') + + res['rows'][0]['vacuum_settings_str'] = '' + + if res['rows'][0]['reloptions'] is not None: + res['rows'][0]['vacuum_settings_str'] += '\n'.\ + join(res['rows'][0]['reloptions']) + + if res['rows'][0]['toast_reloptions'] is not None: + res['rows'][0]['vacuum_settings_str'] += '\n' \ + if res['rows'][0]['vacuum_settings_str'] != "" else "" + res['rows'][0]['vacuum_settings_str'] += '\n'.\ + join(map(lambda o: 'toast.' + o, + res['rows'][0]['toast_reloptions'])) + + res['rows'][0]['vacuum_settings_str'] = res['rows'][0][ + 'vacuum_settings_str' + ].replace('=', ' = ') + SQL = render_template("/".join( [self.template_path, 'sql/acl.sql']), vid=vid) status, dataclres = self.conn.execute_dict(SQL) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/static/js/mview.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/static/js/mview.js index 34d45773c..5036f8a77 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/static/js/mview.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/static/js/mview.js @@ -58,6 +58,7 @@ define('pgadmin.node.mview', [ hasDepends: true, hasScriptTypes: ['create', 'select'], collection_type: 'coll-mview', + width: pgBrowser.stdW.md + 'px', Init: function() { // Avoid mulitple registration of menus @@ -140,8 +141,8 @@ define('pgadmin.node.mview', [ }, defaults: { spcname: undefined, - toast_autovacuum_enabled: false, - autovacuum_enabled: false, + toast_autovacuum_enabled: 'x', + autovacuum_enabled: 'x', warn_text: undefined, }, schema: [{ @@ -207,6 +208,9 @@ define('pgadmin.node.mview', [ id: 'fillfactor', label: gettext('Fill factor'), group: gettext('Storage'), mode: ['edit', 'create'], type: 'int', min: 10, max: 100, + },{ + id: 'vacuum_settings_str', label: gettext('Storage settings'), + type: 'multiline', group: gettext('Storage'), mode: ['properties'], },{ type: 'nested', control: 'tab', id: 'materialization', label: gettext('Parameter'), mode: ['edit', 'create'], @@ -228,6 +232,16 @@ define('pgadmin.node.mview', [ mode: ['edit', 'create'], canAdd: true, control: 'unique-col-collection', uniqueCol : ['provider'], }], + sessChanged: function() { + /* If only custom autovacuum option is enabled the 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) { // Triggers specific error messages for fields @@ -235,9 +249,11 @@ define('pgadmin.node.mview', [ errmsg, field_name = this.get('name'), field_def = this.get('definition'); - if (_.indexOf(keys, 'autovacuum_enabled') != -1 || + + if(_.indexOf(keys, 'autovacuum_custom')) + if (_.indexOf(keys, 'autovacuum_enabled') != -1 || _.indexOf(keys, 'toast_autovacuum_enabled') != -1 ) - return null; + return null; if (_.isUndefined(field_name) || _.isNull(field_name) || String(field_name).replace(/^\s+|\s+$/g, '') == '') { diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/pg/9.3_plus/sql/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/pg/9.3_plus/sql/create.sql index 89b200d39..f092223ac 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/pg/9.3_plus/sql/create.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/pg/9.3_plus/sql/create.sql @@ -7,15 +7,21 @@ {% endif %} {% if data.name and data.schema and data.definition %} CREATE MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} -{% if(data.fillfactor or data['vacuum_data']|length > 0) %} +{% if(data.fillfactor or data.autovacuum_enabled in ('t', 'f') or data.toast_autovacuum_enabled in ('t', 'f') or data['vacuum_data']|length > 0) %} +{% set ns = namespace(add_comma=false) %} WITH ( {% if data.fillfactor %} - FILLFACTOR = {{ data.fillfactor }}{% if data['autovacuum_enabled'] or data['toast_autovacuum_enabled'] or data['vacuum_data']|length > 0 %},{{ '\n' }}{% endif %} + FILLFACTOR = {{ data.fillfactor }}{% set ns.add_comma = true%}{% endif %}{% if data.autovacuum_enabled in ('t', 'f') %} +{% if ns.add_comma %}, {% endif %} + 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 == 't' %}TRUE{% else %}FALSE{% endif %}{% set ns.add_comma = true%}{% endif %} {% for field in data['vacuum_data'] %} {% if field.value is defined and field.value != '' and field.value != none %} -{% if loop.index > 1 %}, -{% endif %} {{ field.name }} = {{ field.value|lower }}{% endif %}{% endfor %} +{% if ns.add_comma %}, +{% endif %} {{ field.name }} = {{ field.value|lower }}{% set ns.add_comma = true%}{% endif %}{% endfor %} {{ '\n' }}) {% endif %} {% if data.spcname %}TABLESPACE {{ data.spcname }} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/pg/9.3_plus/sql/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/pg/9.3_plus/sql/properties.sql index df3fafcdc..39b435cb8 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/pg/9.3_plus/sql/properties.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/pg/9.3_plus/sql/properties.sql @@ -24,8 +24,7 @@ SELECT (SELECT array_agg(provider || '=' || label) FROM pg_seclabels sl1 WHERE sl1.objoid=c.oid AND sl1.objsubid=0) AS seclabels, substring(array_to_string(c.reloptions, ',') FROM 'fillfactor=([0-9]*)') AS fillfactor, - (CASE WHEN (substring(array_to_string(c.reloptions, ',') - FROM 'autovacuum_enabled=([a-z|0-9]*)') = 'true') THEN true ELSE false END) AS autovacuum_enabled, + (substring(array_to_string(c.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS autovacuum_enabled, substring(array_to_string(c.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS autovacuum_vacuum_threshold, substring(array_to_string(c.reloptions, ',') @@ -44,8 +43,7 @@ SELECT FROM 'autovacuum_freeze_max_age=([0-9]*)') AS autovacuum_freeze_max_age, substring(array_to_string(c.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, ',') @@ -65,9 +63,7 @@ SELECT substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age, c.reloptions AS reloptions, tst.reloptions AS toast_reloptions, - (CASE WHEN c.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, - (CASE WHEN array_length(c.reloptions, 1) > 0 THEN true ELSE false END) AS autovacuum_custom, - (CASE WHEN array_length(tst.reloptions, 1) > 0 AND c.reltoastrelid != 0 THEN true ELSE false END) AS toast_autovacuum + (CASE WHEN c.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable FROM pg_class c LEFT OUTER JOIN pg_namespace nsp on nsp.oid = c.relnamespace diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/pg/9.3_plus/sql/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/pg/9.3_plus/sql/update.sql index e7ab7ab07..dc752a2ec 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/pg/9.3_plus/sql/update.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/pg/9.3_plus/sql/update.sql @@ -27,14 +27,17 @@ ALTER TABLE {{ conn|qtIdent(view_schema, view_name) }} {% if def and def != o_data.definition.rstrip(';') %} DROP MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}; CREATE MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} -{% if data.fillfactor or (data['vacuum_data']['changed']|length > 0 ) %} +{% if data.fillfactor or o_data.fillfactor %} WITH( {% if data.fillfactor %} - FILLFACTOR = {{ data.fillfactor }}{% if data['vacuum_data']['changed']|length > 0 %},{% endif %}{{ '\r' }} + FILLFACTOR = {{ data.fillfactor }}{% if (data['vacuum_data'] is defined and data['vacuum_data']['changed']|length > 0) %},{% endif %} +{% elif o_data.fillfactor %} + FILLFACTOR = {{ o_data.fillfactor }}{% if (data['vacuum_data'] is defined and data['vacuum_data']['changed']|length > 0) %},{% endif %} {% endif %} + {% if data['vacuum_data']['changed']|length > 0 %} -{% for field in data['vacuum_data']['changed'] %} - {{ field.name }} = {{ field.value|lower }}{% if not loop.last %},{% endif %}{{ '\r' }} +{% for field in data['vacuum_data']['changed'] %} {{ field.name }} = {{ field.value|lower }}{% if not loop.last %}, +{% endif %} {% endfor %} {% endif %} ) @@ -43,11 +46,14 @@ WITH( {{ def }} {% if data.with_data is defined %} WITH {{ 'DATA' if data.with_data else 'NO DATA' }}; - -{% elif o_data.with_data %} +{% elif o_data.with_data is defined %} WITH {{ 'DATA' if o_data.with_data else 'NO DATA' }}; {% endif %} +{% if o_data.comment and not data.comment %} +COMMENT ON MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} + IS {{ o_data.comment|qtLiteral }}; +{% endif %} {% else %} {# ======= Alter Tablespace ========= #} {%- if data.spcoid and o_data.spcoid != data.spcoid -%} @@ -74,11 +80,8 @@ RESET( REFRESH MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} WITH{{ ' NO' if data.with_data|lower == 'false' else '' }} DATA; {% endif %} -{# ===== Check for Table tab properties ===== #} -{% if ((data.autovacuum_custom is defined and data.autovacuum_custom|lower == 'false') or -(data.toast_autovacuum is defined and data.toast_autovacuum|lower == 'false') -) %} -{% if data.autovacuum_custom|lower == 'false' %} +{# ===== Check for Autovacuum options ===== #} +{% if data.autovacuum_custom is defined and data.autovacuum_custom == False %} ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET( autovacuum_enabled, autovacuum_vacuum_threshold, @@ -92,21 +95,9 @@ ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET( autovacuum_freeze_table_age ); -{% if data.toast_autovacuum is defined and data.toast_autovacuum|lower != 'false' %} -{% if('vacuum_toast' in data and data['vacuum_toast']['changed']|length > 0) %} -ALTER MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} SET( -{% for field in data['vacuum_toast']['changed'] %} -{% if field.value != None %} - {{ field.name }} = {{ field.value|lower }}{% if not loop.last %},{% endif %}{{ '\r' }} -{% endif %} -{% endfor %} -); - -{% endif %} {% endif %} -{% endif %} -{% if data.toast_autovacuum|lower == 'false' %} +{% if data.toast_autovacuum is defined and data.toast_autovacuum == False %} ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET( toast.autovacuum_enabled, toast.autovacuum_vacuum_threshold, @@ -120,47 +111,42 @@ ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET( toast.autovacuum_freeze_table_age ); -{% if data.autovacuum_custom is defined and data.autovacuum_custom|lower != 'false' %} -{% if('vacuum_table' in data and data['vacuum_table']['changed']|length > 0) %} -ALTER MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} SET( -{% for field in data['vacuum_table']['changed'] %} -{% if field.value != None %} - {{ field.name }} = {{ field.value|lower }}{% if not loop.last %},{% endif %}{{ '\r' }} -{% endif %} -{% endfor %} -); - -{% endif %} -{% endif %} {% endif %}{#-- toast_endif ends --#} - -{% else %} -{% if data['vacuum_data']['reset']|length == 0 and -data['vacuum_data']['changed']|length == 0 and data['settings']|length > 0 %} -ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} SET( -{% for field in data['settings'] %} - {{ field }} = {{ data['settings'][field]|lower }}{% if not loop.last %},{% endif %}{{ '\r' }} -{% endfor %} -); - -{% endif %} -{% if(data['vacuum_data']['changed']|length > 0) %} +{% if data['vacuum_data']['changed']|length > 0 or data.autovacuum_enabled in ('t', 'f') or data.toast_autovacuum_enabled in ('t', 'f') %} ALTER MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} SET( +{% if data.autovacuum_enabled in ('t', 'f') %} + autovacuum_enabled = {% if data.autovacuum_enabled == 't' %}true{% else %}false{% endif %}{% if data['vacuum_data']['changed']|length > 0 or data.toast_autovacuum_enabled in ('t', 'f') %}, +{% endif %} +{% endif %} +{% if data.toast_autovacuum_enabled in ('t', 'f') %} + toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}true{% else %}false{% endif %}{% if data['vacuum_data']['changed']|length > 0 %}, +{% endif %} +{% endif %} {% for field in data['vacuum_data']['changed'] %} -{% if field.value != None %} - {{ field.name }} = {{ field.value|lower }}{% if not loop.last %},{% endif %}{{ '\r' }} +{% if field.value != None %} {{ field.name }} = {{ field.value|lower }}{% if not loop.last %}, +{% endif %} {% endif %} {% endfor %} + ); {% endif %} -{% if data['vacuum_data']['reset']|length > 0 %} +{% if data['vacuum_data']['reset']|length > 0 or data.autovacuum_enabled == 'x' or data.toast_autovacuum_enabled == 'x' %} ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET( -{% for field in data['vacuum_data']['reset'] %} - {{ field.name }}{% if not loop.last %},{% endif %}{{ '\r' }} +{% if data.autovacuum_enabled == 'x' %} + autovacuum_enabled{% if data['vacuum_data']['reset']|length > 0 or data.toast_autovacuum_enabled == 'x' %}, +{% endif %} +{% endif %} +{% if data.toast_autovacuum_enabled == 'x' %} + toast.autovacuum_enabled{% if data['vacuum_data']['reset']|length > 0 %}, +{% endif %} +{% endif %} +{% for field in data['vacuum_data']['reset'] %} {{ field.name }}{% if not loop.last %}, +{% endif %} {% endfor %} + ); {% endif %} -{% endif %}{# ===== End check for custom autovacuum ===== #} +{# ===== End check for custom autovacuum ===== #} {% endif %}{# ===== End block for check data definition ===== #} {% set old_comment = o_data.comment|default('', true) %} {% if (data.comment is defined and (data.comment != old_comment)) %} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/pg/9.4_plus/sql/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/pg/9.4_plus/sql/create.sql index 89b200d39..f092223ac 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/pg/9.4_plus/sql/create.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/pg/9.4_plus/sql/create.sql @@ -7,15 +7,21 @@ {% endif %} {% if data.name and data.schema and data.definition %} CREATE MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} -{% if(data.fillfactor or data['vacuum_data']|length > 0) %} +{% if(data.fillfactor or data.autovacuum_enabled in ('t', 'f') or data.toast_autovacuum_enabled in ('t', 'f') or data['vacuum_data']|length > 0) %} +{% set ns = namespace(add_comma=false) %} WITH ( {% if data.fillfactor %} - FILLFACTOR = {{ data.fillfactor }}{% if data['autovacuum_enabled'] or data['toast_autovacuum_enabled'] or data['vacuum_data']|length > 0 %},{{ '\n' }}{% endif %} + FILLFACTOR = {{ data.fillfactor }}{% set ns.add_comma = true%}{% endif %}{% if data.autovacuum_enabled in ('t', 'f') %} +{% if ns.add_comma %}, {% endif %} + 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 == 't' %}TRUE{% else %}FALSE{% endif %}{% set ns.add_comma = true%}{% endif %} {% for field in data['vacuum_data'] %} {% if field.value is defined and field.value != '' and field.value != none %} -{% if loop.index > 1 %}, -{% endif %} {{ field.name }} = {{ field.value|lower }}{% endif %}{% endfor %} +{% if ns.add_comma %}, +{% endif %} {{ field.name }} = {{ field.value|lower }}{% set ns.add_comma = true%}{% endif %}{% endfor %} {{ '\n' }}) {% endif %} {% if data.spcname %}TABLESPACE {{ data.spcname }} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/pg/9.4_plus/sql/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/pg/9.4_plus/sql/properties.sql index df3fafcdc..39b435cb8 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/pg/9.4_plus/sql/properties.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/pg/9.4_plus/sql/properties.sql @@ -24,8 +24,7 @@ SELECT (SELECT array_agg(provider || '=' || label) FROM pg_seclabels sl1 WHERE sl1.objoid=c.oid AND sl1.objsubid=0) AS seclabels, substring(array_to_string(c.reloptions, ',') FROM 'fillfactor=([0-9]*)') AS fillfactor, - (CASE WHEN (substring(array_to_string(c.reloptions, ',') - FROM 'autovacuum_enabled=([a-z|0-9]*)') = 'true') THEN true ELSE false END) AS autovacuum_enabled, + (substring(array_to_string(c.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS autovacuum_enabled, substring(array_to_string(c.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS autovacuum_vacuum_threshold, substring(array_to_string(c.reloptions, ',') @@ -44,8 +43,7 @@ SELECT FROM 'autovacuum_freeze_max_age=([0-9]*)') AS autovacuum_freeze_max_age, substring(array_to_string(c.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, ',') @@ -65,9 +63,7 @@ SELECT substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age, c.reloptions AS reloptions, tst.reloptions AS toast_reloptions, - (CASE WHEN c.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, - (CASE WHEN array_length(c.reloptions, 1) > 0 THEN true ELSE false END) AS autovacuum_custom, - (CASE WHEN array_length(tst.reloptions, 1) > 0 AND c.reltoastrelid != 0 THEN true ELSE false END) AS toast_autovacuum + (CASE WHEN c.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable FROM pg_class c LEFT OUTER JOIN pg_namespace nsp on nsp.oid = c.relnamespace diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/pg/9.4_plus/sql/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/pg/9.4_plus/sql/update.sql index 922b11887..dc752a2ec 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/pg/9.4_plus/sql/update.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/pg/9.4_plus/sql/update.sql @@ -30,13 +30,14 @@ CREATE MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} {% if data.fillfactor or o_data.fillfactor %} WITH( {% if data.fillfactor %} -FILLFACTOR = {{ data.fillfactor }}{% if (data['vacuum_data'] is defined and data['vacuum_data']['changed']|length > 0) %},{% endif %} + FILLFACTOR = {{ data.fillfactor }}{% if (data['vacuum_data'] is defined and data['vacuum_data']['changed']|length > 0) %},{% endif %} {% elif o_data.fillfactor %} -FILLFACTOR = {{ o_data.fillfactor }}{% if (data['vacuum_data'] is defined and data['vacuum_data']['changed']|length > 0) %},{% endif %} + FILLFACTOR = {{ o_data.fillfactor }}{% if (data['vacuum_data'] is defined and data['vacuum_data']['changed']|length > 0) %},{% endif %} {% endif %} {% if data['vacuum_data']['changed']|length > 0 %} -{% for field in data['vacuum_data']['changed'] %} {{ field.name }} = {{ field.value|lower }}{% if not loop.last %},{{ '\n' }}{% endif %} +{% for field in data['vacuum_data']['changed'] %} {{ field.name }} = {{ field.value|lower }}{% if not loop.last %}, +{% endif %} {% endfor %} {% endif %} ) @@ -79,11 +80,8 @@ RESET( REFRESH MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} WITH{{ ' NO' if data.with_data|lower == 'false' else '' }} DATA; {% endif %} -{# ===== Check for Table tab properties ===== #} -{% if ((data.autovacuum_custom is defined and data.autovacuum_custom|lower == 'false') or -(data.toast_autovacuum is defined and data.toast_autovacuum|lower == 'false') -) %} -{% if data.autovacuum_custom|lower == 'false' %} +{# ===== Check for Autovacuum options ===== #} +{% if data.autovacuum_custom is defined and data.autovacuum_custom == False %} ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET( autovacuum_enabled, autovacuum_vacuum_threshold, @@ -97,20 +95,9 @@ ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET( autovacuum_freeze_table_age ); -{% if data.toast_autovacuum is defined and data.toast_autovacuum|lower != 'false' %} -{% if('vacuum_toast' in data and data['vacuum_toast']['changed']|length > 0) %} -ALTER MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} SET( -{% for field in data['vacuum_toast']['changed'] %} -{% if field.value != None %} {{ field.name }} = {{ field.value|lower }}{% if not loop.last %},{{ '\n' }}{% endif %} -{% endif %} -{% endfor %} -); - -{% endif %} {% endif %} -{% endif %} -{% if data.toast_autovacuum|lower == 'false' %} +{% if data.toast_autovacuum is defined and data.toast_autovacuum == False %} ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET( toast.autovacuum_enabled, toast.autovacuum_vacuum_threshold, @@ -124,40 +111,42 @@ ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET( toast.autovacuum_freeze_table_age ); -{% if data.autovacuum_custom is defined and data.autovacuum_custom|lower != 'false' %} -{% if('vacuum_table' in data and data['vacuum_table']['changed']|length > 0) %} -ALTER MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} SET( -{% for field in data['vacuum_table']['changed'] %} -{% if field.value != None %} {{ field.name }} = {{ field.value|lower }}{% if not loop.last %},{% endif %}{% endif %} -{% endfor %} -); - -{% endif %} -{% endif %} {% endif %}{#-- toast_endif ends --#} - -{% else %} -{% if data['vacuum_data']['reset']|length == 0 and -data['vacuum_data']['changed']|length == 0 and data['settings']|length > 0 %} -ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} SET( -{% for field in data['settings'] %} {{ field }} = {{ data['settings'][field]|lower }}{% if not loop.last %},{{ '\n' }}{% endif %} -{% endfor %} -); - -{% endif %} -{% if(data['vacuum_data']['changed']|length > 0) %} +{% if data['vacuum_data']['changed']|length > 0 or data.autovacuum_enabled in ('t', 'f') or data.toast_autovacuum_enabled in ('t', 'f') %} ALTER MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} SET( +{% if data.autovacuum_enabled in ('t', 'f') %} + autovacuum_enabled = {% if data.autovacuum_enabled == 't' %}true{% else %}false{% endif %}{% if data['vacuum_data']['changed']|length > 0 or data.toast_autovacuum_enabled in ('t', 'f') %}, +{% endif %} +{% endif %} +{% if data.toast_autovacuum_enabled in ('t', 'f') %} + toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}true{% else %}false{% endif %}{% if data['vacuum_data']['changed']|length > 0 %}, +{% endif %} +{% endif %} {% for field in data['vacuum_data']['changed'] %} -{% if field.value != None %} {{ field.name }} = {{ field.value|lower }}{% if not loop.last %},{% endif %}{{ '\n' }}{% endif %} +{% if field.value != None %} {{ field.name }} = {{ field.value|lower }}{% if not loop.last %}, +{% endif %} +{% endif %} {% endfor %} + ); {% endif %} -{% if data['vacuum_data']['reset']|length > 0 %} +{% if data['vacuum_data']['reset']|length > 0 or data.autovacuum_enabled == 'x' or data.toast_autovacuum_enabled == 'x' %} ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET( -{% for field in data['vacuum_data']['reset'] %} {{ field.name }}{% if not loop.last %},{% endif %}{{ '\n' }}{% endfor %} +{% if data.autovacuum_enabled == 'x' %} + autovacuum_enabled{% if data['vacuum_data']['reset']|length > 0 or data.toast_autovacuum_enabled == 'x' %}, +{% endif %} +{% endif %} +{% if data.toast_autovacuum_enabled == 'x' %} + toast.autovacuum_enabled{% if data['vacuum_data']['reset']|length > 0 %}, +{% endif %} +{% endif %} +{% for field in data['vacuum_data']['reset'] %} {{ field.name }}{% if not loop.last %}, +{% endif %} +{% endfor %} + ); {% endif %} -{% endif %}{# ===== End check for custom autovacuum ===== #} +{# ===== End check for custom autovacuum ===== #} {% endif %}{# ===== End block for check data definition ===== #} {% set old_comment = o_data.comment|default('', true) %} {% if (data.comment is defined and (data.comment != old_comment)) %} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/ppas/9.3_plus/sql/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/ppas/9.3_plus/sql/create.sql index 89b200d39..f092223ac 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/ppas/9.3_plus/sql/create.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/ppas/9.3_plus/sql/create.sql @@ -7,15 +7,21 @@ {% endif %} {% if data.name and data.schema and data.definition %} CREATE MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} -{% if(data.fillfactor or data['vacuum_data']|length > 0) %} +{% if(data.fillfactor or data.autovacuum_enabled in ('t', 'f') or data.toast_autovacuum_enabled in ('t', 'f') or data['vacuum_data']|length > 0) %} +{% set ns = namespace(add_comma=false) %} WITH ( {% if data.fillfactor %} - FILLFACTOR = {{ data.fillfactor }}{% if data['autovacuum_enabled'] or data['toast_autovacuum_enabled'] or data['vacuum_data']|length > 0 %},{{ '\n' }}{% endif %} + FILLFACTOR = {{ data.fillfactor }}{% set ns.add_comma = true%}{% endif %}{% if data.autovacuum_enabled in ('t', 'f') %} +{% if ns.add_comma %}, {% endif %} + 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 == 't' %}TRUE{% else %}FALSE{% endif %}{% set ns.add_comma = true%}{% endif %} {% for field in data['vacuum_data'] %} {% if field.value is defined and field.value != '' and field.value != none %} -{% if loop.index > 1 %}, -{% endif %} {{ field.name }} = {{ field.value|lower }}{% endif %}{% endfor %} +{% if ns.add_comma %}, +{% endif %} {{ field.name }} = {{ field.value|lower }}{% set ns.add_comma = true%}{% endif %}{% endfor %} {{ '\n' }}) {% endif %} {% if data.spcname %}TABLESPACE {{ data.spcname }} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/ppas/9.3_plus/sql/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/ppas/9.3_plus/sql/properties.sql index df3fafcdc..39b435cb8 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/ppas/9.3_plus/sql/properties.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/ppas/9.3_plus/sql/properties.sql @@ -24,8 +24,7 @@ SELECT (SELECT array_agg(provider || '=' || label) FROM pg_seclabels sl1 WHERE sl1.objoid=c.oid AND sl1.objsubid=0) AS seclabels, substring(array_to_string(c.reloptions, ',') FROM 'fillfactor=([0-9]*)') AS fillfactor, - (CASE WHEN (substring(array_to_string(c.reloptions, ',') - FROM 'autovacuum_enabled=([a-z|0-9]*)') = 'true') THEN true ELSE false END) AS autovacuum_enabled, + (substring(array_to_string(c.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS autovacuum_enabled, substring(array_to_string(c.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS autovacuum_vacuum_threshold, substring(array_to_string(c.reloptions, ',') @@ -44,8 +43,7 @@ SELECT FROM 'autovacuum_freeze_max_age=([0-9]*)') AS autovacuum_freeze_max_age, substring(array_to_string(c.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, ',') @@ -65,9 +63,7 @@ SELECT substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age, c.reloptions AS reloptions, tst.reloptions AS toast_reloptions, - (CASE WHEN c.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, - (CASE WHEN array_length(c.reloptions, 1) > 0 THEN true ELSE false END) AS autovacuum_custom, - (CASE WHEN array_length(tst.reloptions, 1) > 0 AND c.reltoastrelid != 0 THEN true ELSE false END) AS toast_autovacuum + (CASE WHEN c.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable FROM pg_class c LEFT OUTER JOIN pg_namespace nsp on nsp.oid = c.relnamespace diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/ppas/9.3_plus/sql/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/ppas/9.3_plus/sql/update.sql index 922b11887..dc752a2ec 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/ppas/9.3_plus/sql/update.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/ppas/9.3_plus/sql/update.sql @@ -30,13 +30,14 @@ CREATE MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} {% if data.fillfactor or o_data.fillfactor %} WITH( {% if data.fillfactor %} -FILLFACTOR = {{ data.fillfactor }}{% if (data['vacuum_data'] is defined and data['vacuum_data']['changed']|length > 0) %},{% endif %} + FILLFACTOR = {{ data.fillfactor }}{% if (data['vacuum_data'] is defined and data['vacuum_data']['changed']|length > 0) %},{% endif %} {% elif o_data.fillfactor %} -FILLFACTOR = {{ o_data.fillfactor }}{% if (data['vacuum_data'] is defined and data['vacuum_data']['changed']|length > 0) %},{% endif %} + FILLFACTOR = {{ o_data.fillfactor }}{% if (data['vacuum_data'] is defined and data['vacuum_data']['changed']|length > 0) %},{% endif %} {% endif %} {% if data['vacuum_data']['changed']|length > 0 %} -{% for field in data['vacuum_data']['changed'] %} {{ field.name }} = {{ field.value|lower }}{% if not loop.last %},{{ '\n' }}{% endif %} +{% for field in data['vacuum_data']['changed'] %} {{ field.name }} = {{ field.value|lower }}{% if not loop.last %}, +{% endif %} {% endfor %} {% endif %} ) @@ -79,11 +80,8 @@ RESET( REFRESH MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} WITH{{ ' NO' if data.with_data|lower == 'false' else '' }} DATA; {% endif %} -{# ===== Check for Table tab properties ===== #} -{% if ((data.autovacuum_custom is defined and data.autovacuum_custom|lower == 'false') or -(data.toast_autovacuum is defined and data.toast_autovacuum|lower == 'false') -) %} -{% if data.autovacuum_custom|lower == 'false' %} +{# ===== Check for Autovacuum options ===== #} +{% if data.autovacuum_custom is defined and data.autovacuum_custom == False %} ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET( autovacuum_enabled, autovacuum_vacuum_threshold, @@ -97,20 +95,9 @@ ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET( autovacuum_freeze_table_age ); -{% if data.toast_autovacuum is defined and data.toast_autovacuum|lower != 'false' %} -{% if('vacuum_toast' in data and data['vacuum_toast']['changed']|length > 0) %} -ALTER MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} SET( -{% for field in data['vacuum_toast']['changed'] %} -{% if field.value != None %} {{ field.name }} = {{ field.value|lower }}{% if not loop.last %},{{ '\n' }}{% endif %} -{% endif %} -{% endfor %} -); - -{% endif %} {% endif %} -{% endif %} -{% if data.toast_autovacuum|lower == 'false' %} +{% if data.toast_autovacuum is defined and data.toast_autovacuum == False %} ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET( toast.autovacuum_enabled, toast.autovacuum_vacuum_threshold, @@ -124,40 +111,42 @@ ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET( toast.autovacuum_freeze_table_age ); -{% if data.autovacuum_custom is defined and data.autovacuum_custom|lower != 'false' %} -{% if('vacuum_table' in data and data['vacuum_table']['changed']|length > 0) %} -ALTER MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} SET( -{% for field in data['vacuum_table']['changed'] %} -{% if field.value != None %} {{ field.name }} = {{ field.value|lower }}{% if not loop.last %},{% endif %}{% endif %} -{% endfor %} -); - -{% endif %} -{% endif %} {% endif %}{#-- toast_endif ends --#} - -{% else %} -{% if data['vacuum_data']['reset']|length == 0 and -data['vacuum_data']['changed']|length == 0 and data['settings']|length > 0 %} -ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} SET( -{% for field in data['settings'] %} {{ field }} = {{ data['settings'][field]|lower }}{% if not loop.last %},{{ '\n' }}{% endif %} -{% endfor %} -); - -{% endif %} -{% if(data['vacuum_data']['changed']|length > 0) %} +{% if data['vacuum_data']['changed']|length > 0 or data.autovacuum_enabled in ('t', 'f') or data.toast_autovacuum_enabled in ('t', 'f') %} ALTER MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} SET( +{% if data.autovacuum_enabled in ('t', 'f') %} + autovacuum_enabled = {% if data.autovacuum_enabled == 't' %}true{% else %}false{% endif %}{% if data['vacuum_data']['changed']|length > 0 or data.toast_autovacuum_enabled in ('t', 'f') %}, +{% endif %} +{% endif %} +{% if data.toast_autovacuum_enabled in ('t', 'f') %} + toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}true{% else %}false{% endif %}{% if data['vacuum_data']['changed']|length > 0 %}, +{% endif %} +{% endif %} {% for field in data['vacuum_data']['changed'] %} -{% if field.value != None %} {{ field.name }} = {{ field.value|lower }}{% if not loop.last %},{% endif %}{{ '\n' }}{% endif %} +{% if field.value != None %} {{ field.name }} = {{ field.value|lower }}{% if not loop.last %}, +{% endif %} +{% endif %} {% endfor %} + ); {% endif %} -{% if data['vacuum_data']['reset']|length > 0 %} +{% if data['vacuum_data']['reset']|length > 0 or data.autovacuum_enabled == 'x' or data.toast_autovacuum_enabled == 'x' %} ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET( -{% for field in data['vacuum_data']['reset'] %} {{ field.name }}{% if not loop.last %},{% endif %}{{ '\n' }}{% endfor %} +{% if data.autovacuum_enabled == 'x' %} + autovacuum_enabled{% if data['vacuum_data']['reset']|length > 0 or data.toast_autovacuum_enabled == 'x' %}, +{% endif %} +{% endif %} +{% if data.toast_autovacuum_enabled == 'x' %} + toast.autovacuum_enabled{% if data['vacuum_data']['reset']|length > 0 %}, +{% endif %} +{% endif %} +{% for field in data['vacuum_data']['reset'] %} {{ field.name }}{% if not loop.last %}, +{% endif %} +{% endfor %} + ); {% endif %} -{% endif %}{# ===== End check for custom autovacuum ===== #} +{# ===== End check for custom autovacuum ===== #} {% endif %}{# ===== End block for check data definition ===== #} {% set old_comment = o_data.comment|default('', true) %} {% if (data.comment is defined and (data.comment != old_comment)) %} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/9.4_plus/alter_mview_add_fillfactor.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/9.4_plus/alter_mview_add_fillfactor.sql index a79299f2e..c79991c4f 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/9.4_plus/alter_mview_add_fillfactor.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/9.4_plus/alter_mview_add_fillfactor.sql @@ -4,8 +4,7 @@ CREATE MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" WITH ( - FILLFACTOR = 18, - autovacuum_enabled = false + FILLFACTOR = 18 ) TABLESPACE pg_default AS diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/9.4_plus/alter_mview_add_table_parameter.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/9.4_plus/alter_mview_add_table_parameter.sql index 72fb22614..824b3d13f 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/9.4_plus/alter_mview_add_table_parameter.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/9.4_plus/alter_mview_add_table_parameter.sql @@ -5,8 +5,8 @@ CREATE MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" WITH ( FILLFACTOR = 18, - autovacuum_analyze_scale_factor = 0.2, - autovacuum_enabled = true + autovacuum_enabled = TRUE, + autovacuum_analyze_scale_factor = 0.2 ) TABLESPACE pg_default AS diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/9.4_plus/alter_mview_add_table_parameter_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/9.4_plus/alter_mview_add_table_parameter_msql.sql index 737ffaa32..6f13ab46d 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/9.4_plus/alter_mview_add_table_parameter_msql.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/9.4_plus/alter_mview_add_table_parameter_msql.sql @@ -1,4 +1,4 @@ ALTER MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" SET( - autovacuum_analyze_scale_factor = 0.2, - autovacuum_enabled = true + autovacuum_enabled = true, + autovacuum_analyze_scale_factor = 0.2 ); diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/9.4_plus/alter_mview_remove_table_parameter.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/9.4_plus/alter_mview_remove_table_parameter.sql index a79299f2e..c79991c4f 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/9.4_plus/alter_mview_remove_table_parameter.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/9.4_plus/alter_mview_remove_table_parameter.sql @@ -4,8 +4,7 @@ CREATE MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" WITH ( - FILLFACTOR = 18, - autovacuum_enabled = false + FILLFACTOR = 18 ) TABLESPACE pg_default AS diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/9.4_plus/alter_mview_remove_table_parameter_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/9.4_plus/alter_mview_remove_table_parameter_msql.sql index 8aed82923..cccaa3885 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/9.4_plus/alter_mview_remove_table_parameter_msql.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/9.4_plus/alter_mview_remove_table_parameter_msql.sql @@ -1,6 +1,4 @@ -ALTER MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" SET( - autovacuum_enabled = false -); ALTER MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" RESET( - autovacuum_analyze_scale_factor + autovacuum_enabled, + autovacuum_analyze_scale_factor ); diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/9.4_plus/test_mview.json b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/9.4_plus/test_mview.json index 7f0bd477d..29ff3e27f 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/9.4_plus/test_mview.json +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/pg/9.4_plus/test_mview.json @@ -8,62 +8,8 @@ "msql_endpoint": "NODE-mview.msql", "data": { "spcname": "pg_default", - "toast_autovacuum_enabled": false, - "autovacuum_enabled": false, "schema": "public", "owner": "postgres", - "vacuum_table": [ - { - "name": "autovacuum_analyze_scale_factor" - }, - { - "name": "autovacuum_analyze_threshold" - }, - { - "name": "autovacuum_freeze_max_age" - }, - { - "name": "autovacuum_vacuum_cost_delay" - }, - { - "name": "autovacuum_vacuum_cost_limit" - }, - { - "name": "autovacuum_vacuum_scale_factor" - }, - { - "name": "autovacuum_vacuum_threshold" - }, - { - "name": "autovacuum_freeze_min_age" - }, - { - "name": "autovacuum_freeze_table_age" - } - ], - "vacuum_toast": [ - { - "name": "autovacuum_freeze_max_age" - }, - { - "name": "autovacuum_vacuum_cost_delay" - }, - { - "name": "autovacuum_vacuum_cost_limit" - }, - { - "name": "autovacuum_vacuum_scale_factor" - }, - { - "name": "autovacuum_vacuum_threshold" - }, - { - "name": "autovacuum_freeze_min_age" - }, - { - "name": "autovacuum_freeze_table_age" - } - ], "datacl": [], "seclabels": [], "name": "testmview_$%{}[]()&*^!/@`#", @@ -218,7 +164,7 @@ "msql_endpoint": "NODE-mview.msql_id", "data": { "autovacuum_custom": true, - "autovacuum_enabled": true, + "autovacuum_enabled": "t", "vacuum_table": { "changed": [ { @@ -239,7 +185,7 @@ "msql_endpoint": "NODE-mview.msql_id", "data": { "autovacuum_custom": true, - "autovacuum_enabled": false, + "autovacuum_enabled": "x", "vacuum_table": { "changed": [ { diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/9.4_plus/alter_mview_add_fillfactor.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/9.4_plus/alter_mview_add_fillfactor.sql index 8a297d450..d281242c3 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/9.4_plus/alter_mview_add_fillfactor.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/9.4_plus/alter_mview_add_fillfactor.sql @@ -4,8 +4,7 @@ CREATE MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" WITH ( - FILLFACTOR = 18, - autovacuum_enabled = false + FILLFACTOR = 18 ) TABLESPACE pg_default AS diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/9.4_plus/alter_mview_add_table_parameter.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/9.4_plus/alter_mview_add_table_parameter.sql index 3fc763dd4..b38de214f 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/9.4_plus/alter_mview_add_table_parameter.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/9.4_plus/alter_mview_add_table_parameter.sql @@ -5,8 +5,8 @@ CREATE MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" WITH ( FILLFACTOR = 18, - autovacuum_analyze_scale_factor = 0.2, - autovacuum_enabled = true + autovacuum_enabled = TRUE, + autovacuum_analyze_scale_factor = 0.2 ) TABLESPACE pg_default AS diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/9.4_plus/alter_mview_add_table_parameter_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/9.4_plus/alter_mview_add_table_parameter_msql.sql index 737ffaa32..6f13ab46d 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/9.4_plus/alter_mview_add_table_parameter_msql.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/9.4_plus/alter_mview_add_table_parameter_msql.sql @@ -1,4 +1,4 @@ ALTER MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" SET( - autovacuum_analyze_scale_factor = 0.2, - autovacuum_enabled = true + autovacuum_enabled = true, + autovacuum_analyze_scale_factor = 0.2 ); diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/9.4_plus/alter_mview_remove_table_parameter.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/9.4_plus/alter_mview_remove_table_parameter.sql index 8a297d450..d281242c3 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/9.4_plus/alter_mview_remove_table_parameter.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/9.4_plus/alter_mview_remove_table_parameter.sql @@ -4,8 +4,7 @@ CREATE MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" WITH ( - FILLFACTOR = 18, - autovacuum_enabled = false + FILLFACTOR = 18 ) TABLESPACE pg_default AS diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/9.4_plus/alter_mview_remove_table_parameter_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/9.4_plus/alter_mview_remove_table_parameter_msql.sql index 8aed82923..cccaa3885 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/9.4_plus/alter_mview_remove_table_parameter_msql.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/9.4_plus/alter_mview_remove_table_parameter_msql.sql @@ -1,6 +1,4 @@ -ALTER MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" SET( - autovacuum_enabled = false -); ALTER MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" RESET( - autovacuum_analyze_scale_factor + autovacuum_enabled, + autovacuum_analyze_scale_factor ); diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/9.4_plus/test_mview.json b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/9.4_plus/test_mview.json index 4ea610331..33d0f9ba7 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/9.4_plus/test_mview.json +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/ppas/9.4_plus/test_mview.json @@ -8,62 +8,8 @@ "msql_endpoint": "NODE-mview.msql", "data": { "spcname": "pg_default", - "toast_autovacuum_enabled": false, - "autovacuum_enabled": false, "schema": "public", "owner": "enterprisedb", - "vacuum_table": [ - { - "name": "autovacuum_analyze_scale_factor" - }, - { - "name": "autovacuum_analyze_threshold" - }, - { - "name": "autovacuum_freeze_max_age" - }, - { - "name": "autovacuum_vacuum_cost_delay" - }, - { - "name": "autovacuum_vacuum_cost_limit" - }, - { - "name": "autovacuum_vacuum_scale_factor" - }, - { - "name": "autovacuum_vacuum_threshold" - }, - { - "name": "autovacuum_freeze_min_age" - }, - { - "name": "autovacuum_freeze_table_age" - } - ], - "vacuum_toast": [ - { - "name": "autovacuum_freeze_max_age" - }, - { - "name": "autovacuum_vacuum_cost_delay" - }, - { - "name": "autovacuum_vacuum_cost_limit" - }, - { - "name": "autovacuum_vacuum_scale_factor" - }, - { - "name": "autovacuum_vacuum_threshold" - }, - { - "name": "autovacuum_freeze_min_age" - }, - { - "name": "autovacuum_freeze_table_age" - } - ], "datacl": [], "seclabels": [], "name": "testmview_$%{}[]()&*^!/@`#", @@ -218,7 +164,7 @@ "msql_endpoint": "NODE-mview.msql_id", "data": { "autovacuum_custom": true, - "autovacuum_enabled": true, + "autovacuum_enabled": "t", "vacuum_table": { "changed": [ { @@ -239,7 +185,7 @@ "msql_endpoint": "NODE-mview.msql_id", "data": { "autovacuum_custom": true, - "autovacuum_enabled": false, + "autovacuum_enabled": "x", "vacuum_table": { "changed": [ { diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/test_mviews_parameters.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/test_mviews_parameters.py index c84276ef6..177aa21b5 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/test_mviews_parameters.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/test_mviews_parameters.py @@ -24,25 +24,105 @@ from . import utils as views_utils class MViewsUpdateParameterTestCase(BaseTestGenerator): """This class will update the view/mview under schema node.""" scenarios = [ - ('Enable custom auto vacuum and set the parameters for table', - dict(url='/browser/mview/obj/', type='set_vacuum_parameters') + # Fetching default URL for table node. + ('Enable custom auto vacuum and set the parameters for table ' + 'without autovacuum_enabled', + dict(url='/browser/mview/obj/', + api_data={ + 'autovacuum_custom': True, + 'vacuum_table': { + 'changed': [ + {'name': 'autovacuum_vacuum_cost_delay', + 'value': 20}, + {'name': 'autovacuum_vacuum_threshold', + 'value': 20} + ] + }} + ) ), - ('Disable auto vacuum and reset the parameters for table', - dict(url='/browser/mview/obj/', type='reset_vacuum_parameters') + ('Change a parameter to zero value ' + 'without autovacuum_enabled', + dict(url='/browser/mview/obj/', + api_data={ + 'vacuum_table': { + 'changed': [ + {'name': 'autovacuum_vacuum_cost_delay', + 'value': 0} + ] + }} + ) ), - ('Disable custom auto vacuum and reset all the parameters for table', - dict(url='/browser/mview/obj/', type='reset_all_vacuum_parameters') + ('Enable autovacuum_enabled', + dict(url='/browser/mview/obj/', + api_data={'autovacuum_enabled': 't'} + ) ), - ('Enable custom auto vacuum and set the toast parameters for table', - dict(url='/browser/mview/obj/', type='set_toast_parameters') + ('Reset individual parameters for table', + dict(url='/browser/mview/obj/', + api_data={ + 'autovacuum_enabled': 'x', + 'vacuum_table': { + 'changed': [ + {'name': 'autovacuum_vacuum_cost_delay', + 'value': None}, + ] + }} + ) ), - ('Disable auto vacuum and reset the toast parameters for table', - dict(url='/browser/mview/obj/', type='reset_toast_parameters') + ('Reset custom auto vacuum', + dict(url='/browser/mview/obj/', + api_data={'autovacuum_custom': False} + ) + ), + ('Enable toast custom auto vacuum and set the parameters for table ' + 'without autovacuum_enabled', + dict(url='/browser/mview/obj/', + api_data={ + 'toast_autovacuum': True, + 'vacuum_toast': { + 'changed': [ + {'name': 'autovacuum_vacuum_cost_delay', + 'value': 20}, + {'name': 'autovacuum_vacuum_threshold', + 'value': 20} + ] + }} + ) + ), + ('Change a toast parameter to zero value ' + 'without autovacuum_enabled', + dict(url='/browser/mview/obj/', + api_data={ + 'vacuum_toast': { + 'changed': [ + {'name': 'autovacuum_vacuum_cost_delay', + 'value': 0} + ] + }} + ) + ), + ('Enable toast.autovacuum_enabled', + dict(url='/browser/mview/obj/', + api_data={'toast_autovacuum_enabled': 't'} + ) + ), + ('Reset individual toast parameters for table', + dict(url='/browser/mview/obj/', + api_data={ + 'toast_autovacuum_enabled': 'x', + 'vacuum_toast': { + 'changed': [ + {'name': 'autovacuum_vacuum_cost_delay', + 'value': None}, + ] + }} + ) + ), + ('Reset auto vacuum', + dict(url='/browser/mview/obj/', + api_data={'toast_autovacuum': False} + ) ), - ('Disable custom auto vacuum and reset all the toast ' - 'parameters for table', - dict(url='/browser/mview/obj/', type='reset_all_toast_parameters') - ) ] @classmethod @@ -88,49 +168,8 @@ class MViewsUpdateParameterTestCase(BaseTestGenerator): if not mview_response: raise Exception("Could not find the mview to update.") - data = None - if self.type == 'set_vacuum_parameters': - data = dict({'oid': self.m_view_id, - 'autovacuum_custom': True, - 'autovacuum_enabled': True, - 'vacuum_table': dict({'changed': [ - {'name': 'autovacuum_vacuum_cost_delay', - 'value': 20}, - {'name': 'autovacuum_vacuum_threshold', - 'value': 20} - ]})}) - elif self.type == 'reset_vacuum_parameters': - data = dict({'oid': self.m_view_id, - 'autovacuum_enabled': False, - 'vacuum_table': dict({'changed': [ - {'name': 'autovacuum_vacuum_cost_delay', - 'value': None}, - {'name': 'autovacuum_vacuum_threshold', - 'value': None} - ]})}) - elif self.type == 'reset_all_vacuum_parameters': - data = dict({'oid': self.m_view_id, 'autovacuum_custom': False}) - elif self.type == 'set_toast_parameters': - data = dict({'oid': self.m_view_id, - 'autovacuum_custom': True, - 'autovacuum_enabled': True, - 'vacuum_toast': dict({'changed': [ - {'name': 'autovacuum_vacuum_cost_delay', - 'value': 20}, - {'name': 'autovacuum_vacuum_threshold', - 'value': 20} - ]})}) - elif self.type == 'reset_toast_parameters': - data = dict({'oid': self.m_view_id, - 'autovacuum_enabled': False, - 'vacuum_toast': dict({'changed': [ - {'name': 'autovacuum_vacuum_cost_delay', - 'value': None}, - {'name': 'autovacuum_vacuum_threshold', - 'value': None} - ]})}) - elif self.type == 'reset_all_toast_parameters': - data = dict({'oid': self.m_view_id, 'autovacuum_custom': False}) + data = self.api_data + data['oid'] = self.m_view_id response = self.tester.put(self.url + str(utils.SERVER_GROUP) + '/' + str(self.server_id) + '/' +