What is rlwrap?
rlwrap, short for Readline Wrapper, is a utility that provides command history, input editing, and autocomplete features to programs that don’t natively support them. It works by wrapping around your command-line utilities, allowing you to use common features such as the up/down arrow keys to navigate through previously executed commands, text editing capabilities (such as moving the cursor or deleting text), and autocomplete to save time when typing commands.
For Oracle database administrators using tools like SQL*Plus and RMAN on Linux, rlwrap can be a game-changer, bringing much-needed functionality to these otherwise bare-bones utilities.
Benefits of Using rlwrap:
Command History: Navigate through previously run commands using the up and down arrow keys.
Input Editing: Edit your SQL or RMAN commands more easily.
Autocomplete: Use tab completion for table names, SQL keywords, and more.
Consistency: Enjoy a consistent editing experience across different utilities.
How to Install rlwrap
There are two ways to install rlwrap on your Linux system: via the EPEL repository (for RHEL/CentOS-based distributions) or by performing a manual installation.
A.1. Installing rlwrap from EPEL
The easiest way to install rlwrap on your system is by using the EPEL (Extra Packages for Enterprise Linux) repository.
Configure the EPEL repository: First, ensure that EPEL is enabled on your system.
Run command to install the EPEL release package:
sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Install rlwrap: After configuring EPEL,install rlwrap using the yum package manager:
sudo yum install rlwrap
Installation is completed, and you’re ready to start using rlwrap with SQL*Plus and RMAN.
A.2. Manual Installation
Download and install the latest version of rlwrap directly from the GitHub repository.
Download rlwrap from GitHub
After downloading the .tar.gz file, extract it and build the software:
tar -xvf rlwrap*.tar
cd rlwrap*
./configure
make
make check
sudo make install
How to Use rlwrap with SQL*Plus and RMAN
let's look at how to use it with SQL*Plus and RMAN to enhance your command-line experience.
Manual Usage:
To use rlwrap with SQL*Plus and RMAN, simply run the following commands:
For SQL*Plus:
rlwrap sqlplus / as sysdba
For RMAN:
rlwrap rman
Automate with Aliases:
Create aliases in your ~/.bash_profile to automatically invoke rlwrap every time you use SQL*Plus or RMAN. Add the following lines to your .bash_profile:
alias sqlplus='rlwrap sqlplus'
alias rman='rlwrap rman'
After adding these aliases, run source ~/.bash_profile to apply the changes.
Demo: SQL*Plus and RMAN with rlwrap:
Without rlwrap:
Before using rlwrap, if you're logged into SQL*Plus and want to recall a previous command, you’d have to either retype it or deal with the awkward behavior of arrow keys:
SQL> select database_role,open_mode,name from gv$database;
DATABASE_ROLE OPEN_MODE NAME
---------------- -------------------- ---------
PRIMARY READ WRITE PRODDB21
SQL> ^[[A^[[B (pressing the up and down arrow keys results in weird characters)
As shown above, the arrow keys don’t work as expected. It’s difficult to navigate the history of commands.
With rlwrap:
SQL> select database_role,open_mode,name from gv$database;
DATABASE_ROLE OPEN_MODE NAME
---------------- -------------------- ---------
PRIMARY READ WRITE PRODDB21
press the up arrow key to recall previous command:
SQL> select database_role,open_mode,name from gv$database;
DATABASE_ROLE OPEN_MODE NAME
---------------- -------------------- ---------
PRIMARY READ WRITE PRODDB21
Similarly, this feature works seamlessly with RMAN for backup and recovery operations, making it easier to re-run complex RMAN scripts without having to manually type them each time.
No comments:
Post a Comment