Thursday, April 3, 2014

Oracle - Tablespace vs Schema

This may not be a new things to someone work with Oracle for ages, however, I feel confused when I come across the term tablesapce and it is different from schema

The main catch is there is no relationship between schemas and tablespaces. Ok... that surprised me a little.

But comes to think of it, it is 2 different concepts.

By Oracle definition

Schema - A schema is a collection of database objects. A schema is owned by a database user and has the same name as that user. Schema objects are the logical structures that directly refer to the database's data. Schema objects include structures like tables, views, and indexes.

Tablespaces - A tablespaces is a collection of logical storage units in a database. It groups related logical structures together. For example, tablespaces commonly group together all application objects to simplify some administrative operations.

So, in fact, a tablespace can contain objects from different schemas, and the objects for a schema can be contained in different tablespaces.

Below are 2 very good figure from Oracles to explains Schema Objects, Tablespaces, and Datafiles

Text description of cncpt041.gif follows

Description of Figure 3-1 follows

Now, an example between schema and tablespaces. Below is an example of a single schema that exists in 2 different tablespaces

CREATE TABLE hr.payroll (
         empno      NUMBER(5) PRIMARY KEY,
         ename      VARCHAR2(15) NOT NULL,
         salary        NUMBER(9) ENCRYPT)
   TABLESPACE payroll_tbs;

         empno      NUMBER(5) PRIMARY KEY,
         ename      VARCHAR2(15) NOT NULL,
         ssn        NUMBER(9) ENCRYPT)
   TABLESPACE emp_tbs;

The above statement create 2 tables payroll and emp under hr schema and owned by me. Although it is under the same schema, hr.payroll exists in payroll_tbs tablespaces and hr.emp exists in emp_tbs tablespaces.

Some good readings and references:

Tuesday, March 18, 2014

Database - IBM Informix - Turning On/Off Transactional Database

A transactional database is a DBMS where write transactions on the database are able to be rolled back if they are not completed properly (e.g. due to power or connectivity loss). This is to enforce each database transaction comply with ACID (atomic, consistent, isolated and durable) properties.

IBM Informix database server make use of transaction logging to keep a record of each change that is applied to the database during a transaction. If transaction is cancel due to unforeseen circumstances, it can restored to the same state as before the transaction started. This is call a rollback.

Now, if you see error such as transaction not available when using Informix, it can means that the database administrator could have turn off transaction logging or create a database without logging. Switching transaction log off will make a database "un-transactional".

To fix this, you can either

1)  Turn on transaction logging with ontape command

The following will add unbuffered logging to the database

ontape -s -U your_database

2) Create database with regular logging

The following will create a database with regular unbuffered logging


Both ways are sufficient for most database. In the event of a failure, you lose only uncommitted transactions.

Reference :

Wednesday, February 26, 2014

Linux - set -vx

Set command in Linux is used to set or unset values of shell options and positional parameters.

It has many useful options, and specifically, set -vx is very useful to debug a Linux script.

-v  Print shell input lines as they are read.
-x  Print commands and their arguments as they are executed.

To use this, simply put set -vx before an interested script line. Usually, I will put it at the top of my script to print out everything.

For example, you can use set -vx as follow script call

set -vx
export foo=$1
echo $foo 

Executing the with

./ hello

The output will be

export foo=$1
+ export foo=hello
+ foo=hello
echo $foo
+ echo hello

Those line with + sign are evaluated value during execution


Sunday, February 2, 2014

Whatsapp for Android - Video color become bluish when sharing the video

When you make a video, you could save it and shared it with Whatsapp. The video appears to be normal in Gallery, however, when you shared it with Whatsapp, the video become "bluish" and the recipients receive "bluish" video as well. It only happens when sharing video via Whatsapp. Local pictures, local video and sharing pictures via Whatsapp appear to be normal.

An example of "bluish" video is as follow (This is snapshot from a video where the camera is pointing to a brown flooring)

