
--- postgresql-8.2.6/contrib/Makefile	2006-09-09 00:07:51.000000000 -0400
+++ postgresql-8.2.6-new/contrib/Makefile	2008-01-15 11:07:16.000000000 -0500
@@ -30,7 +30,8 @@
 		spi		\
 		tablefunc	\
 		tsearch2	\
-		vacuumlo
+		vacuumlo \
+		xml2
 
 ifeq ($(with_openssl),yes)
 WANTED_DIRS += sslinfo
--- postgresql-8.2.6/pgsql.sh	1969-12-31 19:00:00.000000000 -0500
+++ postgresql-8.2.6-new/pgsql.sh	2008-01-15 11:07:26.000000000 -0500
@@ -0,0 +1,73 @@
+#!/bin/sh
+
+die () {
+	echo "failed"
+	echo ""
+	echo "*** bailing because an error ocurred:"
+	echo ""
+	echo "$*"
+	exit 1
+}
+
+PREFIX="@INSTPREFIX@"
+DATADIR="${PREFIX}/var/postgresql-8.2/data"
+LOGFILE="${PREFIX}/var/postgresql-8.2/pgsql.log"
+
+export LANG=C
+unset LC_ALL
+
+SHMMAX=`sysctl kern.sysv.shmmax | cut -d' ' -f2-`
+SHMMNI=`sysctl kern.sysv.shmmni | cut -d' ' -f2-`
+SHMALL=`sysctl kern.sysv.shmall | cut -d' ' -f2-`
+
+if [ "$SHMMAX" -lt "8388608" ] || [ "$SHMMNI" -lt "64" ] || [ "$SHMALL" -lt "32768" ]; then
+	echo "WARNING: You probably need to set your shared memory resources higher for"
+	echo "         PostgreSQL to function.  For more information on raising your shared"
+	echo "         memory settings, see:"
+	echo "         http://wiki.finkproject.org/index.php/Shared_Memory_Regions_on_Darwin"
+	echo ""
+	echo "         I am also creating a default configuration in /etc/sysctl.conf.pg"
+	echo "         that contains values that will work with the default PostgreSQL "
+	echo "         memory settings.  To use it, rename it to /etc/sysctl.conf (if you"
+	echo "         don't have one already) and reboot."
+	echo ""
+	echo "         For now, I'll try setting your sysctl to something higher and then"
+	echo "         running things anyways.  Good luck!  =)"
+	echo ""
+	sysctl -w kern.sysv.shmmax=8388608
+	sysctl -w kern.sysv.shmmin=1
+	sysctl -w kern.sysv.shmmni=64
+	sysctl -w kern.sysv.shmseg=8
+	sysctl -w kern.sysv.shmall=32768
+	echo ""
+	cat <<END >/etc/sysctl.conf.pg
+kern.sysv.shmmax=8388608
+kern.sysv.shmmin=1
+kern.sysv.shmmni=64
+kern.sysv.shmseg=8
+kern.sysv.shmall=32768
+END
+fi
+
+if [ ! -d "$DATADIR" ]; then
+	printf -- "- making postgresql directories: "
+	sudo mkdir -p "$DATADIR"
+	sudo chown -R postgres "$DATADIR/.."
+	echo "ok"
+
+	printf -- "- initializing database in $DATADIR: "
+	sudo -u postgres ${PREFIX}/bin/initdb-8.2 -D "$DATADIR" >/tmp/pgsql-init-8.2.log 2>&1 || die "couldn't initialize database"
+	echo "ok"
+fi
+
+case "$1" in
+	start)
+		unset LC_ALL; LANG=C sudo -u postgres "${PREFIX}/bin/pg_ctl-8.2" start -D "$DATADIR" -l "$LOGFILE"
+		;;
+	restart)
+		unset LC_ALL; LANG=C sudo -u postgres "${PREFIX}/bin/pg_ctl-8.2" restart -D "$DATADIR" -m fast
+		;;
+	stop)
+		unset LC_ALL; LANG=C sudo -u postgres "${PREFIX}/bin/pg_ctl-8.2" stop -D "$DATADIR" -m fast
+		;;
+esac
--- postgresql-8.2.6/src/Makefile.global.in	2006-10-08 13:15:33.000000000 -0400
+++ postgresql-8.2.6-new/src/Makefile.global.in	2008-01-15 11:07:16.000000000 -0500
@@ -73,14 +73,14 @@
 datadir := @datadir@
 ifeq "$(findstring pgsql, $(datadir))" ""
 ifeq "$(findstring postgres, $(datadir))" ""
