lunedì 4 novembre 2013

Oracle: free space on datafile

Per recuperare dello spazio disco è possibile restringere i DATAFILE di Oracle. Per farlo è sufficiente usare il comando:

ALTER DATABASE DATAFILE '<path_to_datafile>' RESIZE <size>;

Per non andare per tentativi con questa procedura SQL è possibile ricavare quanto spazio libero ci sia per ogni DATAFILE, raggruppando il tutto per TABLESPACE:

SET PAUSE ON
SET PAUSE 'Press Return to Continue'
SET PAGESIZE 60
SET LINESIZE 300
COLUMN "Tablespace Name" FORMAT A20
COLUMN "File Name" FORMAT A80
 
SELECT  Substr(df.tablespace_name,1,20) "Tablespace Name",
        Substr(df.file_name,1,80) "File Name",
        Round(df.bytes/1024/1024,0) "Size (M)",
        decode(e.used_bytes,NULL,0,Round(e.used_bytes/1024/1024,0)) "Used (M)",
        decode(f.free_bytes,NULL,0,Round(f.free_bytes/1024/1024,0)) "Free (M)",
        decode(e.used_bytes,NULL,0,Round((e.used_bytes/df.bytes)*100,0)) "% Used"
FROM    DBA_DATA_FILES DF,
       (SELECT file_id,
               sum(bytes) used_bytes
        FROM dba_extents
        GROUP by file_id) E,
       (SELECT Max(bytes) free_bytes,
               file_id
        FROM dba_free_space
        GROUP BY file_id) f
WHERE    e.file_id (+) = df.file_id
AND      df.file_id  = f.file_id (+)
ORDER BY df.tablespace_name,
         df.file_name


Solaris: Memoria e Core

Oggi ho dovuto recuperare informazioni hardware per i sistemi Solaris. Riporto un po' dei comandi che ho utilizzato.
Per recuperare le informazioni relative alla memoria il comando è
prtconf | grep Mem
Per recuperare informazioni relative ai Core il comando è
psrinfo -pv
Oltre a questi comandi sono utili anche
uname -a
isainfo -kv
per recuperare informazioni sul sistema operativo.

Oracle: import di uno schema da un utente ad un altro.

Per questa attività è necessaria la creazione di una directory all'interno dell'istanza target di ORACLE su cui andrà messo il file da importare.
create or replace directory <TARGET_DIR> as '<path>';
grant read, write on directory <TARGET_DIR> to <user_target>;
I grant di read e write sulla directory vanno assegnati anche all'utente system.
La directory <path> sul File System deve essere accessibile in lettura e scrittura all'utente unix con cui il database viene eseguito (nel mio caso oracle).
Una volta superati questi check è sufficiente dare:
impdp system/<password> SCHEMAS=<schema> \
            remap_schema=<user_orig>:<user_target> \
            remap_tablespace=<user_orig>:<user_target> \
            directory=<TARGET_DIR> \
            dumpfile=<DMP_FILE> logfile=<LOG_FILE>

giovedì 3 gennaio 2013

Jboss e file di properties

Fin dal primo approccio a jboss mi sono imbattuto nel problema dei file di properties utilizzati dalle mie applicazioni java. Al contrario di quanto accade su tomcat, il deploy dei war non è di facile accesso e quindi modificare i file di properties risulta essere poco agevole. In contesti dove la stessa applicazione deve essere distribuita su più sistemi con diversi riferimenti questo inconveniente fa sicuramente sentire il suo peso.
Con l'ultimo sviluppo realizzato ho deciso di impegnarmi per aggirare l'ostacolo. Dopo alcune ricerche è saltata fuori la funzione

System.getProperty("jboss.server.config.dir")

che restituisce il path a <JBOSS_HOME>/standalone/configuration (per il deploy sotto jboss 7). Concatenando questo path al nome del file di properties ho così la possibilità di posizionare i file in una directory dove siano facilmente accessibili.
Al momento ho potuto verificare questa procedura solo per la modalità standalone di jboss.

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