Kamis, 23 Juli 2020

Latihan 03

03. Install and Maintain Oracle Database

Teori :

1. Saat linux di start maka ada file yang akan dibaca dan dieksekusi isinya
   yaitu /etc/rc.d/rc.local, hanya root yang bisa update file ini
   
2. Saat install oracle, ada file yang dicreate dengan nama /etc/oratab
   file ini juga dibaca saat linux di start. 

3. Oracle memiliki program untuk start database yaitu dbstart dan 
   untuk stop yaitu dbshut. Program ini berhubungan dengan file /etc/oratab
   
4. Script di redhat linux bisa untuk menjalankan program-program yang telah
   diinstall seperti sqlplus, lsnrctl, dbstart, dbshut, psql, pg_ctl dll
   
5. Contoh script linux untuk menjalankan query sqlplus sbb :
   
   Direktori : /home/oracle/bin
   Nama file : RunSql.sh
   
   #!/bin/sh
   PATH=$PATH:$HOME/bin:/oracle/home/bin
   ORACLE_HOME=/u01/oracle/product/12.1.0/db
   LD_LIBRARY_PATH=/u01/oracle/product/12.1.0/db/lib
   ORACLE_SID=ora121
   export  PATH ORACLE_HOME ORACLE_SID LD_LIBRARY_PATH
   sqlplus /nolog<<EOF
   conn usr01/pwdusr01
   select I_TOOL_MTRLG,D_CALIB, n_tool
   from tmtool
   where n_tool like '%MICRO JACK%';
   EOF
   exit

6. Berikan properti execute dengan chmod
   jalankan dari user oracle : RunSql.sh
   Output spt ini :
   [oracle@oravbox bin]$ RunSQL.sh 

   SQL*Plus: Release 12.1.0.2.0 Production on Thu Jun 25 08:58:05 2020

   Copyright (c) 1982, 2014, Oracle.  All rights reserved.
   
   SQL> Connected.
   SQL>   2    3  
   I_TOOL D_CALIB   N_TOOL
   ------ --------- -------------------------
   140193 19-NOV-99 MICRO JACK
   140192 19-NOV-99 MICRO JACK
   140191 21-JUL-02 MICRO JACK
   140015 19-NOV-99 MICRO JACK
   
   SQL> Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
   With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

7. Untuk menjalankan script milik oracle dari root, gunakan perintah berikut
   /bin/su - oracle -c /home/oracle/bin/RunSql.sh  
   
8. Contoh untuk database postgres :
   /home/postgres/bin/RunPsql.sh
   
   #!/bin/sh
   PGHOME=/usr/local/pgsql;export PGHOME
   PGDATA=$PGHOME/data;export PGDATA
   PATH=$HOME:$PATH:$PGHOME/bin;export PATH
   psql -U usr01 -d db01 -c "select * from tmtest" 
   
   
   [postgres@oravbox bin]$ RunPsql.sh 
   Outputnya :
   
   i_id | n_emp  
   ------+--------
     1  | JAJANG
     2  | BUDI
  (2 rows)


9. Untuk menjalankan script milik postgres dari root, gunakan perintah berikut
   /bin/su - oracle -c /home/postgres/bin/RunSql.sh


=======================================================

Latihan-03

A. Database Oracle

1. Mencoba start oracle dengan program dbstart
   - Setting file /etc/oratab
   - Pastikan listener dan database not running
   - Pastikas variable $ORACLE_HOME sudah di set 
     echo $ORACLE_HOME
     /u01/oracle/product/12.1.0/db
   - Pastikan variable $PATH mengandung $ORACLE_HOME/bin
     echo $PATH
     /u01/oracle/product/12.1.0/db/bin:/usr/lib64/qt-3.3/bin .... dst

2. Jalankan program dbstart
   dbstart $ORACLE_HOME
   outputnya :
   Processing Database instance "ora121": log file /u01/oracle/product/12.1.0/db/startup.log
        
3. Buat file OraStart.sh di /home/oracle/bin
   file tersebut menjalankan program dbstart
   
4. Test OraStart.sh
   - Pastikan listener stop dan database not running
   - jalankan script : 
     cd /home/oracle/bin
     OraStart.sh
   - Output :
     Processing Database instance "ora121": log file /u01/oracle/product/12.1.0/db/startup.log
   - Periksa listener dan database harusnya sudah up

5. Setting oracle listener dan database agar otomatis start saat linux di start / boot   
   dengan memanfaatkan file OraStart.sh

6. Buat file OraShut.sh di /home/oracle/bin
   file tersebut menjalankan program dbshut

7. Test OraShut.sh
   - Pastikan listener dan database running
   - jalankan script : 
     cd /home/oracle/bin
     OraShut.sh
   - Output :
     Processing Database instance "ora121": log file /u01/oracle/product/12.1.0/db/startup.log
   - Periksa listener dan database harusnya sudah down
   
8. Buat crontab di user oracle untuk menjalankan script OraShut.sh pada menit dan jam tertentu 
   (sesuaikan saat akan mencoba)
   
      
B. Database Postgresql

1. Postgres tidak memiliki program semacam dbstart seperti di oracle
   Buat file PgStart.sh di /home/postgres/bin
   file tersebut menjalankan program pg_ctl
   Modifikasi contoh pada bagian teori

2. Test OraStart.sh
   - Pastikan postgres database not running
   - jalankan script : 
     postgres@oravbox bin]$ PgStart.sh 
    [postgres@oravbox bin]$ server starting
    LOG:  database system was shut down at 2020-06-25 10:08:06 WIB
    LOG:  MultiXact member wraparound protections are now enabled
    LOG:  database system is ready to accept connections
    LOG:  autovacuum launcher started
    
    <tekan enter>
   
   - Periksa database harusnya sudah up
   
3. Setting database postgres agar otomatis start saat linux di start / boot   
   dengan memanfaatkan file PgStart.sh    
   

4. Postgres tidak memiliki program semacam dbshut seperti di oracle
   Buat file PgShut.sh di /home/postgres/bin
   file tersebut menjalankan program pg_ctl untuk stop dengan mode immediate

5. Test OraShut.sh
   - Pastikan postgres database running
   - jalankan script : 
     postgres@oravbox bin]$ PgShut.sh 
     
     Output :
   
      [postgres@oravbox bin]$ LOG:  received immediate shutdown request
      WARNING:  terminating connection because of crash of another server process
      DETAIL:  The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
      HINT:  In a moment you should be able to reconnect to the database and repeat your command.
      WARNING:  terminating connection because of crash of another server process
      DETAIL:  The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
      HINT:  In a moment you should be able to reconnect to the database and repeat your command.
      waiting for server to shut down... done
      server stopped


6. Buat crontab di user postgres untuk menjalankan script PgShut.sh pada menit dan jam tertentu 
   (sesuaikan saat akan mencoba)