Skip to content

Commit 4e8de53

Browse files
committed
Make a defined type for setting table attributes
Prior to this commit, there was a psql command to change a table attribute. This was difficult when trying to point people to an example that would allow them to do the same for a different table After this commit, the psql command has been abstracted into a defined type that makes it easier to set arbitrary table attributes. A new defined type has been made for the specific case of setting autovacuum_cost_delay=0
1 parent b17b537 commit 4e8de53

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

manifests/postgresql_settings.pp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,6 @@
9393
}
9494

9595
if $manage_fact_values_autovacuum_cost_delay {
96-
postgresql_psql { 'Set autovacuum_cost_delay=0 for fact_values' :
97-
command => 'ALTER TABLE fact_values SET ( autovacuum_vacuum_cost_delay = 0 )',
98-
unless => 'SELECT reloptions FROM pg_class WHERE relname = \'fact_values\' AND CAST(reloptions as text) LIKE \'%autovacuum_vacuum_cost_delay=0%\'',
99-
db => 'pe-puppetdb',
100-
psql_user => 'pe-postgres',
101-
psql_group => 'pe-postgres',
102-
psql_path => '/opt/puppetlabs/server/bin/psql',
103-
}
96+
pe_databases::set_puppetdb_table_autovacuum_cost_delay_zero { 'fact_values' : }
10497
}
10598
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
define pe_databases::set_puppetdb_table_autovacuum_cost_delay_zero (
2+
String $table_name = $title,
3+
) {
4+
5+
pe_databases::set_table_attribute { "Set autovacuum_cost_delay=0 for ${table_name}" :
6+
db => 'pe-puppetdb',
7+
table_name => $table_name,
8+
table_attribute => 'autovacuum_vacuum_cost_delay',
9+
table_attribute_value => '0',
10+
}
11+
}

manifests/set_table_attribute.pp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
define pe_databases::set_table_attribute (
2+
String $db,
3+
String $table_name,
4+
String $table_attribute,
5+
String $table_attribute_value,
6+
) {
7+
8+
postgresql_psql { "Set ${table_attribute}=${table_attribute_value} for ${table_name}" :
9+
command => "ALTER TABLE ${table_name} SET ( ${table_attribute} = 0 )",
10+
unless => "SELECT reloptions FROM pg_class WHERE relname = '${table_name}' AND CAST(reloptions as text) LIKE '%${table_attribute}=${table_attribute_value}%'",
11+
db => $db,
12+
psql_user => 'pe-postgres',
13+
psql_group => 'pe-postgres',
14+
psql_path => '/opt/puppetlabs/server/bin/psql',
15+
}
16+
}

0 commit comments

Comments
 (0)