This commit is contained in:
Yogesh Sharma 2025-03-17 09:41:36 -04:00
parent 202b89c381
commit 26cb8314f7
Signed by: yogesh.sharma
GPG key ID: 47778BF1D2A81254

140
pg-env
View file

@ -12,11 +12,13 @@
#
create_pgenv() {
cat >../${2}/.pg-env <<EOF
export PGV=${1}
PG_DEV_NAME=${2}
export SKIP_MESON_BUILD=1
EOF
}
commitfest() {
@ -32,18 +34,18 @@ commitfest() {
echo "or"
echo "Usage: $0 commitfest CommitFestID EntryID <PG_RELEASED_BRANCH_NAME>"
fi
if [ ! -f src/include/postgres.h ] || [ ! -d .git ] ; then
if [ ! -f src/include/postgres.h ] || [ ! -d .git ]; then
EXIT_VALUE=1
echo "Run this command from PostgreSQL git checkout"
fi
git remote show -n commitfest > /dev/null
git remote show -n commitfest >/dev/null
if [ $? -ne 0 ]; then
echo "Adding commitfest as remote using https://github.com/postgresql-cfbot/postgresql.git"
git remote add commitfest https://github.com/postgresql-cfbot/postgresql.git
fi
git fetch commitfest ${branch_name}
if [ $# -eq 2 ]; then
IsBranchPresent=$( git worktree list | grep "${branch_name}" )
IsBranchPresent=$(git worktree list | grep "${branch_name}")
#else
# IsBranchPresent=$( git worktree list | grep "${branch_name}_${3}\]" )
fi
@ -80,14 +82,14 @@ branch() {
echo "or"
echo "Usage: $0 branch <Name of new Branch <PG_RELEASED_BRANCH_NAME>"
fi
if [ ! -f src/include/postgres.h ] || [ ! -d .git ] ; then
if [ ! -f src/include/postgres.h ] || [ ! -d .git ]; then
EXIT_VALUE=1
echo "Run this command from PostgreSQL git checkout"
fi
if [ $# -eq 2 ]; then
IsBranchPresent=$( git worktree list | grep '\[${branch_name}\]' )
IsBranchPresent=$(git worktree list | grep '\[${branch_name}\]')
else
IsBranchPresent=$( git worktree list | grep '\[${branch_name}_${2}\]' )
IsBranchPresent=$(git worktree list | grep '\[${branch_name}_${2}\]')
fi
if [ ! -z "${IsBranchPresent}" ]; then
EXIT_VALUE=1
@ -192,23 +194,51 @@ else
fi
fi
distclean() {
distclean() {
resetinst "$@"
pushd ${PG_DEV_SRC}
make clean
make distclean
if [ -z ${MESON_BUILD_PRESENT} ]; then
(cd build; ninja clean)
(
cd build
ninja clean
)
fi
popd
}
}
compile() {
compile() {
pushd ${PG_DEV_SRC}
if [ -z ${MESON_BUILD_PRESENT} ]; then
(time ./configure --prefix=${PG_DEV_INST} --enable-injection-points --enable-debug --with-pgport=${PGPORT} --with-systemd --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 ${PG_ENV_CFLAGS}") |& tee /tmp/pg_compile.log
(
time ./configure \
--prefix=${PG_DEV_INST} \
--enable-injection-points \
--enable-debug \
--with-pgport=${PGPORT} \
--with-systemd --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 ${PG_ENV_CFLAGS}"
) |& tee /tmp/pg_compile.log
else
(time meson setup build --prefix=${PG_DEV_INST} -Dpgport=${PGPORT} -Dlz4=enabled -Dssl=openssl -Dplpython=enabled -Dsystemd -Dplperl=enabled -Ddebug=true -Dcassert=true -Dtap_tests=enabled -Dc_args="-ggdb -O0 -g3 -ggdb3 -fno-omit-frame-pointer ${PG_ENV_CFLAGS}") |& tee /tmp/pg_compile.log
(
time meson setup build \
--prefix=${PG_DEV_INST} \
-Dpgport=${PGPORT} \
-Dlz4=enabled \
-Dssl=openssl \
-Dplpython=enabled \
-Dsystemd \
-Dplperl=enabled \
-Ddebug=true \
-Dcassert=true \
-Dtap_tests=enabled \
-Dc_args="-ggdb -O0 -g3 -ggdb3 -fno-omit-frame-pointer ${PG_ENV_CFLAGS}" \
) |& tee /tmp/pg_compile.log
fi
if [ $? -gt 0 ]; then
if [ -z ${MESON_BUILD_PRESENT} ]; then
@ -218,18 +248,23 @@ compile() {
fi
else
if [ -z ${MESON_BUILD_PRESENT} ]; then
(time make install) |& tee -a /tmp/pg_compile.log
(
time make install \
) |& tee -a /tmp/pg_compile.log
else
(cd build; time ninja -v install) |& tee -a /tmp/pg_compile.log
(
cd build
time ninja -v install
) |& tee -a /tmp/pg_compile.log
fi
if [ $? -gt 0 ]; then
echo "make install failed"
fi
fi
popd
}
}
compile_contrib() {
compile_contrib() {
if [ -z ${MESON_BUILD_PRESENT} ]; then
pushd ${PG_DEV_SRC}/contrib
(time make install) |& tee -a /tmp/pg_compile.log
@ -238,56 +273,52 @@ compile_contrib() {
fi
popd
fi
}
}
startdb(){
startdb() {
if [ -z "$1" ]; then
[ -d "${PGDATA}" ] && pg_ctl start
else
for NodeN in $@
do
for NodeN in $@; do
echo "Starting pg_ctl start -D ${PGDATA}-${NodeN}"
[ -d "${PGDATA}-${NodeN}" ] && pg_ctl start -D ${PGDATA}-${NodeN}
done
fi
}
stopdb(){
}
stopdb() {
if [ -z "$1" ]; then
[ -d "${PGDATA}" ] && pg_ctl stop
else
for NodeN in $@
do
for NodeN in $@; do
[ -d "${PGDATA}-${NodeN}" ] && pg_ctl stop -D ${PGDATA}-${NodeN}
done
fi
}
}
restartdb(){
restartdb() {
stopdb "$@"
startdb "$@"
}
}
cleandb(){
cleandb() {
stopdb "$@"
if [ -z "$1" ]; then
[ -n "$ZSH_VERSION" ] && setopt localoptions rmstarsilent
rm -rf $PGDATA/*
else
for NodeN in $@
do
for NodeN in $@; do
[ -n "$ZSH_VERSION" ] && setopt localoptions rmstarsilent
rm -rf ${PGDATA}-${NodeN}/*
done
fi
}
}
### TODO ###
pexec(){
### TODO ###
pexec() {
args=""
while [ $# -gt 0 ]
do
while [ $# -gt 0 ]; do
case "$1" in
--PEXEC_CMD=*|PEXEC_CMD=*)
--PEXEC_CMD=* | PEXEC_CMD=*)
PEXEC_CMD=${1#*=}
;;
*)
@ -301,56 +332,54 @@ pexec(){
echo psql -U ${USER} ${PEXEC_CMD}
psql -U ${USER} ${PEXEC_CMD}
else
for NodeN in $@
do
for NodeN in $@; do
cmd="psql -U ${USER} -p ${NodeN}${PGPORT} ${PEXEC_CMD}"
echo $cmd
$cmd
done
fi
}
}
setupdb(){
setupdb() {
if [ -z "$1" ]; then
initdb --data-checksums --username=${USER}
echo "include = '${GIT_DIR}/pgconfigs/pg${PGV}.conf'" >> ${PGDATA}/postgresql.conf
echo "include = '${GIT_DIR}/pgconfigs/pg${PGV}.conf'" >>${PGDATA}/postgresql.conf
if [ -f "$(pwd)/.pg${PGV}.conf" ]; then
echo "include = '$(pwd)/.pg${PGV}.conf'" >> ${PGDATA}/postgresql.conf
echo "include = '$(pwd)/.pg${PGV}.conf'" >>${PGDATA}/postgresql.conf
fi
else
for NodeN in $@
do
for NodeN in $@; do
initdb --data-checksums --username=${USER} -D ${PGDATA}-${NodeN}
echo "include = '${GIT_DIR}/pgconfigs/pg${PGV}-${NodeN}.conf'" >> ${PGDATA}-${NodeN}/postgresql.conf
echo "include = '${GIT_DIR}/pgconfigs/pg${PGV}-${NodeN}.conf'" >>${PGDATA}-${NodeN}/postgresql.conf
if [ -f "$(pwd)/.pg${PGV}-${NodeN}.conf" ]; then
echo "include = '$(pwd)/.pg${PGV}-${NodeN}.conf'" >> ${PGDATA}-${NodeN}/postgresql.conf
echo "include = '$(pwd)/.pg${PGV}-${NodeN}.conf'" >>${PGDATA}-${NodeN}/postgresql.conf
fi
done
fi
}
}
resetdb() {
resetdb() {
stopdb "$@"
cleandb "$@"
setupdb "$@"
startdb "$@"
}
}
resetinst() {
resetinst() {
stopdb "$@"
[ -n "$ZSH_VERSION" ] && setopt localoptions rmstarsilent
rm -rf $PG_DEV_INST/*
}
}
resetall() {
resetall() {
distclean
compile
compile_contrib
resetdb "$@"
}
}
deactivate() {
deactivate() {
stopdb
stopdb 1 2 3
export PATH=${SAVED_PATH}
@ -413,9 +442,8 @@ deactivate() {
unset SAVED_PGV
unset PG_DEV_NAME
unset GIT_DIR
}
}
else
echo "Already in pg-env VENV"
fi
fi