#!/bin/bash
################################################################################
# Copyright (c) 2011-2016 VMware, Inc. All rights reserved.
################################################################################
# Drop a replication slot

ENCODING=UTF8
THIS_DIR=`dirname $0`

# Load global parameters
if [ -z $VMWARE_POSTGRES_BASE ]; then
   echo "VMWARE_POSTGRES_BASE is not set."
   echo "Check your installation."
   exit 1
fi
SANITY_FILE=$VMWARE_POSTGRES_BASE/scripts/vpostgres_sanity_checks
if [ -f $SANITY_FILE ]; then
   source $SANITY_FILE
else
   echo "Sanity check file for environment variables of VMware Postgres"
   echo "is not available. Check your installation."
   exit 1
fi

SLOT_NAME=$1
if [ -z "$SLOT_NAME" ]; then
   echo "Usage: $0 <slot_name>"
   exit 1
fi

# Now drop the slot
$VMWARE_POSTGRES_BASE/psql -c "SELECT pg_drop_replication_slot('$SLOT_NAME');"
exit $?
