openGauss-server/contrib/pgxc_ctl/pgxc_ctl_bash.org

36 KiB
Raw Permalink Blame History

#!/bin/bash #

#

#

# # #========================================================================================================================== #

#

#

# #================================================================

#

#=============================================================== # # #—- Home dir of pgxc_ctl pgxc_ctl_home=$HOME/.pgxc_ctl #---- Configuration File pgxcInstallDir=$HOME/pgxc configFile=$pgxcInstallDir/pgxcConf #—- OVERALL ———————————————————————————————————– # pgxcOwner=pgxc # owner of the Postgres-XC database cluster. Here, we use this

pgxcUser=$pgxcOwner # OS user of Postgres-XC owner

tmpDir=/tmp # temporary dir used in XC servers localTmpDir=$tmpDir # temporary dir used here locally

logOpt=y # If you want log logDir=$pgxc_ctl_home/pgxc_ctl_log # Directory to write pgxc_ctl logs

configBackup=y # If you want config file backup configBackupHost=pgxc-linker # host to backup config file configBackupDir=$pgxcInstallDir configBackupFile=`basename $configFile` # Backup file name > Need to synchronize when original changed.

#—- GTM ————————————————————————————————————–

#—- Overall ——- gtmName=gtm

#—- GTM Master ———————————————–

#—- Overall —- gtmMasterServer=node13 gtmMasterPort=20001 gtmMasterDir=$HOME/pgxc/nodes/gtm

#—- Configuration — gtmExtraConfig=none # Will be added gtm.conf for both Master and Slave (done at initilization only) gtmMasterSpecificExtraConfig=none # Will be added to Master's gtm.conf (done at initialization only)

#—- GTM Slave ———————————————–

#—- Overall —— gtmSlave=y # Specify y if you configure GTM Slave. Otherwise, GTM slave will not be configured and

gtmSlaveServer=node12 # value none means GTM slave is not available. Give none if you don't configure GTM Slave. gtmSlavePort=20001 # Not used if you don't configure GTM slave. gtmSlaveDir=$HOME/pgxc/nodes/gtm # Not used if you don't configure GTM slave.

#—- Configuration —- gtmSlaveSpecificExtraConfig=none # Will be added to Slave's gtm.conf (done at initialization only)

#—- GTM Proxy ——————————————————————————————————-

#

#

#—- Shortcuts —— gtmProxyDir=$HOME/pgxc/nodes/gtm_pxy

#—- Overall ——- gtmProxy=y # Specify y if you conifugre at least one GTM proxy. You may not configure gtm proxies

gtmProxyNames=(gtm_pxy1 gtm_pxy2 gtm_pxy3 gtm_pxy4) # No used if it is not configured gtmProxyServers=(node06 node07 node08 node09) # Specify none if you dont' configure it. gtmProxyPorts=(20001 20001 20001 20001) # Not used if it is not configured. gtmProxyDirs=($gtmProxyDir $gtmProxyDir $gtmProxyDir $gtmProxyDir) # Not used if it is not configured.

#—- Configuration —- gtmPxyExtraConfig=none # Extra configuration parameter for gtm_proxy gtmPxySpecificExtraConfig=(none none none none)

#—- Coordinators —————————————————————————————————-

#—- shortcuts ———- coordMasterDir=$HOME/pgxc/nodes/coord coordSlaveDir=$HOME/pgxc/nodes/coord_slave coordArchLogDir=$HOME/pgxc/nodes/coord_archlog

#—- Overall ———— coordNames=(coord1 coord2 coord3 coord4) # Master and slave use the same name coordPorts=(20004 20005 20004 20005) # Master and slave use the same port poolerPorts=(20010 20011 20010 20011) # Master and slave use the same pooler port coordPgHbaEntries=(192.168.1.0/24) # Assumes that all the coordinator (master/slave) accepts

#—- Master ————- coordMasterServers=(node06 node07 node08 node09) # none means this master is not available coordMasterDirs=($coordMasterDir $coordMasterDir $coordMasterDir $coordMasterDir) coordMaxWALsernder=5 # max_wal_senders: needed to configure slave. If zero value is specified,

coordMaxWALSenders=($coordMaxWALsernder $coordMaxWALsernder $coordMaxWALsernder $coordMaxWALsernder)

#—- Slave ————- coordSlave=y # Specify y if you configure at least one coordiantor slave. Otherwise, the following