There are a few solutions you could try

Resetting Camera Setting

You can try to fix the coloring problem by resetting the device camera setting. Different phone manufacturers have different ways to reset the camera setting. For Samsung phone, you can reset your camera setting as follow

1. Launch your camera
2. Locate a setting icon similar to the following

3. Locate a Reset option and click on it.

The reason to apply this fix is to reset the White Balance setting to default. White balance is a global adjustment of the intensities of white in a photo. A wrong setting in White Balance may create a blue tint effect. For example, if your White Balance setting in the camera is Incandescent and you are not under light bulb setting in your home, your image may appear bluish. You can try it out by take a photo with Incandescent White Balance setting under a bight sunlight environment.

You may argue that only Whatsapp video has the problem. However, it is possible that Whatsapp had cached the wrong camera setting and resetting the camera setting will removed all cache and restore to factory default camera setting.

Reinstalling Whatsapp

An alternative is to re-install Whatsapp. Since the problem persist and happen only in Whatsapp, reinstalling Whatsapp may fix the problem as it will remove all settings to the application. Before doing this, please backup your chat history.

Wednesday, January 22, 2014

Cygwin - Using alternate home root

Often, you wish to use an alternate home root in your Cygwin environment. In Cygwin Webpage, it provides the following in Example 3.11

mkpasswd -l -p "$(cygpath -H)" > /etc/passwd


-l means print local user account

-p "$(cygpath -H)" means set specific home path with cygpath command. cygpath convert Unix and Windows format path to Cygwin path (ie, /cygdrive/c/). cygpath -H means output current Home root for the current user.

To include domain users in the output, add -d switch

mkpasswd -d -l -p "$(cygpath -H)" > /etc/passwd


However, this method makes an assumption that you have write access to /etc/passwd. Normally, your system administrator does not give you write access to this file. In addition, the above command overwrite /etc/passwd which could be dangerous.

An alternative solution is to create a HOME user environmental variable in Windows.

When Cygwin start up, it checks for a HOME environmental variable in the system. If the variable is found, Cygwin will set user home path to the HOME environmental variable, else, it will default to system home root. This solution can be done by any user and less invasive

To use this solution, do the following

1. Open Environmental Variable dialog box

2. Create a HOME user environmental variable. Set the value to your desired home path

3. Apply the setting.

4. Restart your Cygwin shell and Cygwin should point your home root to your HOME environment variable. You can perform a echo $HOME or pwd to see the current setting

Tuesday, January 21, 2014

SSH - SSH Tunneling

SSH Tunneling are useful for the following scenario

1. Bypassing firewall to access certain prohibited Internet services
2. Poor man VPN

In a nutshell, SSH tunneling is forwarding a specific local port to port at a remote machine over a encrypted tunnel created by SSH protocol connection.

While there are GUI SSH clients that help to setup SSH tunnel (ie, PuTTY), below are some ssh command that will do the same

In general, the ssh tunnel command format is

ssh username@your_ssh_server -f -N -L local_port:remote_host:remote_port


-f means executes command at background
-N means do not execute a remote command
username@your_ssh_server means your ssh connection information
-L local_port:remote_host:remote_port means your binding port information

For example, if a firewall policy blocks Google access, you can try to bypass the firewall through a SSH tunnel as follows

ssh -f -N -L

The above command set up a ssh tunneling via that you have access. It forwards any request from localhost:12345 to through the ssh tunnel. So, when you type localhost:12345 at your favorite browser, it will fetch via the ssh tunnel.


Thursday, December 12, 2013

Python - Compiling Python code from py to pyc

Although Python script does not need to be explicitly compiled before running them, it is possible to manually compile them into bytes code (.pyc) from the script (.py) for better efficiency.

You can read to know more about compiling a Python code from py to pyc

Or, you can use the following command to compile a Python source file.

python -c "import py_compile; py_compile.compile('', 'test.pyc')"