Skip to content

Commit f47ac68

Browse files
committed
Add pg_repack as default maintenance strategy
1 parent 2f7a570 commit f47ac68

File tree

5 files changed

+171
-68
lines changed

5 files changed

+171
-68
lines changed

manifests/maintenance.pp

Lines changed: 14 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,25 @@
11
class pe_databases::maintenance (
2-
Boolean $disable_maintenace = false,
3-
Optional[Integer] $maint_cron_weekday = undef, #DEPRECATED
4-
Optional[Integer] $maint_cron_hour = undef, #DEPRECATED
5-
Optional[Integer] $maint_cron_minute = undef, #DEPRECATED
2+
Boolean $disable_maintenance = false,
63
String $logging_directory = '/var/log/puppetlabs/pe_databases_cron',
74
String $script_directory = $pe_databases::scripts_dir,
85
){
96

10-
$ensure_cron = $disable_maintenace ? {
11-
true => absent,
12-
default => present
7+
#If the PE Version includes pg_repack (2018.1.7 and 2019.0.2) then use pg_repack and remove the old script and cron jobs
8+
if ( versioncmp( '2018.1.7', $facts['pe_server_version']) <= 0 and versioncmp($facts['pe_server_version'], '2019.0.0') < 0 ) {
9+
include pe_databases::maintenance::pg_repack
10+
class { 'pe_databases::maintenance::vacuum_full':
11+
disable_maintenance => true,
12+
}
13+
} elsif ( versioncmp( '2019.0.2', $facts['pe_server_version']) <= 0 ) {
14+
include pe_databases::maintenance::pg_repack
15+
class { 'pe_databases::maintenance::vacuum_full':
16+
disable_maintenance => true,
17+
}
18+
} else {
19+
include pe_databases::maintenance::vacuum_full
1320
}
1421

1522
file { $logging_directory :
1623
ensure => directory,
1724
}
18-
19-
$vacuum_script_path = "${script_directory}/vacuum_full_tables.sh"
20-
21-
file { $vacuum_script_path:
22-
ensure => file,
23-
source => 'puppet:///modules/pe_databases/vacuum_full_tables.sh',
24-
owner => 'pe-postgres',
25-
group => 'pe-postgres',
26-
mode => '0744',
27-
}
28-
29-
cron { 'VACUUM FULL facts tables' :
30-
ensure => $ensure_cron,
31-
user => 'root',
32-
weekday => [2,6],
33-
hour => 4,
34-
minute => 30,
35-
command => "${vacuum_script_path} facts",
36-
require => File[$logging_directory, $script_directory],
37-
}
38-
39-
cron { 'VACUUM FULL catalogs tables' :
40-
ensure => $ensure_cron,
41-
user => 'root',
42-
weekday => [0,4],
43-
hour => 4,
44-
minute => 30,
45-
command => "${vacuum_script_path} catalogs",
46-
require => File[$logging_directory, $script_directory],
47-
}
48-
49-
cron { 'VACUUM FULL other tables' :
50-
ensure => $ensure_cron,
51-
user => 'root',
52-
monthday => 20,
53-
hour => 5,
54-
minute => 30,
55-
command => "${vacuum_script_path} other",
56-
require => File[$logging_directory, $script_directory],
57-
}
58-
59-
#Remove old versions of maintenance cron jobs
60-
cron { 'Maintain PE databases' :
61-
ensure => absent,
62-
user => 'root',
63-
weekday => $maint_cron_weekday,
64-
hour => $maint_cron_hour,
65-
minute => $maint_cron_minute,
66-
command => "su - pe-postgres -s /bin/bash -c '/opt/puppetlabs/server/bin/reindexdb --all; /opt/puppetlabs/server/bin/vacuumdb --analyze --verbose --all' > ${logging_directory}/output.log 2> ${logging_directory}/output_error.log",
67-
require => File[$logging_directory, $script_directory],
68-
}
69-
70-
if empty($maint_cron_weekday) == false {
71-
warning('pe_databases::maintenance::maint_cron_weekday is deprecated and will be removed in a future release')
72-
}
73-
if empty($maint_cron_hour) == false {
74-
warning('pe_databases::maintenance::maint_cron_hour is deprecated and will be removed in a future release')
75-
}
76-
if empty($maint_cron_minute) == false {
77-
warning('pe_databases::maintenance::maint_cron_minute is deprecated and will be removed in a future release')
78-
}
7925
}

manifests/maintenance/pg_repack.pp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# A description of what this class does
2+
#
3+
# @summary A short summary of the purpose of this class
4+
#
5+
# @example
6+
# include pe_databases::maintenance::pg_repack
7+
class pe_databases::maintenance::pg_repack (
8+
Boolean $disable_maintenance = $pe_databases::maintenance::disable_maintenance,
9+
String $logging_directory = $pe_databases::maintenance::logging_directory,
10+
) {
11+
12+
$ensure_cron = $disable_maintenance ? {
13+
true => absent,
14+
default => present
15+
}
16+
17+
$repack = 'su - pe-postgres -s /bin/bash -c "/opt/puppetlabs/server/apps/postgresql/bin/pg_repack -d pe-puppetdb'
18+
$facts_tables = '-t factsets -t fact_paths"'
19+
$catalogs_tables = '-t catalogs -t catalog_resources -t edges -t certnames"'
20+
$other_tables = '-t producers -t resource_params -t resource_params_cache"'
21+
$reports_tables = '-t reports"'
22+
$logging = "> ${logging_directory}/output.log 2>&1"
23+
24+
cron { 'pg_repack facts tables' :
25+
ensure => $ensure_cron,
26+
user => 'root',
27+
weekday => [2,6],
28+
hour => 4,
29+
minute => 30,
30+
command => "${repack} ${facts_tables} ${logging}",
31+
require => File[$logging_directory],
32+
}
33+
34+
cron { 'pg_repack catalogs tables' :
35+
ensure => $ensure_cron,
36+
user => 'root',
37+
weekday => [0,4],
38+
hour => 4,
39+
minute => 30,
40+
command => "${repack} ${catalogs_tables} ${logging}",
41+
require => File[$logging_directory],
42+
}
43+
44+
cron { 'pg_repack other tables' :
45+
ensure => $ensure_cron,
46+
user => 'root',
47+
monthday => 20,
48+
hour => 5,
49+
minute => 30,
50+
command => "${repack} ${other_tables} ${logging}",
51+
require => File[$logging_directory],
52+
}
53+
54+
cron { 'pg_repack reports tables' :
55+
ensure => $ensure_cron,
56+
user => 'root',
57+
monthday => 10,
58+
hour => 5,
59+
minute => 30,
60+
command => "${repack} ${reports_tables} ${logging}",
61+
require => File[$logging_directory],
62+
}
63+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# A description of what this class does
2+
#
3+
# @summary A short summary of the purpose of this class
4+
#
5+
# @example
6+
# include pe_databases::maintenance::vacuum_full
7+
class pe_databases::maintenance::vacuum_full (
8+
Boolean $disable_maintenance = $pe_databases::maintenance::disable_maintenance,
9+
String $logging_directory = $pe_databases::maintenance::logging_directory,
10+
String $script_directory = $pe_databases::maintenance::script_directory,
11+
){
12+
13+
$ensure_cron = $disable_maintenance ? {
14+
true => absent,
15+
default => present
16+
}
17+
18+
$ensure_vacuum_script = $disable_maintenance ? {
19+
true => absent,
20+
default => file
21+
}
22+
23+
$vacuum_script_path = "${script_directory}/vacuum_full_tables.sh"
24+
25+
file { $vacuum_script_path:
26+
ensure => $ensure_vacuum_script,
27+
source => 'puppet:///modules/pe_databases/vacuum_full_tables.sh',
28+
owner => 'pe-postgres',
29+
group => 'pe-postgres',
30+
mode => '0744',
31+
}
32+
33+
cron { 'VACUUM FULL facts tables' :
34+
ensure => $ensure_cron,
35+
user => 'root',
36+
weekday => [2,6],
37+
hour => 4,
38+
minute => 30,
39+
command => "${vacuum_script_path} facts",
40+
require => File[$logging_directory, $script_directory],
41+
}
42+
43+
cron { 'VACUUM FULL catalogs tables' :
44+
ensure => $ensure_cron,
45+
user => 'root',
46+
weekday => [0,4],
47+
hour => 4,
48+
minute => 30,
49+
command => "${vacuum_script_path} catalogs",
50+
require => File[$logging_directory, $script_directory],
51+
}
52+
53+
cron { 'VACUUM FULL other tables' :
54+
ensure => $ensure_cron,
55+
user => 'root',
56+
monthday => 20,
57+
hour => 5,
58+
minute => 30,
59+
command => "${vacuum_script_path} other",
60+
require => File[$logging_directory, $script_directory],
61+
}
62+
63+
#Remove old versions of maintenance cron jobs
64+
cron { 'Maintain PE databases' :
65+
ensure => absent,
66+
user => 'root',
67+
command => "su - pe-postgres -s /bin/bash -c '/opt/puppetlabs/server/bin/reindexdb --all; /opt/puppetlabs/server/bin/vacuumdb --analyze --verbose --all' > ${logging_directory}/output.log 2> ${logging_directory}/output_error.log",
68+
require => File[$logging_directory, $script_directory],
69+
}
70+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require 'spec_helper'
2+
3+
describe 'pe_databases::maintenance::pg_repack' do
4+
on_supported_os.each do |os, os_facts|
5+
context "on #{os}" do
6+
let(:pre_condition) { "class { 'pe_databases': }" }
7+
let(:facts) { os_facts }
8+
9+
it { is_expected.to compile }
10+
end
11+
end
12+
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require 'spec_helper'
2+
3+
describe 'pe_databases::maintenance::vacuum_full' do
4+
on_supported_os.each do |os, os_facts|
5+
context "on #{os}" do
6+
let(:pre_condition) { "class { 'pe_databases': }" }
7+
let(:facts) { os_facts }
8+
9+
it { is_expected.to compile }
10+
end
11+
end
12+
end

0 commit comments

Comments
 (0)