Merge lp:~dpb/storm/db-setup-pg-shmmax into lp:storm

Proposed by David Britton
Status: Merged
Approved by: Andreas Hasenack
Approved revision: 460
Merged at revision: 457
Proposed branch: lp:~dpb/storm/db-setup-pg-shmmax
Merge into: lp:storm
Diff against target: 44 lines (+22/-3)
1 file modified
dev/db-setup (+22/-3)
To merge this branch: bzr merge lp:~dpb/storm/db-setup-pg-shmmax
Reviewer Review Type Date Requested Status
Andreas Hasenack (community) Approve
Review via email: mp+150625@code.launchpad.net

Description of the change

On pg9.1 and certain memory configurations, the settings introduced by dev/db-setup can overrun the default shmmax settings on the kernel. This change catches the error and attempts to tune the kernel correctly.

To post a comment you must log in.
lp:~dpb/storm/db-setup-pg-shmmax updated
458. By David Britton

s/foo/output/

459. By David Britton

s/-E/-r/ on sed command

Revision history for this message
Andreas Hasenack (ahasenack) wrote :

Just make sure $size is a number before writing it to that file and feeding it to sysctl. That regexp might fail one day if the error message from postgresql changes.

review: Approve
lp:~dpb/storm/db-setup-pg-shmmax updated
460. By David Britton

use is_number bash function to test, before setting kernel tunable

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'dev/db-setup'
2--- dev/db-setup 2012-03-28 10:36:14 +0000
3+++ dev/db-setup 2013-02-26 21:42:20 +0000
4@@ -5,12 +5,33 @@
5 PGINIT=/etc/init.d/postgresql*
6 MYSQL_PRIVS="GRANT ALL PRIVILEGES ON *.* TO '$USER'@'localhost' IDENTIFIED BY '' WITH GRANT OPTION;"
7
8+is_number() {
9+ test "$1" && printf '%f' "$1" >/dev/null;
10+}
11+
12+# Restart service and examine output to attempt to adjust kernel tunables
13+restart_service() {
14+ sudo $PGINIT stop
15+ set +e
16+ output=$(sudo $PGINIT start 2>&1)
17+ rc=$?
18+ set -e
19+ if [ $rc -ne 0 ]; then
20+ size=$(echo $output | grep -E 'size=[0-9]+' | sed -r 's/.*size=([0-9]+).*/\1/')
21+ is_number $size
22+ SYSCTLCONF=/etc/sysctl.d/90-storm.conf
23+ sudo sh -c "echo kernel.shmmax = $size > $SYSCTLCONF"
24+ sudo sysctl -p $SYSCTLCONF
25+ sudo $PGINIT start
26+ fi
27+}
28+
29 echo " * Fixing localhost access to postgres, restarting service"
30 sudo sed -i.bak -r 's/(host.*127\.0\.0\.1.*)\s+\w+$/\1 trust/' $PGHBA
31 sudo sed -i.bak -r 's/(host.*::1\/128.*)\s+\w+$/\1 trust/' $PGHBA
32 sudo sed -i.bak -r 's/(host.*::1\/128.*)\s+\w+$/\1 trust/' $PGHBA
33 sudo sed -i.bak -r 's/#(max_prepared_transactions.*)= 0/\1 = 200/' $PGCONF
34-sudo $PGINIT restart
35+restart_service
36
37 echo " * Create postgres superuser ($USER - will fail if existing)"
38 # If this fails, we will get errors later, so don't fail.
39@@ -28,5 +49,3 @@
40 mysqldump -u $USER storm_test > /dev/null
41
42 echo " * All Done."
43-
44-

Subscribers

People subscribed via source and target branches

to status/vote changes: