This is a small script that tries to establish an exclusive connection to the given database (forcing all existing connections to the database).
|>>--- . dbtuxconnect.sh --- ALIAS ---><|
Sometimes it is necessary to get an exclusive connection to the database. Often there are reconnecting client programs that make it hard to be fast enough. That is where this script will be helpful.
First of all it is important to call this script with the "." or source command, so that is interpreted in the actual shell (therefore the x-attribute of this script is not set). Otherwise the shell calls a subshell, runs the script and returns (this also ends the established connection). In my environment I use the following alias to hide this:
|alias dbtuxconnect.sh=". dbtuxconnect.sh"|
Sample alias definiton
Using dbtuswitch.sh [more] to configure the environment, you don't have to worry about it (the script will create this alias as well).
After calling the script with the database alias (ALIAS) to connect to, you are asked to confirm your choice. Pressing Enter (you can stop the script in any phase by pressing Ctrl+C) starts the process. The script tries to connect in exclusive mode. If the command fails, all connections to the database are collected and forced. Again, the script tries to connect in exclusive mode,... This loop runs until the exclusive connection has been established.