segunda-feira, 25 de abril de 2016

Como converter arquivos de sistema para ASM Storage, usando o RMAN // How to convert file system to ASM Storage using RMAN

Hoje me foi solicitado instalar o ASM e mover os arquivos do sistema de arquivos para o armazenamento ASM. A grosso modo, o ASM permite que o oracle gerencie o seu storage.  // Today I was asked to install the ASM and move the file system files to ASM storage. Roughly, ASM allows Oracle to manage your storage.

Agora, basta localizar os arquivos de sistema, convertê-los para ASM (via rman), colocar os arquivos de sistemas "antigos" offline e renomear os arquivos de sistemas que passarão a ser utilizados. // Now, just find the system files , convert them to ASM (via rman ) , place the system offline files and rename the file systems which will be used.

Vamos ao que interessa! // Lets go to what matters!

1) Localizando os arquivos de sistema: // Finding the file system :

SQL> select name from V$datafile;

NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/system01.dbf
/u01/app/oracle/oradata/orcl/sysaux01.dbf
/u01/app/oracle/oradata/orcl/undotbs01.dbf
/u01/app/oracle/oradata/orcl/example01.dbf
/u01/app/oracle/oradata/orcl/users01.dbf


2) Por questão de segurança, é recomendado que se faça backup com os comandos de criação do control file. // For safety, it is recommended to back up with the control file creation commands.

SQL> alter database backup controlfile to trace;

2.1) Fazer um backup no rman. // Make a backup in rman.
RMAN> backup database;

3) Caso o banco esteja em Archivelog, deve-se fazer um arquivo por vez. // If the base is Archivelog , you should do one file at a time.

3.1) Colocando os arquivos de sistemas offline. // Putting the offline file systems.

SQL> alter database datafile '/u01/app/oracle/oradata/orcl/example01.dbf' offline;

SQL> alter database datafile '/u01/app/oracle/oradata/orcl/system01.dbf' offline;

SQL> alter database datafile '/u01/app/oracle/oradata/orcl/sysaux01.dbf' offline;

SQL> alter database datafile '/u01/app/oracle/oradata/orcl/undotbs01.dbf' offline;

SQL> alter database datafile '/u01/app/oracle/oradata/orcl/users01.dbf' offline;


3.2) Convertendo para ASM (Esse processo demora um pouco! (: Tenha paciência!) // Converting to ASM ( This process takes a little ( : Be patient !)

RMAN> convert datafile '/u01/app/oracle/oradata/orcl/example01.dbf' format '+data';

Starting conversion at target at 18-APR-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=51 device type=DISK
channel ORA_DISK_1: starting datafile conversion
input file name=/u01/app/oracle/oradata/orcl/example01.dbf

converted datafile=+DATA/ORCL/DATAFILE/example.256.909512635
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:20:05
Finished conversion at target at 18-APR-16

Agora faça em todos os outros arquivos de sistema. // Now do all other system files.

RMAN> convert datafile '/u01/app/oracle/oradata/orcl/system02.dbf' format '+data';
RMAN> convert datafile '/u01/app/oracle/oradata/orcl/sysaux01.dbf' format '+data';
RMAN> convert datafile '/u01/app/oracle/oradata/orcl/undotbs01.dbf' format '+data';
RMAN>


3.3) Renomeando os arquivos de sistemas que passarão a ser utilizados.  // Renaming the file systems which will be used.

SQL> alter database rename file '/u01/app/oracle/oradata/orcl/example01.dbf' to '+DATA/ORCL/DATAFILE/example.256.909512635';

SQL> alter database rename file '/u01/app/oracle/oradata/orcl/system01.dbf' to '+DATA/ORCL/DATAFILE/system.262.909524257';

SQL> alter database rename file '/u01/app/oracle/oradata/orcl/sysaux01.dbf' to '+DATA/ORCL/DATAFILE/example.256.909512635';

SQL> alter database rename file '/u01/app/oracle/oradata/orcl/undotbs01.dbf' to '+DATA/ORCL/DATAFILE/example.256.909512635';

SQL> alter database rename file '/u01/app/oracle/oradata/orcl/users01.dbf' to '+DATA/ORCL/DATAFILE/example.256.909512635';

3.4) Agora, localize os arquivos de sistema:  // Now locate the file system:

SQL> select name from V$datafile;

NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/system01.dbf
/u01/app/oracle/oradata/orcl/sysaux01.dbf
/u01/app/oracle/oradata/orcl/undotbs01.dbf
+DATA/ORCL/DATAFILE/example.256.909512635
/u01/app/oracle/oradata/orcl/users01.dbf

