vicker313 tech blog

June 11, 2011

Copy or Move Oracle Database

Filed under: Oracle — Tags: , , — vicker313 @ 12:18 pm

Consider the following scenario: I got a oracle database that reside in /db/mydb. For some reason I need to copy or move the database to somewhere else, let’s say /db2/mydb2.

To do this, follow the steps:

  1. Shutdown the database either using service or sql statement: shutdown immediate.
  2. Copy or move the database to /db2 and rename the new database directory to mydb2.
  3. Edit the initialize parameter file in the mydb2 (something like initxxx.ora), change the all the paths to the new path (from /db/mydb to /db2/mydb2)
  4. Log in to sqlplus with NOLOG (run in terminal): sqlplus /nolog
  5. Connect to empty instance (run in SQLPLUS): connection / as sysdba
  6. Create SPFILE, aware that the path of the initialize parameter file might be vary (run in SQLPLUS): create spfile from pfile='/db2/mydb2/admin/pfile/initxxx.ora';
  7. Start database in mount mode (run in SQLPLUS): startup mount;
  8. Change the data file path to the new path (run in SQLPLUS): alter database rename file '/db/mydb/data.dbf', '/db/mydb/system.dbf' to '/db2/mydb2/data.dbf', '/db2/mydb2/system.dbf';
  9. Ensure you change all the data file path! Or else it will cause the orginal database cannot be startup! (Refer updates below)
  10. Open your database (run in SQLPLUS): alter database open;
  11. Now it is good to go.

If you want to run both databases in the same time, you need to rename the new database. Follow the following steps:

  1. Rename the new database to mydb2
  2. Remember to change the database name in mydb2 parameter file as well.
  3. Log into SQLPLUS. At this point, you need to aware the SID_NAME in your environment parameter, need to be point to the database that you want to log in. Now we want to log in to the original, so we set the SID_NAME to mydb (terminal): export SID_NAME=mydb
  4. Connect to empty instance (SQLPLUS): connect / as sysdba
  5. Create the SPFILE again using the original parameter file (SQLPLUS): create spfile from pfile='/db/mydb/admin/pfile/initxxx.ora';
  6. Now you should able to start your database (SQLPLUS): startup

Update 2013/2/24

You may find out the data files path using the following query (thanks to Concerned_Netizen):

  • select name from v$datafile
  • select member from v$tempfile
  • select member from v$logfile

June 8, 2011

Recover Root Password in RHEL6

Filed under: Linux — Tags: , , — vicker313 @ 10:59 pm

There are a lot of guide lines on recovering ROOT password in a Red Hat or Fedora, by entering single user mode and change the ROOT password using passwd command. However the trick isn’t work in RHEL 6 any more, where issuing the passwd command in single user mode will not prompt you to enter the new password.

Here is a trick where I discover in order to recover the ROOT password in RHEL6.

  1. First enter single user mode. To do this, boot your machine and wait until the message to enter GRUB (the one with a counter). Press any key to enter GRUB, then press e to edit the boot argument. Just append the word single at the back of the arguments and press enter to continue boot.
  2. You should enter single user mode, with the root prompt. Instead of using entering only passwd, enter the following command:passwd -d root
  3. “-d” is meant for making the password blank. Now your root password should be blank. Reboot your machine and change your ROOT password.

Rebuild Partition after Change Hard Disk in Disk Array of HPUX Machine

Filed under: HPUX — Tags: , , , — vicker313 @ 10:38 pm

A little experience on dealing with Disk Array in HPUX machine to be shared.

It is happened at an old HPUX machine with disk array attached. After 2 of the hard disks in the disk array are being replaced, the new hard disks cannot be seen in SAM. To discover back the missing hard disks, issue the following command:

armdiscover <array alias>

After the command, you should able to see the hard disks in SAM, and even can see the unmounted partitions. However you wouldn’t able to do anything with it, either mount it, remove it or recreate it. You should get some errors like “can’t find /dev/dsk/cxtxdx”. Then issue the following command:

armdsp -s <array alias>

This command will show the hard disks path in the disk array. You will see that the path is not the same inside the error. The unmounted partitions are actually still referring to the old hard disk path, where you need to remove it using the following command:

vgreduce -l /dev/vgxx /dev/dsk/cxtxdx

You must include “-l” in the command to remove the missing path. After that you need to add back the actual hard disk path either using SAM or vgextend command, and everything should be back to normal.

April 8, 2011

Turn on MYSQL Trace Feature

Filed under: MySQL — Tags: , — vicker313 @ 2:34 pm

To turn on MySQL trace feature, simply issue following command in MySQL console (OFF to turn off)

SET GLOBAL general_log = 'ON';

