Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion postgres-appliance/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ARG PGVERSION
ARG TIMESCALEDB_APACHE_ONLY=true
ARG TIMESCALEDB_TOOLKIT=true
ARG COMPRESS
ARG PGOLDVERSIONS="14 15 16 17"
ARG PGOLDVERSIONS="12 13 14 15 16 17"
ARG WITH_PERL=false

ARG DEB_PG_SUPPORTED_VERSIONS="$PGOLDVERSIONS $PGVERSION"
Expand Down
8 changes: 6 additions & 2 deletions postgres-appliance/build_scripts/base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ for version in $DEB_PG_SUPPORTED_VERSIONS; do
"postgresql-${version}-decoderbufs"
"postgresql-${version}-pllua"
"postgresql-${version}-pgvector"
"postgresql-${version}-roaringbitmap"
"postgresql-${version}-pgfaceting")
"postgresql-${version}-roaringbitmap")

# pgfaceting only available for PG >= 14
if [ "$version" -ge 14 ]; then
EXTRAS+=("postgresql-${version}-pgfaceting")
fi

if [ "$version" != "18" ]; then
EXTRAS+=("postgresql-${version}-pgl-ddl-deploy"
Expand Down
39 changes: 29 additions & 10 deletions postgres-appliance/scripts/basebackup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash

RETRIES=2
SLOT_NAME=""
KEEP_WAL_FAST=""

while getopts ":-:" optchar; do
[[ "${optchar}" == "-" ]] || continue
Expand All @@ -14,6 +16,12 @@ while getopts ":-:" optchar; do
retries=* )
RETRIES=${OPTARG#*=}
;;
primary_slot_name=* )
SLOT_NAME=${OPTARG#*=}
;;
keep_wal_fast=* )
KEEP_WAL_FAST=${OPTARG#*=}
;;
esac
done

Expand Down Expand Up @@ -59,15 +67,17 @@ function start_receivewal() {
[ -z "$SEGMENT" ] && exit 1

# run pg_receivewal until postgres will not start streaming
(
while ! pgrep -cf 'wal {0,1}receiver( process){0,1}\s+streaming' > /dev/null; do
# exit if pg_receivewal is not running
kill -0 $receivewal_pid && sleep 1 || exit
done

kill $receivewal_pid && sleep 1
rm -f "${WAL_FAST:?}"/*
)&
if [[ $KEEP_WAL_FAST != 1 ]]; then
(
while ! pgrep -cf 'wal {0,1}receiver( process){0,1}\s+streaming' > /dev/null; do
# exit if pg_receivewal is not running
kill -0 $receivewal_pid && sleep 1 || exit
done

kill $receivewal_pid && sleep 1
rm -f "${WAL_FAST:?}"/*
)&
fi

# calculate the name of previous segment
timeline=${SEGMENT:0:8}
Expand All @@ -86,7 +96,12 @@ function start_receivewal() {
# therefore we will "precreate" previous file and pg_receivewal will start fetching the next one
dd if=/dev/zero of="$WAL_FAST/$SEGMENT" bs=16k count=1k

exec $PG_RECEIVEWAL --directory="$WAL_FAST" --dbname="$CONNSTR"
PG_RECEIVEWAL_ARGS=(--directory="$WAL_FAST" --dbname="$CONNSTR")
if [[ -n "$SLOT_NAME" ]]; then
PG_RECEIVEWAL_ARGS+=(--slot="$SLOT_NAME")
fi

exec "$PG_RECEIVEWAL" "${PG_RECEIVEWAL_ARGS[@]}"
}

# make sure that there is only one receivewal running
Expand All @@ -111,6 +126,10 @@ while [[ $((ATTEMPT++)) -le $RETRIES ]]; do
wait $basebackup_pid
EXITCODE=$?
if [[ $EXITCODE == 0 ]]; then
if [[ -n $receivewal_pid && $KEEP_WAL_FAST == 1 ]]; then
kill "$receivewal_pid"
wait "$receivewal_pid" 2>/dev/null || true
fi
break
elif [[ $ATTEMPT -le $RETRIES ]]; then
sleep $((ATTEMPT*10))
Expand Down
4 changes: 2 additions & 2 deletions postgres-appliance/scripts/callback_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
KUBE_TOKEN_FILENAME = KUBE_SERVICE_DIR + 'token'
KUBE_CA_CERT = KUBE_SERVICE_DIR + 'ca.crt'

KUBE_API_URL = 'https://kubernetes.default.svc.cluster.local/api/v1/namespaces'
KUBE_API_URL = os.environ.get('KUBERNETES_SERVICE_HOST', 'https://kubernetes.default.svc.cluster.local') + '/api/v1/namespaces'

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -94,4 +94,4 @@ def main():


if __name__ == '__main__':
main()
main()
12 changes: 11 additions & 1 deletion postgres-appliance/scripts/configure_spilo.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,14 @@ def deep_update(a, b):
{{#STANDBY_WITH_WALG}}
- bootstrap_standby_with_wale
{{/STANDBY_WITH_WALG}}
- basebackup_fast_xlog
- basebackup_fast_xlog_standby
{{#STANDBY_WITH_WALG}}
restore_command: envdir "{{STANDBY_WALG_ENV_DIR}}" timeout "{{WAL_RESTORE_TIMEOUT}}"
/scripts/restore_command.sh "%f" "%p"
{{/STANDBY_WITH_WALG}}
{{^STANDBY_WITH_WALG}}
restore_command: env WAL_FAST_ONLY=true /scripts/restore_command.sh "%f" "%p"
{{/STANDBY_WITH_WALG}}
{{#STANDBY_HOST}}
host: {{STANDBY_HOST}}
{{/STANDBY_HOST}}
Expand Down Expand Up @@ -384,6 +387,13 @@ def deep_update(a, b):
basebackup_fast_xlog:
command: /scripts/basebackup.sh
retries: 2
basebackup_fast_xlog_standby:
command: /scripts/basebackup.sh
retries: 2
keep_wal_fast: 1
{{#STANDBY_PRIMARY_SLOT_NAME}}
primary_slot_name: {{STANDBY_PRIMARY_SLOT_NAME}}
{{/STANDBY_PRIMARY_SLOT_NAME}}
{{#STANDBY_WITH_WALG}}
bootstrap_standby_with_wale:
command: envdir "{{STANDBY_WALG_ENV_DIR}}" bash /scripts/walg_restore.sh
Expand Down
2 changes: 2 additions & 0 deletions postgres-appliance/scripts/restore_command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ readonly wal_fast_source

[[ -f $wal_fast_source ]] && exec mv "${wal_fast_source}" "${wal_destination}"

[[ "$WAL_FAST_ONLY" == "true" ]] && exit 1

if [[ "$wal_destination" =~ /$wal_filename$ ]]; then # Patroni fetching missing files for pg_rewind
export WALG_DOWNLOAD_CONCURRENCY=1
fi
Expand Down