summaryrefslogtreecommitdiff
path: root/databases/postgresql91-server/files/502.pgsql.in
diff options
context:
space:
mode:
authorPalle Girgensohn <girgen@FreeBSD.org>2011-04-18 23:34:27 +0000
committerPalle Girgensohn <girgen@FreeBSD.org>2011-04-18 23:34:27 +0000
commit73c856222edb8c22377bf9a1c81a724065e3a31c (patch)
tree2a77e52eec6ad4963a7f80ea0b338e506c5e9a85 /databases/postgresql91-server/files/502.pgsql.in
parent- Fix category (diff)
Update PostgreSQL to 9.0.4, 8.4.8, 8.3.15 and 8.2.21.
This update contains a critical fix to the pg_upgrade utility which prevents significant downtime issues. Do not use pg_upgrade without installing this update first. The issue with pg_upgrade and the fix are detailed on the PostgreSQL wiki: http://wiki.postgresql.org/wiki/20110408pg_upgrade_fix Users who have already used pg_upgrade should run the database repair script given on that page on their databases as soon as possible. See the release notes for each version at http://www.postgresql.org/docs/current/static/release.html for a full list of changes with details. Allow the username of the postgresql user to configurable for 8.4 and 9.0. Largely inspired by the work of Jason Helfman [153668, 153136]. Change PGUSER knob to PG_USER not to clash with PGUSER environment. PR: 153668, 153136, 155493, 155137
Notes
Notes: svn path=/head/; revision=272900
Diffstat (limited to 'databases/postgresql91-server/files/502.pgsql.in')
-rw-r--r--databases/postgresql91-server/files/502.pgsql.in112
1 files changed, 112 insertions, 0 deletions
diff --git a/databases/postgresql91-server/files/502.pgsql.in b/databases/postgresql91-server/files/502.pgsql.in
new file mode 100644
index 000000000000..266a822efb61
--- /dev/null
+++ b/databases/postgresql91-server/files/502.pgsql.in
@@ -0,0 +1,112 @@
+%%PG_USER%%#!/bin/sh
+#
+# $FreeBSD: /tmp/pcvs/ports/databases/postgresql91-server/files/502.pgsql.in,v 1.1 2011-04-18 23:34:27 girgen Exp $
+#
+# Maintenance shell script to vacuum and backup database
+# Put this in /usr/local/etc/periodic/daily, and it will be run
+# every night
+#
+# Written by Palle Girgensohn <girgen@pingpong.net>
+#
+# In public domain, do what you like with it,
+# and use it at your own risk... :)
+#
+
+# Define these variables in either /etc/periodic.conf or
+# /etc/periodic.conf.local to override the default values.
+#
+# daily_pgsql_backup_enable="YES" # do backup of all databases
+# daily_pgsql_backup_enable="foo bar db1 db2" # only do backup of a limited selection of databases
+# daily_pgsql_vacuum_enable="YES" # do vacuum
+
+daily_pgsql_vacuum_args="-z"
+daily_pgsql_pgdump_args="-b -F c"
+# backupdir is relative to ~pgsql home directory unless it begins with a slash:
+daily_pgsql_backupdir="~%%PG_USER%%/backups"
+daily_pgsql_savedays="7"
+
+# If there is a global system configuration file, suck it in.
+#
+if [ -r /etc/defaults/periodic.conf ]
+then
+ . /etc/defaults/periodic.conf
+ source_periodic_confs
+fi
+
+# allow '~´ in dir name
+eval backupdir=${daily_pgsql_backupdir}
+
+rc=0
+
+pgsql_backup() {
+ # daily_pgsql_backupdir must be writeable by user %%PG_USER%%
+ # ~%%PG_USER%% is just that under normal circumstances,
+ # but this might not be where you want the backups...
+ if [ ! -d ${backupdir} ] ; then
+ echo Creating ${backupdir}
+ mkdir -m 700 ${backupdir}; chown %%PG_USER%% ${backupdir}
+ fi
+
+ echo
+ echo "PostgreSQL backups"
+
+ # Protect the data
+ umask 077
+ rc=$?
+ now=`date "+%Y-%m-%dT%H:%M:%S"`
+ file=${daily_pgsql_backupdir}/pgglobals_${now}
+ su -l %%PG_USER%% -c "umask 077; pg_dumpall -g -U %%PG_USER%% | gzip -9 > ${file}.gz"
+
+ db=$1
+ while shift; do
+ echo -n " $db"
+ file=${backupdir}/pgdump_${db}_${now}
+ su -l %%PG_USER%% -c "umask 077; pg_dump ${daily_pgsql_pgdump_args} -U %%PG_USER%% -f ${file} ${db}"
+ [ $? -gt 0 ] && rc=3
+ db=$1
+ done
+
+ if [ $rc -gt 0 ]; then
+ echo
+ echo "Errors were reported during backup."
+ fi
+
+ # cleaning up old data
+ find ${backupdir} \( -name 'pgdump_*' -o -name 'pgglobals_*' \) \
+ -a -mtime +${daily_pgsql_savedays} -delete
+ echo
+}
+
+case "$daily_pgsql_backup_enable" in
+ [Yy][Ee][Ss])
+ dbnames=`su -l %%PG_USER%% -c "umask 077; psql -q -t -A -d template1 -U %%PG_USER%% -c SELECT\ datname\ FROM\ pg_database\ WHERE\ datname!=\'template0\'"`
+ pgsql_backup $dbnames
+ ;;
+
+ [Nn][Oo])
+ ;;
+
+ "")
+ ;;
+
+ *)
+ pgsql_backup $daily_pgsql_backup_enable
+ ;;
+esac
+
+case "$daily_pgsql_vacuum_enable" in
+ [Yy][Ee][Ss])
+
+ echo
+ echo "PostgreSQL vacuum"
+ su -l %%PG_USER%% -c "vacuumdb -a -q -U %%PG_USER%% ${daily_pgsql_vacuum_args}"
+ if [ $? -gt 0 ]
+ then
+ echo
+ echo "Errors were reported during vacuum."
+ rc=3
+ fi
+ ;;
+esac
+
+exit $rc