Mostrando entradas con la etiqueta system. Mostrar todas las entradas
Mostrando entradas con la etiqueta system. Mostrar todas las entradas

viernes, 21 de marzo de 2014

Como se Puede Mover un Datafile en Oracle 12c

Hallé esto aquí y decidí traducirlo para los hispanohablantes. Lo probé en Oracle 12.1. En versiones anteriores, era necesario seguir varias etapas para mover un datafile. Ahora es posible hacerlo con un comando como se puede ver bajo estas líneas: 

SQL> l
  1  select file_name from dba_data_files
  2* where tablespace_name = 'USERS'
SQL> /
 
FILE_NAME
----------------------------------------------------------------------
C:\APP\ADMINISTRATOR\ORADATA\ORCL1\DATAFILE\O1_MF_USERS_9LM1W41L_.DBF
 
SQL> alter database move datafile
  2  'C:\APP\ADMINISTRATOR\ORADATA\ORCL1\DATAFILE\O1_MF_USERS_9LM1W41L_.DBF'
  3  to
  4  'C:\APP\ADMINISTRATOR\ORADATA\ORCL1\DATAFILE\USERS.DBF'
  5  /
 
Base de datos modificada.
 
SQL> select file_name from dba_data_files
  2  where tablespace_name = 'USERS'
  3  /
 
FILE_NAME
----------------------------------------------------------------------
C:\APP\ADMINISTRATOR\ORADATA\ORCL1\DATAFILE\USERS.DBF
 
SQL> 

... y aquí está el nuevo archivo en el sistema operativo para probarlo: 

PS C:\app\administrator\oradata\orcl1\datafile> dir users.*
 
 
    Directory: C:\app\administrator\oradata\orcl1\datafile
 
 
Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---        20/03/2014     18:55    5251072 USERS.DBF
 
 
PS C:\app\administrator\oradata\orcl1\datafile> 

El comando aun parece funcionar con el tablespace SYSTEM

SQL> select file_name from dba_data_files
  2  where tablespace_name = 'SYSTEM'
  3  /
 
FILE_NAME
--------------------------------------------------------------------------------
C:\APP\ADMINISTRATOR\ORADATA\ORCL1\DATAFILE\O1_MF_SYSTEM_9LM1SGKN_.DBF
 
SQL> alter database move datafile
  2  'C:\APP\ADMINISTRATOR\ORADATA\ORCL1\DATAFILE\O1_MF_SYSTEM_9LM1SGKN_.DBF'
  3  to
  4  'C:\APP\ADMINISTRATOR\ORADATA\ORCL1\DATAFILE\SYSTEM.DBF'
  5  /
 
Base de datos modificada.
 
SQL> exit
Desconectado de Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
PS C:\app\administrator\oradata\orcl1\datafile> dir system.*
 
 
    Directory: C:\app\administrator\oradata\orcl1\datafile
 
 
Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---        20/03/2014     19:01  817897472 SYSTEM.DBF
 
 
PS C:\app\administrator\oradata\orcl1\datafile>

martes, 14 de mayo de 2013

Como se Puede Renombrar un Tablespace Oracle

En Oracle 9 no era posible cambiar el nombre de un tablespace:

SQL> l
  1* alter tablespace users rename to andrew
SQL> /
alter tablespace users rename to andrew
                              *
ERROR at line 1:
ORA-01904: DATAFILE keyword expected
 
SQL>

... pero desde Oracle 10 es posible hacerlo. Decidí renombrar el tablespace USERS y llamarlo ANDREW para hacer una demostración. Para empezar comprobé que tenía un tablespace USERS y que no  tenía un tablespace ANDREW: 

SQL> l
  1  select tablespace_name from dba_tablespaces
  2* where tablespace_name in ('ANDREW', 'USERS')
SQL> /
 
TABLESPACE_NAME
------------------------------
USERS
 
SQL>

Luego mostré que había una tabla llamada COCHES en el tablespace USERS:
 
SQL> l
  1  select tablespace_name from dba_tables
  2* where table_name = 'COCHES'
SQL> /
 
TABLESPACE_NAME
------------------------------
USERS
 
SQL>

Cambié el nombre del tablespace USERS y lo llamé ANDREW: 

SQL> alter tablespace users rename to andrew;
 
Tablespace modificado.
 
SQL>

Entonces comprobé que tenía un tablespace ANDREW y que no  tenía un tablespace USERS:

SQL> l
  1  select tablespace_name from dba_tablespaces
  2* where tablespace_name in ('ANDREW', 'USERS')
SQL> /
 
TABLESPACE_NAME
------------------------------
ANDREW
 
SQL>

También comprobé que la tabla COCHES estaba en el tablespace ANDREW: 

SQL> l
  1  select tablespace_name from dba_tables
  2* where table_name = 'COCHES'
SQL> /
 
TABLESPACE_NAME
------------------------------
ANDREW
 
SQL>

Hice el tablespace ANDREW offline:
 
SQL> alter tablespace andrew offline;
 
Tablespace modificado.

SQL>

Luego intenté renombrarlo pero no era permitido:
 
SQL> alter tablespace andrew rename to users;
alter tablespace andrew rename to users
*
ERROR en linea 1:
ORA-01135: el archivo 4 accedido para LMD/consulta
esta offline
ORA-01110: archivo de datos 4:
'/database/ORCL/datafiles/users01.dbf'
 
SQL>

Tampoco se puede cambiar los nombres de los tablespaces SYSTEM y SYSAUX:
 
SQL> alter tablespace system rename to fred;
alter tablespace system rename to fred
*
ERROR en linea 1:
ORA-00712: no se puede cambiar el nombre del
tablespace del sistema
 
SQL> alter tablespace sysaux rename to fred;
alter tablespace sysaux rename to fred
*
ERROR en linea 1:
ORA-13502: No se puede cambiar el nombre del
tablespace SYSAUX
 
SQL>

Por fin, si intentas a dar un nuevo nombre inválido a tu tablespace, Oracle responde con un ORA-02150:

SQL> alter tablespace users rename to 123;
alter tablespace users rename to 123
                                 *
ERROR en linea 1:
ORA-02150: nuevo nombre de tablespace no valido
 
SQL>

Así, ahora mi problema es - ¿Cómo se puede tener un ORA-00711? Desafortunadamente, no tengo una versión española de este error: 

Solaris > oerr ora 00711
00711, 00000, "new tablespace name is invalid"
// *Cause:  An attempt to rename a tablespace failed because the new name
//          is invalid.
// *Action: Choose a valid new name and retry the command.
Solaris >