Login Register Actian.com  

Actian Community Wiki

Navigation
Learn About
Developing With
Ingres Talk
Information
Toolbox

Another terminal monitor

From Ingres Community Wiki

Jump to: navigation, search

Updated: Nov 3, 2010


Contents

Short Description

This is not a new idea, just another implementation for the Ingres Terminal Monitor. Since I had some time past winter to look at another databases and see what is good (and bad) about it, I found that some things can be (and should be) done better in Ingres. For example, there is no reason to leave TM session to connect to another database (or at least we will pretend we are in the same session). Or to run accessdb just to check database name, or check user names... Etc etc
I am sure list here can be expended to some reasonable degree of useful things. So, at some point, back in May I spent few hours and came up with simple script which make my life a bit simpler, since I like to do a lot of things by hand (re using TM). Here are things you can do with this approach:


        database_name : to connect to an existing database
        create        : to create a new database and connect to it
        create i      : to create a new unicode database (NFD) and connect
        create n      : to create a new unicode database (NFC) and connect
        delete        : to delete a user database
        backup        : to backup a database
        listdb        : list user databases
        version       : show Ingres version
        user          : show current user
        users         : show existing users
        now           : show current time
        help          : to show this message
        cls           : clear screen
        bye           : to exit Terminal Monitor session