Or add following option to MySQL start up command (to turn off use 0):

mysqld --general_log=1

You can find the trace log at the database folder. The file name is something like host_name.log.

Setup Customized User Access Trace Log in Oracle Database

Filed under: Oracle — Tags: , , — vicker313 @ 2:26 pm

Here is a simple way to trace user access (log in and log out) in Oracle, by using trigger and table.

  1. Create a trace log table. For example:
    CREATE TABLE TRACELOG
    (
       SESSION_ID        NUMBER(20),
       SESSION_USER      VARCHAR2(30 BYTE),
       OS_USER           VARCHAR2(30 BYTE),
       HOST              VARCHAR2(30 BYTE),
       IP_ADDRESS        VARCHAR2(30 BYTE),
       TERMINAL          VARCHAR2(30 BYTE),
       MODULE            VARCHAR2(30 BYTE),
       LAST_ACTION       VARCHAR2(32 BYTE),
       LAST_ACTION_DATE  DATE,
       LOGON_DATE        DATE,
       LOGOFF_DATE       DATE
    )
  2. Grand privilege to public to update the TRACELOG table
    GRANT INSERT, UPDATE, SELECT ON TEMP_TRACE TO PUBLIC;
  3. Create Log On Trigger. For example:
    CREATE OR REPLACE TRIGGER on_logon_trigger
    after logon on database
    begin
       insert into tracelog(session_id, session_user, os_user, host, ip_address, terminal, module, logon_date)
       SELECT sys_context('USERENV', 'sessionid'),
       user,
       sys_context('USERENV', 'os_user'),
       sys_context('USERENV', 'host'),
       sys_context('USERENV', 'ip_address'),
       sys_context('USERENV', 'terminal'),
       sys_context('USERENV', 'module'),
       sysdate
       FROM dual;
       commit;
    end;
  4. Create Log Off Trigger. For example:
    CREATE OR REPLACE TRIGGER on_logoff_trigger
    before logoff on database
    begin
       update tracelog
       set logoff_date = sysdate
       where session_id = sys_context('USERENV', 'sessionid')
       and logoff_date is null;
       commit;
    end;

Now you can trace user access by querying the TRACELOG table.

February 19, 2011

How Flashing in Android Works?

Filed under: Android — Tags: — vicker313 @ 9:00 pm

After rooting your Android phone, flashing is just a piece of cake.

  1. Put your new android installation file in SD Card (it will be in ZIP file)
  2. Boot your phone in Recover Tool
  3. Do a Backup, just in case (it will backup everything inside your internal memory)
  4. Wipe your phone internal memory (normally MUST if you are flashing a completely different Android, but if it is upgrade or downgrade of the same Android, probably can skip)
  5. Then install zip file from SD Card
  6. Reboot and done

The only painful thing of flashing is that you might need to reconfigure everything and install back what application you want (just like format a PC). So the more tricky part is to pick the correct one. You can only know this version of Android is your favorite or not until you use it, and switching between different Android is troublesome.

The customized Android is roughly divided by 2 types: Android with HTC Sense UI, and Android with AOSP UI. After choosing the UI that you want, then choose the version based on the application that come with it.

Some major player of customized Android include cyanogenmod, defrost, oxygen and some more.

My favorite comparison chart on customized Android

Basic Understanding on How Android Works

Basic Understanding on How Android Works

Filed under: Android — Tags: — vicker313 @ 8:35 pm

Playing with my new Android Smart Phone for 3 months, from rooting, to ROM flashing, then S-OFF, I have roughly came out with some basic understanding on how Android really works. Following are based on my experiences, some might based on some references, and might have some misunderstanding. Anything not right feel free to comment.

Android is Linux

This might be obvious but I point this out any way. So if you browse the file system using any file manager, you can see the file structure is following Linux style: /system, /data, /cache, /mnt and some more. Since it is Linux, Android is using EXT as hard disk format (Froyo using EXT3 while Gingerbread using EXT4).

ROM, Internal Memory, Memory and SD Card

We always heard of flashing ROM in Android, which the term is not exactly correct. Most of the time we are actually flashing the internal memory. Like a PC, Android boots from HBOOT (equivalent to BIOS) that stay at ROM, then loads the system files from Internal Memory, and lastly loads any applications that installed to SD Card.

Not sure what kind of format is used in ROM, but roughly it is partitioned into few partitions like HBOOT, RECOVERY and SPLASH1

Internal Memory is definitely in EXT format that partitioned into few partitions as well. The main partitions are SYSTEM (basically where Android files stay), CACHE and DATA (where application installed). So if you check the Internal Memory size from Settings, you might be confused by the size of it (much lower than the specification). Actually the size showed is the size of DATA partition, while the rest of the size is used by other partitions.