-override datadir := $(datadir)/postgresql
+override datadir := $(datadir)/postgresql-8.2
 endif
 endif
 
 sysconfdir := @sysconfdir@
 ifeq "$(findstring pgsql, $(sysconfdir))" ""
 ifeq "$(findstring postgres, $(sysconfdir))" ""
-override sysconfdir := $(sysconfdir)/postgresql
+override sysconfdir := $(sysconfdir)/postgresql-8.2
 endif
 endif
 
@@ -89,7 +89,7 @@
 pkglibdir = $(libdir)
 ifeq "$(findstring pgsql, $(pkglibdir))" ""
 ifeq "$(findstring postgres, $(pkglibdir))" ""
-override pkglibdir := $(pkglibdir)/postgresql
+override pkglibdir := $(pkglibdir)/postgresql-8.2
 endif
 endif
 
@@ -109,7 +109,7 @@
 ifneq (,$(docdir))
 ifeq "$(findstring pgsql, $(docdir))" ""
 ifeq "$(findstring postgres, $(docdir))" ""
-override docdir := $(docdir)/postgresql
+override docdir := $(docdir)/postgresql-8.2
 endif
 endif
 endif
--- postgresql-8.2.6/src/Makefile.shlib	2006-09-19 11:36:07.000000000 -0400
+++ postgresql-8.2.6-new/src/Makefile.shlib	2008-01-15 11:07:16.000000000 -0500
@@ -107,11 +107,11 @@
   ifeq ($(DLTYPE), library)
     # linkable library
     DLSUFFIX		:= .dylib
-    LINK.shared		= $(COMPILER) -dynamiclib -install_name $(libdir)/lib$(NAME).$(SO_MAJOR_VERSION)$(DLSUFFIX) $(version_link) $(exported_symbols_list) -multiply_defined suppress
+    LINK.shared		= $(CXX) $(CFLAGS) -dynamiclib -install_name $(libdir)/lib$(NAME).$(SO_MAJOR_VERSION)$(DLSUFFIX) $(version_link) $(exported_symbols_list) -multiply_defined suppress
   else
     # loadable module (default case)
     DLSUFFIX		:= .so
-    LINK.shared		= $(COMPILER) -bundle -multiply_defined suppress
+    LINK.shared		= $(CXX) $(CFLAGS) -bundle -multiply_defined suppress
   endif
   shlib			= lib$(NAME).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)$(DLSUFFIX)
   shlib_major		= lib$(NAME).$(SO_MAJOR_VERSION)$(DLSUFFIX)
--- postgresql-8.2.6/src/backend/storage/file/fd.c	2006-11-06 12:10:22.000000000 -0500
+++ postgresql-8.2.6-new/src/backend/storage/file/fd.c	2008-01-15 11:07:16.000000000 -0500
@@ -51,6 +51,7 @@
 #include "storage/fd.h"
 #include "storage/ipc.h"
 
