Add legacy action scripts, fix oom_score_adj usage

This commit is contained in:
Tom Lane 2012-07-14 23:45:13 -04:00
parent b937d0f13c
commit 67b80785ce
4 changed files with 105 additions and 3 deletions

16
initdb.sh Executable file
View File

@ -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 $?

View File

@ -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
{

View File

@ -53,7 +53,7 @@ Summary: PostgreSQL client programs
Name: postgresql
%global majorversion 9.1
Version: 9.1.4
Release: 2%{?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@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 11 2012 Petr Pisar <ppisar@redhat.com> - 9.1.4-2
- Perl 5.16 rebuild

16
upgrade.sh Executable file
View File

@ -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 $?