Lastly SD Card is in FAT format.

Rooting, Recovering and Flashing

Rooting in Android is more than gaining back the root privilege. In order to protect the phone from user, manufacturer puts a lot of security features to the ROM and Internal Memory. So rooting is actually mean disable the security features.

Aside from disable the security, rooting also includes step to install a recover tools in ROM. By using the recover tools, user can flash the internal memory with other version of Android (just boot into HBOOT and select to boot from recover, like multi boot in PC).

Unrevoked provides tool to do rooting for HTC.

S-OFF and Repartition

However flashing the internal memory only put in the new system files, but it cannot repartition it (you might want to have a bigger size of DATA partition to install more application). To do repartition, we need to do S-OFF and patch HBOOT. After S-OFF and the patching, we now can have the options to repartition by flashing HBOOT in ROM.

AlphaRev provides tool to do S-OFF and repartition for HTC.

December 23, 2010

Setup SSL Certificate at Tomcat

Filed under: Server, Tomcat — Tags: , , — vicker313 @ 9:12 am

The method here is to implement CA certified SSL certificate in Tomcat Service.

  1. Generate a key store file using keytool utility (installed together with JDK). It will ask for a password to generate the key store file.
    keytool -genkey -alias <any alias name> -keyalg RSA -keystore <output file>
    For example:
    keytool -genkey -alias tomcat -keyalg RSA -keystore tomcat.key
  2. Generate a certificate request file.
    keytool -certreq -keyalg RSA -alias <alias> -file <output file> -keystore <keystore file>
    Example:
    keytool -certreq -keyalg RSA -alias tomcat -file certreq.csr -keystore tomcat.key
  3. Then submit the certificate request to your CA. Normally you just need to submit the content of the request file.
  4. As a result you will get the content of the certificate. Copy the content and save it as a certificate file (for example tomcat.cer)
  5. For some CA (like Thawte), you need to download the CA trusted certificate from the their website in order to complete the implementation (EV_Root.cer and EV_intermediate.cer)
  6. Finally import the certificates using command below:
    keytool -import -alias <alias name> -keystore <keystore file> -trustcacerts -file <certificate>
    For example:
    keytool -import -alias EV_Root -keystore online.key -trustcacerts -file EV_Root.cer
    keytool -import -alias EV_intermediate -keystore online.key -trustcacerts -file EV_intermediate.cer
    keytool -import -alias tomcat -keystore tomcat.key -trustcacerts -file tomcat.cer

Some references to retrieve private key from the key store that you generate.

November 5, 2010

Restrict IP coming to Tomcat Service

Filed under: Tomcat — Tags: , — vicker313 @ 8:24 pm

We can restrict incoming connection by IP address in Tomcat, for example we only allow connection from IP 10.10.10.* to access. We only need to add a valve tag in the context:

<Context>
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="192\.168\.56\..*" deny="192\.168\.56\.1"/>
</Context>

It is quite straight forward: allow attribute to allow what IP pattern to go through, while deny is to block. The value of the attribute use regular expression. Another example of regular expression, 192.168.*.* need to set as 192\.168\..*\..*.

2 ways to do this: either you want to implement the restriction to all the applications, or to particular application. If you want to apply to all applications, put the tag in TOMCAT_HOME/conf/context.xml.

If you only want to apply the restriction to particular application, put the tag in TOMCAT_HOME/conf/catalina/locahost/<webapp>.xml. The name of the file follow the name of your web application. Create the file if it is not exist.

Enable or Disable All Constraints in MSSQL

Filed under: MSSQL — Tags: , — vicker313 @ 8:11 pm

There is no method provided by MSSQL to enable or disable all constraints of table in a go. However we can create a simple procedure to archive this goal. Use script below to create the procedure:

CREATE PROCEDURE sp_ConstraintState
@TblName VARCHAR(128),
@State BIT = 1
AS
DECLARE @SQLState VARCHAR(500)
IF @State = 0
BEGIN
SET @SQLState = 'ALTER TABLE '+ @TblName + ' NOCHECK CONSTRAINT ALL'
END
ELSE
BEGIN
SET @SQLState = 'ALTER TABLE ' + @TblName + ' CHECK CONSTRAINT ALL'
END
EXEC (@SQLState)
go

To execute the procedure, run script below:

sp_MsForEachTable 'sp_ConstraintState ''?'', 0'

sp_MsForEachTable is system defined procedure in MSSQL, to run the procedure created above in each table. o at the back is to disable, 1 is for enable.

« Newer PostsOlder Posts »

Create a free website or blog at WordPress.com.