Quantcast
Channel: CodeSection,代码区,数据库(综合) - CodeSec
Viewing all articles
Browse latest Browse all 6262

The rlwrap utility for DBA.

$
0
0

I spend most of my time as a DBA in linux terminal and sqlplus. Everybody who works withoracle sqlplus knows about its power, but also about its limitations. For many years I have used the rlwrap utility developed by Hans Lub. It gives me command history, and the ability to edit my SQL Plus commands, and use auto completion if I set it up. In this post I will share some tips about installation and basic usage.

First we need to install the utility, and there are several options for that. We will check a few of them below. Please keep in mind that all of my examples are tested on Oracle Linux 6.

For the first one we need git, yum and automake packages. We will use the latest and greatest source code from the project site on GitHub: https://github.com/hanslub42/rlwrap and your standard Yum repository. Assuming you have connection to GitHub and your Yum repo.

Let’s run it step-by-step:

[root@sandbox ~]# yum install readline-devel .... [root@sandbox ~]# yum install automake .... [root@sandbox ~]# yum install git .... [root@ovmcloud01 ~]# git clone https://github.com/hanslub42/rlwrap.git Initialized empty Git repository in /root/rlwrap/.git/ remote: Counting objects: 1250, done. remote: Total 1250 (delta 0), reused 0 (delta 0), pack-reused 1250 Receiving objects: 100% (1250/1250), 565.53 KiB, done. Resolving deltas: 100% (867/867), done. [root@ovmcloud01 ~]# cd rlwrap [root@ovmcloud01 rlwrap]# autoreconf --install configure.ac:32: installing `tools/config.guess' configure.ac:32: installing `tools/config.sub' configure.ac:34: installing `tools/install-sh' configure.ac:34: installing `tools/missing' src/Makefile.am: installing `tools/depcomp' [root@ovmcloud01 rlwrap]# automake --add-missing [root@ovmcloud01 rlwrap]# ./configure .... [root@ovmcloud01 rlwrap]# make install ....

That’s it. You have it installed in your system.

The second way is to compile it from source you have downloaded from http://utopia.knoware.nl/~hlub/uck/rlwrap/ . It may be useful if you don’t have connection to Yum and GitHub.

Keep in mind you will need GNU readline and ncurses libraries and headers installed in your system. So, we download the binaries, unpack it, compile and install.

[root@sandbox]$wget http://utopia.knoware.nl/~hlub/uck/rlwrap/rlwrap-0.42.tar.gz .... [root@sandbox]$tar xfz rlwrap-0.42.tar.gz [root@sandbox]$cd rlwrap-0.42 [root@sandbox]$./configure [root@sandbox]$make install

The third way is to copy previously compiled rlwrap execution file and use it on a new system adding it to */bin directory in standard path.

It works if you have several similar, binary compatible systems and don’t want to spend time compiling the same binaries on each one.

[root@sandbox]$cd rlwrap-0.42 [root@sandbox]$ls -l src/rlwrap -rwxr-xr-x. 1 root root 225023 Aug 16 12:49 src/rlwrap [root@sandbox]$cp src/rlwrap /usr/local/bin/ [root@sandbox]$rlwrap --help Usage: rlwrap [options] command ... Options: -a[password prompt] --always-readline[=password prompt] -A --ansi-colour-aware .....

Of course you may consider to make your own rpm or use EPEL (Extra Packages for Enterprise Linux) yum repository and install it from there. Just keep in mind the version you get from EPEL may be slightly outdated.

[root@sandbox]$yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm [root@sandbox]$yum install rlwrap

Having the rlwrap installed you may find use for it.

Here some basic examples how you can use the utility:

Create an alias in your bashrc for sqlplus :

vi ~/.bashrc

and add

alias sqlp='rlwrap sqlplus'

The same you can do for rman :

alias rman='rlwrap rman'

For Oracle GoldenGate command line utility

alias ggsci='rlwrap ./ggsci'

In rlwrap you can use ! and TAB to call list of commands or use prefix and CTRL+R to search for certain command in command history. Also you can create your own dictionary and use it for auto completion.

Let’s try to build some dictionary for auto-completion

I created a file “lsql.lst” with the following contents:

[oracle@sandbox ~]$ vi lsql.lst ~ select from where and update insert delete tablespace v$database .... [oracle@sandbox ~]$alias sqlp="rlwrap -f lsql.lst sqlplus / as sysdba" [oracle@sandbox ~]$ sqlp SQL*Plus: Release 12.1.0.2.0 Production on Wed Aug 17 15:36:04 2016 Copyright (c) 1982, 2014, Oracle. All rights reserved. Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production ............................................. cdb> desc v$t

― here we are pressing TAB and getting list of suggestions:

cdb> desc v$t table tablespace cdb> desc v$tablespace Name Null? Type ----------------------------------------------------------------------------------------------------------------- -------- ---------------------------------------------------------------------------- TS# NUMBER

We can make it even better. Let’s upload name for all dba_views

In our sqlplus session we run :

cdb> spool lsql.lst append cdb> select name from V$FIXED_TABLE; ...... cdb>spool off

logoff and logon again to reload the file and try :

cdb> select * from V$PA -- TAB PARALLEL_DEGREE_LIMIT_MTH PARAMETER PARAMETER2 PARAMETER_VALID_VALUES PATCHES cdb> select * from V$B -- TAB BACKUP BACKUP_CONTROLFILE_SUMMARY BACKUP_DATAFILE_SUMMARY BACKUP_SET BACKUP_SYNC_IO BSP BUFFERED_PUBLISHERS BACKUP_ARCHIVELOG_DETAILS BACKUP_COPY_DETAILS BACKUP_DEVICE BACKUP_SET_DETAILS BGPROCESS BTS_STAT BUFFERED_QUEUES BACKUP_ARCHIVELOG_SUMMARY BACKUP_COPY_SUMMARY BACKUP_NONLOGGED BACKUP_SET_SUMMARY BH BT_SCAN_CACHE BUFFERED_SUBSCRIBERS BACKUP_ASYNC_IO BACKUP_CORRUPTION BACKUP_PIECE BACKUP_SPFILE BLOCKING_QUIESCE BT_SCAN_OBJ_TEMPS BUFFER_POOL BACKUP_COMPRESSION_PROGRESS BACKUP_DATAFILE BACKUP_PIECE_DETAILS BACKUP_SPFILE_DETAILS BLOCK_CHANGE_TRACKING BUFFER BUFFER_POOL_STATISTICS BACKUP_CONTROLFILE_DETAILS BACKUP_DATAFILE_DETAILS BACKUP_REDOLOG BACKUP_SPFILE_SUMMARY BMAPNONDURSUB BUFFER2 cdb> select * from V$B

You can see we have all “V$” views and it can be extremely handy when you don’t really have any time to search for a view name and only vaguely remember that you have a view to look up for certain information.

The rlwrap may not be most sophisticated program but it can make your life much easier. There may be a more advanced tool for sqlplus like SQLcl that provides a lot more options. But―the beauty of rlwrap is in its “lightness” and ability to work not only with sqlplus, but with practically any command line tool.


Viewing all articles
Browse latest Browse all 6262

Latest Images

Trending Articles