[postgresql/f16] Resurrect startup check for database presence.
Tom Lane
tgl at fedoraproject.org
Mon Jan 9 20:29:01 UTC 2012
commit 485e3afc026150b78df62efa557649132562e435
Author: Tom Lane <tgl at redhat.com>
Date: Mon Jan 9 15:24:29 2012 -0500
Resurrect startup check for database presence.
postgresql-check-db-dir | 57 +++++++++++++++++++++++++++++++++++++++++++++++
postgresql.service | 1 +
postgresql.spec | 20 ++++++++++++++-
3 files changed, 76 insertions(+), 2 deletions(-)
---
diff --git a/postgresql-check-db-dir b/postgresql-check-db-dir
new file mode 100644
index 0000000..4266c7a
--- /dev/null
+++ b/postgresql-check-db-dir
@@ -0,0 +1,57 @@
+#!/bin/sh
+
+# This script verifies that the postgresql data directory has been correctly
+# initialized. We do not want to automatically initdb it, because that has
+# a risk of catastrophic failure (ie, overwriting a valuable database) in
+# corner cases, such as a remotely mounted database on a volume that's a
+# bit slow to mount. But we can at least emit a message advising newbies
+# what to do.
+
+PGDATA="$1"
+
+if [ -z "$PGDATA" ]
+then
+ echo "Usage: $0 database-path"
+ exit 1
+fi
+
+# PGVERSION is the full package version, e.g., 9.1.2
+# Note: the specfile inserts the correct value during package build
+PGVERSION=xxxx
+# PGMAJORVERSION is major version, e.g., 9.1 (this should match PG_VERSION)
+PGMAJORVERSION=`echo "$PGVERSION" | sed 's/^\([0-9]*\.[0-9]*\).*$/\1/'`
+# PREVMAJORVERSION is the previous major version, e.g., 8.4, for upgrades
+# Note: the specfile inserts the correct value during package build
+PREVMAJORVERSION=xxxx
+# PGDOCDIR is the directory containing the package's documentation
+# Note: the specfile inserts the correct value during package build
+PGDOCDIR=xxxx
+
+# Check for the PGDATA structure
+if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base" ]
+then
+ # Check version of existing PGDATA
+ if [ x`cat "$PGDATA/PG_VERSION"` = x"$PGMAJORVERSION" ]
+ then
+ : A-OK
+ elif [ x`cat "$PGDATA/PG_VERSION"` = x"$PREVMAJORVERSION" ]
+ then
+ echo $"An old version of the database format was found."
+ echo $"Use \"postgresql-setup upgrade\" to upgrade to version $PGMAJORVERSION."
+ echo $"See $PGDOCDIR/README.rpm-dist for more information."
+ exit 1
+ else
+ echo $"An old version of the database format was found."
+ echo $"You need to dump and reload before using PostgreSQL $PGMAJORVERSION."
+ echo $"See $PGDOCDIR/README.rpm-dist for more information."
+ exit 1
+ fi
+else
+ # No existing PGDATA! Warn the user to initdb it.
+ echo $"\"$PGDATA\" is missing or empty."
+ echo $"Use \"postgresql-setup initdb\" to initialize the database cluster."
+ echo $"See $PGDOCDIR/README.rpm-dist for more information."
+ exit 1
+fi
+
+exit 0
diff --git a/postgresql.service b/postgresql.service
index 0c733bd..e59ce5c 100644
--- a/postgresql.service
+++ b/postgresql.service
@@ -25,6 +25,7 @@ StandardOutput=syslog
# Disable OOM kill on the postmaster
OOMScoreAdjust=-1000
+ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA}
ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300
ExecStop=/usr/bin/pg_ctl stop -D ${PGDATA} -s -m fast
ExecReload=/usr/bin/pg_ctl reload -D ${PGDATA} -s
diff --git a/postgresql.spec b/postgresql.spec
index 9e096ce..606a0d1 100644
--- a/postgresql.spec
+++ b/postgresql.spec
@@ -53,7 +53,7 @@ Summary: PostgreSQL client programs
Name: postgresql
%global majorversion 9.1
Version: 9.1.2
-Release: 1%{?dist}
+Release: 2%{?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.
@@ -76,6 +76,7 @@ Source1: postgresql-%{version}-US.pdf
# generate-pdf.sh is not used during RPM build, but include for documentation
Source2: generate-pdf.sh
Source3: ftp://ftp.postgresql.org/pub/source/v%{prevversion}/postgresql-%{prevversion}.tar.bz2
+Source4: postgresql-check-db-dir
Source5: Makefile.regress
Source6: pg_config.h
Source7: ecpg_config.h
@@ -450,7 +451,7 @@ case `uname -i` in
esac
install -d -m 755 $RPM_BUILD_ROOT%{_libdir}/pgsql/tutorial
-cp src/tutorial/* $RPM_BUILD_ROOT%{_libdir}/pgsql/tutorial
+cp -p src/tutorial/* $RPM_BUILD_ROOT%{_libdir}/pgsql/tutorial
# prep the setup script, including insertion of some values it needs
sed -e 's|^PGVERSION=.*$|PGVERSION=%{version}|' \
@@ -458,8 +459,17 @@ sed -e 's|^PGVERSION=.*$|PGVERSION=%{version}|' \
-e 's|^PREVMAJORVERSION=.*$|PREVMAJORVERSION=%{prevmajorversion}|' \
-e 's|^PREVPGENGINE=.*$|PREVPGENGINE=%{_libdir}/pgsql/postgresql-%{prevmajorversion}/bin|' \
<%{SOURCE9} >postgresql-setup
+touch -r %{SOURCE9} postgresql-setup
install -m 755 postgresql-setup $RPM_BUILD_ROOT%{_bindir}/postgresql-setup
+# prep the startup check script, including insertion of some values it needs
+sed -e 's|^PGVERSION=.*$|PGVERSION=%{version}|' \
+ -e 's|^PREVMAJORVERSION=.*$|PREVMAJORVERSION=%{prevmajorversion}|' \
+ -e 's|^PGDOCDIR=.*$|PGDOCDIR=%{_docdir}/%{name}-%{version}|' \
+ <%{SOURCE4} >postgresql-check-db-dir
+touch -r %{SOURCE4} postgresql-check-db-dir
+install -m 755 postgresql-check-db-dir $RPM_BUILD_ROOT%{_bindir}/postgresql-check-db-dir
+
install -d $RPM_BUILD_ROOT%{_unitdir}
install -m 644 %{SOURCE10} $RPM_BUILD_ROOT%{_unitdir}/postgresql.service
@@ -831,6 +841,7 @@ rm -rf $RPM_BUILD_ROOT
%{_bindir}/postgres
%{_bindir}/postmaster
%{_bindir}/postgresql-setup
+%{_bindir}/postgresql-check-db-dir
%{_mandir}/man1/initdb.*
%{_mandir}/man1/pg_basebackup.*
%{_mandir}/man1/pg_controldata.*
@@ -916,6 +927,11 @@ rm -rf $RPM_BUILD_ROOT
%endif
%changelog
+* Mon Jan 9 2012 Tom Lane <tgl at redhat.com> 9.1.2-2
+- Make systemd unit file more user-friendly by resurrecting the old init
+ script's checks for data directory presence and version match
+Resolves: #771496
+
* Mon Dec 5 2011 Tom Lane <tgl at redhat.com> 9.1.2-1
- Update to PostgreSQL 9.1.2, for various fixes described at
http://www.postgresql.org/docs/9.1/static/release-9-1-2.html
More information about the scm-commits
mailing list