[postgresql/f16] Add legacy action scripts, fix oom_score_adj usage

Tom Lane tgl at fedoraproject.org
Sun Jul 15 04:09:27 UTC 2012


commit b97444f170519f89a4e89c7f76022c2a4961cac3
Author: Tom Lane <tgl at redhat.com>
Date:   Sun Jul 15 00:07:02 2012 -0400

    Add legacy action scripts, fix oom_score_adj usage

 initdb.sh                      |   16 ++++++++++++
 postgresql-oom_score_adj.patch |   52 ++++++++++++++++++++++++++++++++++++++++
 postgresql.service             |    4 +-
 postgresql.spec                |   24 ++++++++++++++++--
 upgrade.sh                     |   16 ++++++++++++
 5 files changed, 107 insertions(+), 5 deletions(-)
---
diff --git a/initdb.sh b/initdb.sh
new file mode 100755
index 0000000..c238574
--- /dev/null
+++ b/initdb.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+#
+# Legacy action script for "service postgresql initdb"
+
+# Find the name of the service
+SERVICE_NAME=$(basename $(dirname "$0"))
+if [ x"$SERVICE_NAME" = x. ]
+then
+    SERVICE_NAME=postgresql
+fi
+
+echo Hint: the preferred way to do this is now '"postgresql-setup initdb"' >&2
+
+/usr/bin/postgresql-setup initdb "$SERVICE_NAME"
+
+exit $?
diff --git a/postgresql-oom_score_adj.patch b/postgresql-oom_score_adj.patch
new file mode 100644
index 0000000..aade1d5
--- /dev/null
+++ b/postgresql-oom_score_adj.patch
@@ -0,0 +1,52 @@
+Back-patch upstream's 9.2 patch to add support for setting oom_score_adj.
+
+
+diff -Naur postgresql-9.1.4.orig/src/backend/postmaster/fork_process.c postgresql-9.1.4/src/backend/postmaster/fork_process.c
+--- postgresql-9.1.4.orig/src/backend/postmaster/fork_process.c	2012-05-31 19:07:09.000000000 -0400
++++ postgresql-9.1.4/src/backend/postmaster/fork_process.c	2012-07-14 17:55:42.911859485 -0400
+@@ -68,12 +68,40 @@
+ 		 * process sizes *including shared memory*.  (This is unbelievably
+ 		 * stupid, but the kernel hackers seem uninterested in improving it.)
+ 		 * Therefore it's often a good idea to protect the postmaster by
+-		 * setting its oom_adj value negative (which has to be done in a
+-		 * root-owned startup script).	If you just do that much, all child
++		 * setting its oom_score_adj value negative (which has to be done in a
++		 * root-owned startup script). If you just do that much, all child
+ 		 * processes will also be protected against OOM kill, which might not
+-		 * be desirable.  You can then choose to build with LINUX_OOM_ADJ
+-		 * #defined to 0, or some other value that you want child processes to
+-		 * adopt here.
++		 * be desirable.  You can then choose to build with
++		 * LINUX_OOM_SCORE_ADJ #defined to 0, or to some other value that you
++		 * want child processes to adopt here.
++		 */
++#ifdef LINUX_OOM_SCORE_ADJ
++		{
++			/*
++			 * Use open() not stdio, to ensure we control the open flags. Some
++			 * Linux security environments reject anything but O_WRONLY.
++			 */
++			int			fd = open("/proc/self/oom_score_adj", O_WRONLY, 0);
++
++			/* We ignore all errors */
++			if (fd >= 0)
++			{
++				char		buf[16];
++				int			rc;
++
++				snprintf(buf, sizeof(buf), "%d\n", LINUX_OOM_SCORE_ADJ);
++				rc = write(fd, buf, strlen(buf));
++				(void) rc;
++				close(fd);
++			}
++		}
++#endif   /* LINUX_OOM_SCORE_ADJ */
++
++		/*
++		 * Older Linux kernels have oom_adj not oom_score_adj.  This works
++		 * similarly except with a different scale of adjustment values.
++		 * If it's necessary to build Postgres to work with either API,
++		 * you can define both LINUX_OOM_SCORE_ADJ and LINUX_OOM_ADJ.
+ 		 */
+ #ifdef LINUX_OOM_ADJ
+ 		{
diff --git a/postgresql.service b/postgresql.service
index 123c4fe..6545b6e 100644
--- a/postgresql.service
+++ b/postgresql.service
@@ -22,7 +22,6 @@
 
 [Unit]
 Description=PostgreSQL database server
-After=syslog.target
 After=network.target
 
 [Service]
@@ -39,7 +38,8 @@ Environment=PGDATA=/var/lib/pgsql/data
 
 # Where to send early-startup messages from the server (before the logging
 # options of postgresql.conf take effect)
-StandardOutput=syslog
+# This is normally controlled by the global default set by systemd
+# StandardOutput=syslog
 
 # Disable OOM kill on the postmaster
 OOMScoreAdjust=-1000
diff --git a/postgresql.spec b/postgresql.spec
index 8b72f46..2985b12 100644
--- a/postgresql.spec
+++ b/postgresql.spec
@@ -53,7 +53,7 @@ Summary: PostgreSQL client programs
 Name: postgresql
 %global majorversion 9.1
 Version: 9.1.4
-Release: 1%{?dist}
+Release: 3%{?dist}
 
 # The PostgreSQL license is very similar to other MIT licenses, but the OSI
 # recognizes it as an independent license, so we do as well.
@@ -83,6 +83,8 @@ Source7: ecpg_config.h
 Source8: README.rpm-dist
 Source9: postgresql-setup
 Source10: postgresql.service
+Source11: initdb.sh
+Source12: upgrade.sh
 Source14: postgresql.pam
 Source15: postgresql-bashprofile
 
@@ -90,6 +92,7 @@ Source15: postgresql-bashprofile
 Patch1: rpm-pgsql.patch
 Patch2: postgresql-logging.patch
 Patch3: postgresql-perl-rpath.patch
+Patch4: postgresql-oom_score_adj.patch
 
 BuildRequires: perl(ExtUtils::MakeMaker) glibc-devel bison flex gawk
 BuildRequires: perl(ExtUtils::Embed), perl-devel
@@ -301,6 +304,7 @@ benchmarks.
 %patch1 -p1
 %patch2 -p1
 %patch3 -p1
+%patch4 -p1
 
 # We used to run autoconf here, but there's no longer any real need to,
 # since Postgres ships with a reasonably modern configure script.
@@ -330,8 +334,8 @@ CFLAGS="${CFLAGS:-%optflags}" ; export CFLAGS
 
 # Strip out -ffast-math from CFLAGS....
 CFLAGS=`echo $CFLAGS|xargs -n 1|grep -v ffast-math|xargs -n 100`
-# Add LINUX_OOM_ADJ=0 to ensure child processes reset postmaster's oom_adj
-CFLAGS="$CFLAGS -DLINUX_OOM_ADJ=0"
+# Add LINUX_OOM_SCORE_ADJ=0 to ensure child processes reset postmaster's oom_score_adj
+CFLAGS="$CFLAGS -DLINUX_OOM_SCORE_ADJ=0"
 # let's try removing this kluge, it may just be a workaround for bz#520916
 # # use -O1 on sparc64 and alpha
 # %%ifarch sparc64 alpha
@@ -473,6 +477,10 @@ install -m 755 postgresql-check-db-dir $RPM_BUILD_ROOT%{_bindir}/postgresql-chec
 install -d $RPM_BUILD_ROOT%{_unitdir}
 install -m 644 %{SOURCE10} $RPM_BUILD_ROOT%{_unitdir}/postgresql.service
 
+install -d $RPM_BUILD_ROOT/usr/libexec/initscripts/legacy-actions/postgresql
+install -m 755 %{SOURCE11} $RPM_BUILD_ROOT/usr/libexec/initscripts/legacy-actions/postgresql/initdb
+install -m 755 %{SOURCE12} $RPM_BUILD_ROOT/usr/libexec/initscripts/legacy-actions/postgresql/upgrade
+
 %if %pam
 install -d $RPM_BUILD_ROOT/etc/pam.d
 install -m 644 %{SOURCE14} $RPM_BUILD_ROOT/etc/pam.d/postgresql
@@ -830,6 +838,8 @@ rm -rf $RPM_BUILD_ROOT
 %files server -f server.lst
 %defattr(-,root,root)
 %{_unitdir}/postgresql.service
+%dir /usr/libexec/initscripts/legacy-actions/postgresql
+/usr/libexec/initscripts/legacy-actions/postgresql/*
 %if %pam
 %config(noreplace) /etc/pam.d/postgresql
 %endif
@@ -927,6 +937,14 @@ rm -rf $RPM_BUILD_ROOT
 %endif
 
 %changelog
+* Sat Jul 14 2012 Tom Lane <tgl at redhat.com> 9.1.4-3
+- Update code to use oom_score_adj not oom_adj, thereby suppressing
+  whining in the kernel log
+- Add "legacy action" scripts to support "service postgresql initdb" and
+  "service postgresql upgrade" in a now-approved fashion (requires a
+  recent version of initscripts to work)
+Resolves: #800416
+
 * Mon Jun  4 2012 Tom Lane <tgl at redhat.com> 9.1.4-1
 - Update to PostgreSQL 9.1.4, for various fixes described at
   http://www.postgresql.org/docs/9.1/static/release-9-1-4.html
diff --git a/upgrade.sh b/upgrade.sh
new file mode 100755
index 0000000..c542494
--- /dev/null
+++ b/upgrade.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+#
+# Legacy action script for "service postgresql upgrade"
+
+# Find the name of the service
+SERVICE_NAME=$(basename $(dirname "$0"))
+if [ x"$SERVICE_NAME" = x. ]
+then
+    SERVICE_NAME=postgresql
+fi
+
+echo Hint: the preferred way to do this is now '"postgresql-setup upgrade"' >&2
+
+/usr/bin/postgresql-setup upgrade "$SERVICE_NAME"
+
+exit $?


More information about the scm-commits mailing list