coordSlaveSync=y # Specify to connect with synchronized mode. coordSlaveServers=(node07 node08 node09 node06) # none means this slave is not available coordSlaveDirs=($coordSlaveDir $coordSlaveDir $coordSlaveDir $coordSlaveDir) coordArchLogDirs=($coordArchLogDir $coordArchLogDir $coordArchLogDir $coordArchLogDir)

#—- Configuration files—

coordExtraConfig=none # Extra configuration file for coordinators. This file will be added to all the coordinators'

coordSpecificExraConfig=(none none none none) coordExtraPgHba=none # Extra entry for pg_hba.conf. This file will be added to all the coordinators' pg_hba.conf coordSpecificExtraPgHba=(none none none none)

#—– Additional Slaves —– coordAdditionalSlaves=n # Additional slave can be specified as follows: where you coordAdditionalSlaveSet=(cad1) # Each specifies set of slaves. This case, two set of slaves are

cad1_Sync=n # All the slaves at "cad1" are connected with asynchronous mode.

cad1_Servers=(node08 node09 node06 node07) # Hosts cad1_dir=$HOME/pgxc/nodes/coord_slave_cad1 cad1_Dirs=($cad1_dir $cad1_dir $cad1_dir $cad1_dir) cad1_ArchLogDir=$HOME/pgxc/nodes/coord_archlog_cad1 cad1_ArchLogDirs=($cad1_ArchLogDir $cad1_ArchLogDir $cad1_ArchLogDir $cad1_ArchLogDir)

#—- Datanodes ——————————————————————————————————-

#—- Shortcuts ————– datanodeMasterDir=$HOME/pgxc/nodes/dn_master datanodeSlaveDir=$HOME/pgxc/nodes/dn_slave datanodeArchLogDir=$HOME/pgxc/nodes/datanode_archlog

#—- Overall ————— #primaryDatanode=datanode1 # Primary Node.

primaryDatanode=datanode1 # Primary Node. datanodeNames=(datanode1 datanode2 datanode3 datanode4) datanodePorts=(20008 20009 20008 20009) # Master and slave use the same port! datanodePgHbaEntries=(192.168.1.0/24) # Assumes that all the coordinator (master/slave) accepts

#—- Master —————- datanodeMasterServers=(node06 node07 node08 node09) # none means this master is not available.

datanodeMasterDirs=($datanodeMasterDir $datanodeMasterDir $datanodeMasterDir $datanodeMasterDir) datanodeMaxWalSender=5 # max_wal_senders: needed to configure slave. If zero value is

datanodeMaxWalSenders=($datanodeMaxWalSender $datanodeMaxWalSender $datanodeMaxWalSender $datanodeMaxWalSender)

#—- Slave —————– datanodeSlave=y # Specify y if you configure at least one coordiantor slave. Otherwise, the following

datanodeSlaveServers=(node07 node08 node09 node06) # value none means this slave is not available datanodeSlaveDirs=($datanodeSlaveDir $datanodeSlaveDir $datanodeSlaveDir $datanodeSlaveDir) datanodeArchLogDirs=( $datanodeArchLogDir $datanodeArchLogDir $datanodeArchLogDir $datanodeArchLogDir )

datanodeExtraConfig=none # Extra configuration file for datanodes. This file will be added to all the

datanodeSpecificExtraConfig=(none none none none) datanodeExtraPgHba=none # Extra entry for pg_hba.conf. This file will be added to all the datanodes' postgresql.conf datanodeSpecificExtraPgHba=(none none none none)

#—– Additional Slaves —– datanodeAdditionalSlaves=n # Additional slave can be specified as follows: where you

#—- WAL archives ————————————————————————————————- walArchive=n # If you'd like to configure WAL archive, edit this section.

walArchiveSet=(war1 war2) war1_source=(master) # you can specify master, slave or ano other additional slaves as a source of WAL archive.

wal1_source=(slave) wal1_source=(additiona_coordinator_slave_set additional_datanode_slave_set) war1_host=node10 # All the nodes are backed up at the same host for a given archive set war1_backupdir=$HOME/pgxc/backup_war1 wal2_source=(master) war2_host=node11 war2_backupdir=$HOME/pgxc/backup_war2 #

# #==========================================================================================================================

xc_prompt='PGXC$ ' interactive=n verbose=n progname=$0 bin=pgxc_ctl # Just in case. Never touch this logfile=none

#

# function create_config_file_template { cat > $configFile <<EOF #!/bin/bash #

#

#

# # #========================================================================================================================== #

#

#

# #================================================================

#

