mercoledì 21 marzo 2012

Oracle impdb, expdb

In queste ultime settimane mi sono trovato a lavorare con import e export di DB Oracle 11g.
Ho quindi preso confidenza con le utility di impdp e expdp.
Per maggiori dettagli consiglio di visitare questa pagina: Oracle Data Pump 10g


Creare la directory


per effettuare import/export su una directory specifica è necessario definire la directory all'interno del DB:

CREATE OR REPLACE DIRECTORY test_dir AS '/u01/app/oracle/oradata/';
GRANT READ, WRITE ON DIRECTORY test_dir TO scott;
Le directory così create sono visibili all'interno della vista ALL_DIRECTORIES.
Per far si che le operazioni su questa directory funzionino questa deve appartenere all'utente oracle.

Esempi di import/export

Table Exports/Imports

expdp scott/tiger@db10g tables=EMP,DEPT directory=TEST_DIR dumpfile=EMP_DEPT.dmp logfile=expdpEMP_DEPT.log

impdp scott/tiger@db10g tables=EMP,DEPT directory=TEST_DIR dumpfile=EMP_DEPT.dmp logfile=impdpEMP_DEPT.log
Schema Exports/Imports
expdp scott/tiger@db10g schemas=SCOTT directory=TEST_DIR dumpfile=SCOTT.dmp logfile=expdpSCOTT.log

impdp scott/tiger@db10g schemas=SCOTT directory=TEST_DIR dumpfile=SCOTT.dmp logfile=impdpSCOTT.log
Database Exports/Imports
expdp system/password@db10g full=Y directory=TEST_DIR dumpfile=DB10G.dmp logfile=expdpDB10G.log

impdp system/password@db10g full=Y directory=TEST_DIR dumpfile=DB10G.dmp logfile=impdpDB10G.log

Oracle Privileges

Combattendo con i privilegi di oracle 11g mi sono imbattuto in questa pagina: Recursively_list_privilege il cui contenuto riporto per futura memoria:


Users to roles and system privileges

This is a script that shows the hierarchical relationship between system privileges, roles and users.
select
  lpad(' ', 2*level) || granted_role "User, his roles and privileges"
from
  (
  /* THE USERS */
    select 
      null     grantee, 
      username granted_role
    from 
      dba_users
    where
      username like upper('%&enter_username%')
  /* THE ROLES TO ROLES RELATIONS */ 
  union
    select 
      grantee,
      granted_role
    from
      dba_role_privs
  /* THE ROLES TO PRIVILEGE RELATIONS */ 
  union
    select
      grantee,
      privilege
    from
      dba_sys_privs
  )
start with grantee is null
connect by grantee = prior granted_role;

System privileges to roles and users

This is also possible the other way round: showing the system privileges in relation to roles that have been granted this privilege and users that have been granted either this privilege or a role:
select
  lpad(' ', 2*level) || c "Privilege, Roles and Users"
from
  (
  /* THE PRIVILEGES */
    select 
      null   p, 
      name   c
    from 
      system_privilege_map
    where
      name like upper('%&enter_privliege%')
  /* THE ROLES TO ROLES RELATIONS */ 
  union
    select 
      granted_role  p,
      grantee       c
    from
      dba_role_privs
  /* THE ROLES TO PRIVILEGE RELATIONS */ 
  union
    select
      privilege     p,
      grantee       c
    from
      dba_sys_privs
  )
start with p is null
connect by p = prior c;

Object privileges

select
  case when level = 1 then own || '.' || obj || ' (' || typ || ')' else
  lpad (' ', 2*(level-1)) || obj || nvl2 (typ, ' (' || typ || ')', null)
  end
from
  (
  /* THE OBJECTS */
    select 
      null          p1, 
      null          p2,
      object_name   obj,
      owner         own,
      object_type   typ
    from 
      dba_objects
    where
       owner not in 
        ('SYS', 'SYSTEM', 'WMSYS', 'SYSMAN','MDSYS','ORDSYS','XDB', 'WKSYS', 'EXFSYS', 
         'OLAPSYS', 'DBSNMP', 'DMSYS','CTXSYS','WK_TEST', 'ORDPLUGINS', 'OUTLN')
      and object_type not in ('SYNONYM', 'INDEX')
  /* THE OBJECT TO PRIVILEGE RELATIONS */ 
  union
    select
      table_name p1,
      owner      p2,
      grantee,
      grantee,
      privilege
    from
      dba_tab_privs
  /* THE ROLES TO ROLES/USERS RELATIONS */ 
  union
    select 
      granted_role  p1,
      granted_role  p2,
      grantee,
      grantee,
      null
    from
      dba_role_privs
  )
start with p1 is null and p2 is null
connect by p1 = prior obj and p2 = prior own;

martedì 20 marzo 2012

Unix IF

Non mi capita molto spesso di scrivere script di shell, ma ogni volta mi capita di litigare con l'if di cui non ricordo mai la sintassi.
Questa volta ho trovato aiuto in questa pagina http://www.dreamsyssoft.com/sp_ifelse.jsp e ne riporto in parte il contenuto per comodità:


If/Else

In order for a script to be very useful, you will need to be able to test the conditions of variables. Most programming and scripting languages have some sort of if/else expression and so does the bourne shell. Unlike most other languages, spaces are very important when using an ifstatement. Let's do a simple script that will ask a user for a password before allowing him to continue. This is obviously not how you would implement such security in a real system, but it will make a good example of using if and else statements. 
#!/bin/sh
# This is some secure program that uses security.

VALID_PASSWORD="secret" #this is our password.

echo "Please enter the password:"
read PASSWORD

if [ "$PASSWORD" == "$VALID_PASSWORD" ]; then
 echo "You have access!"
else
 echo "ACCESS DENIED!"
fi
Remember that the spacing is very important in the if statement. Notice that the termination of the if statement is fi. You will need to use thefi statement to terminate an if whether or not use use an else as well. You can also replace the "==" with "!=" to test if the variables are NOT equal. There are other tokens that you can put in place of the "==" for other types of tests. The following table shows the different expressions allowed. 
Comparisons:
-eqequal to
-nenot equal to
-ltless than
-leless than or equal to
-gtgreater than
-gegreater than or equal to

File Operations:
-sfile exists and is not empty
-ffile exists and is not a directory
-ddirectory exists
-xfile is executable
-wfile is writable
-rfile is readable

mercoledì 14 marzo 2012

Installazione Oracle11gR2

Nuovo task questa settimana: installazione Oracle11 e creazione istanza su macchina Unix (Solaris 5.10) in remoto.
Non essendo ancora un vero DBA mi sono avvalso delle GUI messe a disposizione da Oracle e ho quindi sfruttato il fidatissimo Putty unito al buon Xming.

Ho provato quindi il runInstaller con l'opzione di installazione del software e configurazione di una nuova istanza, ma l'esecuzione si bloccava all'invocazione del dbca.
Ho quindi ripulito la macchina e effettuato l'installazione del solo software per cercare poi a parte di creare l'istanza con il solo dbca. L'installazione è andata a buon fine senza particolari problemi, ma l'utilizzo del dbca ha continuato a dare problemi non creando i datafile, nonostante avessi scelto un template che li contemplava.
A questo punto ho deciso di procedere manualmente alla creazione dell'istanza utilizzando la guida Creating a Database with the CREATE DATABASE Statement e seguendola alla lettera la mia istanza è up and running.

Un'ultima menzione per il netca che utilizzato per creare il listener ha funzionato senza particolari intoppi.

lunedì 5 marzo 2012

Eseguire procedure esterne con IBM Netcool Omnibus

Mi è capitato di recente di dover sincronizzare alla chiusura di un allarme su Omnibus l'esecuzione di uno script esterno.

Per fare questo ho creato una procedura:

create or replace procedure close_ttmars_ticket (in identifier character(255), in tt_id character(255))
executable '$OMNIHOME/utils/closeTTMARS.sh'
host 'localhost'
user 0
group 0
arguments '\'' + identifier + '\' \'' + tt_id + '\'';

e l'ho richiamata dall'interno di un trigger after reinsert.
Alla prima esecuzione della procedura all'interno del log del Process Agent deamon (PAD) viene intercettato il seguente errore:

Mar 2 15:46:16 2012: Error: Failed to find the specified group 0 for process launch.

La configurazione del PAD per l'Object Server (OS) in questione era la seguente:

nco_process 'ROS_Server'
{
Command '$OMNIHOME/bin/nco_objserv -name ROS -pa NCO_PA -listeningport 6970' run as 0
Host = 'hostname'
Managed = True
RestartMsg = '${NAME} running as ${EUID} has been restored on ${HOST}.'
AlertMsg = '${NAME} running as ${EUID} has died on ${HOST}.'
RetryCount = 0
ProcessType = PaPA_AWARE
}

Il PAD viene eseguito come utente root, così come l'OS.
Grazie al gruppo IBM Tivoli Netcool di linkedin ho scoperto che per superare l'errrore era sufficiente agganciare l'utente root al gruppo ncoadmin e restartare il PAD.
Alla successiva esecuzione della procedura lo script è stato richiamato correttamente.

lunedì 30 gennaio 2012

Wrap degli starkits in tcl

Mi è capitato di recente di dovere eseguire l'unwrap di un starkit tcl.
Il comando per eseguire l'unwrap è:

<tclkit> sdx unwrap <starkit>

Questo comando crea nella directory di esecuzione una direcotry <starkit>.vfs
Per eseguire il wrap partendo dalla directory .vfs il comando è:

<tclkit> sdx wrap <starkit> -interp <tclkit>


Lo <starkit> di questo comando è il nome della directory .vfs senza l'estensione. Perchè lo starkit generato da questo comando funzioni è necessario fornire un tclkit tramite l'opzione -interp. Il tclkit passato a questa opzione può essere lo stesso utilizzato per effettuare il wrap.
Se in alternativa all'opzione interp si usa l'opzione runtime, è necessario fornire un altro tclkit perchè quello utilizzato per il comando di wrap risulterebbe busy.