Subject: [alpine-devel] testing/pgcluster

From: Cameron Banta <[email-masked]>
Date: Sat, 30 May 2009 19:13:15 -0500

Please review and commit.

-Cameron
From 0234365cf3e0f76a1dfe285e272dc110c70a5b77 Mon Sep 17 00:00:00 2001
From: Cameron Banta <[email-masked]>
Date: Sun, 31 May 2009 00:10:11 +0000
Subject: [PATCH] Initial commit

---
 testing/pgcluster/APKBUILD        |   50 ++++++++++++++++
 testing/pgcluster/pgcluster.confd |   52 +++++++++++++++++
 testing/pgcluster/pgcluster.initd |  114 +++++++++++++++++++++++++++++++++++++
 3 files changed, 216 insertions(+), 0 deletions(-)
 create mode 100644 testing/pgcluster/APKBUILD
 create mode 100644 testing/pgcluster/pgcluster.confd
 create mode 100644 testing/pgcluster/pgcluster.initd

diff --git a/testing/pgcluster/APKBUILD b/testing/pgcluster/APKBUILD
new file mode 100644
index 0000000..760f661
--- /dev/null
+++ b/testing/pgcluster/APKBUILD
@@ -0,0 +1,50 @@
+# Maintainer: Cameron Banta <[email-masked]>
+pkgname=pgcluster
+pkgver=1.9.0rc5
+pkgrel=0
+pkgdesc="A sophisticated object-relational DBMS with multimaster cluster patch"
+url="http://pgfoundry.org/projects/pgcluster/"
+license="BSD"
+depends="uclibc openssl libpq bbsuid zlib"
+makedepends="readline-dev openssl-dev zlib-dev"
+subpackages="$pkgname-dev $pkgname-doc libpgcluster $pkgname-client"
+source="http://pgfoundry.org/frs/download.php/1705/$pkgname-$pkgver.tar.gz
+	$pkgname.initd
+	$pkgname.confd
+	"
+
+build() {
+	cd "$srcdir"/$pkgname-$pkgver || return 1
+	./configure --prefix=/usr \
+		--mandir=/usr/share/man \
+		--with-docdir=/usr/share/doc \
+		--with-openssl \
+		|| return 1
+
+	make || return 1
+	make DESTDIR="$pkgdir" install || return 1
+
+	install -D -m755 "$srcdir"/$pkgname.initd \
+		"$pkgdir"/etc/init.d/$pkgname
+	install -D -m644 "$srcdir"/$pkgname.confd \
+		"$pkgdir"/etc/conf.d/$pkgname || return 1
+}
+
+libpgcluster() {
+	depends="uclibc openssl"
+	pkgdesc="PGCluster libraries"
+	mkdir -p "$subpkgdir"/usr/lib
+	mv "$pkgdir"/usr/lib/libpq.so* "$subpkgdir"/usr/lib/
+}
+
+client() {
+	depends="uclibc openssl libpq readline"
+	pkgdesc="PGCluster client"
+	mkdir -p "$subpkgdir"/usr/bin
+	mv "$pkgdir"/usr/bin/psql "$subpkgdir"/usr/bin/
+}
+
+
+md5sums="d2fe705e25a01c19c8f8daa1fbcc55d1  pgcluster-1.9.0rc5.tar.gz
+7ed7e95246798ac3d5474ed12bf98e98  pgcluster.initd
+ea3320c56a22f5c305199886c2766387  pgcluster.confd"
diff --git a/testing/pgcluster/pgcluster.confd b/testing/pgcluster/pgcluster.confd
new file mode 100644
index 0000000..56561b0
--- /dev/null
+++ b/testing/pgcluster/pgcluster.confd
@@ -0,0 +1,52 @@
+# PostgreSQL's Database Directory
+PGDATA="/var/lib/postgresql/8.3/data"
+
+# PostgreSQL User
+PGUSER="postgres"
+
+# PostgreSQL Group
+PGGROUP="postgres"
+
+# Extra options to run postmaster with, e.g.:
+# -N is the maximal number of client connections
+# -B is the number of shared buffers and has to be at least 2x the value for -N
+# Please read the man-page to postmaster for more options. Many of these options
+# can be set directly in the configuration-file.
+#PGOPTS="-N 512 -B 1024"
+
+
+# SERVER SHUTDOWN:
+# The server will receive 3 signals in the worst case:
+# 1. SIGTERM
+#  This signals the server to ignore new connections and to
+#  wait for all clients to end their transactions before shutting down.
+#  Use WAIT_FOR_DISCONNECT to control how much time the clients
+#  should have until the next signal is being sent.
+# 2. SIGINT
+#  Tell the server to forcefully disconnect all clients.
+#  Terminating a client results in a rollback of the open transactions for this client.
+#  Use WAIT_FOR_CLEANUP to determine how much time the server has
+#  for cleanup.
+# 3. SIGQUIT
+#  This will terminate the server immediately and results in a recovery run for the next start.
+
+# Wait for clients to disconnect
+WAIT_FOR_DISCONNECT=30
+
+# Time the server has to clean up
+WAIT_FOR_CLEANUP=60
+
+# Time the server has to quit (with a recover-run on next startup)
+# Set to 0 to deactivate it
+WAIT_FOR_QUIT=60
+
+# Comment this out if you don't want to wait for the server to
+# startup before continuing.  For example, if this server is a 
+# PITR log shipping based replication standby
+WAIT_FOR_START="-w"
+
+# If you have to export environment variables for the database process,
+# this can be done here.
+#
+# Example:
+#   export R_HOME="/usr/lib/R"
diff --git a/testing/pgcluster/pgcluster.initd b/testing/pgcluster/pgcluster.initd
new file mode 100644
index 0000000..bc50ae2
--- /dev/null
+++ b/testing/pgcluster/pgcluster.initd
@@ -0,0 +1,114 @@
+#!/sbin/runscript
+# Copyright 1999-2008 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/dev-db/postgresql-server/files/postgresql.init-8.3,v 1.4 2008/09/28 22:53:02 caleb Exp $
+
+opts="${opts} reload setup"
+
+depend() {
+	use net
+	provide postgresql
+}
+
+checkconfig() {
+	if [ ! -d "$PGDATA" ] ; then
+		eerror "Directory not found: $PGDATA"
+		eerror "Please make sure that PGDATA points to the right path."
+		eerror "You can run '/etc/init.d/postgresql setup' to setup a new database cluster."
+		return 1
+	fi
+}
+
+start() {
+	checkconfig || return 1
+
+	ebegin "Starting PostgreSQL"
+
+	if [ -f "$PGDATA/postmaster.pid" ] ; then
+		rm -f "$PGDATA/postmaster.pid"
+	fi
+
+	local retval
+
+	su -l ${PGUSER} \
+		-c "env PGDATA=\"${PGDATA}\" /usr/bin/pg_ctl start ${WAIT_FOR_START} -o '--silent-mode=true ${PGOPTS}'" >/dev/null
+	retval=$?
+	[ $retval -ne 0 ] && eend $retval && return $retval
+
+	# The following is to catch the case of an already running server
+	# in which pg_ctl doesn't know to which server it connected to and false reports the server as 'up'
+	sleep 2
+	if [ ! -f "$PGDATA/postmaster.pid" ] ; then
+		eerror "The pid-file doesn't exist but pg_ctl reported a running server."
+		eerror "Please check whether there is another server running on the same port or read the log-file."
+		eend 1
+		return 1
+	fi
+
+	local pid=$(grep "^[0-9]\+" "$PGDATA/postmaster.pid")
+	test -d /proc/"${pid}" 
+	eend $?
+}
+
+stop() {
+	ebegin "Stopping PostgreSQL (this can take up to $(( ${WAIT_FOR_DISCONNECT} + ${WAIT_FOR_CLEANUP} )) seconds)"
+
+	local retval
+
+	su -l ${PGUSER} \
+		-c "env PGDATA=\"${PGDATA}\" /usr/bin/pg_ctl stop -t ${WAIT_FOR_DISCONNECT} -m smart" >/dev/null
+
+	retval=$?
+	[ $retval -eq 0 ] && eend $retval && return $retval
+
+	ewarn "Some clients did not disconnect within ${WAIT_FOR_DISCONNECT} seconds."
+	ewarn "Going to shutdown the server anyway."
+
+	su -l ${PGUSER} \
+		-c "env PGDATA=\"${PGDATA}\" /usr/bin/pg_ctl stop -m fast" >/dev/null
+
+	retval=$?
+	[ $retval -eq 0 ] && eend $retval && return $retval
+
+	if [ ${WAIT_FOR_QUIT} -eq 0 ] ; then
+		eerror "Server did not shut down and sending the SIGQUIT has been disabled."
+		eend $retval
+		return $retval
+	fi
+
+	ewarn "Shutting down the server gracefully failed."
+	ewarn "Forcing it to shutdown which leads to a recover-run on next startup."
+
+	su -l ${PGUSER} \
+		-c "env PGDATA=\"${PGDATA}\" /usr/bin/pg_ctl stop -m immediate" >/dev/null
+
+	retval=$?
+	[ $retval -eq 0 ] && eend $retval && return $retval
+
+	eerror "Forced shutdown failed!!! Something is wrong with your system, please take care of it manually."
+	eend $?
+}
+
+reload() {
+	ebegin "Reloading PostgreSQL configuration"
+	su -l ${PGUSER} \
+		-c "env PGDATA=\"${PGDATA}\" /usr/bin/pg_ctl reload" >/dev/null
+	eend $?
+}
+
+setup() { 
+	ebegin "Creating a new PostgreSQL database cluster" 
+	if [ -d "${PGDATA}" ] ; then 
+		eend 1 "${PGDATA} already exist" 
+		return 
+	fi 
+	mkdir -p "${PGDATA}" 
+	chown -Rf postgres:postgres "${PGDATA}" 
+	chmod 0700 "${PGDATA}" 
+	cd "${PGDATA}" # to avoid the: could not change directory to "/root" 
+	su -c "/usr/bin/initdb --pgdata ${PGDATA}" postgres
+	einfo "You can use the '/etc/init.d/postgresql' script to run PostgreSQL instead"
+	einfo "of 'pg_ctl'."
+	eend $? 
+} 
+
-- 
1.6.2.5

