Oracle Tablespaces Usage Query: Bytes used, Bytes free, Percent used

7Oct2011 In: Oracle

Example query to check free,used space and Percent used per tablespace:

         a.BYTES bytes_used,
         b.BYTES bytes_free,
         round(((a.BYTES-b.BYTES)/a.BYTES)*100,2) percent_used
                select  TABLESPACE_NAME,
                        sum(BYTES) BYTES
                from     dba_data_files
                group   by TABLESPACE_NAME
                select  TABLESPACE_NAME,
                        sum(BYTES) BYTES ,
                        max(BYTES) largest
                from     dba_free_space
                group   by TABLESPACE_NAME
order   by ((a.BYTES-b.BYTES)/a.BYTES) desc

Sample output:

------------------------------ ---------- ---------- ---------- ------------
SYSTEM    1101004800    12648448    9371648    98.85
USERS    4806082560    311296000    152043520    93.52
SYSAUX    1145372672    77856768    53739520    93.2
EXAMPLE    104857600    23724032    20905984    77.38
AG_INDX2    5368709120    1396768768    320864256    73.98
AG_DATA1    5368709120    1641086976    506462208    69.43
AG_INDX3    10737418240    3517972480    901120000    67.24
AG_INDX1    5368709120    1947795456    586219520    63.72
AG_DATA2    10737418240    4090298368    987103232    61.91
AG_DATA3    10737418240    5334171648    1006632960    50.32
AG_DATA4    5368709120    2759720960    339738624    48.6
AG_INDX4    5368709120    4873191424    3503292416    9.23
UNDOTBS1    2034237440    2020278272    1898840064    0.69

Create Tablespaces in Oracle

7Oct2011 In: Oracle

A tablespace is a storage location where the actual data underlying database objects can be kept, it is a logical storage unit within an Oracle database and not visible in the file system of the machine on which the database resides.

We can simply Use the CREATE TABLESPACE statement to create a tablespace, which is an allocation of space in the database that can contain schema objects.

  1. A permanent tablespace are permanently stored in datafiles with persistent schema objects.
  2. An undo tablespace is a type of permanent tablespace used by Oracle Database to manage undo data if you are running your database in automatic undo management mode. Oracle strongly recommends that you use automatic undo management mode rather than using rollback segments for undo.
  3. A temporary tablespace are temporary stored in tempfiles which is visible only for the duration of a session.

Read the rest of this entry »

Oracle import/export Utilities: imp and exp

7Oct2011 In: Oracle

Oracle’s export (exp/expdp) and import (imp/impdp) utilities are used to perform logical database backup and recovery. When exporting, database objects are dumped to a binary file which can then be imported into another Oracle database.

These utilities can be used to move data between different machines, databases or schema. However, as they use a proprietary binary file format, they can only be used between Oracle databases. One cannot export data and expect to import it into a non-Oracle database. Read the rest of this entry »

Java Access Modifiers: Public, Protected, Friendly and Private

7Oct2011 In: Core Java

The access to classes, constructors, methods and fields are regulated using access modifiers in Java, by signing the access Modifiers, a class or method can control what information or data would be exposed to other classes, the developer can take full advantage of java access modifiers to maximize re-usability and refectory. Read the rest of this entry »

Eclipse plugin Cobertura, Clover and Eclemma for TestNG coverage

7Oct2011 In: TestNG

TestNG is a popular Java testing framework, Eclipse is a multi-language software development environment comprising an integrated development environment (IDE) and an extensible plug-in system. it is mostly we used Eclipse as IDE and TestNG as Unit testing framework. So that is helpful to use Eclipse plugin to help us analyze code coverage for TestNG unit tests. Here is some options: Read the rest of this entry »

How to Release system-wide(Global) Hotkeys, Keyboard Shortcut in Java

7Oct2011 In: Core Java

Here is one way to perform a system-wide (global) keyboard shortcut in out-of-JVM applications.

package com.asjava;

import java.awt.*;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;

public class Main {
    public static void main(String[] args) throws Exception {

        java.awt.datatransfer.Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        Transferable tText = new StringSelection("Where this come from?");
        clipboard.setContents(tText, null);

        Robot robot = new Robot();

        //Press Hotkey Ctrl+V

        //Typing something

        //Moving mouse to location(0,0)
        robot.mouseMove(0, 0);

When starting this program, please switch the focused window to another windows/OS-defined application(for example: notepad) to see what happen.

TestNG tutorial – Time Test with Annotation Timeout

6Nov2010 In: TestNG

Some test cases may expect longer time to excute, in order to avoid take more than the specified number of milliseconds or not to block TestNG forever, we specify a timeout in the @Test annotation, if a unit case takes more than the expected time, ThreadPoolExecutor will be interrupted and test case will be terminated and mark it as failure. Read the rest of this entry »

TestNG tutorial – Ignore Test

6Nov2010 In: TestNG

Annotation @ignore in TestNG allows a test to be deffered until it is ready (or the feature is). In TestNG, you can use annotation @Test(enabled = false) to bypass one test case if it is not ready to test.

package com.asjava;

import org.testng.annotations.*;

public class TestNGIgnoreTest {

    @Test(enabled = false)
    public void testsetProperty() {
        String path = this.getClass().getResource("/").getPath();
        System.setProperty("CurrentDir", path);
        assert ("c:/testProject".equals(System.getProperty("CurrentDir")));
        System.out.println("Method is not ready yet");

In this example, the test TestNGIgnoreTest is skipped, so it is a exclusion of tests by group to execute. If you are not familiar how to run testng test case, please get first chance reading TestNG Tutorial and Example: Getting Started Run TestNG test

TestNG Tutorials – Expectedexception Test

27Oct2010 In: TestNG

This is a consequence of the fact that exceptions are expected in a unit case.

What is traditional testing design pattern to do Expectedexception test?

package com.asjava;

import org.testng.Assert;
import org.testng.annotations.Test;

import java.util.List;

public class TestNGExpectedExceptionTest extends Assert {

    public void testNullPointerException() {
        try {
            List list = null;
            int size = list.size();
            fail("The test should have failed");
        } catch (NullPointerException e) {
            // success, do nothing: the test will pass

This is somehow popular testing design pattern in the past, it reverse logic (“pass if an exception is thrown, fail when all goes well”). Read the rest of this entry »

TestNG Basic Concepts and Annotations

22Oct2010 In: TestNG

TestNG engine supports a series of annotations, with these annotations it even has stronger flexibility and extensibility than Junit, we will learn these annotations from this tutorial,  first of all, let us take a quick view the life cycle of a typical TestNG case. Read the rest of this entry »