Add distclean command
rename rmdb to cleandb simplify resetdb by using other functions all functions can support nodes, this also obsoletes resetdbN
This commit is contained in:
parent
22d36f283b
commit
f267123d4e
2 changed files with 109 additions and 53 deletions
42
README.md
42
README.md
|
@ -7,6 +7,9 @@ export PGV=<major version|HEAD>
|
||||||
## Activate PostgreSQL Developmnent ENvironment
|
## Activate PostgreSQL Developmnent ENvironment
|
||||||
`source pg-env`
|
`source pg-env`
|
||||||
|
|
||||||
|
## Run distclean on PostgreSQL source
|
||||||
|
`distclean`
|
||||||
|
|
||||||
## Compile PostgreSQL source and install
|
## Compile PostgreSQL source and install
|
||||||
`compile`
|
`compile`
|
||||||
|
|
||||||
|
@ -14,29 +17,48 @@ export PGV=<major version|HEAD>
|
||||||
`compile_contrib`
|
`compile_contrib`
|
||||||
|
|
||||||
## Start PostgreSQL
|
## Start PostgreSQL
|
||||||
`startdb`
|
`startdb <Nodes>`
|
||||||
|
ex:
|
||||||
|
startdb
|
||||||
|
startdb 1 2 3
|
||||||
|
|
||||||
## Stop PostgtreSQL
|
## Stop PostgtreSQL
|
||||||
`stopdb`
|
`stopdb <Nodes>`
|
||||||
|
ex:
|
||||||
|
stopdb
|
||||||
|
stopdb 1 2 3
|
||||||
|
|
||||||
## Restart PostgreSQL
|
## Restart PostgreSQL
|
||||||
`restartdb`
|
`restartdb <Nodes>`
|
||||||
|
ex:
|
||||||
|
restartdb
|
||||||
|
restartdb 1 2 3
|
||||||
|
|
||||||
## Remove PGDATA
|
## Remove PGDATA
|
||||||
`rmdb`
|
`cleandb <Nodes>`
|
||||||
|
ex:
|
||||||
|
cleandb
|
||||||
|
cleandb 1 2 3
|
||||||
|
|
||||||
## Initialize PostgreSQL Cluster and include custom config
|
## Initialize PostgreSQL Cluster and include custom config
|
||||||
`setupdb`
|
`setupdb <Nodes>`
|
||||||
|
ex:
|
||||||
|
setupdb
|
||||||
|
setupdb 1 2 3
|
||||||
|
|
||||||
## Reset DB
|
## Reset DB
|
||||||
`resetdb`
|
`resetdb <Nodes>`
|
||||||
|
ex:
|
||||||
## Reset and Setup Node N
|
resetdb
|
||||||
`resetdbN`
|
resetdb 1 2 3
|
||||||
|
|
||||||
## Reset database and install direcotory
|
## Reset database and install direcotory
|
||||||
`resetall`
|
`resetall <Nodes>`
|
||||||
|
ex:
|
||||||
|
resetall
|
||||||
|
resetall 1 2 3
|
||||||
|
|
||||||
## deactivate the environment
|
## deactivate the environment
|
||||||
`deactivate`
|
`deactivate`
|
||||||
|
Exit from pg-env
|
||||||
|
|
||||||
|
|
118
pg-env
118
pg-env
|
@ -5,11 +5,23 @@
|
||||||
# Copyright Yogesh Sharma
|
# Copyright Yogesh Sharma
|
||||||
##
|
##
|
||||||
#
|
#
|
||||||
1
|
echo "\$0 is $0"
|
||||||
|
echo "\$1 is $1"
|
||||||
|
echo "\$BASH_SOURCE is $BASH_SOURCE"
|
||||||
if [ "$0" = "$BASH_SOURCE" ]; then
|
if [ "$0" = "$BASH_SOURCE" ]; then
|
||||||
echo "source $0"
|
echo "source $0"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
if [[ -f ~/.pg-env ]]; then
|
||||||
|
source ~/.pg-env
|
||||||
|
else
|
||||||
|
PG_REPO_DIR=${HOME}/gitwork
|
||||||
|
PG_REPO_NAME=postgresql
|
||||||
|
DEV_REPO_DIR=${PG_REPO_DIR}
|
||||||
|
SRC_DIR="${SRC_DIR}"
|
||||||
|
INST_DIR="pg-${PGV}-inst"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z $SAVED_PATH ]; then
|
if [ -z $SAVED_PATH ]; then
|
||||||
SAVED_PATH=${PATH}
|
SAVED_PATH=${PATH}
|
||||||
fi
|
fi
|
||||||
|
@ -23,13 +35,13 @@ if [ -z "PGV" ]; then
|
||||||
echo "Missing PGV, export PGV=HEAD or export PGV=15"
|
echo "Missing PGV, export PGV=HEAD or export PGV=15"
|
||||||
else
|
else
|
||||||
if [ -z $PG_SRC ]; then
|
if [ -z $PG_SRC ]; then
|
||||||
PG_SRC=${HOME}/gitwork/${PG_PREFIX}pg-${PGV}-src
|
PG_SRC=${PG_REPO_DIR}/${PG_PREFIX}${SRC_DIR}
|
||||||
fi
|
fi
|
||||||
PG_BASE=${HOME}/gitwork/${PG_PREFIX}pg-${PGV}-inst
|
PG_BASE=${PG_REPO_DIR}/${PG_PREFIX}${INST_DIR}
|
||||||
if [ ! -d ${PG_SRC} ] || [ ! -d ${HOME}/gitwork/${PG_PREFIX}pg-${PGV}-inst ]; then
|
if [ ! -d ${PG_SRC} ] || [ ! -d ${PG_REPO_DIR}/${PG_PREFIX}${INST_DIR} ]; then
|
||||||
echo "Missing source worktree/clone in ${PG_SRC} or ${PG_BASE}"
|
echo "Missing source worktree/clone in ${PG_SRC} or ${PG_BASE}"
|
||||||
echo "git worktree add --track -b <local branch> ../<local dir> origin/<Branch/TAG>\ngit clone ...\n\n"
|
echo "git worktree add --track -b <local branch> ../<local dir> origin/<Branch/TAG>\ngit clone ...\n\n"
|
||||||
echo "git worktree add --track -b ${PG_PREFIX}REL_${PGV}_STABLE ../${PG_PREFIX}pg-${PGV}-src origin/${PG_PREFIX}REL_${PGV}_STABLE"
|
echo "git worktree add --track -b ${PG_PREFIX}REL_${PGV}_STABLE ../${PG_PREFIX}${SRC_DIR} origin/${PG_PREFIX}REL_${PGV}_STABLE"
|
||||||
echo "mkdir -p ${PG_BASE}"
|
echo "mkdir -p ${PG_BASE}"
|
||||||
else
|
else
|
||||||
|
|
||||||
|
@ -41,13 +53,19 @@ else
|
||||||
export PGDATABASE=postgres
|
export PGDATABASE=postgres
|
||||||
export LD_LIBRARY_PATH=${PG_BASE}/lib
|
export LD_LIBRARY_PATH=${PG_BASE}/lib
|
||||||
export PATH=${PG_BIN}:${SAVED_PATH}
|
export PATH=${PG_BIN}:${SAVED_PATH}
|
||||||
if [[ "$PGV" = <-> ]]; then
|
if [[ "$PGV" =~ '^[0-9]+$' ]]; then
|
||||||
export PGPORT=54${PGV}
|
export PGPORT=54${PGV}
|
||||||
else
|
else
|
||||||
export PGPORT=5432
|
export PGPORT=5432
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
distclean() {
|
||||||
|
pushd ${PG_SRC}
|
||||||
|
make distclean
|
||||||
|
popd
|
||||||
|
}
|
||||||
|
|
||||||
compile() {
|
compile() {
|
||||||
pushd ${PG_SRC}
|
pushd ${PG_SRC}
|
||||||
./configure --prefix=${PG_BASE} --enable-debug --with-pgport=${PGPORT} --with-lz4 --with-ssl=openssl --with-python --with-perl --enable-debug --enable-cassert --enable-tap-tests CFLAGS="-ggdb -O0 -g3 -ggdb3 -fno-omit-frame-pointer"
|
./configure --prefix=${PG_BASE} --enable-debug --with-pgport=${PGPORT} --with-lz4 --with-ssl=openssl --with-python --with-perl --enable-debug --enable-cassert --enable-tap-tests CFLAGS="-ggdb -O0 -g3 -ggdb3 -fno-omit-frame-pointer"
|
||||||
|
@ -72,51 +90,67 @@ compile_contrib() {
|
||||||
}
|
}
|
||||||
|
|
||||||
startdb(){
|
startdb(){
|
||||||
pg_ctl stop
|
if [ -z $1 ]; then
|
||||||
|
pg_ctl start
|
||||||
|
else
|
||||||
|
for NodeN in "$@"
|
||||||
|
do
|
||||||
|
pg_ctl start -D ${PGDATA}-${NodeN}
|
||||||
|
done
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
stopdb(){
|
stopdb(){
|
||||||
pg_ctl stop
|
|
||||||
}
|
|
||||||
restartdb(){
|
|
||||||
stopdb
|
|
||||||
startdb
|
|
||||||
}
|
|
||||||
|
|
||||||
rmdb(){
|
|
||||||
rm -rf $PGDATA/*
|
|
||||||
}
|
|
||||||
setupdb(){
|
|
||||||
initdb --data-checksums --username=sharyogi
|
|
||||||
echo "include = '../../pg${PGV}.conf'" >> $PGDATA/postgresql.conf
|
|
||||||
}
|
|
||||||
resetdb() {
|
|
||||||
stopdb
|
|
||||||
rmdb
|
|
||||||
setupdb
|
|
||||||
startdb
|
|
||||||
}
|
|
||||||
|
|
||||||
resetdbN() {
|
|
||||||
if [ -z $1 ]; then
|
if [ -z $1 ]; then
|
||||||
echo "resetdbN <node number>"
|
pg_ctl stop
|
||||||
else
|
else
|
||||||
NodeN=$1
|
for NodeN in "$@"
|
||||||
|
do
|
||||||
pg_ctl stop -D ${PGDATA}-${NodeN}
|
pg_ctl stop -D ${PGDATA}-${NodeN}
|
||||||
rm -rf ${PGDATA}-${NodeN}/*
|
done
|
||||||
initdb --data-checksums --username=sharyogi -D ${PGDATA}-${NodeN}
|
|
||||||
echo "include = '../../pg${PGV}-${NodeN}.conf'" >> ${PGDATA}-${NodeN}/postgresql.conf
|
|
||||||
pg_ctl start -D ${PGDATA}-${NodeN}
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
restartdb(){
|
||||||
|
stopdb "$@"
|
||||||
|
startdb "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
cleandb(){
|
||||||
|
if [ -z $1 ]; then
|
||||||
|
rm -rf $PGDATA/*
|
||||||
|
else
|
||||||
|
for NodeN in "$@"
|
||||||
|
do
|
||||||
|
rm -rf ${PGDATA}-${NodeN}/*
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
setupdb(){
|
||||||
|
if [ -z $1 ]; then
|
||||||
|
initdb --data-checksums --username=sharyogi
|
||||||
|
else
|
||||||
|
for NodeN in "$@"
|
||||||
|
do
|
||||||
|
initdb --data-checksums --username=sharyogi -D ${PGDATA}-${NodeN}
|
||||||
|
echo "include = '../../pg${PGV}-${NodeN}.conf'" >> ${PGDATA}-${NodeN}/postgresql.conf
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
resetdb() {
|
||||||
|
stopdb "$@"
|
||||||
|
cleandb "$@"
|
||||||
|
setupdb "$@"
|
||||||
|
startdb "$@"
|
||||||
|
}
|
||||||
|
|
||||||
resetall() {
|
resetall() {
|
||||||
pg_ctl stop
|
stopdb "$@"
|
||||||
rm -rf $PG_BASE/*
|
rm -rf $PG_BASE/*
|
||||||
pushd ${PG_SRC}
|
distclean
|
||||||
make clean
|
|
||||||
popd
|
|
||||||
compile
|
compile
|
||||||
resetdb
|
compile_contrib
|
||||||
|
resetdb "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
deactivate() {
|
deactivate() {
|
||||||
|
@ -131,15 +165,15 @@ deactivate() {
|
||||||
unset PGDATABASE
|
unset PGDATABASE
|
||||||
unset SAVED_PATH
|
unset SAVED_PATH
|
||||||
unset SAVED_PS1
|
unset SAVED_PS1
|
||||||
|
unset -f distclean
|
||||||
unset -f compile
|
unset -f compile
|
||||||
unset -f compile_contrib
|
unset -f compile_contrib
|
||||||
unset -f startdb
|
unset -f startdb
|
||||||
unset -f stopdb
|
unset -f stopdb
|
||||||
unset -f restartdb
|
unset -f restartdb
|
||||||
unset -f rmdb
|
unset -f cleandb
|
||||||
unset -f setupdb
|
unset -f setupdb
|
||||||
unset -f resetdb
|
unset -f resetdb
|
||||||
unset -f resetdbN
|
|
||||||
unset -f resetall
|
unset -f resetall
|
||||||
unset -f deactivate
|
unset -f deactivate
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue