Fixed reverse engineered SQL for partitions when storage parameters are specified. Fixes #5569.

This commit is contained in:
Rahul Shirsat
2020-07-14 19:16:33 +05:30
committed by Akshay Joshi
parent 4f34bc0f0e
commit d6893f9d8a
37 changed files with 1018 additions and 120 deletions

View File

@@ -33,6 +33,7 @@ Bug fixes
| `Issue #5463 <https://redmine.postgresql.org/issues/5463>`_ - Fixed an issue where CSV download quotes numeric columns. | `Issue #5463 <https://redmine.postgresql.org/issues/5463>`_ - Fixed an issue where CSV download quotes numeric columns.
| `Issue #5470 <https://redmine.postgresql.org/issues/5470>`_ - Fixed backgrid row hover issue where on hover background color is set for edit and delete cell only. | `Issue #5470 <https://redmine.postgresql.org/issues/5470>`_ - Fixed backgrid row hover issue where on hover background color is set for edit and delete cell only.
| `Issue #5530 <https://redmine.postgresql.org/issues/5530>`_ - Ensure that the referenced table should be displayed on foreign key constraints. | `Issue #5530 <https://redmine.postgresql.org/issues/5530>`_ - Ensure that the referenced table should be displayed on foreign key constraints.
| `Issue #5569 <https://redmine.postgresql.org/issues/5569>`_ - Fixed reverse engineered SQL for partitions when storage parameters are specified.
| `Issue #5621 <https://redmine.postgresql.org/issues/5621>`_ - Remove extra brackets from reverse engineering SQL of RLS Policy. | `Issue #5621 <https://redmine.postgresql.org/issues/5621>`_ - Remove extra brackets from reverse engineering SQL of RLS Policy.
| `Issue #5629 <https://redmine.postgresql.org/issues/5629>`_ - Fixed an issue where the user is able to edit properties when some of the collection nodes are selected. | `Issue #5629 <https://redmine.postgresql.org/issues/5629>`_ - Fixed an issue where the user is able to edit properties when some of the collection nodes are selected.
| `Issue #5630 <https://redmine.postgresql.org/issues/5630>`_ - Fixed an issue where installation of pgadmin4 not working on 32-bit Windows. | `Issue #5630 <https://redmine.postgresql.org/issues/5630>`_ - Fixed an issue where installation of pgadmin4 not working on 32-bit Windows.

View File

@@ -634,41 +634,8 @@ 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 # Update autovacuum properties
# x: No set, t: true, f: false self.update_autovacuum_properties(res['rows'][0])
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

View File