---

From: Natanael Copa <[email-masked]>
Date: Mon, 01 Jun 2009 08:12:07 +0200

> Please review and commit.

This looks like a fork of postgresql, with its own libraries
(libpgcluster) that conflicts with postgresql. However, looks like this
APKBUILD uses the origial postgresql libpq libraries reather than the
libs thats build in this package (libpgcluster). Is that intentional?

Did you try install the package and test that it runs?

-nc

> -Cameron

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---

---

From: Cameron Banta <[email-masked]>
Date: Mon, 1 Jun 2009 09:40:31 -0500

Hi Natanael,

That is correct. It is a fork (actually just a large patch) to postgresql.
There really isn't a way to have them both installed at the same time.
That's why I've just stuck it in testing for now. Do we have any kind of
conflict idea for APKBUILD?

As far as libpq, I did do that intentionally, but I'm now realizing that
that was a mistake. All the binaries execute - but I haven't got the
replication working yet. I will change the package and send you a new patch.

-Cameron

---

From: Cameron Banta <[email-masked]>
Date: Mon, 1 Jun 2009 10:24:41 -0500

> replication working yet. I will change the package and send you a new patch.
I've attached a patch that uses the libpq library from pgcluster.

-Cameron
From 0234365cf3e0f76a1dfe285e272dc110c70a5b77 Mon Sep 17 00:00:00 2001
From: Cameron Banta <[email-masked]>
Date: Sun, 31 May 2009 00:10:11 +0000
Subject: [PATCH 1/2] Initial commit

