summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/components/sqldb
diff options
context:
space:
mode:
Diffstat (limited to 'sca-cpp/trunk/components/sqldb')
-rwxr-xr-xsca-cpp/trunk/components/sqldb/pgsql-conf33
-rwxr-xr-xsca-cpp/trunk/components/sqldb/pgsql-standby-conf27
2 files changed, 41 insertions, 19 deletions
diff --git a/sca-cpp/trunk/components/sqldb/pgsql-conf b/sca-cpp/trunk/components/sqldb/pgsql-conf
index 482048a295..8adbb902c9 100755
--- a/sca-cpp/trunk/components/sqldb/pgsql-conf
+++ b/sca-cpp/trunk/components/sqldb/pgsql-conf
@@ -24,12 +24,16 @@ root=`echo "import os; print os.path.realpath('$1')" | python`
addr=$2
if [ "$addr" = "" ]; then
- ip="*"
+ host="localhost"
+ listen="*"
port="5432"
else
- ip=`$here/../../modules/http/httpd-addr ip $addr`
- if [ "$ip" = "" ]; then
- ip="*"
+ host=`$here/../../modules/http/httpd-addr ip $addr`
+ if [ "$host" = "" ]; then
+ host="localhost"
+ listen="*"
+ else
+ listen=$host
fi
port=`$here/../../modules/http/httpd-addr port $addr`
fi
@@ -38,6 +42,8 @@ bport=`expr $port + 1000`
pgsql_prefix=`cat $here/pgsql.prefix`
pgbouncer_prefix=`cat $here/pgbouncer.prefix`
+user=`id -un`
+
mkdir -p $root/sqldb/data
chmod 700 $root/sqldb/data
mkdir -p $root/sqldb/archive
@@ -50,6 +56,7 @@ else
pgsql_log="cat >>$root/logs/postgresql"
fi
mkdir -p $root/sqldb
+mkdir -p $root/sqldb/tmp
echo $pgsql_log >$root/sqldb/logger
# Initialize PostgreSQL
@@ -77,12 +84,13 @@ log_lock_waits = on
log_statement = none
# Listen
-listen_addresses = '$ip'
+listen_addresses = '$listen'
port = $port
+unix_socket_directory = '$root/sqldb/tmp'
# Setup archival
archive_mode = on
-archive_command = '$here/pgsql-archive $root localhost $bport %p %f'
+archive_command = '$here/pgsql-archive $root $host $bport %p %f'
# Setup hot standby with streaming replication
wal_level = hot_standby
@@ -114,12 +122,16 @@ while [ $sti -ne 30 ]; do
sti=$((sti+1))
done
-$pgsql_prefix/bin/createdb -h localhost -p $port db 2>&1 | sh $root/sqldb/logger
+$pgsql_prefix/bin/createdb -h $host -p $port db 2>&1 | sh $root/sqldb/logger
+
+# Create default user roles
+$pgsql_prefix/bin/psql -h $host -p $port -c "create role standby with login replication" db 2>&1 | sh $root/sqldb/logger
+$pgsql_prefix/bin/psql -h $host -p $port -c "create role bouncer with login" db 2>&1 | sh $root/sqldb/logger
# Backup the db if there's no backup for it yet
baks=`ls $root/sqldb/archive | sort -r | grep "\.backup\.tar\.gz$"`
if [ "$baks" = "" ]; then
- $here/pgsql-backup $root localhost $port
+ $here/pgsql-backup $root $host $port
fi
$pgsql_prefix/bin/pg_ctl stop -w -D $root/sqldb/data 2>&1 | sh $root/sqldb/logger
@@ -151,12 +163,13 @@ id=`id -un`
cat >$root/sqldb/data/pgbouncer.conf <<EOF
[databases]
-db = host=localhost dbname=db
+db = host=$host port=$port dbname=db user=bouncer
[pgbouncer]
pool_mode = session
+listen_addr = $listen
listen_port = $bport
-listen_addr = $ip
+unix_socket_dir =
auth_type = trust
auth_file=$root/sqldb/data/pgbouncer-auth.conf
logfile = $root/logs/pgbouncer
diff --git a/sca-cpp/trunk/components/sqldb/pgsql-standby-conf b/sca-cpp/trunk/components/sqldb/pgsql-standby-conf
index 77d1dfa8e2..5f76b5b332 100755
--- a/sca-cpp/trunk/components/sqldb/pgsql-standby-conf
+++ b/sca-cpp/trunk/components/sqldb/pgsql-standby-conf
@@ -25,12 +25,16 @@ root=`echo "import os; print os.path.realpath('$1')" | python`
# Server address
addr=$2
if [ "$addr" = "" ]; then
- ip="*"
+ host="localhost"
+ listen="*"
port="5432"
else
- ip=`$here/../../modules/http/httpd-addr ip $addr`
- if [ "$ip" = "" ]; then
- ip="*"
+ host=`$here/../../modules/http/httpd-addr ip $addr`
+ if [ "$host" = "" ]; then
+ host="localhost"
+ listen="*"
+ else
+ listen=$host
fi
port=`$here/../../modules/http/httpd-addr port $addr`
fi
@@ -50,6 +54,8 @@ fi
pgsql_prefix=`cat $here/pgsql.prefix`
pgbouncer_prefix=`cat $here/pgbouncer.prefix`
+user=`id -un`
+
mkdir -p $root/sqldb/data
chmod 700 $root/sqldb/data
mkdir -p $root/sqldb/archive
@@ -62,6 +68,7 @@ else
pgsql_log="cat >>$root/logs/postgresql"
fi
mkdir -p $root/sqldb
+mkdir -p $root/sqldb/tmp
echo $pgsql_log >$root/sqldb/logger
# Initialize from a backup of the master
@@ -95,12 +102,13 @@ log_lock_waits = on
log_statement = none
# Listen
-listen_addresses = '$ip'
+listen_addresses = '$listen'
port = $port
+unix_socket_directory = '$root/sqldb/tmp'
# Setup archival
archive_mode = on
-archive_command = '$here/pgsql-archive $root localhost $bport %p %f'
+archive_command = '$here/pgsql-archive $root $host $bport %p %f'
# Setup hot standby with streaming replication
wal_level = hot_standby
@@ -118,7 +126,7 @@ cat >$root/sqldb/data/recovery.conf << EOF
# Start in standby mode
standby_mode = 'on'
-primary_conninfo = 'host=$mhost port=$mport'
+primary_conninfo = 'host=$mhost port=$mport user=standby'
# Failover
trigger_file = '$root/sqldb/failover'
@@ -154,12 +162,13 @@ id=`id -un`
cat >$root/sqldb/data/pgbouncer.conf <<EOF
[databases]
-db = host=localhost dbname=db
+db = host=$host port=$port dbname=db user=bouncer
[pgbouncer]
pool_mode = session
+listen_addr = $listen
listen_port = $bport
-listen_addr = $ip
+unix_socket_dir =
auth_type = trust
auth_file=$root/sqldb/data/pgbouncer-auth.conf
logfile = $root/logs/pgbouncer