@@ -356,20 +356,44 @@ class PartitionsView(BaseTableView, DataTypeReader, VacuumSettings,
JSON of selected table node JSON of selected table node
""" """
SQL = render_template("/".join([self.partition_template_path, status, res = self._fetch_properties(did, scid, tid, ptid)
'properties.sql']),
did=did, scid=scid, tid=tid,
ptid=ptid, datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0: if len(res['rows']) == 0:
return gone(gettext( return gone(gettext(
"The specified partitioned table could not be found.")) "The specified partitioned table could not be found."))
return super(PartitionsView, self).properties( return super(PartitionsView, self).properties(
gid, sid, did, scid, ptid, res) gid, sid, did, scid, ptid, res=res)
def _fetch_properties(self, did, scid, tid, ptid=None):
"""
This function is used to fetch the properties of the specified object
:param did:
:param scid:
:param tid:
:return:
"""
try:
SQL = render_template("/".join([self.partition_template_path,
'properties.sql']),
did=did, scid=scid, tid=tid,
ptid=ptid, datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return False, gone(
gettext("The specified table could not be found."))
# Update autovacuum properties
self.update_autovacuum_properties(res['rows'][0])
except Exception as e:
return False, internal_server_error(errormsg=str(e))
return True, res
@BaseTableView.check_precondition @BaseTableView.check_precondition
def fetch_objects_to_compare(self, sid, did, scid, tid, ptid=None): def fetch_objects_to_compare(self, sid, did, scid, tid, ptid=None):
@@ -444,13 +468,7 @@ class PartitionsView(BaseTableView, DataTypeReader, VacuumSettings,
""" """
main_sql = [] main_sql = []
SQL = render_template("/".join([self.partition_template_path, status, res = self._fetch_properties(did, scid, tid, ptid)
'properties.sql']),
did=did, scid=scid, tid=tid,
ptid=ptid, datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0: if len(res['rows']) == 0:
return gone(gettext( return gone(gettext(
@@ -627,13 +645,7 @@ class PartitionsView(BaseTableView, DataTypeReader, VacuumSettings,
data[k] = v data[k] = v
if ptid is not None: if ptid is not None:
SQL = render_template("/".join([self.partition_template_path, status, res = self._fetch_properties(did, scid, tid, ptid)
'properties.sql']),
did=did, scid=scid, tid=tid,
ptid=ptid, datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
SQL, name = self.get_sql(did, scid, ptid, data, res) SQL, name = self.get_sql(did, scid, ptid, data, res)
SQL = re.sub('\n{2,}', '\n\n', SQL) SQL = re.sub('\n{2,}', '\n\n', SQL)
@@ -674,16 +686,10 @@ class PartitionsView(BaseTableView, DataTypeReader, VacuumSettings,
data[k] = v data[k] = v
try: try:
SQL = render_template("/".join([self.partition_template_path, status, res = self._fetch_properties(did, scid, tid, ptid)
'properties.sql']),
did=did, scid=scid, tid=tid,
ptid=ptid, datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
return super(PartitionsView, self).update( return super(PartitionsView, self).update(
gid, sid, did, scid, ptid, data, res, parent_id=tid) gid, sid, did, scid, ptid, data=data, res=res, parent_id=tid)
except Exception as e: except Exception as e:
return internal_server_error(errormsg=str(e)) return internal_server_error(errormsg=str(e))

View File

@@ -995,6 +995,16 @@ function(
id: 'vacuum_settings_str', label: gettext('Storage settings'), id: 'vacuum_settings_str', label: gettext('Storage settings'),
type: 'multiline', group: gettext('Advanced'), mode: ['properties'], type: 'multiline', group: gettext('Advanced'), mode: ['properties'],
}], }],
sessChanged: function() {
/* If only custom autovacuum option is enabled then check if the options table is also changed. */
if(_.size(this.sessAttrs) == 2 && this.sessAttrs['autovacuum_custom'] && this.sessAttrs['toast_autovacuum']) {
return this.get('vacuum_table').sessChanged() || this.get('vacuum_toast').sessChanged();
}
if(_.size(this.sessAttrs) == 1 && (this.sessAttrs['autovacuum_custom'] || this.sessAttrs['toast_autovacuum'])) {
return this.get('vacuum_table').sessChanged() || this.get('vacuum_toast').sessChanged();
}
return pgBrowser.DataModel.prototype.sessChanged.apply(this);
},
validate: function(keys) { validate: function(keys) {
var msg, var msg,
name = this.get('name'), name = this.get('name'),

View File

@@ -0,0 +1,26 @@
-- Table: public.test_table_$%{}[]()&*^!@""'`\/#
-- DROP TABLE public."test_table_$%{}[]()&*^!@""""'`\/#";
CREATE TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
(
m_col bigint
) PARTITION BY RANGE (m_col)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
OWNER to postgres;
COMMENT ON TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
IS 'comment_01';
-- Partitions SQL
CREATE TABLE public."test_part_$%{}[]()&*^!@""""""""'`\/#" PARTITION OF public."test_table_$%{}[]()&*^!@""""'`\/#"
FOR VALUES FROM ('0') TO ('1000');
ALTER TABLE public."test_part_$%{}[]()&*^!@""""""""'`\/#"
OWNER to postgres;

View File

@@ -0,0 +1,2 @@
CREATE TABLE public."test_part_$%{}[]()&*^!@""""""""'`\/#" PARTITION OF public."test_table_$%{}[]()&*^!@""""'`\/#"
FOR VALUES FROM (0) TO (1000);

View File

@@ -0,0 +1,18 @@
-- Table: public.test_table_$%{}[]()&*^!@""'`\/#
-- DROP TABLE public."test_table_$%{}[]()&*^!@""""'`\/#";
CREATE TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
(
m_col bigint
) PARTITION BY RANGE (m_col)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
OWNER to postgres;
COMMENT ON TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
IS 'comment_01';

View File

@@ -0,0 +1,13 @@
CREATE TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
(
m_col bigint
) PARTITION BY RANGE (m_col)
WITH (
OIDS = FALSE
);
ALTER TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
OWNER to postgres;
COMMENT ON TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
IS 'comment_01';

View File

@@ -0,0 +1,139 @@
{
"scenarios": [
{
"type": "create",
"name": "Create Table",
"endpoint": "NODE-table.obj",
"sql_endpoint": "NODE-table.sql_id",
"msql_endpoint": "NODE-table.msql",
"data": {
"name": "test_table_$%{}[]()&*^!@\"\"'`\\/#",
"relowner": "postgres",
"relacl": [],
"description": "comment_01",
"coll_inherits": "[]",
"hastoasttable": true,
"toast_autovacuum_enabled": "x",
"autovacuum_enabled": "x",
"primary_key": [],
"partitions": [],
"partition_type": "range",
"is_partitioned": true,
"schema": "public",
"columns": [
{
"name": "m_col",
"cltype": "bigint",
"attacl": [],
"is_primary_key": true,
"attnotnull": false,
"attlen": null,
"attprecision": null,
"attidentity": "a",
"colconstype": "n",
"attoptions": [],
"seclabels": []
}
],
"foreign_key": [],
"check_constraint": [],
"unique_constraint": [],
"exclude_constraint": [],
"partition_keys": [
{
"key_type": "column",
"pt_column": "m_col"
}
],
"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"
}
],
"seclabels": [],
"forcerlspolicy": false,
"like_default_value": false,
"like_constraints": false,
"like_indexes": false,
"like_storage": false,
"like_comments": false,
"autovacuum_custom": false
},
"store_object_id": true,
"expected_sql_file": "create_table_with_partition.sql",
"expected_msql_file": "create_table_with_partition_msql.sql"
},
{
"type": "alter",
"name": "Alert Table - Add Partition",
"endpoint": "NODE-table.obj_id",
"sql_endpoint": "NODE-table.sql_id",
"msql_endpoint": "NODE-table.msql_id",
"data": {
"partitions": {
"added": [
{
"is_attach": false,
"partition_name": "test_part_$%{}[]()&*^!@\"\"\"\"'`\\/#",
"values_from": "0",
"values_to": "1000",
"is_sub_partitioned": false,
"sub_partition_type": "range",
"sub_partition_keys": []
}
]
}
},
"expected_sql_file": "alter_table_add_partition.sql",
"expected_msql_file": "alter_table_add_partition_msql.sql",
"store_object_id": true
}
]
}

View File

@@ -0,0 +1,22 @@
-- Table: public.test_table_$%{}[]()&*^!@""'`\/#
-- DROP TABLE public."test_table_$%{}[]()&*^!@""""'`\/#";
CREATE TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
(
m_col bigint
) PARTITION BY RANGE (m_col);
ALTER TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
OWNER to postgres;
COMMENT ON TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
IS 'comment_01';
-- Partitions SQL
CREATE TABLE public."test_part_$%{}[]()&*^!@""""""""'`\/#" PARTITION OF public."test_table_$%{}[]()&*^!@""""'`\/#"
FOR VALUES FROM ('0') TO ('1000');
ALTER TABLE public."test_part_$%{}[]()&*^!@""""""""'`\/#"
OWNER to postgres;

View File

@@ -0,0 +1,2 @@
CREATE TABLE public."test_part_$%{}[]()&*^!@""""""""'`\/#" PARTITION OF public."test_table_$%{}[]()&*^!@""""'`\/#"
FOR VALUES FROM (0) TO (1000);

View File

@@ -0,0 +1,14 @@
-- Table: public.test_table_$%{}[]()&*^!@""'`\/#
-- DROP TABLE public."test_table_$%{}[]()&*^!@""""'`\/#";
CREATE TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
(
m_col bigint
) PARTITION BY RANGE (m_col);
ALTER TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
OWNER to postgres;
COMMENT ON TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
IS 'comment_01';

View File

@@ -0,0 +1,10 @@
CREATE TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
(
m_col bigint
) PARTITION BY RANGE (m_col);
ALTER TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
OWNER to postgres;
COMMENT ON TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
IS 'comment_01';

View File

@@ -0,0 +1,139 @@
{
"scenarios": [
{
"type": "create",
"name": "Create Table",
"endpoint": "NODE-table.obj",
"sql_endpoint": "NODE-table.sql_id",
"msql_endpoint": "NODE-table.msql",
"data": {
"name": "test_table_$%{}[]()&*^!@\"\"'`\\/#",
"relowner": "postgres",
"relacl": [],
"description": "comment_01",
"coll_inherits": "[]",
"hastoasttable": true,
"toast_autovacuum_enabled": "x",
"autovacuum_enabled": "x",
"primary_key": [],
"partitions": [],
"partition_type": "range",
"is_partitioned": true,
"schema": "public",
"columns": [
{
"name": "m_col",
"cltype": "bigint",
"attacl": [],
"is_primary_key": true,
"attnotnull": false,
"attlen": null,
"attprecision": null,
"attidentity": "a",
"colconstype": "n",
"attoptions": [],
"seclabels": []
}
],
"foreign_key": [],
"check_constraint": [],
"unique_constraint": [],
"exclude_constraint": [],
"partition_keys": [
{
"key_type": "column",
"pt_column": "m_col"
}
],
"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"
}
],
"seclabels": [],
"forcerlspolicy": false,
"like_default_value": false,
"like_constraints": false,
"like_indexes": false,
"like_storage": false,
"like_comments": false,
"autovacuum_custom": false
},
"store_object_id": true,
"expected_sql_file": "create_table_with_partition.sql",
"expected_msql_file": "create_table_with_partition_msql.sql"
},
{
"type": "alter",
"name": "Alert Table - Add Partition",
"endpoint": "NODE-table.obj_id",
"sql_endpoint": "NODE-table.sql_id",
"msql_endpoint": "NODE-table.msql_id",
"data": {
"partitions": {
"added": [
{
"is_attach": false,
"partition_name": "test_part_$%{}[]()&*^!@\"\"\"\"'`\\/#",
"values_from": "0",
"values_to": "1000",
"is_sub_partitioned": false,
"sub_partition_type": "range",
"sub_partition_keys": []
}
]
}
},
"expected_sql_file": "alter_table_add_partition.sql",
"expected_msql_file": "alter_table_add_partition_msql.sql",
"store_object_id": true
}
]
}

View File

@@ -0,0 +1,26 @@
-- Table: public.test_table_$%{}[]()&*^!@""'`\/#
-- DROP TABLE public."test_table_$%{}[]()&*^!@""""'`\/#";
CREATE TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
(
m_col bigint
) PARTITION BY RANGE (m_col)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
OWNER to enterprisedb;
COMMENT ON TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
IS 'comment_01';
-- Partitions SQL
CREATE TABLE public."test_part_$%{}[]()&*^!@""""""""'`\/#" PARTITION OF public."test_table_$%{}[]()&*^!@""""'`\/#"
FOR VALUES FROM ('0') TO ('1000');
ALTER TABLE public."test_part_$%{}[]()&*^!@""""""""'`\/#"
OWNER to enterprisedb;

View File

@@ -0,0 +1,2 @@
CREATE TABLE public."test_part_$%{}[]()&*^!@""""""""'`\/#" PARTITION OF public."test_table_$%{}[]()&*^!@""""'`\/#"
FOR VALUES FROM (0) TO (1000);

View File

@@ -0,0 +1,18 @@
-- Table: public.test_table_$%{}[]()&*^!@""'`\/#
-- DROP TABLE public."test_table_$%{}[]()&*^!@""""'`\/#";
CREATE TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
(
m_col bigint
) PARTITION BY RANGE (m_col)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
OWNER to enterprisedb;
COMMENT ON TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
IS 'comment_01';

View File

@@ -0,0 +1,13 @@
CREATE TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
(
m_col bigint
) PARTITION BY RANGE (m_col)
WITH (
OIDS = FALSE
);
ALTER TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
OWNER to enterprisedb;
COMMENT ON TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
IS 'comment_01';

View File

@@ -0,0 +1,139 @@
{
"scenarios": [
{
"type": "create",
"name": "Create Table",
"endpoint": "NODE-table.obj",
"sql_endpoint": "NODE-table.sql_id",
"msql_endpoint": "NODE-table.msql",
"data": {
"name": "test_table_$%{}[]()&*^!@\"\"'`\\/#",
"relowner": "enterprisedb",
"relacl": [],
"description": "comment_01",
"coll_inherits": "[]",
"hastoasttable": true,
"toast_autovacuum_enabled": "x",
"autovacuum_enabled": "x",
"primary_key": [],
"partitions": [],
"partition_type": "range",
"is_partitioned": true,
"schema": "public",
"columns": [
{
"name": "m_col",
"cltype": "bigint",
"attacl": [],
"is_primary_key": true,
"attnotnull": false,
"attlen": null,
"attprecision": null,
"attidentity": "a",
"colconstype": "n",
"attoptions": [],
"seclabels": []
}
],
"foreign_key": [],
"check_constraint": [],
"unique_constraint": [],
"exclude_constraint": [],
"partition_keys": [
{
"key_type": "column",
"pt_column": "m_col"
}
],
"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"
}
],
"seclabels": [],
"forcerlspolicy": false,
"like_default_value": false,
"like_constraints": false,
"like_indexes": false,
"like_storage": false,
"like_comments": false,
"autovacuum_custom": false
},
"store_object_id": true,
"expected_sql_file": "create_table_with_partition.sql",
"expected_msql_file": "create_table_with_partition_msql.sql"
},
{
"type": "alter",
"name": "Alert Table - Add Partition",
"endpoint": "NODE-table.obj_id",
"sql_endpoint": "NODE-table.sql_id",
"msql_endpoint": "NODE-table.msql_id",
"data": {
"partitions": {
"added": [
{
"is_attach": false,
"partition_name": "test_part_$%{}[]()&*^!@\"\"\"\"'`\\/#",
"values_from": "0",
"values_to": "1000",
"is_sub_partitioned": false,
"sub_partition_type": "range",
"sub_partition_keys": []
}
]
}
},
"expected_sql_file": "alter_table_add_partition.sql",
"expected_msql_file": "alter_table_add_partition_msql.sql",
"store_object_id": true
}
]
}

View File

@@ -0,0 +1,22 @@
-- Table: public.test_table_$%{}[]()&*^!@""'`\/#
-- DROP TABLE public."test_table_$%{}[]()&*^!@""""'`\/#";
CREATE TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
(
m_col bigint
) PARTITION BY RANGE (m_col);
ALTER TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
OWNER to enterprisedb;
COMMENT ON TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
IS 'comment_01';
-- Partitions SQL
CREATE TABLE public."test_part_$%{}[]()&*^!@""""""""'`\/#" PARTITION OF public."test_table_$%{}[]()&*^!@""""'`\/#"
FOR VALUES FROM ('0') TO ('1000');
ALTER TABLE public."test_part_$%{}[]()&*^!@""""""""'`\/#"
OWNER to enterprisedb;

View File

@@ -0,0 +1,2 @@
CREATE TABLE public."test_part_$%{}[]()&*^!@""""""""'`\/#" PARTITION OF public."test_table_$%{}[]()&*^!@""""'`\/#"
FOR VALUES FROM (0) TO (1000);

View File

@@ -0,0 +1,14 @@
-- Table: public.test_table_$%{}[]()&*^!@""'`\/#
-- DROP TABLE public."test_table_$%{}[]()&*^!@""""'`\/#";
CREATE TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
(
m_col bigint
) PARTITION BY RANGE (m_col);
ALTER TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
OWNER to enterprisedb;
COMMENT ON TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
IS 'comment_01';

View File

@@ -0,0 +1,10 @@
CREATE TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
(
m_col bigint
) PARTITION BY RANGE (m_col);
ALTER TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
OWNER to enterprisedb;
COMMENT ON TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
IS 'comment_01';

View File

@@ -0,0 +1,139 @@
{
"scenarios": [
{
"type": "create",
"name": "Create Table",
"endpoint": "NODE-table.obj",
"sql_endpoint": "NODE-table.sql_id",
"msql_endpoint": "NODE-table.msql",
"data": {
"name": "test_table_$%{}[]()&*^!@\"\"'`\\/#",
"relowner": "enterprisedb",
"relacl": [],
"description": "comment_01",
"coll_inherits": "[]",
"hastoasttable": true,
"toast_autovacuum_enabled": "x",
"autovacuum_enabled": "x",
"primary_key": [],
"partitions": [],
"partition_type": "range",
"is_partitioned": true,
"schema": "public",
"columns": [
{
"name": "m_col",
"cltype": "bigint",
"attacl": [],
"is_primary_key": true,
"attnotnull": false,
"attlen": null,
"attprecision": null,
"attidentity": "a",
"colconstype": "n",
"attoptions": [],
"seclabels": []
}
],
"foreign_key": [],
"check_constraint": [],
"unique_constraint": [],
"exclude_constraint": [],
"partition_keys": [
{
"key_type": "column",
"pt_column": "m_col"
}
],
"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"
}
],
"seclabels": [],
"forcerlspolicy": false,
"like_default_value": false,
"like_constraints": false,
"like_indexes": false,
"like_storage": false,
"like_comments": false,
"autovacuum_custom": false
},
"store_object_id": true,
"expected_sql_file": "create_table_with_partition.sql",
"expected_msql_file": "create_table_with_partition_msql.sql"
},
{
"type": "alter",
"name": "Alert Table - Add Partition",
"endpoint": "NODE-table.obj_id",
"sql_endpoint": "NODE-table.sql_id",
"msql_endpoint": "NODE-table.msql_id",
"data": {
"partitions": {
"added": [
{
"is_attach": false,
"partition_name": "test_part_$%{}[]()&*^!@\"\"\"\"'`\\/#",
"values_from": "0",
"values_to": "1000",
"is_sub_partitioned": false,
"sub_partition_type": "range",
"sub_partition_keys": []
}
]
}
},
"expected_sql_file": "alter_table_add_partition.sql",
"expected_msql_file": "alter_table_add_partition_msql.sql",
"store_object_id": true
}
]
}

View File

@@ -30,8 +30,7 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r
WHERE i.inhrelid = rel.oid) AS inherited_tables_cnt, 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,
@@ -41,8 +40,7 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r
substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS autovacuum_freeze_min_age, substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_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,

View File

@@ -21,26 +21,28 @@ CREATE {% if data.relpersistence %}UNLOGGED {% endif %}TABLE {{conn|qtIdent(data
{{ data.partition_value }}{% if data.is_partitioned is defined and data.is_partitioned %} {{ data.partition_value }}{% if data.is_partitioned is defined and data.is_partitioned %}
PARTITION BY {{ data.partition_scheme }}{% endif %} PARTITION BY {{ data.partition_scheme }}{% endif %}
{% if data.fillfactor or data.autovacuum_custom or data.autovacuum_enabled or data.toast_autovacuum or data.toast_autovacuum_enabled or (data.autovacuum_enabled and data.vacuum_table|length > 0) or (data.toast_autovacuum_enabled and data.vacuum_toast|length > 0) %} {% if data.fillfactor or data.autovacuum_custom or data.autovacuum_enabled in ('t', 'f') or data.toast_autovacuum or data.toast_autovacuum_enabled in ('t', 'f') or (data.autovacuum_enabled in ('t', 'f') and data.vacuum_table|length > 0) or (data.toast_autovacuum_enabled in ('t', 'f') and data.vacuum_toast|length > 0) %}
{% set 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.autovacuum_custom %} FILLFACTOR = {{ data.fillfactor }}{% 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 %}
{% endif %}{% if data.autovacuum_enabled and data.vacuum_table|length > 0 %} {% 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 %}
{% if ns.add_comma %},
{% endif %}
{{opt.name}} = {{opt.value}}{% endif %}{% if opt.name and opt.value is defined %}{% set ns.add_comma = true%}{% endif %}
{% endfor %}{% endif %}
{% if data.toast_autovacuum and data.vacuum_toast|length > 0 %}
{% for opt in data.vacuum_toast %}{% if opt.name and opt.value is defined %}
, ,
{{opt.name}} = {{opt.value}}{% endif %} toast.{{opt.name}} = {{opt.value}}{% endif %}{% if opt.name and opt.value is defined %}{% set ns.add_comma = true%}{% endif %}
{% endfor %}{% endif %}{% if data.toast_autovacuum_enabled and data.vacuum_toast|length > 0 %}
{% for opt in data.vacuum_toast %}{% if opt.name and opt.value %}
,
toast.{{opt.name}} = {{opt.value}}{% endif %}
{% endfor %}{% endif %} {% endfor %}{% endif %}
){% endif %} ){% endif %}

View File

@@ -7,11 +7,38 @@ SELECT rel.oid, rel.relname AS name,
(CASE WHEN rel.relkind = 'p' THEN true ELSE false END) AS is_partitioned, (CASE WHEN rel.relkind = 'p' THEN true ELSE false END) AS is_partitioned,
(CASE WHEN rel.relkind = 'p' THEN true ELSE false END) AS is_sub_partitioned, (CASE WHEN rel.relkind = 'p' THEN true ELSE false END) AS is_sub_partitioned,
(CASE WHEN rel.relkind = 'p' THEN pg_get_partkeydef(rel.oid::oid) ELSE '' END) AS partition_scheme, (CASE WHEN rel.relkind = 'p' THEN pg_get_partkeydef(rel.oid::oid) ELSE '' END) AS partition_scheme,
(CASE WHEN rel.relkind = 'p' THEN pg_get_partkeydef(rel.oid::oid) ELSE '' END) AS sub_partition_scheme (CASE WHEN rel.relkind = 'p' THEN pg_get_partkeydef(rel.oid::oid) ELSE '' END) AS sub_partition_scheme,
(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 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS autovacuum_enabled,
substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS autovacuum_vacuum_threshold,
substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.]?[0-9]*)') AS autovacuum_vacuum_scale_factor,
substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_analyze_threshold=([0-9]*)') AS autovacuum_analyze_threshold,
substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_analyze_scale_factor=([0-9]*[.]?[0-9]*)') AS autovacuum_analyze_scale_factor,
substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_cost_delay=([0-9]*)') AS autovacuum_vacuum_cost_delay,
substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_cost_limit=([0-9]*)') AS autovacuum_vacuum_cost_limit,
substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS autovacuum_freeze_min_age,
substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS autovacuum_freeze_max_age,
substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS autovacuum_freeze_table_age,
(substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS toast_autovacuum_enabled,
substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS toast_autovacuum_vacuum_threshold,
substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.]?[0-9]*)') AS toast_autovacuum_vacuum_scale_factor,
substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_analyze_threshold=([0-9]*)') AS toast_autovacuum_analyze_threshold,
substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_analyze_scale_factor=([0-9]*[.]?[0-9]*)') AS toast_autovacuum_analyze_scale_factor,
substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_cost_delay=([0-9]*)') AS toast_autovacuum_vacuum_cost_delay,
substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_cost_limit=([0-9]*)') AS toast_autovacuum_vacuum_cost_limit,
substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS toast_autovacuum_freeze_min_age,
substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS toast_autovacuum_freeze_max_age,
substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age,
rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, rel.reloftype, typ.typname,
typ.typrelid AS typoid, des.description, pg_get_userbyid(rel.relowner) AS relowner
FROM FROM
(SELECT * FROM pg_inherits WHERE inhparent = {{ tid }}::oid) inh (SELECT * FROM pg_inherits WHERE inhparent = {{ tid }}::oid) inh
LEFT JOIN pg_class rel ON inh.inhrelid = rel.oid LEFT JOIN pg_class rel ON inh.inhrelid = rel.oid
LEFT JOIN pg_namespace nsp ON rel.relnamespace = nsp.oid LEFT JOIN pg_namespace nsp ON rel.relnamespace = nsp.oid
LEFT OUTER JOIN pg_class tst ON tst.oid = rel.reltoastrelid
LEFT OUTER JOIN pg_description des ON (des.objoid=rel.oid AND des.objsubid=0 AND des.classoid='pg_class'::regclass)
LEFT JOIN pg_type typ ON rel.reloftype=typ.oid
WHERE rel.relispartition WHERE rel.relispartition
{% if ptid %} AND rel.oid = {{ ptid }}::OID {% endif %} {% if ptid %} AND rel.oid = {{ ptid }}::OID {% endif %}
ORDER BY rel.relname; ORDER BY rel.relname;

View File

@@ -27,8 +27,7 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r
WHERE i.inhrelid = rel.oid) AS inherited_tables_cnt, 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,
@@ -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,

View File

@@ -27,8 +27,7 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r
WHERE i.inhrelid = rel.oid) AS inherited_tables_cnt, 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,
@@ -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,

