ports/databases/postgresql94-server/files/502.pgsql.in
Palle Girgensohn 871f7f3137 The PostgreSQL Global Development Group announced that the first beta
release of PostgreSQL 9.4, the latest version of the world's leading
open source database, is available today.  This beta contains previews
of all of the features which will be available in version 9.4, and is
ready for testing by the worldwide PostgreSQL community.  Please
download, test, and report what you find.

Major Features
--------------

The new major features available for testing in this beta include:

* JSONB: 9.4 includes the new JSONB "binary JSON" type. This new
  storage format for document data is higher-performance, and comes with
  indexing, functions and operators for manipulating JSON data.
* Replication: The new Data Change Streaming API allows decoding and
  transformation of the replication stream.  This lays the foundation
  for new replication tools that support high-speed and more flexible
  replication and scale-out solutions.
* Materialized Views with "Refresh Concurrently", which permit
  fast-response background summary reports for complex data.
* ALTER SYSTEM SET, which enables modifications to postgresql.conf
  from the SQL command line and from remote clients, easing
  administration tasks.
2014-05-18 14:44:53 +00:00

115 lines
2.9 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
#
# $FreeBSD: /tmp/pcvs/ports/databases/postgresql92-server/files/502.pgsql.in,v 1.4 2011-10-18 09:03:32 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_user=%%PG_USER%%
daily_pgsql_vacuum_args="-U ${daily_pgsql_user} -qaz"
daily_pgsql_pgdump_args="-U ${daily_pgsql_user} -bF c"
daily_pgsql_pgdumpall_globals_args="-U ${daily_pgsql_user}"
# backupdir is relative to ~pgsql home directory unless it begins with a slash:
daily_pgsql_backupdir="~${daily_pgsql_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 ${daily_pgsql_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 ${daily_pgsql_user} -c \
"umask 077; pg_dumpall -g ${daily_pgsql_pgdumpall_globals_args} | gzip -9 > ${file}.gz"
db=$1
while shift; do
echo -n " $db"
file=${backupdir}/pgdump_${db}_${now}
su -l ${daily_pgsql_user} -c "umask 077; pg_dump ${daily_pgsql_pgdump_args} -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 ${daily_pgsql_user} -c "vacuumdb ${daily_pgsql_vacuum_args}"
if [ $? -gt 0 ]
then
echo
echo "Errors were reported during vacuum."
rc=3
fi
;;
esac
exit $rc