Just save below file into some name (mine is somehow called mytm.bat) and run it as "mytm" or "mytm s"
(for silent SQL mode [no prompt will be shown in TM sessions). If you have any other ideas or comments I would be glad to hear it.

Actual Code

@echo off
REM  -------------------------------------------------------------------------
REM  DATE     NAME                  REMARKS
REM  05/12/10 Eugene Karapetyants   Initial Version
REM
REM  -------------------------------------------------------------------------
REM  Another Ingres Terminal Monitor.
REM  Script allow user to connect to a different databases within one session,
REM  create, delete databases, list user databases in current installation,
REM  display Ingres version, current user, current time and more. 
REM  See HELP label in the code for the list of available options.
REM  Command line can include one flag as "s", to use silent connection
REM  to the database, no prompt will be shown in such case (like "sql -s..." option).
REM
setlocal
cls
set flag1=%1
if "%flag1%" == "s" set opt1=-s

:LOOP1
echo.
set dbname=
set /p dbname="INGRES TERMINAL MONITOR:  "
echo.
if "%dbname%" == "bye"       goto :END
if "%dbname%" == "help"      goto :HELP
if "%dbname%" == "create"    goto :CREATE
if "%dbname%" == "create i"  goto :CREATEI
if "%dbname%" == "create n"  goto :CREATEN
if "%dbname%" == "delete"    goto :DELETE
if "%dbname%" == "backup"    goto :BACKUP
if "%dbname%" == "listdb"    goto :LIST
if "%dbname%" == "now"       goto :NOW
if "%dbname%" == "version"   goto :VERSION
if "%dbname%" == "user"      goto :USER
if "%dbname%" == "users"     goto :USERS
if "%dbname%" == "cls"       goto :CLS
if "%dbname%" == ""          goto :LOOP1
sql %opt1% %dbname% 
goto :LOOP1

:CREATE
echo.
set dbnamec=
set /p dbnamec="CREATE DATABASE:  "
if "%dbnamec%" == "A" echo ABORTING ...&goto :LOOP1
if "%dbnamec%" == "" echo ENTER NAME OR "A" TO ABORT&goto :CREATE
echo.
createdb %dbnamec% 
if errorlevel 0 echo CONNECTING TO %dbnamec% ...
echo.
sql %opt1% %dbnamec%
goto :LOOP1

:CREATEI
echo.
set dbnamec=
set /p dbnamec="CREATE DATABASE:  "
if "%dbnamec%" == "A" echo ABORTING ...&goto :LOOP1
if "%dbnamec%" == "" echo ENTER NAME OR "A" TO ABORT&goto :CREATEI
echo.
createdb -i %dbnamec% 
if errorlevel 0 echo CONNECTING TO %dbnamec% ...
echo.
sql %opt1% %dbnamec%
goto :LOOP1

:CREATEN
echo.
set dbnamec=
set /p dbnamec="CREATE DATABASE:  "
if "%dbnamec%" == "A" echo ABORTING ...&goto :LOOP1
if "%dbnamec%" == "" echo ENTER NAME OR "A" TO ABORT&goto :CREATEN
echo.
createdb -n %dbnamec% 
if errorlevel 0 echo CONNECTING TO %dbnamec% ...
echo.
sql %opt1% %dbnamec%
goto :LOOP1

:DELETE
echo.
set dbnamed=
set /p dbnamed="DELETE DATABASE:  "
if "%dbnamed%" == "A" echo ABORTING ...&goto :LOOP1
if "%dbnamed%" == "" echo ENTER NAME OR "A" TO ABORT&goto :DELETE
:MARK1
SET /P mess1="CONFIRM DELETION OF THE DATABASE %dbnamed% (y/n): "
if "%mess1%" == "y" goto :CONT1
if "%mess1%" == "n" echo ABORTING ...&goto :LOOP1
goto :MARK1
:CONT1
echo.
destroydb %dbnamed% 
goto :LOOP1

:BACKUP
echo.
set dbnameb=
set /p dbnameb="BACKUP DATABASE:  "
if "%dbnameb%" == "A" echo ABORTING ...&goto :LOOP1
if "%dbnameb%" == "" echo ENTER NAME OR "A" TO ABORT&goto :BACKUP
echo.
echo CREATING BACKUP FOR THE DATABASE %dbnameb% (CHECKPOINT) ...
ckpdb %dbnameb% >NUL
echo.
echo BACKUP CREATED SUCCESSFULLY
echo.
goto :LOOP1

:LIST
echo.
echo select name as database, own as owner from iidatabase where own != '$ingres';\g > temp_sql001.sql
sql -s iidbdb < temp_sql001.sql > temp_sql001.out
more +2 temp_sql001.out
del temp_sql001.out
del temp_sql001.sql
echo.
goto :LOOP1

:NOW
echo.
echo select date('now') as current_date_and_time;\g > temp_sql002.sql
sql -s iidbdb < temp_sql002.sql > temp_sql002.out
more +2 temp_sql002.out
del temp_sql002.out
del temp_sql002.sql
echo.
goto :LOOP1

:VERSION
echo.
echo select dbmsinfo('_version') as ingres_version;\g > temp_sql003.sql
sql -s iidbdb < temp_sql003.sql > temp_sql003.out
more +2 temp_sql003.out
del temp_sql003.sql
del temp_sql003.out
echo.
goto :LOOP1

:USER
echo.
echo select username() as current_user;\g > temp_sql004.sql
sql -s iidbdb < temp_sql004.sql > temp_sql004.out
more +2 temp_sql004.out
del temp_sql004.sql
del temp_sql004.out
echo.
goto :LOOP1

:USERS
echo.
echo select user_name from iiusers where user_name not like '$%%';\g > temp_sql005.sql
sql -s iidbdb < temp_sql005.sql > temp_sql005.out
more +2 temp_sql005.out
del temp_sql005.sql
del temp_sql005.out
echo.
goto :LOOP1

:CLS
cls
goto :LOOP1

:HELP
echo.
echo INGRES TERMINAL MONITOR OPTIONS:
echo.
echo          database_name : to connect to an existing database 
echo          create        : to create a new database and connect 
echo          create i      : to create a new unicode database (NFD) and connect
echo          create n      : to create a new unicode database (NFC) and connect
echo          delete        : to delete a user database
echo          backup        : to backup a database
echo          listdb        : list user databases
echo          version       : show Ingres version
echo          user          : show current user
echo          users         : show existing users
echo          now           : show current time
echo          help          : to show this message
echo          cls           : clear screen
echo          bye           : to exit Terminal Monitor session
echo.
goto :LOOP1

:END
echo.
echo INGRES TERMINAL MONITOR:  Connection closed___________________
echo.
endlocal

Some Comments

Above code can be enhanced to provide more functionality, better error checking. It would be nice to have execution time option for queries - if option is selected - execution time is shown once query is finished. Since I have added backup (or checkpoint) option to the script, it would be a good idea to add more maintenance tasks, such usermod as well. Hopefully, I can get some feedback and work more to make this script better and more useful.

Screen shots

Image:mytm001.JPG


Version 2

Another Terminal Monitor, version 2 Updated version, added remote vnode handle.

Version 3

Another Terminal Monitor, version 3 Added more stuff - start/stop, check ingres status, show errlog messages (n last lines) - read all on the page above.

Version 4

I came across small problem on some production systems. If errlog.log has a big size, it might take some time to get few last lines back with command "errlog". By big size I mean anything over ballpark of 10 - 20 MB (which is not that big in reality). So I came up with some solution and modified script, so now it return requested N last lines without any delays. I also made limit of 200 last lines for this function, not sure if anybody needs more to view in TM. I find it useful to check just few last errors. If anybody wants to see actual change/script - let me know and I will post it.

Updated: Nov 3, 2010

Personal tools
© 2011 Actian Corporation. All Rights Reserved