View File

@@ -20,24 +20,25 @@ CREATE {% if data.relpersistence %}UNLOGGED {% endif %}TABLE {{conn|qtIdent(data
{{ data.partition_value }}{% if data.is_partitioned is defined and data.is_partitioned %} {{ data.partition_value }}{% if data.is_partitioned is defined and data.is_partitioned %}
PARTITION BY {{ data.partition_scheme }}{% endif %} PARTITION BY {{ data.partition_scheme }}{% endif %}
{% if data.fillfactor or data.autovacuum_custom or data.autovacuum_enabled or data.toast_autovacuum or data.toast_autovacuum_enabled or (data.autovacuum_enabled and data.vacuum_table|length > 0) or (data.toast_autovacuum_enabled and data.vacuum_toast|length > 0) %} {% if data.fillfactor or data.autovacuum_custom or data.autovacuum_enabled in ('t', 'f') or data.toast_autovacuum or data.toast_autovacuum_enabled in ('t', 'f') or (data.autovacuum_enabled in ('t', 'f') and data.vacuum_table|length > 0) or (data.toast_autovacuum_enabled in ('t', 'f') and data.vacuum_toast|length > 0) %}
{% set 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.autovacuum_custom %} FILLFACTOR = {{ data.fillfactor }}{% 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 %}
{% endif %}{% if data.autovacuum_enabled and data.vacuum_table|length > 0 %} {% 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 %}
, {% if ns.add_comma %},
{{opt.name}} = {{opt.value}}{% endif %} {% endif %}
{% endfor %}{% endif %}{% if data.toast_autovacuum_enabled and data.vacuum_toast|length > 0 %} {{opt.name}} = {{opt.value}}{% endif %}{% if opt.name and opt.value is defined %}{% set ns.add_comma = true%}{% endif %}
{% for opt in data.vacuum_toast %}{% if opt.name and opt.value %} {% endfor %}{% endif %}{% if data.toast_autovacuum and data.vacuum_toast|length > 0 %}
{% for opt in data.vacuum_toast %}{% if opt.name and opt.value is defined %}
, ,
toast.{{opt.name}} = {{opt.value}}{% endif %} toast.{{opt.name}} = {{opt.value}}{% endif %}
{% endfor %}{% endif %} {% endfor %}{% endif %}

View File

@@ -7,11 +7,38 @@ SELECT rel.oid, rel.relname AS name,
(CASE WHEN rel.relkind = 'p' THEN true ELSE false END) AS is_partitioned, (CASE WHEN rel.relkind = 'p' THEN true ELSE false END) AS is_partitioned,
(CASE WHEN rel.relkind = 'p' THEN true ELSE false END) AS is_sub_partitioned, (CASE WHEN rel.relkind = 'p' THEN true ELSE false END) AS is_sub_partitioned,
(CASE WHEN rel.relkind = 'p' THEN pg_get_partkeydef(rel.oid::oid) ELSE '' END) AS partition_scheme, (CASE WHEN rel.relkind = 'p' THEN pg_get_partkeydef(rel.oid::oid) ELSE '' END) AS partition_scheme,
(CASE WHEN rel.relkind = 'p' THEN pg_get_partkeydef(rel.oid::oid) ELSE '' END) AS sub_partition_scheme (CASE WHEN rel.relkind = 'p' THEN pg_get_partkeydef(rel.oid::oid) ELSE '' END) AS sub_partition_scheme,
(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 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS autovacuum_enabled,
substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS autovacuum_vacuum_threshold,
substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.]?[0-9]*)') AS autovacuum_vacuum_scale_factor,
substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_analyze_threshold=([0-9]*)') AS autovacuum_analyze_threshold,
substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_analyze_scale_factor=([0-9]*[.]?[0-9]*)') AS autovacuum_analyze_scale_factor,
substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_cost_delay=([0-9]*)') AS autovacuum_vacuum_cost_delay,
substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_cost_limit=([0-9]*)') AS autovacuum_vacuum_cost_limit,
substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS autovacuum_freeze_min_age,
substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS autovacuum_freeze_max_age,
substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS autovacuum_freeze_table_age,
(substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS toast_autovacuum_enabled,
substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS toast_autovacuum_vacuum_threshold,
substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.]?[0-9]*)') AS toast_autovacuum_vacuum_scale_factor,
substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_analyze_threshold=([0-9]*)') AS toast_autovacuum_analyze_threshold,
substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_analyze_scale_factor=([0-9]*[.]?[0-9]*)') AS toast_autovacuum_analyze_scale_factor,
substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_cost_delay=([0-9]*)') AS toast_autovacuum_vacuum_cost_delay,
substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_cost_limit=([0-9]*)') AS toast_autovacuum_vacuum_cost_limit,
substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS toast_autovacuum_freeze_min_age,
substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS toast_autovacuum_freeze_max_age,
substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age,
rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, rel.reloftype, typ.typname,
typ.typrelid AS typoid, des.description, pg_get_userbyid(rel.relowner) AS relowner
FROM FROM
(SELECT * FROM pg_inherits WHERE inhparent = {{ tid }}::oid) inh (SELECT * FROM pg_inherits WHERE inhparent = {{ tid }}::oid) inh
LEFT JOIN pg_class rel ON inh.inhrelid = rel.oid LEFT JOIN pg_class rel ON inh.inhrelid = rel.oid
LEFT JOIN pg_namespace nsp ON rel.relnamespace = nsp.oid LEFT JOIN pg_namespace nsp ON rel.relnamespace = nsp.oid
LEFT OUTER JOIN pg_class tst ON tst.oid = rel.reltoastrelid
LEFT OUTER JOIN pg_description des ON (des.objoid=rel.oid AND des.objsubid=0 AND des.classoid='pg_class'::regclass)
LEFT JOIN pg_type typ ON rel.reloftype=typ.oid
WHERE rel.relispartition WHERE rel.relispartition
{% if ptid %} AND rel.oid = {{ ptid }}::OID {% endif %} {% if ptid %} AND rel.oid = {{ ptid }}::OID {% endif %}
ORDER BY rel.relname; ORDER BY rel.relname;

View File

@@ -27,8 +27,7 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r
WHERE i.inhrelid = rel.oid) AS inherited_tables_cnt, 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,
@@ -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,