#=============================================================== # # #—- Home dir of pgxc_ctl pgxc_ctl_home=$HOME/.pgxc_ctl #---- Configuration File pgxcInstallDir=$HOME/pgxc configFile=$pgxcInstallDir/pgxcConf #—- OVERALL ———————————————————————————————————– # pgxcOwner=pgxc # owner of the Postgres-XC database cluster. Here, we use this

pgxcUser=$pgxcOwner # OS user of Postgres-XC owner

tmpDir=/tmp # temporary dir used in XC servers localTmpDir=$tmpDir # temporary dir used here locally

logOpt=y # If you want log logDir=$pgxc_ctl_home/pgxc_ctl_log # Directory to write pgxc_ctl logs

configBackup=y # If you want config file backup configBackupHost=pgxc-linker # host to backup config file configBackupDir=$pgxcInstallDir configBackupFile=`basename $configFile` # Backup file name > Need to synchronize when original changed.

#—- GTM ————————————————————————————————————–

#—- Overall ——- gtmName=gtm

#—- GTM Master ———————————————–

#—- Overall —- gtmMasterServer=node13 gtmMasterPort=20001 gtmMasterDir=$HOME/pgxc/nodes/gtm

#—- Configuration — gtmExtraConfig=none # Will be added gtm.conf for both Master and Slave (done at initilization only) gtmMasterSpecificExtraConfig=none # Will be added to Master's gtm.conf (done at initialization only)

#—- GTM Slave ———————————————–

#—- Overall —— gtmSlave=y # Specify y if you configure GTM Slave. Otherwise, GTM slave will not be configured and

gtmSlaveServer=node12 # value none means GTM slave is not available. Give none if you don't configure GTM Slave. gtmSlavePort=20001 # Not used if you don't configure GTM slave. gtmSlaveDir=$HOME/pgxc/nodes/gtm # Not used if you don't configure GTM slave.

#—- Configuration —- gtmSlaveSpecificExtraConfig=none # Will be added to Slave's gtm.conf (done at initialization only)

#—- GTM Proxy ——————————————————————————————————-

#

#

#—- Shortcuts —— gtmProxyDir=$HOME/pgxc/nodes/gtm_pxy

#—- Overall ——- gtmProxy=y # Specify y if you conifugre at least one GTM proxy. You may not configure gtm proxies

gtmProxyNames=(gtm_pxy1 gtm_pxy2 gtm_pxy3 gtm_pxy4) # No used if it is not configured gtmProxyServers=(node06 node07 node08 node09) # Specify none if you dont' configure it. gtmProxyPorts=(20001 20001 20001 20001) # Not used if it is not configured. gtmProxyDirs=($gtmProxyDir $gtmProxyDir $gtmProxyDir $gtmProxyDir) # Not used if it is not configured.

#—- Configuration —- gtmPxyExtraConfig=none # Extra configuration parameter for gtm_proxy gtmPxySpecificExtraConfig=(none none none none)

#—- Coordinators —————————————————————————————————-

#—- shortcuts ———- coordMasterDir=$HOME/pgxc/nodes/coord coordSlaveDir=$HOME/pgxc/nodes/coord_slave coordArchLogDir=$HOME/pgxc/nodes/coord_archlog

#—- Overall ———— coordNames=(coord1 coord2 coord3 coord4) # Master and slave use the same name coordPorts=(20004 20005 20004 20005) # Master and slave use the same port poolerPorts=(20010 20011 20010 20011) # Master and slave use the same pooler port coordPgHbaEntries=(192.168.1.0/24) # Assumes that all the coordinator (master/slave) accepts

#—- Master ————- coordMasterServers=(node06 node07 node08 node09) # none means this master is not available coordMasterDirs=($coordMasterDir $coordMasterDir $coordMasterDir $coordMasterDir) coordMaxWALsernder=5 # max_wal_senders: needed to configure slave. If zero value is specified,

coordMaxWALSenders=($coordMaxWALsernder $coordMaxWALsernder $coordMaxWALsernder $coordMaxWALsernder)

#—- Slave ————- coordSlave=y # Specify y if you configure at least one coordiantor slave. Otherwise, the following

coordSlaveSync=y # Specify to connect with synchronized mode. coordSlaveServers=(node07 node08 node09 node06) # none means this slave is not available coordSlaveDirs=($coordSlaveDir $coordSlaveDir $coordSlaveDir $coordSlaveDir) coordArchLogDirs=($coordArchLogDir $coordArchLogDir $coordArchLogDir $coordArchLogDir)

#—- Configuration files—

coordExtraConfig=none # Extra configuration file for coordinators. This file will be added to all the coordinators'

