Skip to content

Commit

Permalink
Add a tool to manage all postgres clusters at once. Improve the creat…
Browse files Browse the repository at this point in the history
…e_cluster.sh tool. This is only the first step that puts the postgres version as parameter and add the missing CREATE EXTENSION btre_gist command in the final psql script.
  • Loading branch information
beaud76 committed Feb 25, 2018
1 parent 78ede5e commit ccd0c57
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 17 deletions.
27 changes: 27 additions & 0 deletions tools/all_cluster.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
# all_cluster.sh
# E-Maj tool, distributed under GPL3 licence
# Perform global operations for all configured clusters
# syntax : all_cluster.sh <start|stop|restart|reload>

if [ $# -lt 1 ]; then
echo "Usage: $0 <start|stop|restart|reload>"
exit 1
fi
ACTION=$1

#echo "==> Cluster 9.1 :"
#/home/postgres/pg/pg91/bin/pg_ctl -D /home/postgres/db91 $ACTION
echo "==> Cluster 9.2 :"
/home/postgres/pg/pg92/bin/pg_ctl -D /home/postgres/db92 $ACTION
echo "==> Cluster 9.3 :"
/home/postgres/pg/pg93/bin/pg_ctl -D /home/postgres/db93 $ACTION
echo "==> Cluster 9.4 :"
/home/postgres/pg/pg94/bin/pg_ctl -D /home/postgres/db94 $ACTION
echo "==> Cluster 9.5 :"
/home/postgres/pg/pg95/bin/pg_ctl -D /home/postgres/db95 $ACTION
echo "==> Cluster 9.6 :"
/home/postgres/pg/pg96/bin/pg_ctl -D /home/postgres/db96 $ACTION
echo "==> Cluster 10 :"
/home/postgres/pg/pg10/bin/pg_ctl -D /home/postgres/db10 $ACTION

Empty file modified tools/check_code.pl
100644 → 100755
Empty file.
Empty file modified tools/check_error_messages.pl
100644 → 100755
Empty file.
38 changes: 21 additions & 17 deletions tools/create_cluster.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
#!/bin/sh
# E-Maj
# Create a postgres cluster
#!/bin/bash
# create_cluster.sh
# E-Maj tool, distributed under GPL3 licence
# Create a postgres cluster suitable to run the E-Maj regression tests
# Syntax: create_cluster <minor postgres version>

export PGMAJORVERSION=96
export PGVERSION=960
if [[ $# -lt 1 || ! "${1}" =~ ^[0-9]{3}$ ]]; then
echo "Usage: $0 <minor postgres version>"
echo "for instance: '$0 102' for version 10.2"
exit 1
fi

export PGVERSION=$1
export PGMAJORVERSION=`echo $PGVERSION | cut -c1-2`

export PGDATA=/home/postgres/db$PGMAJORVERSION
export PGDIR=/usr/local/pg$PGVERSION/bin
export EMAJDIR=/home/postgres/proj/emaj

echo
echo "*********************************************"
echo "**************************************************"
echo "* Create the cluster for version $PGMAJORVERSION *"
echo "*********************************************"
echo "**************************************************"
echo

# Trying to stop the cluster if it already exists and is up
Expand All @@ -26,16 +34,15 @@ mkdir $PGDATA
cd $PGDATA

# Initialize the cluster
#$PGDIR/initdb -D . # pg 9.2-
$PGDIR/initdb -k -D .
$PGDIR/initdb -D .
if [ -f "PG_VERSION" ]; then
echo "Initdb OK"
else
echo "Error during initdb..."
exit 1
fi

# Cluster configuration change
# Cluster configuration changes

cat <<EOF1 >specif.conf
listen_addresses = '*'
Expand All @@ -61,23 +68,21 @@ mkdir emaj_tblsp
mkdir tsplog1
mkdir tsplog2

# Copy and adjust the emaj.control file # if pg 9.1+
# Copy and adjust the emaj.control file
sudo cp $EMAJDIR/emaj.control /usr/local/pg$PGVERSION/share/postgresql/extension/emaj.control
sudo bash -c "echo \"directory = '$EMAJDIR/sql'\" >>/usr/local/pg$PGVERSION/share/postgresql/extension/emaj.control"

# Create all what is needed inside the cluster (tablespaces, roles, extensions,...)
$PGDIR/psql -p 54$PGMAJORVERSION postgres -a <<EOF2
\set ON_ERROR_STOP
--create language plpgsql; -- if pg 8.4-
create tablespace tspemaj location '/home/postgres/db$PGMAJORVERSION/emaj_tblsp';
create tablespace tsplog1 location '/home/postgres/db$PGMAJORVERSION/tsplog1';
create tablespace "tsp log'2" location '/home/postgres/db$PGMAJORVERSION/tsplog2';
create role myUser login password '';
grant all on database postgres to myUser;
--\i ~/pg/postgresql-9.0.23/contrib/dblink/dblink.sql -- if pg 9.0-
create extension dblink; -- if pg 9.1+
--\i $EMAJDIR/sql/emaj.sql -- if pg 9.0-
create extension emaj; -- if pg 9.1+
create extension dblink;
create extension btree_gist;
create extension emaj;
EOF2
if [ $? != 0 ]
then
Expand All @@ -86,4 +91,3 @@ then
fi

echo "Cluster successfuly initialized !!!"

Empty file modified tools/create_version.sh
100644 → 100755
Empty file.
Empty file modified tools/sync_fct_in_upgrade_script.pl
100644 → 100755
Empty file.

0 comments on commit ccd0c57

Please sign in to comment.