Listing all databases in an instance of On-Line
Posted in 1995
Topics: Storage & Space Management
The following are shell/awk scripts (provided by Informix) that will list all databases in the current instance of On-Line. We used them to write a program that reports where all space was being used and the unused space in each table of each database. Anyway, here it is, unmodified, from Informix: ###################### Cut here ############################# #!/bin/ksh # # tbdatabases - For the current tbconfig, list all databases in the # OnLine enviornment. IBIN=$INFORMIXDIR/bin tbcheck -pe | awk -f $IBIN/list_dbs.awk | grep -v WARNING | cut -f1 -d' ' ###################### Cut here ############################# # list_dbs.awk - this awk-script expects its input file to be # the output of 'tbstat -pe', which lists every # extent in the OnLine instance (system) # This script culls the information to provide a list of all the # database names in the current OnLine system, as well as the name of # the dbspace it is in. BEGIN { dbpattern = "[A-Za-z][0-9A-Za-z_]*" # Pattern for name of a # database. uname_pattern = dbpattern # Same for user name tabname_pattern = dbpattern # dittos table name # Now compine these as 1 pattern table_pattern = dbpattern ":" uname_pattern "." tabname_pattern k_per_page = 2 # 4 on some systems page_overhead = 28 # So far constant high_dblength = 0 # For seeing the longest table name high_dslength = 0 # For detecting longest dbspace name sort_command = "sort" # for piping the output } $1 == "DBSpace" { # Starts a new DB-space description cur_dbs = $4 # Keep name of current dbspace if (length(cur_dbs) > high_dslength) high_dslength = length(cur_dbs) # Keep length of longest name } $1 ~ table_pattern { # Match complete tabname from tbcheck cur_dbname = grab_dbname($1) # Isolate the database name space_name[cur_dbname] = cur_dbs # Keep track of which dbspace # this table is in. if (length(cur_dbs) > high_dblength) high_dblength = length(cur_dbs) # Keep length of longest name } END { # Finished gathering stats - print it! # First prepare custom format out_format = "%-" high_dblength "s " \\ "%-" high_dslength "s " \\ "\\n" # # Explanation - Format to print out names of tables, dbspaces, # the allocation and fragmentation of each table in the system # # print out_format for (dbn in space_name) # Loop through the associative array { printf (out_format, dbn, space_name[dbn]) | sort_command } } # # grab_dbname() - function to drop the owner and table names from the # pattern: <database>:<owner_name>.<table> # Returns the database name only function grab_dbname(whole_name) { colon_pos = index(whole_name, ":") # Locate the colon dbname = substr(whole_name, 1, colon_pos - 1) # Get database name return (dbname) } -- ------------------------------------------------------------- Jay @ SAC-UNIX, Sacramento, Ca. pacbell!sactoh0!jak jak@sactoh0 If something is worth doing, it's worth doing correctly.