coordSpecificExraConfig=(none none none none) coordExtraPgHba=none # Extra entry for pg_hba.conf. This file will be added to all the coordinators' pg_hba.conf coordSpecificExtraPgHba=(none none none none)

#—– Additional Slaves —– coordAdditionalSlaveSet=n # Additional slave can be specified as follows: where you

#—- Datanodes ——————————————————————————————————-

#—- Shortcuts ————– datanodeMasterDir=$HOME/pgxc/nodes/dn_master datanodeSlaveDir=$HOME/pgxc/nodes/dn_slave datanodeArchLogDir=$HOME/pgxc/nodes/datanode_archlog

#—- Overall ————— #primaryDatanode=datanode1 # Primary Node.

primaryDatanode=datanode1 # Primary Node. datanodeNames=(datanode1 datanode2 datanode3 datanode4) datanodePorts=(20008 20009 20008 20009) # Master and slave use the same port! datanodePgHbaEntries=(192.168.1.0/24) # Assumes that all the coordinator (master/slave) accepts

#—- Master —————- datanodeMasterServers=(node06 node07 node08 node09) # none means this master is not available.

datanodeMasterDirs=($datanodeMasterDir $datanodeMasterDir $datanodeMasterDir $datanodeMasterDir) datanodeMaxWalSender=5 # max_wal_senders: needed to configure slave. If zero value is

datanodeMaxWalSenders=($datanodeMaxWalSender $datanodeMaxWalSender $datanodeMaxWalSender $datanodeMaxWalSender)

#—- Slave —————– datanodeSlave=y # Specify y if you configure at least one coordiantor slave. Otherwise, the following

datanodeSlaveServers=(node07 node08 node09 node06) # value none means this slave is not available datanodeSlaveDirs=($datanodeSlaveDir $datanodeSlaveDir $datanodeSlaveDir $datanodeSlaveDir) datanodeArchLogDirs=( $datanodeArchLogDir $datanodeArchLogDir $datanodeArchLogDir $datanodeArchLogDir )

datanodeExtraConfig=none # Extra configuration file for datanodes. This file will be added to all the

datanodeSpecificExtraConfig=(none none none none) datanodeExtraPgHba=none # Extra entry for pg_hba.conf. This file will be added to all the datanodes' postgresql.conf datanodeSpecificExtraPgHba=(none none none none)

#—– Additional Slaves —– datanodeAdditionalSlaveSet=n # Additional slave can be specified as follows: where you

#—- WAL archives ————————————————————————————————- walArchive=n # If you'd like to configure WAL archive, edit this section.

walArchiveSet=(war1 war2) war1_source=master # you can specify master, slave or ano other additional slaves as a source of WAL archive.

wal1_source=slave wal1_source=(additiona_coordinator_slave_set additional_datanode_slave_set) war1_host=node10 # All the nodes are backed up at the same host for a given archive set war1_backupdir=$HOME/pgxc/backup_war1 wal2_source=master war2_host=node11 war2_backupdir=$HOME/pgxc/backup_war2 #

# #========================================================================================================================== EOF chmod +x $configFile }

#=========================================================== #

# #===========================================================

function print_array { echo -n $1 " " eval echo '$'{$1[@]} }