3.5) Agora coloque os arquivos de sistema online. // Now putting the online file systems.

SQL> alter database datafile '/u01/app/oracle/oradata/orcl/example01.dbf' online;

SQL> alter database datafile '/u01/app/oracle/oradata/orcl/system01.dbf' online;

SQL> alter database datafile '/u01/app/oracle/oradata/orcl/sysaux01.dbf' online;

SQL> alter database datafile '/u01/app/oracle/oradata/orcl/undotbs01.dbf' online;

SQL> alter database datafile '/u01/app/oracle/oradata/orcl/users01.dbf' online;


4) Caso o banco esteja em Noarchivelog. // If the bank is in NOARCHIVELOG.
4.1) Execute esses comandos para gerar os comandos que serão utilizados no próximo passo. // Run these commands to generate the commands to be used in the next step.

select 'alter database datafile '||file_name||' offline;' from v$datafile;

select 'convert datafile '''||file_name||''' format '''+data''';'

select 'alter database datafile '||file_name||' online;' from v$datafile;

4.2) Coloque o banco em mount
SQL> shutdown immediate;
SQL> startup mount;

4.3) Colocando os arquivos de sistemas offline. // Putting the offline file systems.

4.4) Convertendo para ASM (Esse processo demora um pouco! (: Tenha paciência!) // Converting to ASM ( This process takes a little ( : Be patient !)

4.5) Renomeando os arquivos de sistemas que passarão a ser utilizados.  // Renaming the file systems which will be used.

4.6) Agora coloque os arquivos de sistema online. // Now putting the online file systems

É isso!! Grande abraço e até a próxima! // It is!! Big hug and see you soon!

My linkedin: https://www.linkedin.com/in/salom%C3%A3o-netto-0667851a?trk=nav_responsive_tab_profile

terça-feira, 19 de abril de 2016

Instalando o Oracle ASM // Installing Oracle ASM




Primeiro é preciso instalar os pacotes do ASM. // First you need to install OS packages ASM.

yum install -y oracleasm-support oracleasm expat-devel libao
wget http://download.oracle.com/otn_software/asmlib/oracleasmlib-2.0.12-1.el6.x86_64.rpm
rpm -ivh oracleasmlib-2.0.12-1.el6.x86_64.rpm

Caso esteja utilizando outra plataforma, acesse o site da oracle e baixe o asmlib correto. Veja o exemplo, abaixo, para o caso de um redhat 6: // If you are using another platform, please visit the Oracle website and download the correct asmlib . See the example below for the case of a RedHat 6:
http://www.oracle.com/technetwork/server-storage/linux/asmlib/rhel6-1940776.html

1) Configure o Oracle ASM. // Configure the Oracle ASM.
# /etc/init.d/oracleasm configure -i

1ª Variavel = grid
2ªVariavel=oinstall
3ª e 4ª = [y]


2) Crie a partição primária nos discos que farão parte do ASM. // Create a primary partition on disks that will be part of ASM.
# ls /dev/sd*
# fdisk /dev/sdb
n (nova partição)
p (primária)
1 (numero da partição)
enter (default primeiro cilindro)
enter (default último cilindro)
w (gravar alterações)

3) Configurar Multipath se não o Grid InfraStructure não irá achar os ASM DISKS. Rode em todos os nodes: // Configure Multipath is not the Grid infrastructure will not find the ASM DISKS . Turn on all nodes :

3.1) Modifique o /etc/sysconfig/oracleasm com: // Modify the # /etc/sysconfig/oracleasm with:
ORACLEASM_SCANORDER=”dm”
ORACLEASM_SCANEXCLUDE=”sd”

3.2) Restart o asmlib: // restart the asmlib:
# /etc/init.d/oracleasm restart

3.3) O Resultado Final terá que ficar assim: // The End Result will have to look like this:
# /usr/sbin/oracleasm configure
ORACLEASM_ENABLED=true
ORACLEASM_UID=grid
ORACLEASM_GID=oinstall
ORACLEASM_SCANBOOT=true
ORACLEASM_SCANORDER="dm"
ORACLEASM_SCANEXCLUDE="sd"
ORACLEASM_USE_LOGICAL_BLOCK_SIZE="false"

4) Crie os discos ASM. // create ASM disks.
# /etc/init.d/oracleasm createdisk DSKASM1 /dev/sdb1
# /etc/init.d/oracleasm createdisk DSKASM2 /dev/sdc1

4.1) Liste os discos ASM para conferir. // Liste The ASM disk to check.
# /etc/init.d/oracleasm listdisks
DSKASM1
DSKASM2

5) Crie os diretórios de instalação, altere o owner e de permissão recursiva 775. // Create Installation directories, change the owner and permission recursively 775.

mkdir -p /u01/app/grid
mkdir -p /u01/app/grid/12.1.0
chown -R oracle:oinstall /u01
chmod -R 775 /u01/

groupadd -g 1000 oinstall
groupadd -g 1020 asmadmin
groupadd -g 1021 asmdba
groupadd -g 1031 dba
useradd -u 1100 -g oinstall -G asmadmin,asmdba grid
useradd -u 1101 -g oinstall -G dba,asmdba oracle

6) Defina as variáveis de ambiente. // Set the environment variables.

# vi /home/grid/./.bash_profile

TMP=/tmp
TMPDIR=$TMP
TEMP=$TMP
export ORACLE_SID=+ASM1
export ORACLE_BASE=/u01/app/oracle
export GRID_HOME=/u01/app/12.1.0.1/grid
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0.1/dbhome_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export ORACLE_TERM=xterm
export
PATH=$PATH:$ORACLE_HOME/bin:$PATH:$GRID_HOME/bin:/usr/bin:/sbin:/usr/
sbin:$ORACLE_HOME/OPatch
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
export PS1="[${LOGNAME}@`hostname -s`:"'${PWD} [${ORACLE_SID}] ]$ '
export PERL_HOME=/usr/local/perl
export PERL5LIB=$PERL_HOME/lib
export SQLPATH=/home/oracle/scripts-ora

7)Defina a configuração do Arquivo: vi /etc/security/limits.conf // Set the archive configuration: vi /etc/security/limits.conf

grid soft noproc 131072
grid hard noproc 131072
grid soft nofile 131072
grid hard nofile 131072
grid soft core unlimited
grid hard core unlimited
grid soft memlock unlimited
grid hard memlock unlimited


8)# su -grid
$ cd /home/grid
$ unzip linuxamd64_12102_grid_1of2.zip
$ unzip linuxamd64_12102_grid_2of2.zip
$ cd /home/grid/grid
$ ./runInstaller

9) Marque a opção “Skip software update” e clique em “Next”. // Check the "Skip update software" and click "Next".

Escolha a opção “Standalone Server” e clique em “Next”. // Choose "Standalone Server" and click "Next".

Escolha o idioma e clique em “Next”. // Choose your language and click "Next."

Nesse momento será criado o “Disc Group DATA”. // At that moment will be created the "Disc Group DATA".

Escolha “Redundancy” Normal. // Select "Redundancy" Normal.

“Alocation Unit”(AL) 1MB. // "Alocation Unit" (AL) 1MB.

Selecione dois discos para compor o “Disc Group DATA”. // Select two disks to compose the "Disc Group DATA".

Clique em “Next”. // Click "Next."

Defina a senha para a instância ASM e clique em “Next”. // Set the password for the ASM instance and click "Next."

Selecione os grupos “oinstall” e clique em “Next”. // Select groups "oinstall" and click "Next."

Como as variáveis ORACLE_BASE e GRID_HOME foram definidas, a tela já traz os campos para instalação preenchidos corretamente, clique em “Next”. // As the ORACLE_BASE and GRID_HOME variables were defined, the screen already has the facility to fields filled in correctly, click "Next".

Clique em “Next”. // Click "Next."

Clique em “Install”. // Click "Install".


Nesse momento deve ser rodado os scripts como “root” que a instalação pede. // At this point must be run scripts as "root" the installation asks.

Abra um novo terminal como root e execute os scripts. // Open a new terminal as root and run the scripts.

cd /u01/app/oraInventory
./orainstRoot.sh

cd /u01/app/oracle/product/11.2.0/grid
./root.sh

Feche o terminal. // Close the terminal.

Clique em “OK” na janela onde pede que os scripts sejam executados. // Click "OK" in the window which asks the scripts to run.

Instalação concluída, clique em “Close”. // Installation complete, click "Close".



Como criar o diskgroup no ASM?

1) Neste passo será criado o Diskgroup +DATA onde ficarão armazenados os Dados do novo Database. //  This step will create the diskgroup + DATA where the new data will be stored Database.

Iniciar instalador: // Starting installer:

vi /home/oracle/./.bash_profile
acrescentar: export GRID_HOME=/u01/app/oracle/product/11.2.0/grid
ou digitar: export GRID_HOME=/u01/app/oracle/product/11.2.0/grid
cd $GRID_HOME/bin
./asmca


My Linkedin: https://www.linkedin.com/in/salom%C3%A3o-netto-0667851a?trk=nav_responsive_tab_profile