View File

@@ -27,8 +27,7 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r
WHERE i.inhrelid = rel.oid) AS inherited_tables_cnt, 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,
@@ -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,

View File

@@ -69,7 +69,7 @@ CACHE {{c.seqcache|int}} {% endif %}
{{CONSTRAINTS.EXCLUDE(conn, data.exclude_constraint)}}{% endif %} {{CONSTRAINTS.EXCLUDE(conn, data.exclude_constraint)}}{% endif %}
{% if data.like_relation or data.coll_inherits or data.columns|length > 0 or data.primary_key|length > 0 or data.unique_constraint|length > 0 or data.foreign_key|length > 0 or data.check_constraint|length > 0 or data.exclude_constraint|length > 0 %} {% if data.like_relation or data.coll_inherits or data.columns|length > 0 or data.primary_key|length > 0 or data.unique_constraint|length > 0 or data.foreign_key|length > 0 or data.check_constraint|length > 0 or data.exclude_constraint|length > 0 %}
){% endif %}{% if data.relkind is defined and data.relkind == 'p' %} PARTITION BY {{ data.partition_scheme }} {% endif %} ){% endif %}{% if data.relkind is defined and data.relkind == 'p' %} PARTITION BY {{ data.partition_scheme }}{% endif %}
{### If we are inheriting it from another table(s) ###} {### If we are inheriting it from another table(s) ###}
{% if data.coll_inherits %} {% if data.coll_inherits %}

View File

@@ -69,7 +69,7 @@ CACHE {{c.seqcache|int}} {% endif %}
{{CONSTRAINTS.EXCLUDE(conn, data.exclude_constraint)}}{% endif %} {{CONSTRAINTS.EXCLUDE(conn, data.exclude_constraint)}}{% endif %}
{% if data.like_relation or data.coll_inherits or data.columns|length > 0 or data.primary_key|length > 0 or data.unique_constraint|length > 0 or data.foreign_key|length > 0 or data.check_constraint|length > 0 or data.exclude_constraint|length > 0 %} {% if data.like_relation or data.coll_inherits or data.columns|length > 0 or data.primary_key|length > 0 or data.unique_constraint|length > 0 or data.foreign_key|length > 0 or data.check_constraint|length > 0 or data.exclude_constraint|length > 0 %}
){% endif %}{% if data.relkind is defined and data.relkind == 'p' %} PARTITION BY {{ data.partition_scheme }} {% endif %} ){% endif %}{% if data.relkind is defined and data.relkind == 'p' %} PARTITION BY {{ data.partition_scheme }}{% endif %}
{### If we are inheriting it from another table(s) ###} {### If we are inheriting it from another table(s) ###}
{% if data.coll_inherits %} {% if data.coll_inherits %}

View File

@@ -74,7 +74,7 @@ CACHE {{c.seqcache|int}} {% endif %}
{{CONSTRAINTS.EXCLUDE(conn, data.exclude_constraint)}}{% endif %} {{CONSTRAINTS.EXCLUDE(conn, data.exclude_constraint)}}{% endif %}
{% if data.like_relation or data.coll_inherits or data.columns|length > 0 or data.primary_key|length > 0 or data.unique_constraint|length > 0 or data.foreign_key|length > 0 or data.check_constraint|length > 0 or data.exclude_constraint|length > 0 %} {% if data.like_relation or data.coll_inherits or data.columns|length > 0 or data.primary_key|length > 0 or data.unique_constraint|length > 0 or data.foreign_key|length > 0 or data.check_constraint|length > 0 or data.exclude_constraint|length > 0 %}
){% endif %}{% if data.relkind is defined and data.relkind == 'p' %} PARTITION BY {{ data.partition_scheme }} {% endif %} ){% endif %}{% if data.relkind is defined and data.relkind == 'p' %} PARTITION BY {{ data.partition_scheme }}{% endif %}
{% if not data.coll_inherits and not data.spcname and not with_clause %};{% endif %} {% if not data.coll_inherits and not data.spcname and not with_clause %};{% endif %}
{### If we are inheriting it from another table(s) ###} {### If we are inheriting it from another table(s) ###}

View File

@@ -664,10 +664,64 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
part_data['partition_value'] = row['partition_value'] part_data['partition_value'] = row['partition_value']
part_data['is_partitioned'] = row['is_partitioned'] part_data['is_partitioned'] = row['is_partitioned']
part_data['partition_scheme'] = row['partition_scheme'] part_data['partition_scheme'] = row['partition_scheme']
part_data['description'] = row['description']
part_data['relowner'] = row['relowner']
self.update_autovacuum_properties(row)
part_data['fillfactor'] = row['fillfactor']
part_data['autovacuum_custom'] = row['autovacuum_custom']
part_data['autovacuum_enabled'] = row['autovacuum_enabled']
part_data['autovacuum_vacuum_threshold'] = \
row['autovacuum_vacuum_threshold']
part_data['autovacuum_vacuum_scale_factor'] = \
row['autovacuum_vacuum_scale_factor']
part_data['autovacuum_analyze_threshold'] = \
row['autovacuum_analyze_threshold']
part_data['autovacuum_analyze_scale_factor'] = \
row['autovacuum_analyze_scale_factor']
part_data['autovacuum_vacuum_cost_delay'] = \
row['autovacuum_vacuum_cost_delay']
part_data['autovacuum_vacuum_cost_limit'] = \
row['autovacuum_vacuum_cost_limit']
part_data['autovacuum_freeze_min_age'] = \
row['autovacuum_freeze_min_age']
part_data['autovacuum_freeze_max_age'] = \
row['autovacuum_freeze_max_age']
part_data['autovacuum_freeze_table_age'] = \
row['autovacuum_freeze_table_age']
part_data['toast_autovacuum'] = row['toast_autovacuum']
part_data['toast_autovacuum_enabled'] = \
row['toast_autovacuum_enabled']
part_data['toast_autovacuum_vacuum_threshold'] = \
row['toast_autovacuum_vacuum_threshold']
part_data['toast_autovacuum_vacuum_scale_factor'] = \
row['toast_autovacuum_vacuum_scale_factor']
part_data['toast_autovacuum_analyze_threshold'] = \
row['toast_autovacuum_analyze_threshold']
part_data['toast_autovacuum_analyze_scale_factor'] = \
row['toast_autovacuum_analyze_scale_factor']
part_data['toast_autovacuum_vacuum_cost_delay'] = \
row['toast_autovacuum_vacuum_cost_delay']
part_data['toast_autovacuum_vacuum_cost_limit'] = \
row['toast_autovacuum_vacuum_cost_limit']
part_data['toast_autovacuum_freeze_min_age'] = \
row['toast_autovacuum_freeze_min_age']
part_data['toast_autovacuum_freeze_max_age'] = \
row['toast_autovacuum_freeze_max_age']
part_data['toast_autovacuum_freeze_table_age'] = \
row['toast_autovacuum_freeze_table_age']
# We will add Auto vacuum defaults with out result for grid
part_data['vacuum_table'] = \
copy.deepcopy(self.parse_vacuum_data(
self.conn, row, 'table'))
part_data['vacuum_toast'] = \
copy.deepcopy(self.parse_vacuum_data(
self.conn, row, 'toast'))
partition_sql += render_template("/".join( partition_sql += render_template("/".join(
[self.partition_template_path, 'create.sql']), [self.partition_template_path, 'create.sql']),
data=part_data, conn=self.conn) data=part_data, conn=self.conn) + '\n'
# Add into main sql # Add into main sql
partition_sql = re.sub('\n{2,}', '\n\n', partition_sql partition_sql = re.sub('\n{2,}', '\n\n', partition_sql
@@ -1730,3 +1784,46 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
if len(reset_values) > 0: if len(reset_values) > 0:
data[vacuum_key]['reset_values'] = reset_values data[vacuum_key]['reset_values'] = reset_values
def update_autovacuum_properties(self, res):
"""
This function sets the appropriate value for autovacuum_enabled and
autovacuum_custom for table & toast table both.
:param res:
:return:
"""
# Set value based on
# x: No set, t: true, f: false
if res is not None:
res['autovacuum_enabled'] = 'x' \
if res['autovacuum_enabled'] is None else \
{True: 't', False: 'f'}[res['autovacuum_enabled']]
res['toast_autovacuum_enabled'] = 'x' \
if res['toast_autovacuum_enabled'] is None else \
{True: 't', False: 'f'}[
res['toast_autovacuum_enabled']]
# Enable custom autovaccum only if one of the options is set
# or autovacuum is set
res['autovacuum_custom'] = any([
res['autovacuum_vacuum_threshold'],
res['autovacuum_vacuum_scale_factor'],
res['autovacuum_analyze_threshold'],
res['autovacuum_analyze_scale_factor'],
res['autovacuum_vacuum_cost_delay'],
res['autovacuum_vacuum_cost_limit'],
res['autovacuum_freeze_min_age'],
res['autovacuum_freeze_max_age'],
res['autovacuum_freeze_table_age']]) or \
res['autovacuum_enabled'] in ('t', 'f')
res['toast_autovacuum'] = any([
res['toast_autovacuum_vacuum_threshold'],
res['toast_autovacuum_vacuum_scale_factor'],
res['toast_autovacuum_analyze_threshold'],
res['toast_autovacuum_analyze_scale_factor'],
res['toast_autovacuum_vacuum_cost_delay'],
res['toast_autovacuum_vacuum_cost_limit'],
res['toast_autovacuum_freeze_min_age'],
res['toast_autovacuum_freeze_max_age'],
res['toast_autovacuum_freeze_table_age']]) or \
res['toast_autovacuum_enabled'] in ('t', 'f')