---

From 3bec591bdb99f4c3f6a6ec1da005072390f3c83a Mon Sep 17 00:00:00 2001
From: Cameron Banta <[email-masked]>
Date: Mon, 1 Jun 2009 15:16:24 +0000
Subject: [PATCH 2/2] Change libpq depends to pgcluster-libpq

---
 testing/pgcluster/APKBUILD |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/testing/pgcluster/APKBUILD b/testing/pgcluster/APKBUILD
index 760f661..11fa1cb 100644
--- a/testing/pgcluster/APKBUILD
+++ b/testing/pgcluster/APKBUILD
@@ -1,13 +1,13 @@
 # Maintainer: Cameron Banta <[email-masked]>
 pkgname=pgcluster
 pkgver=1.9.0rc5
-pkgrel=0
-pkgdesc="A sophisticated object-relational DBMS with multimaster cluster patch"
+pkgrel=1
+pkgdesc="PostgreSQL with multi-master cluster/replication patch"
 url="http://pgfoundry.org/projects/pgcluster/"
 license="BSD"
-depends="uclibc openssl libpq bbsuid zlib"
+depends="uclibc openssl $pkgname-libpq bbsuid zlib"
 makedepends="readline-dev openssl-dev zlib-dev"
-subpackages="$pkgname-dev $pkgname-doc libpgcluster $pkgname-client"
+subpackages="$pkgname-dev $pkgname-doc $pkgname-libpq $pkgname-client"
 source="http://pgfoundry.org/frs/download.php/1705/$pkgname-$pkgver.tar.gz
 	$pkgname.initd
 	$pkgname.confd
@@ -30,7 +30,7 @@ build() {
 		"$pkgdir"/etc/conf.d/$pkgname || return 1
 }
 
-libpgcluster() {
+libpq() {
 	depends="uclibc openssl"
 	pkgdesc="PGCluster libraries"
 	mkdir -p "$subpkgdir"/usr/lib
@@ -38,7 +38,7 @@ libpgcluster() {
 }
 
 client() {
-	depends="uclibc openssl libpq readline"
+	depends="uclibc openssl $pkgname-libpq readline"
 	pkgdesc="PGCluster client"
 	mkdir -p "$subpkgdir"/usr/bin
 	mv "$pkgdir"/usr/bin/psql "$subpkgdir"/usr/bin/
-- 
1.6.2.5