function print_values { local i declare -i i local el

echo pgxc_ctl_home $pgxc_ctl_home echo pgxcInstallDir $pgxcInstallDir echo configFile $configFile

echo pgxcOwner $pgxcOwner echo pgxcUser $pgxcUser echo tmpDir $tmpDir echo localTmpDir $localTmpDir echo logOpt $logOpt echo logDir $logDir echo configBackup $configBackup echo configBackupHost $configBackupHost echo configBackupDir $configBackupDir echo configBackupFile $configBackupFile

echo gtmName $gtmName

echo gtmMasterServer $gtmMasterServer echo gtmMasterPort $gtmMasterPort echo gtmMasterDir $gtmMasterDir echo gtmExtraConfig $gtmExtraConfig echo gtmMasterSpecificExtraConfig $gtmMasterSpecificExtraConfig

echo gtmSlave $gtmSlave echo gtmSlaveServer $gtmSlaveServer echo gtmSlavePort $gtmSlavePort echo gtmSlaveDir $gtmSlaveDir echo gtmSlaveSpecificExtraConfig $gtmSlaveSpecificExtraConfig

echo gtmProxy $gtmProxy print_array gtmProxyNames print_array gtmProxyServers print_array gtmProxyPorts print_array gtmProxyDirs echo gtmPxyExtraConfig $gtmPxyExtraConfig print_array gtmPxySpecificExtraConfig

print_array coordNames print_array coordPorts print_array poolerPorts print_array coordPgHbaEntries

print_array coordMasterServers print_array coordMasterDirs print_array coordMaxWALSenders

echo coordSlave $coordSlave echo coordSlaveSync $coordSlaveSync print_array coordSlaveDirs print_array coordArchLogDirs

echo coordExtraConfig $coordExtraConfig print_array coordSpecificExraConfig echo coordExtraPgHba $coordExtraPgHba print_array coordSpecificExtraPgHba

echo coordAdditionalSlaves $coordAdditionalSlaves if [ $coordAdditionalSlaves == "y" ]; then print_array coordAdditionalSlaveSet for ((i=0; i<${#coordAdditionalSlaveSet[@]}; i++)); do el=${coordAdditionalSlaveSet[$i]} echo -n ${el}_Sync " " eval echo '$'"$el"_Sync print_array ${el}_Servers print_array ${el}_Dirs print_array ${el}_ArchLogDirs done fi

echo primaryDatanode $primaryDatanode print_array datanodeNames print_array datanodePorts print_array datanodePgHbaEntries

print_array datanodeMasterServers print_array datanodeMasterDirs print_array datanodeMaxWalSenders

echo datanodeSlave $datanodeSlave print_array datanodeSlaveServers print_array datanodeSlaveDirs print_array datanodeArchLogDirs

echo datanodeExtraConfig $datanodeExtraConfig print_array datanodeSpecificExtraConfig echo datanodeExtraPgHba $datanodeExtraPgHba print_array datanodeSpecificExtraPgHba

echo datanodeAdditionalSlaves $datanodeAdditionalSlaves if [ $datanodeAdditionalSlaves == "y" ]; then print_array datanodeAdditionalSlaveSet for ((i=0; i<${#datanodeAdditionalSlaveSet[@]}; i++)); do el=${datanodeAdditionalSlaveSet[$i]} echo -n ${el}_Sync " " eval echo '$'"$el"_Sync print_array ${el}_Servers print_array ${el}_Dirs print_array ${el}_ArchLogDirs done fi

echo walArchive $walArchive print_array walArchiveSet if [ $walArchive == "y" ]; then for ((i=0; i<${#walArchvieSet[@]}; i++)); do print_array ${el}_source echo -n ${el}_host eval echo '$'"$el"_host echo -n ${el}_backupdir eval echo '$'"$el"_backupdir done fi

echo xc_prompt $xc_prompt echo verbose $verbose echo bin $bin }

#============================================================ #

# #============================================================

function set_home { if [ $# > 1 ]; then echo "Invalid set_home function call" return 1 fi if [ $# == 1 ]; then if [ -d $1 ]; then pgxc_ctl_home=$1 else eecho "set_home: $1 is not a directory." return 1 fi elif [ $PGXC_CTL_HOME != "" ]; then if [ -d $PGXC_CTL_HOME ]; then pgxc_ctl_home=$PGXC_CTL_HOME else eecho "set_home: env PGXC_CTL_HOME($PGXC_CTL_HOME) is not a directory." return 1; fi fi cd $pgxc_ctl_home; }

############################################################################### #

# ###############################################################################

#=======================================================

#=======================================================

progname=$0 moretodo=y cmd_with_log=null #set_home if [ -f $pgxc_ctl_home/.pgxc_ctl_rc ]; then source $pgxc_ctl_home/.pgxc_ctl_rc fi

while [ $moretodo == y ]; do if [ $# -gt 0 ]; then case $1 in -v ) shift; verbose=y; continue;; --verbose ) shift; verbose=y; continue;; --silent ) verbose=n; continue;; -d ) # debug option shift; DEBUG=y; continue;; --debug ) shift; DEBUG=y; continue;; -c ) # Configuraton file shift; if [ $# -le 0 ]; then echo ERROR: no -c option value found exit 1 else configFile=$1 shift fi; continue;; --configuration ) # Configuraion file shift; if [ $# -le 0 ]; then echo ERROR: no configuration option value found exit 1 else configFile=$1 shift fi; continue;; --home ) # PGXC_CTL_HOME shift; if [ $# -le 0 ]; then echo ERROR: no pgxc_ctl_home specified exit 1 else pgxc_ctl_home=$1 cd $pgxc_ctl_home shift fi; continue;;

  • ) moretodo=n continue;;

esac else moretodo=n fi done

if [ -f $configFile ]; then source $configFile fi

print_values