1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
#!/usr/bin/perl
#
# This script creates data and index tablespaces for a single VO.
#
# Author: James Casey <james.casey@cern.ch>
#
# 2004/12/14 : Changes made for the LCG File Catalog (LFC) by Sophie Lemaitre <Sophie.Lemaitre@cern,ch>
#
use strict;
use warnings;
use Getopt::Long;
use Env qw(ORACLE_SID ORACLE_HOME);
#
# forwards
#
sub configuration();
sub usage($);
#
# check env variables
#
die "ORACLE_HOME environment variable not defined."
if !defined($ORACLE_HOME);
die "ORACLE_SID environment variable not defined."
if !defined($ORACLE_SID);
die "Could not find sqlplus binary at $ORACLE_HOME/bin/sqlplus"
if ! -x "$ORACLE_HOME/bin/sqlplus";
#
# Configuration constants. These can be changed on the command line if
# required
#
# Location of the data partition. Files will be placed in the directory
# $dbDatadir/$ORACLE_SID
my $dbDatadir="/ORA/dbs03/oradata";
# initial size of the tablespace file
my $initSize ="128M";
# increment interval when tablespace is increased
my $incrSize="100M";
# maximum size of the tablespace
my $maxSize="20000M";
my $name;
my $verbose=0;
GetOptions("name=s" => \$name,
"v" => \$verbose,
"datadir=s" => \$dbDatadir,
"init-size=s" => \$initSize,
"incr-size=s" => \$incrSize,
"max-size=s" => \$maxSize);
usage("No user name Specified") if !$name;
# capitalize
$name =~ tr/a-z/A-Z/;
# prefix the name with "LFC_"
$name="LFC_${name}";
my $prefix="${dbDatadir}/${ORACLE_SID}/${name}";
my $logFile="/tmp/create-tablespaces.$$.log";
configuration() if $verbose;
print "Running SQLPLUS...\n" if $verbose;
# start sqlplus
open(SQLPLUS, "| $ORACLE_HOME/bin/sqlplus \"/ as sysdba\" > /dev/null")
or die("can't start SQLPLUS");
print SQLPLUS <<EOF;
-- setup error handling and logging
--
WHENEVER OSERROR EXIT FAILURE ROLLBACK
-- WHENEVER SQLERROR EXIT SQL.SQLCODE ROLLBACK
spool $logFile
-- -----------------------------------------
-- Creating tablespaces for ${name}
-- -----------------------------------------
-- DATA
CREATE TABLESPACE "${name}_DATA"
DATAFILE '${prefix}_DATA_01.dbf' SIZE $initSize AUTOEXTEND ON NEXT $incrSize
MAXSIZE $maxSize EXTENT MANAGEMENT LOCAL
SEGMENT SPACE MANAGEMENT AUTO;
-- INDEX
CREATE TABLESPACE "${name}_IDX"
DATAFILE '${prefix}_IDX_01.dbf' SIZE $initSize AUTOEXTEND ON NEXT $incrSize
MAXSIZE $maxSize EXTENT MANAGEMENT LOCAL
SEGMENT SPACE MANAGEMENT AUTO;
EOF
close SQLPLUS;
if($? != 0 ) {
die "Error while running sqlplus : see $logFile for more details";
}
unlink $logFile;
print "Done.\n" if $verbose;
exit;
#################################################################
# end of script
#################################################################
sub usage($) {
my $error = shift @_;
print <<EOF and die "Wrong usage of the script : $error\n";
usage : $0 --vo VO [--datadir dir] [--v]
Options
--name name The LFC database user will be called "LFC_<NAME>"
--datadir dir The name of the oracle data directory to use.
Defaults to "/ORA/dbs03/oradata"
--init-size size Initial tablespace size. Defaults to $initSize
--init-size size Tablespace increment size. Defaults to $incrSize
--max-size size Maximum tablespace size. Defaults to $maxSize
--v verbose mode
EOF
}
sub configuration() {
print <<EOF;
Configuration :
ORACLE_HOME : $ORACLE_HOME
ORACLE_SID : $ORACLE_SID
DB Data Dir : $dbDatadir
Name : $name
EOF
}
|