From 7e1ada58fbc93ea5651ba488ae289037e6414170 Mon Sep 17 00:00:00 2001 From: pea Date: Thu, 8 Jul 2010 16:18:06 +0000 Subject: [PATCH] Import pgbouncer. PgBouncer is a lightweight connection pooler for PostgreSQL. With tweaks from jasper@ ok jasper@ --- databases/pgbouncer/Makefile | 41 +++++++++++++++++++ databases/pgbouncer/distinfo | 5 +++ databases/pgbouncer/files/README.OpenBSD | 28 +++++++++++++ databases/pgbouncer/patches/patch-Makefile | 11 +++++ .../pgbouncer/patches/patch-etc_pgbouncer_ini | 34 +++++++++++++++ .../pgbouncer/patches/patch-etc_userlist_txt | 8 ++++ databases/pgbouncer/patches/patch-src_util_c | 12 ++++++ databases/pgbouncer/pkg/DESCR | 30 ++++++++++++++ databases/pgbouncer/pkg/MESSAGE | 2 + databases/pgbouncer/pkg/PLIST | 22 ++++++++++ 10 files changed, 193 insertions(+) create mode 100644 databases/pgbouncer/Makefile create mode 100644 databases/pgbouncer/distinfo create mode 100644 databases/pgbouncer/files/README.OpenBSD create mode 100644 databases/pgbouncer/patches/patch-Makefile create mode 100644 databases/pgbouncer/patches/patch-etc_pgbouncer_ini create mode 100644 databases/pgbouncer/patches/patch-etc_userlist_txt create mode 100644 databases/pgbouncer/patches/patch-src_util_c create mode 100644 databases/pgbouncer/pkg/DESCR create mode 100644 databases/pgbouncer/pkg/MESSAGE create mode 100644 databases/pgbouncer/pkg/PLIST diff --git a/databases/pgbouncer/Makefile b/databases/pgbouncer/Makefile new file mode 100644 index 00000000000..e2b838b8bfe --- /dev/null +++ b/databases/pgbouncer/Makefile @@ -0,0 +1,41 @@ +# $OpenBSD: Makefile,v 1.1.1.1 2010/07/08 16:18:06 pea Exp $ + +COMMENT = lightweight connection pooler for PostgreSQL + +DISTNAME = pgbouncer-1.3.3 + +CATEGORIES = databases + +HOMEPAGE = http://wiki.postgresql.org/wiki/PgBouncer + +MAINTAINER = Pierre-Emmanuel Andre + +# BSD +PERMIT_PACKAGE_FTP = Yes +PERMIT_PACKAGE_CDROM = Yes +PERMIT_DISTFILES_FTP = Yes +PERMIT_DISTFILES_CDROM =Yes + +WANTLIB = c event + +MASTER_SITES = http://pgfoundry.org/frs/download.php/2677/ + +BUILD_DEPENDS = ::devel/libeventextra + +CONFIGURE_STYLE = gnu +CONFIGURE_ARGS = --with-libevent=${LOCALBASE} + +USE_GMAKE = Yes + +# The actual regress tests are (cd ${WRKSRC}/test; ./test.sh) +# They want to create full postgres install and also play with +# firewall (iptables) +NO_REGRESS = Yes + +post-install: + ${SUBST_CMD} -c ${FILESDIR}/README.OpenBSD \ + ${PREFIX}/share/doc/pgbouncer/README.OpenBSD + chown ${SHAREOWN}:${SHAREGRP} \ + ${PREFIX}/share/doc/pgbouncer/README.OpenBSD + +.include diff --git a/databases/pgbouncer/distinfo b/databases/pgbouncer/distinfo new file mode 100644 index 00000000000..996f7f66779 --- /dev/null +++ b/databases/pgbouncer/distinfo @@ -0,0 +1,5 @@ +MD5 (pgbouncer-1.3.3.tar.gz) = Lr0dkH24UYy540U0NyASrA== +RMD160 (pgbouncer-1.3.3.tar.gz) = j/GS3Uuw33iVhYAmyM9H83Xbjms= +SHA1 (pgbouncer-1.3.3.tar.gz) = JI9OSYwBKVQSd7bB2sUsyqoe61I= +SHA256 (pgbouncer-1.3.3.tar.gz) = bIbik6KJ9Z6G0AUOKtNuGnjMR42zR0Y1/PH8rCYERjY= +SIZE (pgbouncer-1.3.3.tar.gz) = 167476 diff --git a/databases/pgbouncer/files/README.OpenBSD b/databases/pgbouncer/files/README.OpenBSD new file mode 100644 index 00000000000..9ffca65d94f --- /dev/null +++ b/databases/pgbouncer/files/README.OpenBSD @@ -0,0 +1,28 @@ +$OpenBSD: README.OpenBSD,v 1.1.1.1 2010/07/08 16:18:06 pea Exp $ + +1) Carefully edit ${SYSCONFDIR}/pgbouncer/pgbouncer.ini and + ${SYSCONFDIR}/pgbouncer/userlist.txt to fit your needs. + + +2) Launch pgbouncer in foreground mode to see if everything + is ok: + + # install -d -o _pgbouncer /var/run/pgbouncer + # pgbouncer -u _pgbouncer /etc/pgbouncer/pgbouncer.ini + + +3) Add the following to your /etc/rc.local: + + if [ -x ${TRUEPREFIX}/bin/pgbouncer ]; then + echo -n 'pgbouncer' + install -d -o _pgbouncer /var/run/pgbouncer + ${TRUEPREFIX}/bin/pgbouncer -d -u _pgbouncer \ + /etc/pgbouncer/pgbouncer.ini + fi + + + +Random hints: + + * Check /var/log/pgbouncer/pgbouncer.log if something + goes wrong diff --git a/databases/pgbouncer/patches/patch-Makefile b/databases/pgbouncer/patches/patch-Makefile new file mode 100644 index 00000000000..ec09e27f246 --- /dev/null +++ b/databases/pgbouncer/patches/patch-Makefile @@ -0,0 +1,11 @@ +$OpenBSD: patch-Makefile,v 1.1.1.1 2010/07/08 16:18:06 pea Exp $ +--- Makefile.orig Wed Jan 28 11:59:26 2009 ++++ Makefile Wed Jun 16 11:22:46 2010 +@@ -104,6 +104,7 @@ install: $(exe) doc-install + mkdir -p $(DESTDIR)$(docdir) + $(BININSTALL) -m 755 $(exe) $(DESTDIR)$(bindir) + $(INSTALL) -m 644 $(srcdir)/etc/pgbouncer.ini $(DESTDIR)$(docdir) ++ $(INSTALL) -m 644 $(srcdir)/etc/userlist.txt $(DESTDIR)$(docdir) + ifeq ($(PORTNAME),win32) + $(BININSTALL) -m 755 $(dll) $(DESTDIR)$(bindir) + endif diff --git a/databases/pgbouncer/patches/patch-etc_pgbouncer_ini b/databases/pgbouncer/patches/patch-etc_pgbouncer_ini new file mode 100644 index 00000000000..9136a75ad49 --- /dev/null +++ b/databases/pgbouncer/patches/patch-etc_pgbouncer_ini @@ -0,0 +1,34 @@ +$OpenBSD: patch-etc_pgbouncer_ini,v 1.1.1.1 2010/07/08 16:18:06 pea Exp $ +--- etc/pgbouncer.ini.orig Wed Apr 21 12:02:50 2010 ++++ etc/pgbouncer.ini Wed Jun 16 15:29:18 2010 +@@ -22,8 +22,8 @@ nondefaultdb = pool_size=50 reserve_pool=10 + ;;; Administrative settings + ;;; + +-logfile = pgbouncer.log +-pidfile = pgbouncer.pid ++logfile = /var/log/pgbouncer/pgbouncer.log ++pidfile = /var/run/pgbouncer/pgbouncer.pid + + ;;; + ;;; Where to wait for clients +@@ -39,16 +39,16 @@ unix_socket_dir = /tmp + ;;; + + ; any, trust, plain, crypt, md5 +-auth_type = trust ++auth_type = md5 + #auth_file = 8.0/main/global/pg_auth +-auth_file = etc/userlist.txt ++auth_file = /etc/pgbouncer/userlist.txt + + ;;; + ;;; Users allowed into database 'pgbouncer' + ;;; + + ; comma-separated list of users, who are allowed to change settings +-admin_users = user2, someadmin, otheradmin ++admin_users = admin, pgbouncer + + ; comma-separated list of users who are just allowed to use SHOW command + stats_users = stats, root diff --git a/databases/pgbouncer/patches/patch-etc_userlist_txt b/databases/pgbouncer/patches/patch-etc_userlist_txt new file mode 100644 index 00000000000..c90703970fd --- /dev/null +++ b/databases/pgbouncer/patches/patch-etc_userlist_txt @@ -0,0 +1,8 @@ +$OpenBSD: patch-etc_userlist_txt,v 1.1.1.1 2010/07/08 16:18:06 pea Exp $ +--- etc/userlist.txt.orig Wed Jun 16 12:27:35 2010 ++++ etc/userlist.txt Wed Jun 16 12:27:56 2010 +@@ -1,3 +1,2 @@ +-"marko" "asdasd" +-"postgres" "asdasd" ++"admin" "admin" + "pgbouncer" "fake" diff --git a/databases/pgbouncer/patches/patch-src_util_c b/databases/pgbouncer/patches/patch-src_util_c new file mode 100644 index 00000000000..da0b7ca65db --- /dev/null +++ b/databases/pgbouncer/patches/patch-src_util_c @@ -0,0 +1,12 @@ +$OpenBSD: patch-src_util_c,v 1.1.1.1 2010/07/08 16:18:06 pea Exp $ +--- src/util.c.orig Wed Jun 23 09:44:05 2010 ++++ src/util.c Wed Jun 23 09:51:41 2010 +@@ -68,7 +68,7 @@ static void render_time(char *buf, int max) + struct tm *tm; + struct timeval tv; + gettimeofday(&tv, NULL); +- tm = localtime(&tv.tv_sec); ++ tm = localtime((time_t *)&tv.tv_sec); + snprintf(buf, max, "%04d-%02d-%02d %02d:%02d:%02d.%03d", + tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, + tm->tm_hour, tm->tm_min, tm->tm_sec, diff --git a/databases/pgbouncer/pkg/DESCR b/databases/pgbouncer/pkg/DESCR new file mode 100644 index 00000000000..ee9757db61f --- /dev/null +++ b/databases/pgbouncer/pkg/DESCR @@ -0,0 +1,30 @@ +PgBouncer is a lightweight connection pooler for PostgreSQL. + +Features: +* Several levels of brutality when rotating connections: + + Session pooling +Most polite method. When client connects, a server connection will +be assigned to it for the whole duration it stays connected. When +client disconnects, the server connection will be put back into +pool. This mode supports all PostgeSQL features. + + Transaction pooling +Server connection is assigned to client only during a transaction. +When PgBouncer notices that transaction is over, the server will be +put back into pool. This mode breaks few session-based features of +PostgreSQL. You can use it only when application cooperates by not +using features that break. See the table below for incompatible +features. + + Statement pooling +Most aggressive method. This is transaction pooling with a twist - +multi-statement transactions are disallowed. This is meant to +enforce "autocommit" mode on client, mostly targeted for PL/Proxy. + +* Low memory requirements (2k per connection by default). This is due to +the fact that PgBouncer does not need to see full packet at once. +* It is not tied to one backend server, the destination databases can reside +on different hosts. +* Supports online reconfiguration for most of the settings. +* Supports online restart/upgrade without dropping client connections. +* Supports protocol V3 only, so backend version must be >= 7.4. + + diff --git a/databases/pgbouncer/pkg/MESSAGE b/databases/pgbouncer/pkg/MESSAGE new file mode 100644 index 00000000000..7fa582ba901 --- /dev/null +++ b/databases/pgbouncer/pkg/MESSAGE @@ -0,0 +1,2 @@ +Please see ${PREFIX}/share/doc/pgbouncer/README.OpenBSD for +a brief intro to using pgbouncer on OpenBSD. diff --git a/databases/pgbouncer/pkg/PLIST b/databases/pgbouncer/pkg/PLIST new file mode 100644 index 00000000000..4add58a69e6 --- /dev/null +++ b/databases/pgbouncer/pkg/PLIST @@ -0,0 +1,22 @@ +@comment $OpenBSD: PLIST,v 1.1.1.1 2010/07/08 16:18:06 pea Exp $ +@newgroup _pgbouncer:653 +@newuser _pgbouncer:653:653:daemon:pgbouncer:/nonexistent:/sbin/nologin +@bin bin/pgbouncer +@man man/man1/pgbouncer.1 +@man man/man5/pgbouncer.5 +@owner _pgbouncer +@sample ${SYSCONFDIR}/pgbouncer/ +@owner +share/doc/pgbouncer/ +share/doc/pgbouncer/README.OpenBSD +@mode 640 +@group _pgbouncer +share/doc/pgbouncer/pgbouncer.ini +@sample ${SYSCONFDIR}/pgbouncer/pgbouncer.ini +share/doc/pgbouncer/userlist.txt +@sample ${SYSCONFDIR}/pgbouncer/userlist.txt +@mode +@owner _pgbouncer +@group +@sample /var/log/pgbouncer/ +@extraunexec rm -rf /var/log/pgbouncer