FreeBSD Postgresql notes

FreeBSD Postgresql notes

Postby stephen » Wed Dec 16, 2009 9:11 pm

The Freebsd diary has helped with these tips
http://www.freebsddiary.org/postgresql.php

backups
It's time I added backups to this article. This information is taken from the Admin documentation at /usr/local/share/doc/pgsql/admin/.

A backup is done with this:

% pg_dump dbname > dbname.pgdump

A restore is done with this:

cat dbname.pgdump | psql dbname

Depending upon your path settings, you may have to specify the full path to these binaries. Under FreeBSD, this would be /usr/local/bin/pg_dump.

For a backup script, please read the section on mySQL backups in the article I wrote for mySQL. Just substitute pg_dump for mysqldump.

Start Database server
/usr/local/etc/rc.d/postgresql start


We have two postgreSQL servers
/usr/local/etc/rc.d/postgresql start
and
/usr/local/etc/rc.d/postgresql2 start

This is /usr/local/etc/rc.d/postgresql start
Code: Select all
#!/bin/sh

# $FreeBSD: ports/databases/postgresql83-server/files/postgresql.in,v 1.2 2007/01/09 16:29:35 girgen Exp $
#
# PROVIDE: postgresql
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following line to /etc/rc.conf to enable PostgreSQL:
#
#  postgresql_enable="YES"
#  # optional
#  postgresql_data="/usr/local/pgsql/data"
#  postgresql_flags="-w -s -m fast"
#  postgresql_initdb_flags="--encoding=utf-8 --lc-collate=C"
#  postgresql_class="default"
#
# See /usr/local/share/doc/postgresql/README-server for more info
#
# This scripts takes one of the following commands:
#
#   start stop restart reload status initdb
#
# For postmaster startup options, edit ${postgresql_data}/postgresql.conf

prefix=/usr/local
command=${prefix}/bin/pg_ctl

. /etc/rc.subr

load_rc_config postgresql

# set defaults
postgresql_enable=${postgresql_enable:-"NO"}
postgresql_flags=${postgresql_flags:-"-w -s -m fast"}
postgresql_user=pgsql
eval postgresql_data=${postgresql_data:-"~${postgresql_user}/data"}
postgresql_class=${postgresql_class:-"default"}
postgresql_initdb_flags=${postgresql_initdb_flags:-"--encoding=utf-8 --lc-collate=C"}

name=postgresql
rcvar=`set_rcvar`
command_args="-D ${postgresql_data} ${postgresql_flags}"
extra_commands="reload initdb"

start_cmd="postgresql_command start"
stop_cmd="postgresql_command stop"
restart_cmd="postgresql_command restart"
reload_cmd="postgresql_command reload"
status_cmd="postgresql_command status"

initdb_cmd="postgresql_initdb"

postgresql_command()
{
    su -l ${postgresql_user} -c "exec ${command} ${command_args} ${rc_arg}"
}

postgresql_initdb()
{
    su -l -c ${postgresql_class} ${postgresql_user} -c "exec ${prefix}/bin/initdb ${postgresql_initdb_flags} -D ${postgresql_data}"
}

run_rc_command "$1"


and this is /usr/local/etc/rc.d/postgresql2
Code: Select all
#!/bin/sh

prefix=/usr/local
command=${prefix}/bin/pg_ctl

. /etc/rc.subr
name=postgresql2
rcvar=`set_rcvar`

load_rc_config $name

# set defaults
postgresql2_enable=${postgresql2_enable:-"NO"}
postgresql2_flags=${postgresql2_flags:-"-w -s -m fast"}
postgresql2_user=pgsql
eval postgresql2_data=${postgresql2_data:-"~${postgresql2_user}/data"}
postgresql2_class=${postgresql2_class:-"default"}
postgresql2_initdb_flags=${postgresql2_initdb_flags:-"--encoding=utf-8 --lc-collate=C"}

command_args="-D ${postgresql2_data} ${postgresql2_flags}"
extra_commands="reload initdb"

start_cmd="postgresql2_command start"
stop_cmd="postgresql2_command stop"
restart_cmd="postgresql2_command restart"
reload_cmd="postgresql2_command reload"
status_cmd="postgresql2_command status"

initdb_cmd="postgresql2_initdb"

postgresql2_command()
{
    su -l ${postgresql2_user} -c "exec ${command} ${command_args} ${rc_arg}"
}

postgresql2_initdb()
{
    su -l -c ${postgresql2_class} ${postgresql2_user} -c "exec ${prefix}/bin/initdb ${postgresql2_initdb_flags} -D ${postgresql2_data}"
}

run_rc_command "$1"
stephen
 
Posts: 507
Joined: Thu Feb 09, 2006 9:37 am
Location: Brisbane

Return to Linux Server Configuration Notes

Who is online

Users browsing this forum: No registered users and 2 guests

cron