Fixed generated SQL issue for auto vacuum options. Fixes #5398

Fixed some more issues:

 1) pgAdmin allows only true or false values for autovacuum_enabled,
    and there is no way to reset it individually without disabling a custom auto vacuum.
    To fix this, the control is changed from the switch to three state buttons.
 2) Setting any vacuum options to zero made the option disappear from the SQL.
 3) Right-click on a table with vacuum options set and create a new table.
 4) The parameters tab will have the options prefilled.
 5) Changed the UI a bit to remove unnecessary space around. Added "Autovacuum" before enabled.
    The SQL generated was appending a ".0" to decimal vacuum options. Changed to remove the leading ".0".
This commit is contained in:
Aditya Toshniwal authored and Akshay Joshi committed 2020-05-08 14:30:30 +05:30
1 parent e73e2d2502
commit b64896f558
57 files changed
+719 -857

No files matched your search

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 93 KiB

After

Width:  |  Height:  |  Size: 111 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 91 KiB

After

Width:  |  Height:  |  Size: 119 KiB

+4 -3
View File
@@ -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: 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 * Move the *Custom auto-vacuum?* switch to the *Yes* position to perform custom
maintenance on the materialized view. maintenance on the materialized view and to select values in the
* Move the *Enabled?* switch to the *Yes* position to select values in the *Vacuum table*. The *Vacuum Table* provides default values for maintenance
*Vacuum table*. Provide values for each row in the *Value* column. operations.
* Changing *Autovacuum enabled?* to *Not set* will reset autovacuum_enabled.
Click the *Security* tab to continue. Click the *Security* tab to continue.
+1
View File
@@ -26,6 +26,7 @@ Bug fixes
| `Issue #4279 <https://redmine.postgresql.org/issues/4279>`_ - Ensure that file browse "home" button should point to $HOME rather than /. | `Issue #4279 <https://redmine.postgresql.org/issues/4279>`_ - Ensure that file browse "home" button should point to $HOME rather than /.
| `Issue #4840 <https://redmine.postgresql.org/issues/4840>`_ - Ensure that 'With OID' option should be disabled while taking backup of database server version 12 and above. | `Issue #4840 <https://redmine.postgresql.org/issues/4840>`_ - Ensure that 'With OID' option should be disabled while taking backup of database server version 12 and above.
| `Issue #5001 <https://redmine.postgresql.org/issues/5001>`_ - Fixed invalid literal issue when removing the connection limit for the existing role. | `Issue #5001 <https://redmine.postgresql.org/issues/5001>`_ - Fixed invalid literal issue when removing the connection limit for the existing role.
| `Issue #5398 <https://redmine.postgresql.org/issues/5398>`_ - Fixed generated SQL issue for auto vacuum options.
| `Issue #5422 <https://redmine.postgresql.org/issues/5422>`_ - Ensure that the dependencies tab shows correct information for Synonyms. | `Issue #5422 <https://redmine.postgresql.org/issues/5422>`_ - Ensure that the dependencies tab shows correct information for Synonyms.
| `Issue #5434 <https://redmine.postgresql.org/issues/5434>`_ - Fixed an issue where the newly added table is not alphabetically added to the tree. | `Issue #5434 <https://redmine.postgresql.org/issues/5434>`_ - Fixed an issue where the newly added table is not alphabetically added to the tree.
| `Issue #5440 <https://redmine.postgresql.org/issues/5440>`_ - Fixed list sorting issue in the schema diff tool. | `Issue #5440 <https://redmine.postgresql.org/issues/5440>`_ - Fixed list sorting issue in the schema diff tool.
+2 -2
View File
@@ -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: for the table and the associated toast table:
* Move the *Custom auto-vacuum?* switch to the *Yes* position to perform custom * Move the *Custom auto-vacuum?* switch to the *Yes* position to perform custom
maintenance on the table. maintenance on the table and to select values in the
* Move the *Enabled?* switch to the *Yes* position to select values in the
*Vacuum table*. The *Vacuum Table* provides default values for maintenance *Vacuum table*. The *Vacuum Table* provides default values for maintenance
operations. 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 Provide a custom value in the *Value* column for each metric listed in the
*Label* column. *Label* column.
@@ -88,7 +88,9 @@ define('pgadmin.node.schema', [
var gridHeader = _.template([ var gridHeader = _.template([
'<div class="subnode-header">', '<div class="subnode-header">',
' <span class="control-label col-sm-4"><%-label%></span>', '<% if (label && label != "") %> {',
' <span class="control-label col-sm-4"><%-label%></span>',
'}',
'</div>'].join('\n')), '</div>'].join('\n')),
gridBody = $('<div class="pgadmin-control-group backgrid form-group col-12 object subnode"></div>').append( gridBody = $('<div class="pgadmin-control-group backgrid form-group col-12 object subnode"></div>').append(
gridHeader(attributes) gridHeader(attributes)
@@ -151,7 +153,8 @@ define('pgadmin.node.schema', [
},{ },{
id: 'autovacuum_custom', label: gettext('Custom auto-vacuum?'), id: 'autovacuum_custom', label: gettext('Custom auto-vacuum?'),
group: gettext('Table'), mode: ['edit', 'create'], 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) { disabled: function(m) {
// If table is partitioned table then disabled it. // If table is partitioned table then disabled it.
if (m.top && m.top.get('is_partitioned')) { if (m.top && m.top.get('is_partitioned')) {
@@ -169,45 +172,29 @@ define('pgadmin.node.schema', [
return true; return true;
}, },
},{ },{
id: 'autovacuum_enabled', label: gettext('Enabled?'), id: 'autovacuum_enabled', label: gettext('Autovacuum Enabled?'),
group: gettext('Table'), mode: ['edit', 'create'], 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'], deps: ['autovacuum_custom'],
disabled: function(m) { disabled: function(m) {
if(!m.top.inSchema.apply(this, [m]) && if(!m.top.inSchema.apply(this, [m]) &&
m.get('autovacuum_custom') == true) { 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; return false;
} }
// We also need to unset rest of all // We also need to unset rest of all
setTimeout(function() { setTimeout(function() {
m.set('autovacuum_enabled', false); m.set('autovacuum_enabled', 'x');
}, 10); }, 10);
return true; 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: '', id: 'vacuum_table', label: '',
model: Backform.VacuumTableModel, editable: false, type: 'collection', model: Backform.VacuumTableModel, editable: false, type: 'collection',
@@ -224,7 +211,7 @@ define('pgadmin.node.schema', [
name: 'value', label: gettext('Value'), name: 'value', label: gettext('Value'),
cellHeaderClasses:'width_percent_30', cellHeaderClasses:'width_percent_30',
cellFunction: Backform.cellFunction, editable: function(m) { cellFunction: Backform.cellFunction, editable: function(m) {
return m.handler.get('autovacuum_enabled'); return m.handler.get('autovacuum_custom');
}, headerCell: Backgrid.Extension.CustomHeaderCell, }, 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: 'spacer_ctrl', group: gettext('TOAST table'), mode: ['edit', 'create'], type: 'spacer',
},{ },{
id: 'toast_autovacuum', label: gettext('Custom auto-vacuum?'), id: 'toast_autovacuum', label: gettext('Custom auto-vacuum?'),
group: gettext('TOAST table'), mode: ['edit', 'create'], 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) { disabled: function(m) {
// We need to check additional condition to toggle enable/disable // We need to check additional condition to toggle enable/disable
// for table auto-vacuum // for table auto-vacuum
@@ -255,50 +243,32 @@ define('pgadmin.node.schema', [
return true; return true;
}, },
},{ },{
id: 'toast_autovacuum_enabled', label: gettext('Enabled?'), id: 'toast_autovacuum_enabled', label: gettext('Autovacuum Enabled?'),
group: gettext('TOAST table'), mode: ['edit', 'create'], 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'], deps:['toast_autovacuum'],
disabled: function(m) { disabled: function(m) {
// If in schema & in create mode then enable it // If in schema & in create mode then enable it
if(!m.top.inSchema.apply(this, [m]) && if(!m.top.inSchema.apply(this, [m]) &&
m.get('toast_autovacuum') === true) { 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; return false;
} }
if (m.isNew() || m.get('hastoasttable')) { if (m.isNew() || m.get('hastoasttable')) {
// we also need to unset rest of all // we also need to unset rest of all
setTimeout(function() { setTimeout(function() {
m.set('toast_autovacuum_enabled', false); m.set('toast_autovacuum_enabled', 'x');
}, 10); }, 10);
} }
return true; 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: '', id: 'vacuum_toast', label: '',
model: Backform.VacuumTableModel, type: 'collection', editable: function(m) { model: Backform.VacuumTableModel, type: 'collection', editable: function(m) {
@@ -318,7 +288,7 @@ define('pgadmin.node.schema', [
cellHeaderClasses:'width_percent_30', cellHeaderClasses:'width_percent_30',
headerCell: Backgrid.Extension.CustomHeaderCell, headerCell: Backgrid.Extension.CustomHeaderCell,
cellFunction: Backform.cellFunction, editable: function(m) { 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 // Extend the browser's collection class for schema collection
@@ -619,6 +619,42 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings,
return False, gone( return False, gone(
gettext("The specified table could not be found.")) 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 # We will check the threshold set by user before executing
# the query because that can cause performance issues # the query because that can cause performance issues
# with large result set # with large result set
@@ -943,6 +979,11 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings,
data['partition_scheme'] = self.get_partition_scheme(data) data['partition_scheme'] = self.get_partition_scheme(data)
partitions_sql = self.get_partitions_sql(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( SQL = render_template(
"/".join([self.table_template_path, 'create.sql']), "/".join([self.table_template_path, 'create.sql']),
data=data, conn=self.conn data=data, conn=self.conn
@@ -1023,14 +1064,9 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings,
data[k] = v data[k] = v
try: try:
SQL = render_template( status, res = self._fetch_properties(did, scid, tid)
"/".join([self.table_template_path, 'properties.sql']),
did=did, scid=scid, tid=tid,
datlastsysoid=self.datlastsysoid
)
status, res = self.conn.execute_dict(SQL)
if not status: if not status:
return internal_server_error(errormsg=res) return res
return super(TableView, self).update( return super(TableView, self).update(
gid, sid, did, scid, tid, data, res) gid, sid, did, scid, tid, data, res)
@@ -1266,14 +1302,9 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings,
res = None res = None
if tid is not None: if tid is not None:
SQL = render_template( status, res = self._fetch_properties(did, scid, tid)
"/".join([self.table_template_path, 'properties.sql']),
did=did, scid=scid, tid=tid,
datlastsysoid=self.datlastsysoid
)
status, res = self.conn.execute_dict(SQL)
if not status: if not status:
return internal_server_error(errormsg=SQL) return res
SQL, name = self.get_sql(did, scid, tid, data, res) SQL, name = self.get_sql(did, scid, tid, data, res)
SQL = re.sub('\n{2,}', '\n\n', SQL) SQL = re.sub('\n{2,}', '\n\n', SQL)
@@ -1335,17 +1366,9 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings,
""" """
main_sql = [] main_sql = []
SQL = render_template( status, res = self._fetch_properties(did, scid, tid)
"/".join([self.table_template_path, 'properties.sql']),
did=did, scid=scid, tid=tid,
datlastsysoid=self.datlastsysoid
)
status, res = self.conn.execute_dict(SQL)
if not status: if not status:
return internal_server_error(errormsg=res) return res
if len(res['rows']) == 0:
return gone(gettext("The specified table could not be found."))
data = res['rows'][0] data = res['rows'][0]
@@ -330,8 +330,8 @@ function(
is_sys_table: undefined, is_sys_table: undefined,
coll_inherits: [], coll_inherits: [],
hastoasttable: true, hastoasttable: true,
toast_autovacuum_enabled: false, toast_autovacuum_enabled: 'x',
autovacuum_enabled: false, autovacuum_enabled: 'x',
primary_key: [], primary_key: [],
partitions: [], partitions: [],
partition_type: 'range', partition_type: 'range',
@@ -300,8 +300,8 @@ define('pgadmin.node.table', [
is_sys_table: undefined, is_sys_table: undefined,
coll_inherits: [], coll_inherits: [],
hastoasttable: true, hastoasttable: true,
toast_autovacuum_enabled: false, toast_autovacuum_enabled: 'x',
autovacuum_enabled: false, autovacuum_enabled: 'x',
primary_key: [], primary_key: [],
partitions: [], partitions: [],
partition_type: 'range', partition_type: 'range',
@@ -1149,6 +1149,16 @@ define('pgadmin.node.table', [
id: 'vacuum_settings_str', label: gettext('Storage settings'), id: 'vacuum_settings_str', label: gettext('Storage settings'),
type: 'multiline', group: 'advanced', mode: ['properties'], 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() { validate: function() {
var msg, var msg,
name = this.get('name'), name = this.get('name'),
@@ -58,8 +58,6 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r
typ.typrelid AS typoid, typ.typrelid AS typoid,
(CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, (CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable,
-- Added for pgAdmin4 -- 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, NULL AS seclabels,
(CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table, (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table,
-- Added for partition table -- Added for partition table
@@ -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_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_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, 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, rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, rel.reloftype, typ.typname,
typ.typrelid AS typoid, typ.typrelid AS typoid,
(CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, (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, (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, (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table,
-- Added for partition table -- Added for partition table
@@ -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_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_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, 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, rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, rel.reloftype, typ.typname,
typ.typrelid AS typoid, typ.typrelid AS typoid,
(CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, (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, (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, (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table,
-- Added for partition table -- Added for partition table
@@ -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_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_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, 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, rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, rel.reloftype, typ.typname,
typ.typrelid AS typoid, typ.typrelid AS typoid,
(CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, (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, (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, (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table,
-- Added for partition table -- Added for partition table
@@ -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_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_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, 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, rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, rel.reloftype, typ.typname,
typ.typrelid AS typoid, typ.typrelid AS typoid,
(CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, (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, (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, (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table,
-- Added for partition table -- Added for partition table
@@ -78,15 +78,15 @@ CACHE {{c.seqcache|int}} {% endif %}
WITH ( WITH (
OIDS = {% if data.relhasoids %}TRUE{% else %}FALSE{% endif %}{% if data.fillfactor %}, 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 %}, 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 %}, parallel_workers = {{ data.parallel_workers }}{% endif %}{% if data.autovacuum_enabled in ('t', 'f') %},
autovacuum_enabled = {% if data.autovacuum_enabled %}TRUE{% else %}FALSE{% endif %}{% endif %}{% if data.toast_autovacuum %}, 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 %}TRUE{% else %}FALSE{% endif %} toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}TRUE{% else %}FALSE{% endif %}
{% endif %}{% if data.autovacuum_enabled and data.vacuum_table|length > 0 %} {% endif %}{% if data.autovacuum_custom and data.vacuum_table|length > 0 %}
{% for opt in data.vacuum_table %}{% if opt.name and opt.value %} {% for opt in data.vacuum_table %}{% if opt.name and opt.value is defined %}
, ,
{{opt.name}} = {{opt.value}}{% endif %} {{opt.name}} = {{opt.value}}{% endif %}
{% endfor %}{% endif %}{% if data.toast_autovacuum_enabled and data.vacuum_toast|length > 0 %} {% endfor %}{% endif %}{% if data.toast_autovacuum and data.vacuum_toast|length > 0 %}
{% for opt in data.vacuum_toast %}{% if opt.name and opt.value %} {% for opt in data.vacuum_toast %}{% if opt.name and opt.value is defined %}
, ,
toast.{{opt.name}} = {{opt.value}}{% endif %} toast.{{opt.name}} = {{opt.value}}{% endif %}
{% endfor %}{% endif %} {% endfor %}{% endif %}
@@ -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, (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 '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 'parallel_workers=([0-9]*)') AS parallel_workers,
(CASE WHEN (substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)') = 'true') (substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS autovacuum_enabled,
THEN true ELSE false END) 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_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_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, 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_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_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, 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') (substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS toast_autovacuum_enabled,
THEN true ELSE false END) 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_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_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, 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_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_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, 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, 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, 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, typ.typrelid AS typoid,
(CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, (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, (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 (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table
-- Added for partition table -- Added for partition table
@@ -79,15 +79,15 @@ WITH (
OIDS = {% if data.relhasoids %}TRUE{% else %}FALSE{% endif %}{% if data.fillfactor %}, 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 %}, 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 %}, 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 %}, toast_tuple_target = {{ data.toast_tuple_target }}{% endif %}{% if data.autovacuum_enabled in ('t', 'f') %},
autovacuum_enabled = {% if data.autovacuum_enabled %}TRUE{% else %}FALSE{% endif %}{% endif %}{% if data.toast_autovacuum %}, 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 %}TRUE{% else %}FALSE{% endif %} toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}TRUE{% else %}FALSE{% endif %}
{% endif %}{% if data.autovacuum_enabled and data.vacuum_table|length > 0 %} {% endif %}{% if data.autovacuum_custom and data.vacuum_table|length > 0 %}
{% for opt in data.vacuum_table %}{% if opt.name and opt.value %} {% for opt in data.vacuum_table %}{% if opt.name and opt.value is defined %}
, ,
{{opt.name}} = {{opt.value}}{% endif %} {{opt.name}} = {{opt.value}}{% endif %}
{% endfor %}{% endif %}{% if data.toast_autovacuum_enabled and data.vacuum_toast|length > 0 %} {% endfor %}{% endif %}{% if data.toast_autovacuum and data.vacuum_toast|length > 0 %}
{% for opt in data.vacuum_toast %}{% if opt.name and opt.value %} {% for opt in data.vacuum_toast %}{% if opt.name and opt.value is defined %}
, ,
toast.{{opt.name}} = {{opt.value}}{% endif %} toast.{{opt.name}} = {{opt.value}}{% endif %}
{% endfor %}{% endif %} {% endfor %}{% endif %}
@@ -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 '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 'parallel_workers=([0-9]*)') AS parallel_workers,
substring(array_to_string(rel.reloptions, ',') FROM 'toast_tuple_target=([0-9]*)') AS toast_tuple_target, 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') (substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS autovacuum_enabled,
THEN true ELSE false END) 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_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_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, 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_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_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, 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') (substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS toast_autovacuum_enabled,
THEN true ELSE false END) 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_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_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, 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_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_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, 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, 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, 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, typ.typrelid AS typoid,
(CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, (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, (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 (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table
-- Added for partition table -- Added for partition table
@@ -115,14 +115,14 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} RESET (
autovacuum_freeze_table_age autovacuum_freeze_table_age
); );
{% else %} {% 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 ( ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET (
{% if data.autovacuum_enabled is defined and data.autovacuum_enabled != o_data.autovacuum_enabled %} {% if data.autovacuum_enabled in ('t', 'f') and data.autovacuum_enabled != o_data.autovacuum_enabled %}
autovacuum_enabled = {% if data.autovacuum_enabled %}true{% else %}false{% endif %}{% if has_vacuum_set %}, autovacuum_enabled = {% if data.autovacuum_enabled == 't' %}true{% else %}false{% endif %}{% if has_vacuum_set %},
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if has_vacuum_set %} {% 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 %}, {{opt.name}} = {{opt.value}}{% if not loop.last %},
{% endif %} {% endif %}
{% endif %} {% endif %}
@@ -131,13 +131,19 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET (
); );
{% endif %} {% 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 ( 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 %} {% for opt in data.vacuum_table.reset_values %}{% if opt.name %}
{{opt.name}}{% if not loop.last %}, {{opt.name}}{% if not loop.last %},
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endif %}
); );
{% endif %} {% endif %}
@@ -165,14 +171,14 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} RESET (
toast.autovacuum_analyze_scale_factor toast.autovacuum_analyze_scale_factor
); );
{% else %} {% 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 ( 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 %} {% 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 %}true{% else %}false{% endif %}{% if has_vacuum_toast_set %}, toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}true{% else %}false{% endif %}{% if has_vacuum_toast_set %},
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if has_vacuum_toast_set %} {% 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 %}, toast.{{opt.name}} = {{opt.value}}{% if not loop.last %},
{% endif %} {% endif %}
{% endif %} {% endif %}
@@ -181,13 +187,19 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET (
); );
{% endif %} {% 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 ( 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 %} {% for opt in data.vacuum_toast.reset_values %}{% if opt.name %}
toast.{{opt.name}}{% if not loop.last %}, toast.{{opt.name}}{% if not loop.last %},
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endif %}
); );
{% endif %} {% endif %}
@@ -17,7 +17,7 @@
{% set empty_bracket = "\n(\n)"%} {% set empty_bracket = "\n(\n)"%}
{% endif %} {% endif %}
{% set with_clause = false%} {% 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%} {% set with_clause = true%}
{% endif %} {% endif %}
CREATE {% if data.relpersistence %}UNLOGGED {% endif %}TABLE {{conn|qtIdent(data.schema, data.name)}}{{empty_bracket}} 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 %} {% endif %}
{% if with_clause %} {% if with_clause %}
{% set add_comma = false%} {% set ns = namespace(add_comma=false) %}
WITH ( WITH (
{% if data.fillfactor %}{% set add_comma = true%} {% if data.fillfactor %}{% set ns.add_comma = true%}
FILLFACTOR = {{ data.fillfactor }}{% endif %}{% if data.parallel_workers %} FILLFACTOR = {{ data.fillfactor }}{% endif %}{% if data.parallel_workers %}
{% if add_comma %}, {% if ns.add_comma %},
{% endif %} {% endif %}
parallel_workers = {{ data.parallel_workers }}{% set add_comma = true%}{% endif %}{% if data.toast_tuple_target %} parallel_workers = {{ data.parallel_workers }}{% set ns.add_comma = true%}{% endif %}{% if data.toast_tuple_target %}
{% if add_comma %}, {% if ns.add_comma %},
{% endif %} {% endif %}
toast_tuple_target = {{ data.toast_tuple_target }}{% set add_comma = true%}{% endif %}{% if data.autovacuum_custom %} toast_tuple_target = {{ data.toast_tuple_target }}{% set ns.add_comma = true%}{% endif %}{% if data.autovacuum_enabled in ('t', 'f') %}
{% if add_comma %}, {% if ns.add_comma %},
{% endif %} {% endif %}
autovacuum_enabled = {% if data.autovacuum_enabled %}TRUE{% else %}FALSE{% endif %}{% set add_comma = true%}{% endif %}{% if data.toast_autovacuum %} 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 add_comma %}, {% if ns.add_comma %},
{% endif %} {% endif %}
toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled %}TRUE{% else %}FALSE{% endif %} toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}TRUE{% else %}FALSE{% endif %}{% set ns.add_comma = true%}{% endif %}{% if data.autovacuum_custom %}
{% endif %}{% if data.autovacuum_enabled and data.vacuum_table|length > 0 %} {% for opt in data.vacuum_table %}{% if opt.name and opt.value is defined %}
{% for opt in data.vacuum_table %}{% if opt.name and opt.value %} {% if ns.add_comma %},
, {% endif %}
{{opt.name}} = {{opt.value}}{% endif %} {{opt.name}} = {{opt.value}}{% set ns.add_comma = true%}{% endif %}
{% endfor %}{% endif %}{% if data.toast_autovacuum_enabled and data.vacuum_toast|length > 0 %} {% endfor %}{% endif %}{% if data.toast_autovacuum %}
{% for opt in data.vacuum_toast %}{% if opt.name and opt.value %} {% for opt in data.vacuum_toast %}{% if opt.name and opt.value is defined %}
, {% if ns.add_comma %},
toast.{{opt.name}} = {{opt.value}}{% endif %} {% endif %}
toast.{{opt.name}} = {{opt.value}}{% set ns.add_comma = true%}{% endif %}
{% endfor %}{% endif %} {% endfor %}{% endif %}
{% if data.spcname %}){% else %});{% endif %} {% if data.spcname %}){% else %});{% endif %}
@@ -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 '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 'parallel_workers=([0-9]*)') AS parallel_workers,
substring(array_to_string(rel.reloptions, ',') FROM 'toast_tuple_target=([0-9]*)') AS toast_tuple_target, 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') (substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS autovacuum_enabled,
THEN true ELSE false END) 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_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_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, 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_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_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, 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') (substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS toast_autovacuum_enabled,
THEN true ELSE false END) 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_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_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, 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_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_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, 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, 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, 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, typ.typrelid AS typoid,
(CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, (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, (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 (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table
-- Added for partition table -- Added for partition table
@@ -51,7 +51,7 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}}
{% endif %} {% endif %}
{#####################################################} {#####################################################}
{## change fillfactore settings ##} {## change fillfactor settings ##}
{#####################################################} {#####################################################}
{% if data.fillfactor and data.fillfactor != o_data.fillfactor %} {% if data.fillfactor and data.fillfactor != o_data.fillfactor %}
ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} 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 autovacuum_freeze_table_age
); );
{% else %} {% 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 ( ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET (
{% if data.autovacuum_enabled is defined and data.autovacuum_enabled != o_data.autovacuum_enabled %} {% if data.autovacuum_enabled in ('t', 'f') and data.autovacuum_enabled != o_data.autovacuum_enabled %}
autovacuum_enabled = {% if data.autovacuum_enabled %}true{% else %}false{% endif %}{% if has_vacuum_set %}, autovacuum_enabled = {% if data.autovacuum_enabled == 't' %}true{% else %}false{% endif %}{% if has_vacuum_set %},
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if has_vacuum_set %} {% 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 %}, {{opt.name}} = {{opt.value}}{% if not loop.last %},
{% endif %} {% endif %}
{% endif %} {% endif %}
@@ -123,13 +123,19 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET (
); );
{% endif %} {% 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 ( 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 %} {% for opt in data.vacuum_table.reset_values %}{% if opt.name %}
{{opt.name}}{% if not loop.last %}, {{opt.name}}{% if not loop.last %},
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endif %}
); );
{% endif %} {% endif %}
@@ -157,14 +163,14 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} RESET (
toast.autovacuum_analyze_scale_factor toast.autovacuum_analyze_scale_factor
); );
{% else %} {% 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 ( 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 %} {% 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 %}true{% else %}false{% endif %}{% if has_vacuum_toast_set %}, toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}true{% else %}false{% endif %}{% if has_vacuum_toast_set %},
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if has_vacuum_toast_set %} {% 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 %}, toast.{{opt.name}} = {{opt.value}}{% if not loop.last %},
{% endif %} {% endif %}
{% endif %} {% endif %}
@@ -173,13 +179,19 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET (
); );
{% endif %} {% 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 ( 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 %} {% for opt in data.vacuum_toast.reset_values %}{% if opt.name %}
toast.{{opt.name}}{% if not loop.last %}, toast.{{opt.name}}{% if not loop.last %},
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endif %}
); );
{% endif %} {% endif %}
@@ -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, WHERE i.inhrelid = rel.oid) AS inherited_tables_cnt,
(CASE WHEN rel.relpersistence = 'u' THEN true ELSE false END) AS relpersistence, (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 'fillfactor=([0-9]*)') AS fillfactor,
(CASE WHEN (substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)') = 'true') (substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS autovacuum_enabled,
THEN true ELSE false END) 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_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_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, 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_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_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, 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') (substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS toast_autovacuum_enabled,
THEN true ELSE false END) 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_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_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, 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_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_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, 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, 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, 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, typ.typrelid AS typoid,
(CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, (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, (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 (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table
FROM pg_class rel FROM pg_class rel
@@ -66,15 +66,15 @@ CREATE {% if data.relpersistence %}UNLOGGED {% endif %}TABLE {{conn|qtIdent(data
WITH ( WITH (
OIDS = {% if data.relhasoids %}TRUE{% else %}FALSE{% endif %}{% if data.fillfactor %}, 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 %}, 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 %}, parallel_workers = {{ data.parallel_workers }}{% endif %}{% if data.autovacuum_enabled in ('t', 'f') %},
autovacuum_enabled = {% if data.autovacuum_enabled %}TRUE{% else %}FALSE{% endif %}{% endif %}{% if data.toast_autovacuum %}, 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 %}TRUE{% else %}FALSE{% endif %} toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}TRUE{% else %}FALSE{% endif %}
{% endif %}{% if data.autovacuum_enabled and data.vacuum_table|length > 0 %} {% endif %}{% if data.autovacuum_custom and data.vacuum_table|length > 0 %}
{% for opt in data.vacuum_table %}{% if opt.name and opt.value %} {% for opt in data.vacuum_table %}{% if opt.name and opt.value is defined %}
, ,
{{opt.name}} = {{opt.value}}{% endif %} {{opt.name}} = {{opt.value}}{% endif %}
{% endfor %}{% endif %}{% if data.toast_autovacuum_enabled and data.vacuum_toast|length > 0 %} {% endfor %}{% endif %}{% if data.toast_autovacuum and data.vacuum_toast|length > 0 %}
{% for opt in data.vacuum_toast %}{% if opt.name and opt.value %} {% for opt in data.vacuum_toast %}{% if opt.name and opt.value is defined %}
, ,
toast.{{opt.name}} = {{opt.value}}{% endif %} toast.{{opt.name}} = {{opt.value}}{% endif %}
{% endfor %}{% endif %} {% endfor %}{% endif %}
@@ -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, (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 '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 'parallel_workers=([0-9]*)') AS parallel_workers,
(CASE WHEN (substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)') = 'true') (substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS autovacuum_enabled,
THEN true ELSE false END) 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_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_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, 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_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_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, 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') (substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS toast_autovacuum_enabled,
THEN true ELSE false END) 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_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_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, 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_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_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, 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, 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, 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, typ.typrelid AS typoid,
(CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, (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, (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 (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table
FROM pg_class rel FROM pg_class rel
@@ -103,14 +103,14 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} RESET (
autovacuum_freeze_table_age autovacuum_freeze_table_age
); );
{% else %} {% 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 ( ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET (
{% if data.autovacuum_enabled is defined and data.autovacuum_enabled != o_data.autovacuum_enabled %} {% if data.autovacuum_enabled in ('t', 'f') and data.autovacuum_enabled != o_data.autovacuum_enabled %}
autovacuum_enabled = {% if data.autovacuum_enabled %}true{% else %}false{% endif %}{% if has_vacuum_set %}, autovacuum_enabled = {% if data.autovacuum_enabled == 't' %}true{% else %}false{% endif %}{% if has_vacuum_set %},
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if has_vacuum_set %} {% 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 %}, {{opt.name}} = {{opt.value}}{% if not loop.last %},
{% endif %} {% endif %}
{% endif %} {% endif %}
@@ -119,13 +119,19 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET (
); );
{% endif %} {% 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 ( 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 %} {% for opt in data.vacuum_table.reset_values %}{% if opt.name %}
{{opt.name}}{% if not loop.last %}, {{opt.name}}{% if not loop.last %},
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endif %}
); );
{% endif %} {% endif %}
@@ -153,14 +159,14 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} RESET (
toast.autovacuum_analyze_scale_factor toast.autovacuum_analyze_scale_factor
); );
{% else %} {% 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 ( 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 %} {% 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 %}true{% else %}false{% endif %}{% if has_vacuum_toast_set %}, toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}true{% else %}false{% endif %}{% if has_vacuum_toast_set %},
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if has_vacuum_toast_set %} {% 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 %}, toast.{{opt.name}} = {{opt.value}}{% if not loop.last %},
{% endif %} {% endif %}
{% endif %} {% endif %}
@@ -169,13 +175,19 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET (
); );
{% endif %} {% 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 ( 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 %} {% for opt in data.vacuum_toast.reset_values %}{% if opt.name %}
toast.{{opt.name}}{% if not loop.last %}, toast.{{opt.name}}{% if not loop.last %},
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endif %}
); );
{% endif %} {% endif %}
@@ -65,15 +65,15 @@ CREATE {% if data.relpersistence %}UNLOGGED {% endif %}TABLE {{conn|qtIdent(data
{% endif %} {% endif %}
WITH ( WITH (
OIDS = {% if data.relhasoids %}TRUE{% else %}FALSE{% endif %}{% if data.fillfactor %}, OIDS = {% if data.relhasoids %}TRUE{% else %}FALSE{% endif %}{% if data.fillfactor %},
FILLFACTOR = {{ data.fillfactor }}{% endif %}{% if data.autovacuum_custom %}, FILLFACTOR = {{ data.fillfactor }}{% endif %}{% if data.autovacuum_enabled in ('t', 'f') %},
autovacuum_enabled = {% if data.autovacuum_enabled %}TRUE{% else %}FALSE{% endif %}{% endif %}{% if data.toast_autovacuum %}, 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 %}TRUE{% else %}FALSE{% endif %} toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}TRUE{% else %}FALSE{% endif %}
{% endif %}{% if data.autovacuum_enabled and data.vacuum_table|length > 0 %} {% endif %}{% if data.autovacuum_custom and data.vacuum_table|length > 0 %}
{% for opt in data.vacuum_table %}{% if opt.name and opt.value %} {% for opt in data.vacuum_table %}{% if opt.name and opt.value is defined %}
, ,
{{opt.name}} = {{opt.value}}{% endif %} {{opt.name}} = {{opt.value}}{% endif %}
{% endfor %}{% endif %}{% if data.toast_autovacuum_enabled and data.vacuum_toast|length > 0 %} {% endfor %}{% endif %}{% if data.toast_autovacuum and data.vacuum_toast|length > 0 %}
{% for opt in data.vacuum_toast %}{% if opt.name and opt.value %} {% for opt in data.vacuum_toast %}{% if opt.name and opt.value is defined %}
, ,
toast.{{opt.name}} = {{opt.value}}{% endif %} toast.{{opt.name}} = {{opt.value}}{% endif %}
{% endfor %}{% endif %} {% endfor %}{% endif %}
@@ -29,8 +29,7 @@ FROM (
WHERE i.inhrelid = rel.oid) AS inherited_tables_cnt, WHERE i.inhrelid = rel.oid) AS inherited_tables_cnt,
false AS relpersistence, false AS relpersistence,
substring(array_to_string(rel.reloptions, ',') FROM 'fillfactor=([0-9]*)') AS fillfactor, 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') (substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS autovacuum_enabled,
THEN true ELSE false END) 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_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_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, 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_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_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, 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') (substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS toast_autovacuum_enabled,
THEN true ELSE false END) 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_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_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, 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_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_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, 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, rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, NULL AS reloftype, NULL AS typname,
typ.typrelid AS typoid, typ.typrelid AS typoid,
(CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, (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, ARRAY[]::varchar[] AS seclabels,
(CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table
@@ -59,7 +59,7 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}}
{% endif %} {% endif %}
{#####################################################} {#####################################################}
{## change fillfactore settings ##} {## change fillfactor settings ##}
{#####################################################} {#####################################################}
{% if data.fillfactor and data.fillfactor != o_data.fillfactor %} {% if data.fillfactor and data.fillfactor != o_data.fillfactor %}
ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} 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 autovacuum_freeze_table_age
); );
{% else %} {% 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 ( ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET (
{% if data.autovacuum_enabled is defined and data.autovacuum_enabled != o_data.autovacuum_enabled %} {% if data.autovacuum_enabled in ('t', 'f') and data.autovacuum_enabled != o_data.autovacuum_enabled %}
autovacuum_enabled = {% if data.autovacuum_enabled %}true{% else %}false{% endif %}{% if has_vacuum_set %}, autovacuum_enabled = {% if data.autovacuum_enabled == 't' %}true{% else %}false{% endif %}{% if has_vacuum_set %},
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if has_vacuum_set %} {% 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 %}, {{opt.name}} = {{opt.value}}{% if not loop.last %},
{% endif %} {% endif %}
{% endif %} {% endif %}
@@ -108,13 +108,19 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET (
); );
{% endif %} {% 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 ( 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 %} {% for opt in data.vacuum_table.reset_values %}{% if opt.name %}
{{opt.name}}{% if not loop.last %}, {{opt.name}}{% if not loop.last %},
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endif %}
); );
{% endif %} {% endif %}
@@ -142,14 +148,14 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} RESET (
toast.autovacuum_analyze_scale_factor toast.autovacuum_analyze_scale_factor
); );
{% else %} {% 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 ( 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 %} {% 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 %}true{% else %}false{% endif %}{% if has_vacuum_toast_set %}, toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}true{% else %}false{% endif %}{% if has_vacuum_toast_set %},
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if has_vacuum_toast_set %} {% 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 %}, toast.{{opt.name}} = {{opt.value}}{% if not loop.last %},
{% endif %} {% endif %}
{% endif %} {% endif %}
@@ -158,13 +164,19 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}} SET (
); );
{% endif %} {% 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 ( 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 %} {% for opt in data.vacuum_toast.reset_values %}{% if opt.name %}
toast.{{opt.name}}{% if not loop.last %}, toast.{{opt.name}}{% if not loop.last %},
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endif %}
); );
{% endif %} {% endif %}
@@ -62,10 +62,6 @@ FROM (
rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, NULL AS reloftype, typ.typname AS typname, rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, NULL AS reloftype, typ.typname AS typname,
typ.typrelid AS typoid, typ.typrelid AS typoid,
(CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, (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, ARRAY[]::varchar[] AS seclabels,
(CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table, (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table,
@@ -25,25 +25,104 @@ class TableUpdateParameterTestCase(BaseTestGenerator):
"""This class will add new collation under schema node.""" """This class will add new collation under schema node."""
scenarios = [ scenarios = [
# Fetching default URL for table node. # Fetching default URL for table node.
('Enable custom auto vacuum and set the parameters for table', ('Enable custom auto vacuum and set the parameters for table '
dict(url='/browser/table/obj/', type='set_vacuum_parameters') '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', ('Change a parameter to zero value '
dict(url='/browser/table/obj/', type='reset_vacuum_parameters') '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', ('Enable autovacuum_enabled',
dict(url='/browser/table/obj/', type='reset_all_vacuum_parameters') dict(url='/browser/table/obj/',
api_data={'autovacuum_enabled': 't'}
)
), ),
('Enable custom auto vacuum and set the toast parameters for table', ('Reset individual parameters for table',
dict(url='/browser/table/obj/', type='set_toast_parameters') 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', ('Reset custom auto vacuum',
dict(url='/browser/table/obj/', type='reset_toast_parameters') 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 @classmethod
@@ -77,50 +156,8 @@ class TableUpdateParameterTestCase(BaseTestGenerator):
if not table_response: if not table_response:
raise Exception("Could not find the table to update.") raise Exception("Could not find the table to update.")
data = None data = self.api_data
if self.type == 'set_vacuum_parameters': data['oid'] = self.table_id
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})
response = self.tester.put(self.url + str(utils.SERVER_GROUP) + '/' + response = self.tester.put(self.url + str(utils.SERVER_GROUP) + '/' +
str(self.server_id) + '/' + str(self.server_id) + '/' +
str(self.db_id) + '/' + str(self.db_id) + '/' +
@@ -1029,6 +1029,11 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
data['partition_scheme'] = self.get_partition_scheme(data) data['partition_scheme'] = self.get_partition_scheme(data)
partitions_sql = self.get_partitions_sql(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, SQL = render_template("/".join([self.table_template_path,
'create.sql']), 'create.sql']),
data=data, conn=self.conn) data=data, conn=self.conn)
@@ -1191,21 +1196,20 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
""" """
data = res['rows'][0] data = res['rows'][0]
data['vacuum_settings_str'] = "" data['vacuum_settings_str'] = ''
if data['table_vacuum_settings_str'] is not None: if data['reloptions'] is not None:
data['vacuum_settings_str'] += data[ data['vacuum_settings_str'] += '\n'.join(data['reloptions'])
'table_vacuum_settings_str'].replace(',', '\n')
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[ data['vacuum_settings_str'] = data[
'vacuum_settings_str' 'vacuum_settings_str'
].replace("=", " = ") ].replace('=', ' = ')
data = self._formatter(did, scid, tid, data) data = self._formatter(did, scid, tid, data)
@@ -1496,7 +1500,7 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
return schema_name, table_name 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 This function iterate the vacuum and vacuum toast table and create
two new dictionaries. One for set parameter and another for reset. two new dictionaries. One for set parameter and another for reset.
@@ -1507,8 +1511,14 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
:return: :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 # 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: and vacuum_key in old_data:
set_values = [] set_values = []
reset_values = [] reset_values = []
@@ -10,6 +10,7 @@
"""Schema collection node helper class""" """Schema collection node helper class"""
import json import json
import copy
from flask import render_template from flask import render_template
@@ -575,8 +576,8 @@ class VacuumSettings:
* type - table/toast vacuum type * type - table/toast vacuum type
""" """
vacuum_settings_tmp = self.fetch_default_vacuum_settings( vacuum_settings_tmp = copy.deepcopy(self.fetch_default_vacuum_settings(
conn, self.manager.sid, type) conn, self.manager.sid, type))
for row in vacuum_settings_tmp: for row in vacuum_settings_tmp:
row_name = row['name'] row_name = row['name']
@@ -585,6 +586,7 @@ class VacuumSettings:
if row_name in result and result[row_name] is not None: if row_name in result and result[row_name] is not None:
if row['column_type'] == 'number': if row['column_type'] == 'number':
value = float(result[row_name]) value = float(result[row_name])
value = int(value) if value % 1 == 0 else value
else: else:
value = int(result[row_name]) value = int(result[row_name])
row['value'] = value row['value'] = value
@@ -1619,27 +1619,17 @@ class MViewNode(ViewNode, VacuumSettings):
This function will generate sql from model data This function will generate sql from model data
""" """
if vid is not None: if vid is not None:
SQL = render_template("/".join( status, res = self._fetch_properties(did, None, vid)
[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.")
)
old_data = res['rows'][0] if not status:
return res
old_data = res
if 'name' not in data: if 'name' not in data:
data['name'] = res['rows'][0]['name'] data['name'] = res['name']
if 'schema' not in data: if 'schema' not in data:
data['schema'] = res['rows'][0]['schema'] data['schema'] = res['schema']
# merge vacuum lists into one # merge vacuum lists into one
data['vacuum_data'] = {} data['vacuum_data'] = {}
@@ -1660,26 +1650,6 @@ class MViewNode(ViewNode, VacuumSettings):
item['value']))): item['value']))):
data['vacuum_data']['changed'].append(item) 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 # toast autovacuum: separate list of changed and reset data
if 'vacuum_toast' in data: if 'vacuum_toast' in data:
if 'changed' in data['vacuum_toast']: if 'changed' in data['vacuum_toast']:
@@ -1696,27 +1666,6 @@ class MViewNode(ViewNode, VacuumSettings):
item['value']))): item['value']))):
data['vacuum_data']['changed'].append(item) 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 = [] acls = []
try: try:
acls = render_template( acls = render_template(
@@ -1762,32 +1711,15 @@ class MViewNode(ViewNode, VacuumSettings):
data['schema'] = self._get_schema(data['schema']) data['schema'] = self._get_schema(data['schema'])
# merge vacuum lists into one # 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 if 'value' in item.keys() and
item['value'] is not None] item['value'] is not None]
vacuum_toast = [ vacuum_toast = [
{'name': 'toast.' + item['name'], 'value': item['value']} {'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] if 'value' in item.keys() and item['value'] is not None]
# add table_enabled & toast_enabled settings # add vacuum_toast dict to vacuum_data
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
data['vacuum_data'] = [] data['vacuum_data'] = []
if ( if (
'autovacuum_custom' in data and 'autovacuum_custom' in data and
@@ -1838,22 +1770,10 @@ class MViewNode(ViewNode, VacuumSettings):
display_comments = False display_comments = False
SQL_data = '' SQL_data = ''
SQL = render_template("/".join( status, result = self._fetch_properties(did, scid, vid)
[self.template_path, 'sql/properties.sql']),
did=did,
vid=vid,
datlastsysoid=self.datlastsysoid
)
status, res = self.conn.execute_dict(SQL)
if not status: if not status:
return internal_server_error(errormsg=res) return result
if len(res['rows']) == 0:
return gone(
gettext("Could not find the materialized view on the server.")
)
result = res['rows'][0]
if diff_schema: if diff_schema:
result['definition'] = result['definition'].replace( result['definition'] = result['definition'].replace(
@@ -1861,16 +1781,6 @@ class MViewNode(ViewNode, VacuumSettings):
diff_schema) diff_schema)
result['schema'] = 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 # merge vacuum lists into one
vacuum_table = [item for item in result['vacuum_table'] vacuum_table = [item for item in result['vacuum_table']
if if
@@ -1880,43 +1790,7 @@ class MViewNode(ViewNode, VacuumSettings):
for item in result['vacuum_toast'] if for item in result['vacuum_toast'] if
'value' in item.keys() and item['value'] is not None] 'value' in item.keys() and item['value'] is not None]
if 'autovacuum_custom' in result and result['autovacuum_custom']: result['vacuum_data'] = vacuum_table + vacuum_toast
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])
acls = [] acls = []
try: try:
@@ -1996,6 +1870,7 @@ class MViewNode(ViewNode, VacuumSettings):
and render in the properties tab and render in the properties tab
""" """
status, res = self._fetch_properties(did, scid, vid) status, res = self._fetch_properties(did, scid, vid)
if not status: if not status:
return res return res
@@ -2023,6 +1898,59 @@ class MViewNode(ViewNode, VacuumSettings):
return False, gone( return False, gone(
gettext("""Could not find the materialized view.""")) 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( SQL = render_template("/".join(
[self.template_path, 'sql/acl.sql']), vid=vid) [self.template_path, 'sql/acl.sql']), vid=vid)
status, dataclres = self.conn.execute_dict(SQL) status, dataclres = self.conn.execute_dict(SQL)
@@ -58,6 +58,7 @@ define('pgadmin.node.mview', [
hasDepends: true, hasDepends: true,
hasScriptTypes: ['create', 'select'], hasScriptTypes: ['create', 'select'],
collection_type: 'coll-mview', collection_type: 'coll-mview',
width: pgBrowser.stdW.md + 'px',
Init: function() { Init: function() {
// Avoid mulitple registration of menus // Avoid mulitple registration of menus
@@ -140,8 +141,8 @@ define('pgadmin.node.mview', [
}, },
defaults: { defaults: {
spcname: undefined, spcname: undefined,
toast_autovacuum_enabled: false, toast_autovacuum_enabled: 'x',
autovacuum_enabled: false, autovacuum_enabled: 'x',
warn_text: undefined, warn_text: undefined,
}, },
schema: [{ schema: [{
@@ -207,6 +208,9 @@ define('pgadmin.node.mview', [
id: 'fillfactor', label: gettext('Fill factor'), id: 'fillfactor', label: gettext('Fill factor'),
group: gettext('Storage'), mode: ['edit', 'create'], group: gettext('Storage'), mode: ['edit', 'create'],
type: 'int', min: 10, max: 100, 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', type: 'nested', control: 'tab', id: 'materialization',
label: gettext('Parameter'), mode: ['edit', 'create'], label: gettext('Parameter'), mode: ['edit', 'create'],
@@ -228,6 +232,16 @@ define('pgadmin.node.mview', [
mode: ['edit', 'create'], canAdd: true, mode: ['edit', 'create'], canAdd: true,
control: 'unique-col-collection', uniqueCol : ['provider'], 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) { validate: function(keys) {
// Triggers specific error messages for fields // Triggers specific error messages for fields
@@ -235,9 +249,11 @@ define('pgadmin.node.mview', [
errmsg, errmsg,
field_name = this.get('name'), field_name = this.get('name'),
field_def = this.get('definition'); 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 ) _.indexOf(keys, 'toast_autovacuum_enabled') != -1 )
return null; return null;
if (_.isUndefined(field_name) || _.isNull(field_name) || if (_.isUndefined(field_name) || _.isNull(field_name) ||
String(field_name).replace(/^\s+|\s+$/g, '') == '') { String(field_name).replace(/^\s+|\s+$/g, '') == '') {
@@ -7,15 +7,21 @@
{% endif %} {% endif %}
{% if data.name and data.schema and data.definition %} {% if data.name and data.schema and data.definition %}
CREATE MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} 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 ( WITH (
{% if data.fillfactor %} {% 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 %} {% 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'] %} {% for field in data['vacuum_data'] %}
{% if field.value is defined and field.value != '' and field.value != none %} {% if field.value is defined and field.value != '' and field.value != none %}
{% if loop.index > 1 %}, {% if ns.add_comma %},
{% endif %} {{ field.name }} = {{ field.value|lower }}{% endif %}{% endfor %} {% endif %} {{ field.name }} = {{ field.value|lower }}{% set ns.add_comma = true%}{% endif %}{% endfor %}
{{ '\n' }}) {{ '\n' }})
{% endif %} {% endif %}
{% if data.spcname %}TABLESPACE {{ data.spcname }} {% if data.spcname %}TABLESPACE {{ data.spcname }}
@@ -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, (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, ',') substring(array_to_string(c.reloptions, ',')
FROM 'fillfactor=([0-9]*)') AS fillfactor, FROM 'fillfactor=([0-9]*)') AS fillfactor,
(CASE WHEN (substring(array_to_string(c.reloptions, ',') (substring(array_to_string(c.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS autovacuum_enabled,
FROM 'autovacuum_enabled=([a-z|0-9]*)') = 'true') THEN true ELSE false END) AS autovacuum_enabled,
substring(array_to_string(c.reloptions, ',') substring(array_to_string(c.reloptions, ',')
FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS autovacuum_vacuum_threshold, FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS autovacuum_vacuum_threshold,
substring(array_to_string(c.reloptions, ',') substring(array_to_string(c.reloptions, ',')
@@ -44,8 +43,7 @@ SELECT
FROM 'autovacuum_freeze_max_age=([0-9]*)') AS autovacuum_freeze_max_age, FROM 'autovacuum_freeze_max_age=([0-9]*)') AS autovacuum_freeze_max_age,
substring(array_to_string(c.reloptions, ',') substring(array_to_string(c.reloptions, ',')
FROM 'autovacuum_freeze_table_age=([0-9]*)') AS autovacuum_freeze_table_age, FROM 'autovacuum_freeze_table_age=([0-9]*)') AS autovacuum_freeze_table_age,
(CASE WHEN (substring(array_to_string(tst.reloptions, ',') (substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS toast_autovacuum_enabled,
FROM 'autovacuum_enabled=([a-z|0-9]*)') = 'true') THEN true ELSE false END) AS toast_autovacuum_enabled,
substring(array_to_string(tst.reloptions, ',') substring(array_to_string(tst.reloptions, ',')
FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS toast_autovacuum_vacuum_threshold, FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS toast_autovacuum_vacuum_threshold,
substring(array_to_string(tst.reloptions, ',') substring(array_to_string(tst.reloptions, ',')
@@ -65,9 +63,7 @@ SELECT
substring(array_to_string(tst.reloptions, ',') substring(array_to_string(tst.reloptions, ',')
FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age, FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age,
c.reloptions AS reloptions, tst.reloptions AS toast_reloptions, c.reloptions AS reloptions, tst.reloptions AS toast_reloptions,
(CASE WHEN c.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, (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
FROM FROM
pg_class c pg_class c
LEFT OUTER JOIN pg_namespace nsp on nsp.oid = c.relnamespace LEFT OUTER JOIN pg_namespace nsp on nsp.oid = c.relnamespace
@@ -27,14 +27,17 @@ ALTER TABLE {{ conn|qtIdent(view_schema, view_name) }}
{% if def and def != o_data.definition.rstrip(';') %} {% if def and def != o_data.definition.rstrip(';') %}
DROP MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}; DROP MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }};
CREATE 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( WITH(
{% if data.fillfactor %} {% 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 %} {% endif %}
{% if data['vacuum_data']['changed']|length > 0 %} {% if data['vacuum_data']['changed']|length > 0 %}
{% for field in data['vacuum_data']['changed'] %} {% for field in data['vacuum_data']['changed'] %} {{ field.name }} = {{ field.value|lower }}{% if not loop.last %},
{{ field.name }} = {{ field.value|lower }}{% if not loop.last %},{% endif %}{{ '\r' }} {% endif %}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
) )
@@ -43,11 +46,14 @@ WITH(
{{ def }} {{ def }}
{% if data.with_data is defined %} {% if data.with_data is defined %}
WITH {{ 'DATA' if data.with_data else 'NO DATA' }}; WITH {{ 'DATA' if data.with_data else 'NO DATA' }};
{% elif o_data.with_data is defined %}
{% elif o_data.with_data %}
WITH {{ 'DATA' if o_data.with_data else 'NO DATA' }}; WITH {{ 'DATA' if o_data.with_data else 'NO DATA' }};
{% endif %} {% 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 %} {% else %}
{# ======= Alter Tablespace ========= #} {# ======= Alter Tablespace ========= #}
{%- if data.spcoid and o_data.spcoid != data.spcoid -%} {%- 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; REFRESH MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} WITH{{ ' NO' if data.with_data|lower == 'false' else '' }} DATA;
{% endif %} {% endif %}
{# ===== Check for Table tab properties ===== #} {# ===== Check for Autovacuum options ===== #}
{% if ((data.autovacuum_custom is defined and data.autovacuum_custom|lower == 'false') or {% if data.autovacuum_custom is defined and data.autovacuum_custom == False %}
(data.toast_autovacuum is defined and data.toast_autovacuum|lower == 'false')
) %}
{% if data.autovacuum_custom|lower == 'false' %}
ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET( ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET(
autovacuum_enabled, autovacuum_enabled,
autovacuum_vacuum_threshold, autovacuum_vacuum_threshold,
@@ -92,21 +95,9 @@ ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET(
autovacuum_freeze_table_age 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 %}
{% endif %} {% if data.toast_autovacuum is defined and data.toast_autovacuum == False %}
{% if data.toast_autovacuum|lower == 'false' %}
ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET( ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET(
toast.autovacuum_enabled, toast.autovacuum_enabled,
toast.autovacuum_vacuum_threshold, toast.autovacuum_vacuum_threshold,
@@ -120,47 +111,42 @@ ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET(
toast.autovacuum_freeze_table_age 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 --#} {% endif %}{#-- toast_endif ends --#}
{% if data['vacuum_data']['changed']|length > 0 or data.autovacuum_enabled in ('t', 'f') or data.toast_autovacuum_enabled in ('t', 'f') %}
{% 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) %}
ALTER MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} SET( 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'] %} {% for field in data['vacuum_data']['changed'] %}
{% if field.value != None %} {% if field.value != None %} {{ field.name }} = {{ field.value|lower }}{% if not loop.last %},
{{ field.name }} = {{ field.value|lower }}{% if not loop.last %},{% endif %}{{ '\r' }} {% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
); );
{% endif %} {% 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( ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET(
{% for field in data['vacuum_data']['reset'] %} {% if data.autovacuum_enabled == 'x' %}
{{ field.name }}{% if not loop.last %},{% endif %}{{ '\r' }} 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 %} {% endfor %}
); );
{% endif %} {% endif %}
{% endif %}{# ===== End check for custom autovacuum ===== #} {# ===== End check for custom autovacuum ===== #}
{% endif %}{# ===== End block for check data definition ===== #} {% endif %}{# ===== End block for check data definition ===== #}
{% set old_comment = o_data.comment|default('', true) %} {% set old_comment = o_data.comment|default('', true) %}
{% if (data.comment is defined and (data.comment != old_comment)) %} {% if (data.comment is defined and (data.comment != old_comment)) %}
@@ -7,15 +7,21 @@
{% endif %} {% endif %}
{% if data.name and data.schema and data.definition %} {% if data.name and data.schema and data.definition %}
CREATE MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} 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 ( WITH (
{% if data.fillfactor %} {% 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 %} {% 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'] %} {% for field in data['vacuum_data'] %}
{% if field.value is defined and field.value != '' and field.value != none %} {% if field.value is defined and field.value != '' and field.value != none %}
{% if loop.index > 1 %}, {% if ns.add_comma %},
{% endif %} {{ field.name }} = {{ field.value|lower }}{% endif %}{% endfor %} {% endif %} {{ field.name }} = {{ field.value|lower }}{% set ns.add_comma = true%}{% endif %}{% endfor %}
{{ '\n' }}) {{ '\n' }})
{% endif %} {% endif %}
{% if data.spcname %}TABLESPACE {{ data.spcname }} {% if data.spcname %}TABLESPACE {{ data.spcname }}
@@ -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, (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, ',') substring(array_to_string(c.reloptions, ',')
FROM 'fillfactor=([0-9]*)') AS fillfactor, FROM 'fillfactor=([0-9]*)') AS fillfactor,
(CASE WHEN (substring(array_to_string(c.reloptions, ',') (substring(array_to_string(c.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS autovacuum_enabled,
FROM 'autovacuum_enabled=([a-z|0-9]*)') = 'true') THEN true ELSE false END) AS autovacuum_enabled,
substring(array_to_string(c.reloptions, ',') substring(array_to_string(c.reloptions, ',')
FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS autovacuum_vacuum_threshold, FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS autovacuum_vacuum_threshold,
substring(array_to_string(c.reloptions, ',') substring(array_to_string(c.reloptions, ',')
@@ -44,8 +43,7 @@ SELECT
FROM 'autovacuum_freeze_max_age=([0-9]*)') AS autovacuum_freeze_max_age, FROM 'autovacuum_freeze_max_age=([0-9]*)') AS autovacuum_freeze_max_age,
substring(array_to_string(c.reloptions, ',') substring(array_to_string(c.reloptions, ',')
FROM 'autovacuum_freeze_table_age=([0-9]*)') AS autovacuum_freeze_table_age, FROM 'autovacuum_freeze_table_age=([0-9]*)') AS autovacuum_freeze_table_age,
(CASE WHEN (substring(array_to_string(tst.reloptions, ',') (substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS toast_autovacuum_enabled,
FROM 'autovacuum_enabled=([a-z|0-9]*)') = 'true') THEN true ELSE false END) AS toast_autovacuum_enabled,
substring(array_to_string(tst.reloptions, ',') substring(array_to_string(tst.reloptions, ',')
FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS toast_autovacuum_vacuum_threshold, FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS toast_autovacuum_vacuum_threshold,
substring(array_to_string(tst.reloptions, ',') substring(array_to_string(tst.reloptions, ',')
@@ -65,9 +63,7 @@ SELECT
substring(array_to_string(tst.reloptions, ',') substring(array_to_string(tst.reloptions, ',')
FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age, FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age,
c.reloptions AS reloptions, tst.reloptions AS toast_reloptions, c.reloptions AS reloptions, tst.reloptions AS toast_reloptions,
(CASE WHEN c.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, (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
FROM FROM
pg_class c pg_class c
LEFT OUTER JOIN pg_namespace nsp on nsp.oid = c.relnamespace LEFT OUTER JOIN pg_namespace nsp on nsp.oid = c.relnamespace
@@ -30,13 +30,14 @@ CREATE MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}
{% if data.fillfactor or o_data.fillfactor %} {% if data.fillfactor or o_data.fillfactor %}
WITH( WITH(
{% if data.fillfactor %} {% 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 %} {% 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 %} {% endif %}
{% if data['vacuum_data']['changed']|length > 0 %} {% 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 %} {% endfor %}
{% endif %} {% 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; REFRESH MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} WITH{{ ' NO' if data.with_data|lower == 'false' else '' }} DATA;
{% endif %} {% endif %}
{# ===== Check for Table tab properties ===== #} {# ===== Check for Autovacuum options ===== #}
{% if ((data.autovacuum_custom is defined and data.autovacuum_custom|lower == 'false') or {% if data.autovacuum_custom is defined and data.autovacuum_custom == False %}
(data.toast_autovacuum is defined and data.toast_autovacuum|lower == 'false')
) %}
{% if data.autovacuum_custom|lower == 'false' %}
ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET( ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET(
autovacuum_enabled, autovacuum_enabled,
autovacuum_vacuum_threshold, autovacuum_vacuum_threshold,
@@ -97,20 +95,9 @@ ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET(
autovacuum_freeze_table_age 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 %}
{% endif %} {% if data.toast_autovacuum is defined and data.toast_autovacuum == False %}
{% if data.toast_autovacuum|lower == 'false' %}
ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET( ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET(
toast.autovacuum_enabled, toast.autovacuum_enabled,
toast.autovacuum_vacuum_threshold, toast.autovacuum_vacuum_threshold,
@@ -124,40 +111,42 @@ ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET(
toast.autovacuum_freeze_table_age 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 --#} {% endif %}{#-- toast_endif ends --#}
{% if data['vacuum_data']['changed']|length > 0 or data.autovacuum_enabled in ('t', 'f') or data.toast_autovacuum_enabled in ('t', 'f') %}
{% 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) %}
ALTER MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} SET( 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'] %} {% 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 %} {% endfor %}
); );
{% endif %} {% 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( 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 %}
{% endif %}{# ===== End check for custom autovacuum ===== #} {# ===== End check for custom autovacuum ===== #}
{% endif %}{# ===== End block for check data definition ===== #} {% endif %}{# ===== End block for check data definition ===== #}
{% set old_comment = o_data.comment|default('', true) %} {% set old_comment = o_data.comment|default('', true) %}
{% if (data.comment is defined and (data.comment != old_comment)) %} {% if (data.comment is defined and (data.comment != old_comment)) %}
@@ -7,15 +7,21 @@
{% endif %} {% endif %}
{% if data.name and data.schema and data.definition %} {% if data.name and data.schema and data.definition %}
CREATE MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} 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 ( WITH (
{% if data.fillfactor %} {% 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 %} {% 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'] %} {% for field in data['vacuum_data'] %}
{% if field.value is defined and field.value != '' and field.value != none %} {% if field.value is defined and field.value != '' and field.value != none %}
{% if loop.index > 1 %}, {% if ns.add_comma %},
{% endif %} {{ field.name }} = {{ field.value|lower }}{% endif %}{% endfor %} {% endif %} {{ field.name }} = {{ field.value|lower }}{% set ns.add_comma = true%}{% endif %}{% endfor %}
{{ '\n' }}) {{ '\n' }})
{% endif %} {% endif %}
{% if data.spcname %}TABLESPACE {{ data.spcname }} {% if data.spcname %}TABLESPACE {{ data.spcname }}
@@ -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, (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, ',') substring(array_to_string(c.reloptions, ',')
FROM 'fillfactor=([0-9]*)') AS fillfactor, FROM 'fillfactor=([0-9]*)') AS fillfactor,
(CASE WHEN (substring(array_to_string(c.reloptions, ',') (substring(array_to_string(c.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS autovacuum_enabled,
FROM 'autovacuum_enabled=([a-z|0-9]*)') = 'true') THEN true ELSE false END) AS autovacuum_enabled,
substring(array_to_string(c.reloptions, ',') substring(array_to_string(c.reloptions, ',')
FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS autovacuum_vacuum_threshold, FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS autovacuum_vacuum_threshold,
substring(array_to_string(c.reloptions, ',') substring(array_to_string(c.reloptions, ',')
@@ -44,8 +43,7 @@ SELECT
FROM 'autovacuum_freeze_max_age=([0-9]*)') AS autovacuum_freeze_max_age, FROM 'autovacuum_freeze_max_age=([0-9]*)') AS autovacuum_freeze_max_age,
substring(array_to_string(c.reloptions, ',') substring(array_to_string(c.reloptions, ',')
FROM 'autovacuum_freeze_table_age=([0-9]*)') AS autovacuum_freeze_table_age, FROM 'autovacuum_freeze_table_age=([0-9]*)') AS autovacuum_freeze_table_age,
(CASE WHEN (substring(array_to_string(tst.reloptions, ',') (substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS toast_autovacuum_enabled,
FROM 'autovacuum_enabled=([a-z|0-9]*)') = 'true') THEN true ELSE false END) AS toast_autovacuum_enabled,
substring(array_to_string(tst.reloptions, ',') substring(array_to_string(tst.reloptions, ',')
FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS toast_autovacuum_vacuum_threshold, FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS toast_autovacuum_vacuum_threshold,
substring(array_to_string(tst.reloptions, ',') substring(array_to_string(tst.reloptions, ',')
@@ -65,9 +63,7 @@ SELECT
substring(array_to_string(tst.reloptions, ',') substring(array_to_string(tst.reloptions, ',')
FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age, FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age,
c.reloptions AS reloptions, tst.reloptions AS toast_reloptions, c.reloptions AS reloptions, tst.reloptions AS toast_reloptions,
(CASE WHEN c.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable, (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
FROM FROM
pg_class c pg_class c
LEFT OUTER JOIN pg_namespace nsp on nsp.oid = c.relnamespace LEFT OUTER JOIN pg_namespace nsp on nsp.oid = c.relnamespace
@@ -30,13 +30,14 @@ CREATE MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}
{% if data.fillfactor or o_data.fillfactor %} {% if data.fillfactor or o_data.fillfactor %}
WITH( WITH(
{% if data.fillfactor %} {% 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 %} {% 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 %} {% endif %}
{% if data['vacuum_data']['changed']|length > 0 %} {% 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 %} {% endfor %}
{% endif %} {% 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; REFRESH MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} WITH{{ ' NO' if data.with_data|lower == 'false' else '' }} DATA;
{% endif %} {% endif %}
{# ===== Check for Table tab properties ===== #} {# ===== Check for Autovacuum options ===== #}
{% if ((data.autovacuum_custom is defined and data.autovacuum_custom|lower == 'false') or {% if data.autovacuum_custom is defined and data.autovacuum_custom == False %}
(data.toast_autovacuum is defined and data.toast_autovacuum|lower == 'false')
) %}
{% if data.autovacuum_custom|lower == 'false' %}
ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET( ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET(
autovacuum_enabled, autovacuum_enabled,
autovacuum_vacuum_threshold, autovacuum_vacuum_threshold,
@@ -97,20 +95,9 @@ ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET(
autovacuum_freeze_table_age 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 %}
{% endif %} {% if data.toast_autovacuum is defined and data.toast_autovacuum == False %}
{% if data.toast_autovacuum|lower == 'false' %}
ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET( ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET(
toast.autovacuum_enabled, toast.autovacuum_enabled,
toast.autovacuum_vacuum_threshold, toast.autovacuum_vacuum_threshold,
@@ -124,40 +111,42 @@ ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET(
toast.autovacuum_freeze_table_age 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 --#} {% endif %}{#-- toast_endif ends --#}
{% if data['vacuum_data']['changed']|length > 0 or data.autovacuum_enabled in ('t', 'f') or data.toast_autovacuum_enabled in ('t', 'f') %}
{% 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) %}
ALTER MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} SET( 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'] %} {% 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 %} {% endfor %}
); );
{% endif %} {% 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( 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 %}
{% endif %}{# ===== End check for custom autovacuum ===== #} {# ===== End check for custom autovacuum ===== #}
{% endif %}{# ===== End block for check data definition ===== #} {% endif %}{# ===== End block for check data definition ===== #}
{% set old_comment = o_data.comment|default('', true) %} {% set old_comment = o_data.comment|default('', true) %}
{% if (data.comment is defined and (data.comment != old_comment)) %} {% if (data.comment is defined and (data.comment != old_comment)) %}
@@ -4,8 +4,7 @@
CREATE MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" CREATE MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#"
WITH ( WITH (
FILLFACTOR = 18, FILLFACTOR = 18
autovacuum_enabled = false
) )
TABLESPACE pg_default TABLESPACE pg_default
AS AS
@@ -5,8 +5,8 @@
CREATE MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" CREATE MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#"
WITH ( WITH (
FILLFACTOR = 18, FILLFACTOR = 18,
autovacuum_analyze_scale_factor = 0.2, autovacuum_enabled = TRUE,
autovacuum_enabled = true autovacuum_analyze_scale_factor = 0.2
) )
TABLESPACE pg_default TABLESPACE pg_default
AS AS
@@ -1,4 +1,4 @@
ALTER MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" SET( ALTER MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" SET(
autovacuum_analyze_scale_factor = 0.2, autovacuum_enabled = true,
autovacuum_enabled = true autovacuum_analyze_scale_factor = 0.2
); );
@@ -4,8 +4,7 @@
CREATE MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" CREATE MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#"
WITH ( WITH (
FILLFACTOR = 18, FILLFACTOR = 18
autovacuum_enabled = false
) )
TABLESPACE pg_default TABLESPACE pg_default
AS AS
@@ -1,6 +1,4 @@
ALTER MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" SET(
autovacuum_enabled = false
);
ALTER MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" RESET( ALTER MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" RESET(
autovacuum_analyze_scale_factor autovacuum_enabled,
autovacuum_analyze_scale_factor
); );
@@ -8,62 +8,8 @@
"msql_endpoint": "NODE-mview.msql", "msql_endpoint": "NODE-mview.msql",
"data": { "data": {
"spcname": "pg_default", "spcname": "pg_default",
"toast_autovacuum_enabled": false,
"autovacuum_enabled": false,
"schema": "public", "schema": "public",
"owner": "postgres", "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": [], "datacl": [],
"seclabels": [], "seclabels": [],
"name": "testmview_$%{}[]()&*^!/@`#", "name": "testmview_$%{}[]()&*^!/@`#",
@@ -218,7 +164,7 @@
"msql_endpoint": "NODE-mview.msql_id", "msql_endpoint": "NODE-mview.msql_id",
"data": { "data": {
"autovacuum_custom": true, "autovacuum_custom": true,
"autovacuum_enabled": true, "autovacuum_enabled": "t",
"vacuum_table": { "vacuum_table": {
"changed": [ "changed": [
{ {
@@ -239,7 +185,7 @@
"msql_endpoint": "NODE-mview.msql_id", "msql_endpoint": "NODE-mview.msql_id",
"data": { "data": {
"autovacuum_custom": true, "autovacuum_custom": true,
"autovacuum_enabled": false, "autovacuum_enabled": "x",
"vacuum_table": { "vacuum_table": {
"changed": [ "changed": [
{ {
@@ -4,8 +4,7 @@
CREATE MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" CREATE MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#"
WITH ( WITH (
FILLFACTOR = 18, FILLFACTOR = 18
autovacuum_enabled = false
) )
TABLESPACE pg_default TABLESPACE pg_default
AS AS
@@ -5,8 +5,8 @@
CREATE MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" CREATE MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#"
WITH ( WITH (
FILLFACTOR = 18, FILLFACTOR = 18,
autovacuum_analyze_scale_factor = 0.2, autovacuum_enabled = TRUE,
autovacuum_enabled = true autovacuum_analyze_scale_factor = 0.2
) )
TABLESPACE pg_default TABLESPACE pg_default
AS AS
@@ -1,4 +1,4 @@
ALTER MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" SET( ALTER MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" SET(
autovacuum_analyze_scale_factor = 0.2, autovacuum_enabled = true,
autovacuum_enabled = true autovacuum_analyze_scale_factor = 0.2
); );
@@ -4,8 +4,7 @@
CREATE MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" CREATE MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#"
WITH ( WITH (
FILLFACTOR = 18, FILLFACTOR = 18
autovacuum_enabled = false
) )
TABLESPACE pg_default TABLESPACE pg_default
AS AS
@@ -1,6 +1,4 @@
ALTER MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" SET(
autovacuum_enabled = false
);
ALTER MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" RESET( ALTER MATERIALIZED VIEW public."testmview_$%{}[]()&*^!/@`#" RESET(
autovacuum_analyze_scale_factor autovacuum_enabled,
autovacuum_analyze_scale_factor
); );
@@ -8,62 +8,8 @@
"msql_endpoint": "NODE-mview.msql", "msql_endpoint": "NODE-mview.msql",
"data": { "data": {
"spcname": "pg_default", "spcname": "pg_default",
"toast_autovacuum_enabled": false,
"autovacuum_enabled": false,
"schema": "public", "schema": "public",
"owner": "enterprisedb", "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": [], "datacl": [],
"seclabels": [], "seclabels": [],
"name": "testmview_$%{}[]()&*^!/@`#", "name": "testmview_$%{}[]()&*^!/@`#",
@@ -218,7 +164,7 @@
"msql_endpoint": "NODE-mview.msql_id", "msql_endpoint": "NODE-mview.msql_id",
"data": { "data": {
"autovacuum_custom": true, "autovacuum_custom": true,
"autovacuum_enabled": true, "autovacuum_enabled": "t",
"vacuum_table": { "vacuum_table": {
"changed": [ "changed": [
{ {
@@ -239,7 +185,7 @@
"msql_endpoint": "NODE-mview.msql_id", "msql_endpoint": "NODE-mview.msql_id",
"data": { "data": {
"autovacuum_custom": true, "autovacuum_custom": true,
"autovacuum_enabled": false, "autovacuum_enabled": "x",
"vacuum_table": { "vacuum_table": {
"changed": [ "changed": [
{ {
@@ -24,25 +24,105 @@ from . import utils as views_utils
class MViewsUpdateParameterTestCase(BaseTestGenerator): class MViewsUpdateParameterTestCase(BaseTestGenerator):
"""This class will update the view/mview under schema node.""" """This class will update the view/mview under schema node."""
scenarios = [ scenarios = [
('Enable custom auto vacuum and set the parameters for table', # Fetching default URL for table node.
dict(url='/browser/mview/obj/', type='set_vacuum_parameters') ('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', ('Change a parameter to zero value '
dict(url='/browser/mview/obj/', type='reset_vacuum_parameters') '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', ('Enable autovacuum_enabled',
dict(url='/browser/mview/obj/', type='reset_all_vacuum_parameters') dict(url='/browser/mview/obj/',
api_data={'autovacuum_enabled': 't'}
)
), ),
('Enable custom auto vacuum and set the toast parameters for table', ('Reset individual parameters for table',
dict(url='/browser/mview/obj/', type='set_toast_parameters') 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', ('Reset custom auto vacuum',
dict(url='/browser/mview/obj/', type='reset_toast_parameters') 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 @classmethod
@@ -88,49 +168,8 @@ class MViewsUpdateParameterTestCase(BaseTestGenerator):
if not mview_response: if not mview_response:
raise Exception("Could not find the mview to update.") raise Exception("Could not find the mview to update.")
data = None data = self.api_data
if self.type == 'set_vacuum_parameters': data['oid'] = self.m_view_id
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})
response = self.tester.put(self.url + str(utils.SERVER_GROUP) + '/' + response = self.tester.put(self.url + str(utils.SERVER_GROUP) + '/' +
str(self.server_id) + '/' + str(self.server_id) + '/' +