+#include <sys/resource.h>
 
 /*
  * We must leave some file descriptors free for system(), the dynamic loader,
@@ -345,15 +346,21 @@
 	int			used = 0;
 	int			highestfd = 0;
 	int			j;
+ 	struct rlimit	    rlim;
 
 	size = 1024;
 	fd = (int *) palloc(size * sizeof(int));
+ 	getrlimit(RLIMIT_NOFILE, &rlim);
 
 	/* dup until failure or probe limit reached */
 	for (;;)
 	{
 		int			thisfd;
 
+                /* Don't go beyond RLIMIT_NOFILE */
+ 		if (highestfd >= rlim.rlim_cur - 1)
+ 		    break;
+
 		thisfd = dup(0);
 		if (thisfd < 0)
 		{
--- postgresql-8.2.6/src/backend/utils/misc/postgresql.conf.sample	2007-01-20 16:42:06.000000000 -0500
+++ postgresql-8.2.6-new/src/backend/utils/misc/postgresql.conf.sample	2008-01-15 11:07:16.000000000 -0500
@@ -73,7 +73,7 @@
 # - Security & Authentication -
 
 #authentication_timeout = 1min		# 1s-600s
-#ssl = off				# (change requires restart)
+ssl = off				# (change requires restart)
 #password_encryption = on
 #db_user_namespace = off
 
--- postgresql-8.2.6/src/bin/initdb/initdb.c	2006-10-04 14:58:08.000000000 -0400
+++ postgresql-8.2.6-new/src/bin/initdb/initdb.c	2008-01-15 11:07:16.000000000 -0500
@@ -119,7 +119,7 @@
 
 /* defaults */
 static int	n_connections = 10;
-static int	n_buffers = 50;
+static int	n_buffers = 20;
 static int	n_fsm_pages = 20000;
 
 /*
@@ -2646,7 +2646,7 @@
 	sprintf(pgdenv, "PGDATA=%s", pg_data);
 	putenv(pgdenv);
 
-	if ((ret = find_other_exec(argv[0], "postgres", PG_VERSIONSTR,
+	if ((ret = find_other_exec(argv[0], "postgres-8.2", PG_VERSIONSTR,
 							   backend_exec)) < 0)
 	{
 		char		full_path[MAXPGPATH];
@@ -2656,14 +2656,14 @@
 
 		if (ret == -1)
 			fprintf(stderr,
-					_("The program \"postgres\" is needed by %s "
+					_("The program \"postgres-8.2\" is needed by %s "
 					  "but was not found in the\n"
 					  "same directory as \"%s\".\n"
 					  "Check your installation.\n"),
 					progname, full_path);
 		else
 			fprintf(stderr,
-					_("The program \"postgres\" was found by \"%s\"\n"
+					_("The program \"postgres-8.2\" was found by \"%s\"\n"
 					  "but was not the same version as %s.\n"
 					  "Check your installation.\n"),
 					full_path, progname);
@@ -2942,9 +2942,9 @@
 	get_parent_directory(bin_dir);
 
 	printf(_("\nSuccess. You can now start the database server using:\n\n"
-			 "    %s%s%spostgres%s -D %s%s%s\n"
+			 "    %s%s%spostgres-8.2%s -D %s%s%s\n"
 			 "or\n"
-			 "    %s%s%spg_ctl%s -D %s%s%s -l logfile start\n\n"),
+			 "    %s%s%spg_ctl-8.2%s -D %s%s%s -l logfile start\n\n"),
 	   QUOTE_PATH, bin_dir, (strlen(bin_dir) > 0) ? DIR_SEP : "", QUOTE_PATH,
 		   QUOTE_PATH, pg_data_native, QUOTE_PATH,
 	   QUOTE_PATH, bin_dir, (strlen(bin_dir) > 0) ? DIR_SEP : "", QUOTE_PATH,
--- postgresql-8.2.6/src/bin/pg_ctl/pg_ctl.c	2007-07-02 17:58:38.000000000 -0400
+++ postgresql-8.2.6-new/src/bin/pg_ctl/pg_ctl.c	2008-01-15 11:07:16.000000000 -0500
@@ -600,7 +600,7 @@
 
 		postmaster_path = pg_malloc(MAXPGPATH);
 
-		if ((ret = find_other_exec(argv0, "postgres", PM_VERSIONSTR,
+		if ((ret = find_other_exec(argv0, "postgres-8.2", PM_VERSIONSTR,
 								   postmaster_path)) < 0)
 		{
 			char		full_path[MAXPGPATH];
@@ -609,13 +609,13 @@
 				StrNCpy(full_path, progname, MAXPGPATH);
 
 			if (ret == -1)
-				write_stderr(_("The program \"postgres\" is needed by %s "
+				write_stderr(_("The program \"postgres-8.2\" is needed by %s "
 							   "but was not found in the\n"
 							   "same directory as \"%s\".\n"
 							   "Check your installation.\n"),
 							 progname, full_path);
 			else
-				write_stderr(_("The program \"postgres\" was found by \"%s\"\n"
+				write_stderr(_("The program \"postgres-8.2\" was found by \"%s\"\n"
 							   "but was not the same version as %s.\n"
 							   "Check your installation.\n"),
 							 full_path, progname);
@@ -956,10 +956,10 @@
 	}
 	else
 	{
-		ret = find_other_exec(argv0, "postgres", PM_VERSIONSTR, cmdLine);
+		ret = find_other_exec(argv0, "postgres-8.2", PM_VERSIONSTR, cmdLine);
 		if (ret != 0)
 		{
-			write_stderr(_("%s: could not find postgres program executable\n"), progname);
+			write_stderr(_("%s: could not find postgres-8.2 program executable\n"), progname);
 			exit(1);
 		}
 	}
--- postgresql-8.2.6/src/interfaces/ecpg/compatlib/Makefile	2006-09-10 18:07:02.000000000 -0400
+++ postgresql-8.2.6-new/src/interfaces/ecpg/compatlib/Makefile	2008-01-15 11:07:16.000000000 -0500
@@ -20,6 +20,7 @@
 override CPPFLAGS := -I../include -I$(top_srcdir)/src/interfaces/ecpg/include \
 	-I$(libpq_srcdir) -I$(top_srcdir)/src/include/utils $(CPPFLAGS)
 override CFLAGS += $(PTHREAD_CFLAGS)
+override LDFLAGS := -L../ecpglib -L../pgtypeslib -L../../libpq $(LDFLAGS)
 SHLIB_LINK = -L../ecpglib -lecpg -L../pgtypeslib -lpgtypes $(libpq) -lm \
 	$(PTHREAD_LIBS)
 
--- postgresql-8.2.6/src/interfaces/ecpg/ecpglib/Makefile	2006-09-28 10:48:45.000000000 -0400
+++ postgresql-8.2.6-new/src/interfaces/ecpg/ecpglib/Makefile	2008-01-15 11:07:16.000000000 -0500
@@ -20,6 +20,7 @@
 override CPPFLAGS := -DFRONTEND \
 	-I../include -I$(top_srcdir)/src/interfaces/ecpg/include \
 	-I$(libpq_srcdir) -I$(top_builddir)/src/port $(CPPFLAGS)
+override LDFLAGS := -L../ecpglib -L../pgtypeslib -L../../libpq $(LDFLAGS)
 override CFLAGS += $(PTHREAD_CFLAGS)
 
 # Need to recompile any libpgport object files
--- postgresql-8.2.6/src/interfaces/ecpg/test/Makefile.regress	2006-09-19 11:36:08.000000000 -0400
+++ postgresql-8.2.6-new/src/interfaces/ecpg/test/Makefile.regress	2008-01-15 11:07:16.000000000 -0500
@@ -2,7 +2,7 @@
 	-I$(libpq_srcdir) $(CPPFLAGS) 
 override CFLAGS += $(PTHREAD_CFLAGS) 
 
-override LDFLAGS := -L../../ecpglib -L../../pgtypeslib $(LDFLAGS)
+override LDFLAGS := -L../../ecpglib -L../../pgtypeslib -L../../../libpq $(LDFLAGS)
 override LIBS := -lecpg -lpgtypes $(libpq) $(LIBS) $(PTHREAD_LIBS)
 
 ECPG = ../../preproc/ecpg -I$(srcdir)/../../include
--- postgresql-8.2.6/src/makefiles/Makefile.darwin	2006-11-28 00:45:43.000000000 -0500
+++ postgresql-8.2.6-new/src/makefiles/Makefile.darwin	2008-01-15 11:07:16.000000000 -0500
@@ -13,6 +13,6 @@
 # Rule for building shared libs (currently used only for regression test
 # shlib ... should go away, since this is not really enough knowledge)
 %.so: %.o
-	$(CC) $(CFLAGS) -bundle -o $@ $< $(BE_DLLLIBS)
+	$(CXX) $(CFLAGS) -bundle -undefined dynamic_lookup -o $@ $< $(BE_DLLLIBS)
 
 sqlmansect = 7
--- postgresql-8.2.6/src/template/darwin	2006-03-10 23:38:40.000000000 -0500
+++ postgresql-8.2.6-new/src/template/darwin	2008-01-15 11:07:16.000000000 -0500
@@ -1,8 +1,5 @@
 # $PostgreSQL: pgsql/src/template/darwin,v 1.10 2006/03/11 04:38:40 momjian Exp $
 
-# Apple's cpp-precomp seems a tad broken, so don't use it
-# (Note: on OS X before 10.2, you might need -traditional-cpp instead)
-CC="$CC -no-cpp-precomp"
 
 # Select appropriate semaphore support
 USE_NAMED_POSIX_SEMAPHORES=1
