Skip to content

Instantly share code, notes, and snippets.

@chunchet-ng
Created April 7, 2026 01:29
Show Gist options
  • Select an option

  • Save chunchet-ng/012fc498dc68fc9157cb0e695057c193 to your computer and use it in GitHub Desktop.

Select an option

Save chunchet-ng/012fc498dc68fc9157cb0e695057c193 to your computer and use it in GitHub Desktop.
Export Azure Postgres Server Parameters
#!/bin/bash
# export_postgres_params.sh
# Usage: ./export_postgres_params.sh <resource-group> <server-name> [output-file]
RESOURCE_GROUP="${1}"
SERVER_NAME="${2}"
OUTPUT_FILE="${3:-${SERVER_NAME}_params_$(date +%Y%m%d_%H%M%S).txt}"
if [[ -z "$RESOURCE_GROUP" || -z "$SERVER_NAME" ]]; then
echo "Usage: $0 <resource-group> <server-name> [output-file]"
exit 1
fi
echo "Fetching parameters for server: $SERVER_NAME (RG: $RESOURCE_GROUP)..."
# Write header
{
echo "======================================================"
echo " PostgreSQL Server Parameters Export"
echo " Server : $SERVER_NAME"
echo " Resource Group: $RESOURCE_GROUP"
echo " Exported at : $(date '+%Y-%m-%d %H:%M:%S %Z')"
echo "======================================================"
echo ""
printf "%-60s %-30s %-15s %s\n" "PARAMETER_NAME" "VALUE" "DATA_TYPE" "SOURCE"
printf "%-60s %-30s %-15s %s\n" "$(printf '%0.s-' {1..60})" "$(printf '%0.s-' {1..30})" "$(printf '%0.s-' {1..15})" "$(printf '%0.s-' {1..15})"
az postgres flexible-server parameter list \
--resource-group "$RESOURCE_GROUP" \
--server-name "$SERVER_NAME" \
--query "sort_by([], &name)" \
--output json \
| jq -r '.[] | [.name, (.value // "null"), (.dataType // "unknown"), (.source // "unknown")] | @tsv' \
| awk -F'\t' '{ printf "%-60s %-30s %-15s %s\n", $1, $2, $3, $4 }'
} > "$OUTPUT_FILE"
echo "Done. Parameters saved to: $OUTPUT_FILE"
echo "Total lines: $(wc -l < "$OUTPUT_FILE")"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment