Code

postrr.sql: Use "LANGUAGE C" rather than "LANGUAGE 'C'".
[postrr.git] / pgtest.sh
index b88bf6c54938636d0f50f55dcae1c9de03c2615d..d911b5c9dbd47fb3f4e6a8e8966d63dab08697ba 100755 (executable)
--- a/pgtest.sh
+++ b/pgtest.sh
 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-PG_CONFIG=`which pg_config`
+if test -z "$PG_CONFIG"; then
+       PG_CONFIG=`which pg_config`
+fi
 if test -z "$PG_CONFIG"; then
        echo "pg_config not found!" >&2
        exit 1
 fi
 
-BIN_DIR=`pg_config --bindir`
+BIN_DIR=`$PG_CONFIG --bindir`
 if test -z "$TARGET"; then
        TARGET=`pwd`/target
 fi
@@ -44,16 +46,21 @@ set -e
 
 case "$1" in
        setup)
+               if test $# -ne 1; then
+                       echo "Too many arguments!" >&2
+                       echo "Usage: $0 setup" >&2
+                       exit 1
+               fi
                mkdir -p $TARGET/var/lib/postgresql/main
                mkdir -p $TARGET/var/run/postgresql
                mkdir -p $TARGET/var/log/postgresql/main
                $BIN_DIR/initdb -D $TARGET/var/lib/postgresql/main
-               sed -r -i -e 's/^#port = 5432/port = 5435/' \
+               sed -r -i -e 's/^#port = 5432/port = 2345/' \
                        $TARGET/var/lib/postgresql/main/postgresql.conf
                sed -r -i -e "s/^#dynamic_library_path = '\\\$libdir'/dynamic_library_path = '\$libdir:$PWD_esc\/src'/" $TARGET/var/lib/postgresql/main/postgresql.conf
                sed -r -i -e "s/^#unix_socket_directory = ''/unix_socket_directory = '$TARGET_esc\/var\/run\/postgresql'/" $TARGET/var/lib/postgresql/main/postgresql.conf
                $0 start -B
-               $BIN_DIR/createdb -e -h $TARGET/var/run/postgresql/ -p 5435 tokkee
+               $BIN_DIR/createdb -e -h $TARGET/var/run/postgresql/ -p 2345 "$( id -un )"
                $0 stop
                ;;
        client)
@@ -66,20 +73,58 @@ case "$1" in
                                export LD_PRELOAD="$LD_PRELOAD:$libreadline"
                        fi
                fi
-               $BIN_DIR/psql -h $TARGET/var/run/postgresql/ -p 5435
+               shift
+               $BIN_DIR/psql -h $TARGET/var/run/postgresql/ -p 2345 "$@"
                ;;
        stop)
+               if test $# -ne 1; then
+                       echo "Too many arguments!" >&2
+                       echo "Usage: $0 stop" >&2
+                       exit 1
+               fi
                $BIN_DIR/pg_ctl -D $TARGET/var/lib/postgresql/main stop
                ;;
        start)
-               if test "$2" = "-B"; then
-                       $BIN_DIR/pg_ctl -D $TARGET/var/lib/postgresql/main -l logfile -w start
+               shift
+               if test "$1" = "-B"; then
+                       shift
+                       $BIN_DIR/pg_ctl -D $TARGET/var/lib/postgresql/main -l logfile -w start "$@"
                else
-                       $BIN_DIR/postgres -D $TARGET/var/lib/postgresql/main
+                       $BIN_DIR/postgres -D $TARGET/var/lib/postgresql/main "$@"
                fi
                ;;
+       restart)
+               $0 stop && $0 start -B
+               ;;
+       dump)
+               shift
+               $BIN_DIR/pg_dump -h $TARGET/var/run/postgresql/ -p 2345 "$@"
+               ;;
+       restore)
+               shift
+               $BIN_DIR/pg_restore -h $TARGET/var/run/postgresql/ -p 2345 "$@"
+               ;;
        *)
                echo "Usage: $0 setup|client|stop|start" >&2
+               echo ""
+               echo "  - setup"
+               echo "    Set up a new PostgreSQL server listening on port 2345."
+               echo "  - client [<psql args>]"
+               echo "    Start a PostgreSQL interactive terminal connected to the"
+               echo "    PostgreSQL server on port 2345."
+               echo "  - start [-B [<postgres args>]]"
+               echo "    Start the PostgreSQL server."
+               echo "  - stop"
+               echo "    Stop the PostgreSQL server."
+               echo "  - restart"
+               echo "    Restart a background PostgreSQL server process."
+               echo ""
+               echo "Environment variables:"
+               echo "  - TARGET"
+               echo "    Target directory of the PostgreSQL test setup."
+               if test "$1" = "help"; then
+                       exit 0
+               fi
                exit 1
                ;;
 esac