Skip to content

Commit 4daa3cc

Browse files
dbRMRails Machine
authored and
Rails Machine
committed
Update for PostgreSQL 10.
1 parent dc9a118 commit 4daa3cc

File tree

9 files changed

+146
-40
lines changed

9 files changed

+146
-40
lines changed

README.rdoc

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
= Moonshine Postgres9
1+
= Moonshine Postgres10
22

33
=== A plugin for Moonshine[http://github.com/railsmachine/moonshine]
44

5-
A plugin for installing and managing postgres_9.
5+
A plugin for installing and managing postgres_10.
66

77
=== Instructions
88

9-
* <tt>script/plugin install git://github.com/railsmachine/moonshine_postgres_9.git</tt>
9+
* <tt>script/plugin install git://github.com/railsmachine/moonshine_postgres_10.git</tt>
1010
* Configure settings if needed
11-
configure(:postgresql => {:version => '9.2'})
11+
configure(:postgresql => {:version => '10.2'})
1212
* Add the following line near the top of your manifest:
13-
include Moonshine::Postgres9
13+
include Moonshine::Postgres10
1414

15-
As long as you're using one of the standard moonshine stacks, like <code>:default_stack</code>, then the postgres 9 recipes will override the default Postgres recipes and install version 9.x instead.
15+
As long as you're using one of the standard moonshine stacks, like <code>:default_stack</code>, then the postgres 10 recipes will override the default Postgres recipes and install version 10.x instead.
1616

17-
Moonshine Postgres9 enables SSL connections between the client and server. The
17+
Moonshine Postgres10 enables SSL connections between the client and server. The
1818
server requires an SSL certificate and key to be placed at
1919
<code>$PGDATA/server.crt</cody> and <code>$PGDATA/server.key</code> respectively.
20-
The {PostgreSQL docs}(http://www.postgresql.org/docs/9.1/static/ssl-tcp.html)
20+
The {PostgreSQL docs}(http://www.postgresql.org/docs/10.1/static/ssl-tcp.html)
2121
describe the steps to create a self-signed certificate.

lib/moonshine/postgres_9.rb renamed to lib/moonshine/postgres_10.rb

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Moonshine
2-
module Postgres9
2+
module Postgres10
33

44
def self.included(manifest)
55
manifest.class_eval do
@@ -29,14 +29,9 @@ def postgresql_standby_server
2929
end
3030

3131
def postgresql_version
32-
(configuration[:postgresql] && configuration[:postgresql][:version]) || '9.0'
32+
(configuration[:postgresql] && configuration[:postgresql][:version]) || '10.0'
3333
end
3434

35-
def postgresql_supports_custom_variable_classes?
36-
postgresql_version <= '9.1'
37-
end
38-
39-
4035
def postgresql_restart_on_change
4136
restart_on_change = configuration[:postgresql][:restart_on_change]
4237
restart_on_change = true if restart_on_change.nil? # treat nil as true, to be able to default
@@ -99,8 +94,8 @@ def postgresql_client
9994
end
10095

10196

102-
# Installs <tt>postgresql-9.x</tt> from apt and enables the <tt>postgresql</tt>
103-
# service. Using a backports repo to get version 9.x:
97+
# Installs <tt>postgresql-10.x</tt> from apt and enables the <tt>postgresql</tt>
98+
# service. Using a backports repo to get version 10.x:
10499
# https://launchpad.net/~pitti/+archive/postgresql
105100
def postgresql_server(options = {})
106101
version = postgresql_version
@@ -125,6 +120,13 @@ def postgresql_server(options = {})
125120
[]
126121
end
127122
# ensure the postgresql key is present on the configuration hash
123+
file "/usr/share/postgresql-common/init.d-functions",
124+
:ensure => :present,
125+
:content => template(File.join(File.dirname(__FILE__), '..', '..', 'templates', 'init.d-functions.erb'), binding),
126+
:mode => '600',
127+
:owner => 'root',
128+
:group => 'root',
129+
:notify => notifies
128130
file "/etc/postgresql/#{version}/main/pg_hba.conf",
129131
:ensure => :present,
130132
:content => template(File.join(File.dirname(__FILE__), '..', '..', 'templates', 'pg_hba.conf.erb'), binding),
@@ -335,7 +337,7 @@ def postgresql_replication_standby
335337

336338
# it's easy for other postgresql versions get installed. make sure they are uninstalled, and therefore not running
337339
def only_correct_postgres_version
338-
%w(8.4 9.0 9.1 9.2 9.3 9.4 9.5 9.6).each do |version|
340+
%w(9.6 10.0 10.1).each do |version|
339341
if version != postgresql_version.to_s # need to_s, because YAML may think it's a float
340342
package "postgresql-#{version}", :ensure => :absent
341343
package "postgresql-contrib-#{version}", :ensure => :absent

moonshine/init.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
require File.dirname(__FILE__) + '/../lib/moonshine/postgres_9'
1+
require File.dirname(__FILE__) + '/../lib/moonshine/postgres_10'

recipes/moonshine_postgres_recipes.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
set :postgresql_version do
2-
moonshine_yml[:postgresql][:version] || '9.0'
2+
moonshine_yml[:postgresql][:version] || '10.1'
33
end
44

55
namespace :postgresql do

spec/postgres_9_spec.rb renamed to spec/postgres_10_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
describe "A manifest with the Postgres84 plugin" do
44

55
before do
6-
@manifest = Postgres9Manifest.new
7-
@manifest.postgres_9
6+
@manifest = Postgres10Manifest.new
7+
@manifest.postgres_10
88
end
99

1010
it "should be executable" do
@@ -17,4 +17,4 @@
1717
# @manifest.execs['newaliases'].refreshonly.should be_true
1818
#end
1919

20-
end
20+
end

spec/spec_helper.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/../../../..'
44

55
require File.join(File.dirname(__FILE__), '..', '..', 'moonshine', 'lib', 'moonshine.rb')
6-
require File.join(File.dirname(__FILE__), '..', 'lib', 'postgres_9.rb')
6+
require File.join(File.dirname(__FILE__), '..', 'lib', 'postgres_10.rb')
77

88
require 'shadow_puppet/test'
99

10-
class Postgres9Manifest < Moonshine::Manifest::Rails
10+
class Postgres10Manifest < Moonshine::Manifest::Rails
1111
path = Pathname.new(__FILE__).dirname.join('..', 'moonshine', 'init.rb')
1212
Kernel.eval(File.read(path), binding, path)
1313
end

templates/init.d-functions.erb

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# This file contains common functionality for all postgresql server
2+
# package init.d scripts. It is usually included by
3+
# /etc/init.d/postgresql
4+
5+
init_functions=/lib/lsb/init-functions
6+
alias pg_ctlcluster="pg_ctlcluster --skip-systemctl-redirect"
7+
8+
#redhat# init_functions=/usr/share/postgresql-common/init-functions-compat
9+
. $init_functions
10+
11+
PGBINROOT="/usr/lib/postgresql/"
12+
#redhat# PGBINROOT="/usr/pgsql-"
13+
14+
# do pg_ctlcluster action $1 to all clusters of version $2 with command
15+
# description $3; output according to Debian Policy for init scripts
16+
do_ctl_all() {
17+
[ "$1" ] || { echo "Error: invalid command '$1'" >&2; exit 1; }
18+
[ "$2" ] || { echo "Error: invalid version '$2'" >&2; exit 1; }
19+
[ -d "/etc/postgresql/$2" ] || return 0
20+
[ "$(ls /etc/postgresql/$2)" ] || return 0
21+
[ -x "$PGBINROOT$2/bin/postgres" ] || return 0
22+
23+
status=0
24+
log_daemon_msg "$3"
25+
for c in /etc/postgresql/"$2"/*; do
26+
[ -e "$c/postgresql.conf" ] || continue
27+
name=$(basename "$c")
28+
29+
# evaluate start.conf
30+
if [ -e "$c/start.conf" ]; then
31+
start=$(sed 's/#.*$//; /^[[:space:]]*$/d; s/^\s*//; s/\s*$//' "$c/start.conf")
32+
else
33+
start=auto
34+
fi
35+
[ "$start" = "auto" ] || continue
36+
37+
log_progress_msg "$name"
38+
set +e
39+
if [ "$1" = "stop" ] || [ "$1" = "restart" ]; then
40+
ERRMSG=$(pg_ctlcluster --force "$2" "$name" $1 2>&1)
41+
else
42+
ERRMSG=$(pg_ctlcluster "$2" "$name" $1 2>&1)
43+
fi
44+
res=$?
45+
set -e
46+
# Do not fail on success or if cluster is already/not running
47+
[ $res -eq 0 ] || [ $res -eq 2 ] || status=$(($status || $res))
48+
done
49+
if [ $status -ne 0 -a -n "$ERRMSG" ]; then
50+
log_failure_msg "$ERRMSG"
51+
fi
52+
log_end_msg $status
53+
return $status
54+
}
55+
56+
# create /var/run/postgresql
57+
create_socket_directory() {
58+
if [ -d /var/run/postgresql ]; then
59+
chmod 2775 /var/run/postgresql
60+
else
61+
install -d -m 2775 -o postgres -g postgres /var/run/postgresql
62+
[ -x /sbin/restorecon ] && restorecon -R /var/run/postgresql || true
63+
fi
64+
}
65+
66+
# start all clusters of version $1
67+
# output according to Debian Policy for init scripts
68+
start() {
69+
do_ctl_all start "$1" "Starting PostgreSQL $1 database server"
70+
}
71+
72+
# stop all clusters of version $1
73+
# output according to Debian Policy for init scripts
74+
stop() {
75+
do_ctl_all stop "$1" "Stopping PostgreSQL $1 database server"
76+
}
77+
78+
# restart all clusters of version $1
79+
# output according to Debian Policy for init scripts
80+
restart() {
81+
do_ctl_all restart "$1" "Restarting PostgreSQL $1 database server"
82+
}
83+
84+
# reload all clusters of version $1
85+
# output according to Debian Policy for init scripts
86+
reload() {
87+
do_ctl_all reload "$1" "Reloading PostgreSQL $1 database server"
88+
}
89+
90+
status() {
91+
CLUSTERS=`pg_lsclusters -h | grep "^$1[[:space:]]"`
92+
# no clusters -> unknown status
93+
[ -n "$CLUSTERS" ] || exit 4
94+
echo "$CLUSTERS" | awk 'BEGIN {rc=0; printf("Running clusters: ")} {if (match($4, "online")) printf ("%s/%s ", $1, $2); else rc=3} END { printf("\n"); exit rc }'
95+
}
96+
97+
# return all installed versions which do not have their own init script
98+
get_versions() {
99+
versions=''
100+
local v dir skipinit
101+
102+
skipinit=continue
103+
#redhat# skipinit=true # RedHat systems will have /etc/init.d/postgresql-* provided by the yum.pg.o package
104+
dir=$PGBINROOT
105+
#redhat# dir="-d /usr/pgsql-*"
106+
107+
for v in `ls $dir 2>/dev/null`; do
108+
#redhat# v=${v#*-}
109+
[ -x /etc/init.d/postgresql-$v ] && $skipinit
110+
if [ -x $PGBINROOT$v/bin/pg_ctl ]; then
111+
versions="$versions $v"
112+
fi
113+
done
114+
}

templates/postgresql.conf.erb

+2-12
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,7 @@ max_connections = <%= configuration[:postgresql][:max_connections] || 100 %> #
6767
# connection slot, plus lock space (see max_locks_per_transaction). You might
6868
# also need to raise shared_buffers to support more connections.
6969
#superuser_reserved_connections = 3 # (change requires restart)
70-
<% if configuration[:postgresql][:version].to_f > 9.2 %>
7170
unix_socket_directories = '/var/run/postgresql' # (change requires restart)
72-
<% else %>
73-
unix_socket_directory = '/var/run/postgresql' # (change requires restart)
74-
<% end %>
7571
#unix_socket_group = '' # (change requires restart)
7672
#unix_socket_permissions = 0777 # begin with 0 to use octal notation
7773
# (change requires restart)
@@ -178,12 +174,8 @@ wal_buffers = <%= configuration[:postgresql][:wal_buffers] %>
178174

179175
# - Checkpoints -
180176

181-
<% if configuration[:postgresql][:version].to_f > 9.4 %>
182-
max_wal_size = <%= configuration[:postgresql][:max_wal_size] || '1GB' %> # max size to let the WAL grow to between automatic WAL checkpoints
183-
min_wal_size = <%= configuration[:postgresql][:min_wal_size] || '80MB' %> # used to ensure that enough WAL space is reserved to handle spikes in WAL usage
184-
<% else %>
185-
checkpoint_segments = <%= configuration[:postgresql][:checkpoint_segments] || '3' %> # in logfile segments, min 1, 16MB each
186-
<% end %>
177+
min_wal_size = <%= configuration[:postgresql][:min_wal_size] || '80MB ' %>
178+
max_wal_size = <%= configuration[:postgresql][:max_wal_size] || '1024MB' %>
187179
checkpoint_timeout = <%= configuration[:postgresql][:checkpoint_timeout] || '5min' %> # range 30s-1h
188180
checkpoint_completion_target = <%= configuration[:postgresql][:checkpoint_completion_target] || 0.5 %> # checkpoint target duration, 0.0 - 1.0
189181
#checkpoint_warning = 30s # 0 is off
@@ -515,10 +507,8 @@ default_text_search_config = 'pg_catalog.english'
515507
# CUSTOMIZED OPTIONS
516508
#------------------------------------------------------------------------------
517509

518-
#custom_variable_classes = '' # list of custom variable class names
519510

520511
<% if configuration[:postgresql][:shared_preload_libraries] %>shared_preload_libraries = '<%= configuration[:postgresql][:shared_preload_libraries] %>'<% end %>
521-
<% if configuration[:postgresql][:custom_variable_classes] && postgresql_supports_custom_variable_classes? %>custom_variable_classes = '<%= configuration[:postgresql][:custom_variable_classes] %>'<% end %>
522512
<% if configuration[:postgresql][:auto_explain_log_min_duration] %>auto_explain.log_min_duration = '<%= configuration[:postgresql][:auto_explain_log_min_duration] %>'<% end %>
523513

524514
<% if configuration[:postgresql][:pg_stat_statements_max] %>

templates/recovery.conf.erb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# restore with a simple copy
2-
restore_command = 'rsync -aq /var/lib/postgresql/9.2/main/pg_xlogarch/%f %p'
2+
restore_command = 'rsync -aq /var/lib/postgresql/10.1/main/pg_xlogarch/%f %p'
33

44
# get WAL files from barman archive
55
#restore_command = '/var/lib/postgresql/scripts/get_barman_wal.sh archiveserver1 /var/lib/barman/db1/wals %f %p'
66

77
# delete unneeded archive files
8-
archive_cleanup_command = '/usr/lib/postgresql/9.2/bin/pg_archivecleanup /var/lib/postgresql/9.2/main/pg_xlogarch %r'
8+
archive_cleanup_command = '/usr/lib/postgresql/10.1/bin/pg_archivecleanup /var/lib/postgresql/10.1/main/pg_xlogarch %r'
99

1010
# become a standby..if 'off' don't wait for more xlogs
1111
standby_mode = 'on'
@@ -40,4 +40,4 @@ recovery_target_timeline = 'latest'
4040
# NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
4141
# PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS,
4242
# AND POSTGRESQL EXPERTS, INC. HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE,
43-
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
43+
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

0 commit comments

Comments
 (0)