Monday, November 3, 2008

Clone Oracle 10gDB

How to Clone Oracle 10g Database

Oracle Database Cloning:
Larry Catt
Larry.catt@platinumsolutions.com

Cloning and 10g DBCA:

With the release of 10g, a database can be cloned from one location to another by use of the Oracle database Creation Assistant. However, this feature along with many of the new 10g features is worrisome to the veteran database administration crowd. The main reason for this worry is the lack of knowledge our junior associates are getting due to the new EM tool. They are not able to function in a telnet environment and trying to get them to perform any tasks using SQL*Plus is nearly impossible. Do not miss our point. The new EM tool provided by Oracle is a great improvement over past enterprise manager versions, however every tool has its place and a DBA must know far more than a GUI. The instruction set detailed below for the cloning of an oracle database is valid in multiple versions of Oracle from 8.1.5 to 10g and has the added benefit of being performed over a telnet or ssh connection.

Reason for Cloning:

In every oracle development and production environment there will become the need to transport the entire database from one physical machine to another. This copy may be used for development, production testing, beta testing, etc, but rest assured that this need will arise and management will ask you to perform this task quickly. Listed below are the most typical uses:

1. Relocating an Oracle database to another machine.
2. Moving Oracle database to new Storage media.
3. Renaming Oracle database.

Instructions:

1. Ensure that your database is recoverable back to original location and state by backing it up before executing this procedure:

Database in NON-ARCHIVE LOG MODE - take an off-line database backup.
Database in ARCHIVELOG MODE - take an on-line or off-line database backup.

2. Connect to sql*plus as the user ‘SYS AS SYSDBA’ and ensure that all users have logged off the system by executing the following command.

SQL> connect / as sysdba
Connected.
SQL> select username from v$session;
SQL> select username from v$session;
USERNAME
------------------------------




SYS
8 rows selected.
SQL>

You should see several fields returning with no username (these are internal oracle logins and the will not affect your operations) and one SYS login (this is you).

3. Place the system in restricted mode:

SQL> alter system enable restricted session;

System altered.

4. Connect as SYS with SYSDBA privileges and execute the following SQL command:

SQL> connect / as sysdba
Connected.
SQL> alter database backup controlfile to trace;
SQL>

The [alter database backup controlfile to trace;] command will generate a SQL script that can be used to regenerate the database.

5. Execute the sql*plus command show parameter to find your user dump directory.

SQL> show parameter user_dump_dest
NAME TYPE VALUE
-------------------------- ----------- ------------------------------
user_dump_dest string /opt/app/oracle/product/admin/orcl/udump

6. Exit to the OS layer and move to the user_dump_dest directory. Trace file names are generated by oracle in the following format [instance_name]+[oracle generated number].trc, so use the timestamp to locate the last trace file generated. Open the file in a text editor and remove everything above the ‘STARTUP NOMOUNT ..' statement. Alter the ‘CREATE CONTROLFILE’ statement for the following uses:

Rename DB in Archivelog mode:
CREATE CONTROLFILE SET DATABASE "new_db_name" RESETLOGS
ARCHIVELOG

Rename DB in Non-Archivelog mode:
CREATE CONTROLFILE SET DATABASE "new_db_name" NORESETLOGS
NOARCHIVELOG

Reuse DB name in Archivelog mode:
CREATE CONTROLFILE REUSE DATABASE "db_name" RESETLOGS ARCHIVELOG

Reuse DB name in Non-Archivelog mode:
CREATE CONTROLFILE REUSE DATABASE "db_name" NORESETLOGS
NOARCHIVELOG


7. Edit the rest of this file to reference the correct locations of you log files, datafiles and temp files.

8. Move the trace file to an appropriate location and name to recreate_db.sql.

9. Connect as SYS with SYSDBA privileges and shutdown the database in immediate mode:
SQL> connect / as sysdba
Connected.
SQL> shutdown immediate

10. Move the following files to there corresponding locations in updated recreate_db.sql file.
DATAFILES
Log files

NOTE: Do not move your old control files or temp files to the new location.

11. Restore or copy the backup and the archived logs (if any) to the new machine.

12. Move your INIT$ORACLE_SID.ORA file to its new location. Ensure your controlfile and archive destinations in INIT are set properly to the new locations.

13. Connect to SQLPLUS on your new machine as SYS AS SYSDBA and run create_db.sql script as follows:

SQL> @[directory_location]/create_db.sql

14. Change the global database name if you renamed your database as follows:

SQL> ALTER DATABASE RENAME GLOBAL_NAME = new_db_name;

15. Perform full system backup and store in a safe location.

NOTE: This new backup will be you starting point for recovery in the new database location.

You have completed database cloning procedure.


For assistance with Oracle Products, you can contact Larry.catt@Platinumsolutions.com.








Ubuntu Add New Harddisk

1. VM Ware create new Harddisk

2. Check New Disk Hardware

$fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0007b6b3

Device Boot Start End Blocks Id System
/dev/sda1 * 1 1244 9992398+ 83 Linux
/dev/sda2 1245 1305 489982+ 5 Extended
/dev/sda5 1245 1305 489951 82 Linux swap / Solaris

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x6115b0a0

Device Boot Start End Blocks Id System
/dev/sdb1 1 1305 10482381 83 Linux

Disk /dev/sdc: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Disk /dev/sdc doesn't contain a valid partition table


3. Initiate fdisk with the following command:

$sudo fdisk /dev/sdc

=>Fdisk will display the following menu

Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help):

=> We want to add a new partition. Type "n" and press enter.

Command action
e extended
p primary partition (1-4)

=>We want a primary partition. Enter "p" and enter.

Partition number (1-4):

=>Since this will be the only partition on the drive, number 1. Enter "1" and enter.

Command (m for help):

=> Now that the partition is entered, choose option "w" to write the partition table to the disk. Type "w" and enter.

The partition table has been altered!

=>If all went well, you now have a properly partitioned hard drive that's ready to be formatted.

4. Format New Disk
Format the Partition via Command Line To format the disk as ext3 filesystem (best for use under Ubuntu):

Substitute "/dev/sdc1" with your own drive's path.

$sudo mke2fs -j /dev/sdc1


mke2fs 1.40.8 (13-Mar-2008)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1966080 inodes, 7863809 blocks
393190 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
240 block groups 32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000


Writing inode tables: done
Creating journal (32768 blocks):
done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 26 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.

$sudo fdisk -l


5. Create New mount path

$sudo mkdir /d02/oracle

$chmod 777 /d02/oracle

$mount /dev/sda2 /d02/oracle

5. Set Auto mount

vi /etc/fstab



The text editor window will appear with the fstab file loaded up. You will see something that looks kind of like this:

# /etc/fstab: static file system information.
#
# proc /proc proc defaults 0 0
/dev/hda1 / ext3 defaults,errors=remount-ro 0 1
/dev/hda5 none swap sw 0 0
/dev/hdb1 /media/hdb1 ext3 defaults 0 0
/dev/hdc /media/cdrom0 udf,iso9660 user,noauto 0 0
/dev/fd0 /media/floppy0 auto rw,user,noauto 0 0

All you have to do is add a new line for the new drive…
I will add the following line to my fstab for my new drive:

/dev/sdc1 /media/linuxstore ext3 defaults 0 0

$ sudo mount -a

Friday, October 31, 2008

Unix Command

1. Disk Usage
#du -sk (Show summary disk usage in K byte)
#du -k (Show detail disk usage in K byte)
2. Find text on File.
$find . grep filename
3. Search String
Unix
====
$strings -a XXXX.exe | grep header
Windows
=======
C:>find /N "Version" XXXX.exe

FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]]

/V Displays all lines NOT containing the specified string.
/C Displays only the count of lines containing the string.
/N Displays line numbers with the displayed lines.
/I Ignores the case of characters when searching for the string.
/OFF[LINE] Do not skip files with offline attribute set.
"string" Specifies the text string to find.
[drive:][path]filename
Specifies a file or files to search.

If a path is not specified, FIND searches the text typed at the prompt
or piped from another command.

4. Replace word

sed s/"opt"/"d02"/g create_nsdb.sql>create_nsdb.sql.new


5. Remove ^M from file by $vi

On Vi Screen

:%s/^V^M//g

The ^v is a CONTROL-V character and ^m is a CONTROL-M. When you type this, it will look like this:

6. tar

pack file $tar -cvf tar-file directory

unpack $tar -xvf tar-file







Tuesday, October 14, 2008

PostgreSQL Command on Ubuntu

1. Start/Stop PostgreSQL Database

root@postgre:~# sudo /etc/init.d/postgresql-8.3 stop
* Stopping PostgreSQL 8.3 database server [ OK ]
root@postgre:~# sudo /etc/init.d/postgresql-8.3 start
* Starting PostgreSQL 8.3 database server [ OK ]

Thursday, October 9, 2008

Ubuntu Command

Install ksh shell
-----------------
$sudo apt-get install ksh

Environment
-----------
$sudo vi /etc/environment

Friday, October 3, 2008

Oracle Startup Oracle Database on Linux

1. คำสั่ง Start Oracle Console
Your_Server_Shell> $ORACLE_HOME/bin/emctl start dbconsole
http://localhost:1158/em
2. export ORACLE_HOME=path i.e. /opt/oracle/production/10gR2
export ORACLE_SID=instance database i.e. PROD or TEST
3. คำสั่ง Start Database Instance
- shell> $ORACLE_HOME/bin/sqlplus sys/password_sys as sysdba
- sqlplus>startup
- shell> $ORACLE_HOME/bin/lsnrctl start
- shell> $ORACLE_HOME/bin/emctl start dbconsole

การสร้าง auto startup เมื่อ boot เครื่อง ไว้ใน /etc/init.d/oracle ครับ
#!/bin/bash

ORA_HOME="/u01/app/oracle/product/10.1.0/Db\_1"
ORA_OWNR="oracle"
ORACLE_SID="dev"

# if the executables do not exist -- display error

if [ ! -f $ORA_HOME/bin/dbstart -o ! -d $ORA_HOME ]
then
echo "Oracle startup: cannot start"
exit 1
fi

# depending on parameter -- startup, shutdown, restart
# of the instance and listener or usage display

case "$1" in
start)
# Oracle listener and instance startup
echo -n "Starting Oracle: "
su - $ORA_OWNR -c "$ORA_HOME/bin/lsnrctl start"
su - $ORA_OWNR -c $ORA_HOME/bin/dbstart
su - $ORA_OWNR -c "$ORA_HOME/bin/emctl start dbconsole"
touch /var/lock/subsys/oracle
echo "OK"
;;
stop)
# Oracle listener and instance shutdown
echo -n "Shutdown Oracle: "
su - $ORA_OWNR -c "$ORA_HOME/bin/lsnrctl stop"
su - $ORA_OWNR -c $ORA_HOME/bin/dbshut
su - $ORA_OWNR -c "$ORA_HOME/bin/emctl stop dbconsole"
rm -f /var/lock/subsys/oracle
echo "OK"
;;
reload|restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 start|stop|restart|reload"
exit 1
esac
exit 0

##อย่าลืมแก้ค่า ORA_OWNR, ORA_HOME, ORACLE_SID
แล้ว ln -s /etc/init.d/oracle /etc/rc{3,5}.d/S99oracle
และ ln -s /etc/init.d/oracle /etc/rc{0,6}.d/K01oracle
แล้วจะเลือกว่าจะให้ DB ไหน AutoStart บ้างก็ไปแก้ที่ /etc/oratab ครับ อันหลังสุดให้เปลี่ยนเป็น Y

Thursday, October 2, 2008

Oracle 10g on Ubuntu 8.40

  1. Login to ubuntu from your usual administrative account which has sudo access

  2. Make sure you have enough ram, swap space and disk space as per oracle requirements.

  3. Install the required packages (first make sure ‘universe’ is enabled in your sources.list):

    • sudo apt-get install build-essential libaio rpm lesstif2-dev alien

    • apt-get install gcc libaio1 libc6 libstdc++5 make lesstif2 lesstif2-dev rpm

  4. Create the users and groups oracle needs:

    • sudo groupadd oinstall

    • sudo groupadd dba

    • sudo groupadd nobody

    • sudo useradd -g oinstall -G dba,nobody -d /opt/oracle -s /bin/bash oracle

  5. Set oracle user’s password

    • sudo passwd oracle

  6. Create the directory for the software installation and assign ownership to oracle:oinstall

    • sudo mkdir /opt/oracle

    • sudo chown -R oracle:oinstall /opt/oracle

    • sudo chmod -R 775 /opt/oracle

  7. In another console, login as oracle to make sure it works fine, then logout.

  8. Append user oracle’s .bashrc with PATH and ORACLE:BASE,HOME and SID information

    • sudo vi /opt/oracle/.bashrc

    • export ORACLE_BASE=/opt/oracle

    • export ORACLE_HOME=$ORACLE_BASE/product/10gR2

    • export ORACLE_SID=orcl

    • export PATH=$PATH:$ORACLE_HOME/bin

  9. Make sure the correct kernel parmeters are appended to /etc/sysctl.conf

    • kernel.shmall = 2097152

    • kernel.shmmax = 2147483648

    • kernel.shmmni = 4096

    • kernel.sem = 250 32000 100 128

    • net.core.rmem_default = 262144

    • net.core.rmem_max = 262144

    • net.core.wmem_default = 262144

    • net.core.wmem_max = 262144

    • fs.file-max = 65536

    • net.ipv4.ip_local_port_range = 1024 65000

  10. Set the kernel parameters or reboot

    • /sbin/sysctl -p

  11. Set /etc/security/limits.conf

    • * soft nproc 2047

    • * hard nproc 16384

    • * soft nofile 1024

    • * hard nofile 65536

  1. Create symbolic links and camoflage Kubuntu to look more like an enterprise rpm based distro because the oracle installer is expecting rhel, sles or asianux based distros.

    • sudo ln -s /usr/bin/awk /bin/awk

    • sudo ln -s /usr/bin/rpm /bin/rpm

    • sudo ln -s /lib/libgcc_s.so.1 /lib/libgcc_s.so

    • sudo ln -s /usr/bin/basename /bin/basename

  2. Mount the Oracle10g CD and run the installer

    • /runInstaller -ignoreSysPrereqs

  3. Installation will be uneventful provided above steps are followed

  4. Enable the oracle user to dbshut, dbstart and lsnrctl start

    • sudo vi /etc/oratab and change :N to :Y


Monday, July 14, 2008

PostgreSQL ทำ Backup & Restore ด้วย pg_dump


การทำ Backup และ Restore PostgreSQL บน Linuz Server

Step # 1: Login as a pgsql user

Type the following command:
$ su - pgsqlGet list of database(s) to backup:
$ psql -l

Step # 2: Make a backup using pg_dump

Backup database using pg_dump command. pg_dump is a utility for backing up a PostgreSQL database. It dumps only one database at a time. General syntax:pg_dump databasename > outputfile
Task: dump a payroll database
Type the following command
$ pg_dump payroll > payroll.dump.out

To restore a payroll database:
$ psql -d payroll -f payroll.dump.out

OR$ createdb payroll$ psql payroll
However, in real life you need to compress database:
$ pg_dump payroll gzip -c > payroll.dump.out.gz

To restore database use the following command:
$ gunzip payroll.dump.out.gz$ psql -d payroll -f payroll.dump.out

Here is a shell script for same task:

#!/bin/bash
DIR=/backup/psq
#[ ! $DIR ] && mkdir -p $DIR :
[ !$DIR ] && mkdir -p $DIR :
LIST=$(psql -l awk ‘{ print $1}’ grep -vE ‘^-^List^Nametemplate[01]^\(’)
#LIST=$(psql -l awk '{ print $1}' grep -vE '^-^List^Nametemplate[01]')

for d in $LIST
do
pg_dump $d gzip -c > $DIR/$d.out.gz
done

Another option is use to pg_dumpall command. As a name suggest it dumps (backs up) each database, and preserves cluster-wide data such as users and groups. You can use it as follows:

$ pg_dumpall > all.dbs.out

Or

$ pg_dumpall gzip -c > all.dbs.out.gz

To restore backup use the following command:

$ psql -f all.dbs.out postgres



$pg_dump -U devdba -d devdb -p 5438 -F c -b -v -f devdb.dmp

Saturday, July 12, 2008

ติดตั้ง VMWare บน WindowsXP

ติดตั้ง VMWare บน WindowsXP

โปรแกรม VMWare เป็นโปรแกรมที่ใช้เพื่อสร้างคอมพิวเตอร์เสมือน (Virtual Machine) ขึ้นบนระบบปฏิบัติการเดิมที่มีอยู่ มีประโยชน์ในการทดสอบ ติดตั้ง(Deploy)ซอฟท์แวร์ที่พัฒนาขึ้นในระบบปฏิบัติการที่ต่างกัน เช่น Linux , Solaris ทำให้เครื่องคอมพิวเตอร์ที่ลงระบบปฏิบัติการ Windows XP อยู่เดิม แล้วทำการลงระบบปฏิบัติการ Windows NT ผ่านโปรแกรม VMWare อีกทีหนึ่ง ซึ่งเมื่อลงแล้ว ทั้งสองระบบสามารถทำงานพร้อมกันได้โดยแยกจากกันค่อนข้างเด็ดขาด (เสมือนเป็นคนละเครื่อง) โดยคอมพิวเตอร์เสมือนที่สร้างขึ้นมานั้น จะมีสภาพแวดล้อมเหมือนกับคอมพิวเตอร์จริงๆ เครื่องหนึ่ง ซึ่งจะประกอบด้วย พื้นที่ดิสก์ที่ใช้ร่วมกับพื้นที่ดิสก์ของเครื่องนั้นๆ การ์ดแสดงผล การ์ดเน็ตเวิร์ก พื้นที่หน่วยความจำซึ่งจะแบ่งการทำงานมาจากหน่วยความจำของเครื่องนั้นๆ เช่นกัน ปัจจุบันโปรแกรม VMWare มีเวอร์ชันทั้งสำหรับการทำงานบน Windows และ Linux หากเครื่องท่านเป็น Windows ก็สามารถลองเวอร์ชันสำหรับ Windows ได้ โดยท่านสามารถเข้าไปโหลดโปรแกรมมาทดลองใช้งานได้ที่


http://en.wikipedia.org/wiki/VMware_Server

http://www.vmware.com/

ความหมาย Virtual machine เครื่องจักรเสมือน
http://en.wikipedia.org/wiki/Virtual_machine

SME-ERP สำหรับธุรกิจขนาดกลางขนาดเล็ก

SME-ERP สำหรับธุรกิจขนาดกลางขนาดเล็ก
ธุรกิจ ERP Software ปี 2008 ได้ปรับตัวตามยุคโลกาภิวัตน์ ที่เหลือค่ายผู้ผลิต ERP ขนาดให้อยู่ 2 ค่าย ที่ครองส่วนแบ่งของตลาดขนาดใหญ่ เช่นเดียวกับ Pepsi และ Coke การกำหนดราคา การให้บริการ ลักษณะและคุณสมบัติ Feature & Function การใช้งานขึ้นกับ ความต้องการของผู้ใช้ส่วนใหญ่ทั่วโลก การติดตั้ง ERP เพื่อการใช้งานจะเป็นการปรับ ขั้นตอนการทำงานขององค์กรให้เข้ากับ ซอฟท์แวร์ที่ถูกออกแบบเป็นมาตรฐานสำหรับทุกประเทศ ดังนั้นจึงเป็นการยากที่องค์กร/บริษัทขนาดกลางและขนาดเล็ก จะใช้งาน ERP ขนาดใหญ่ได้เต็มรูปแบบ ในประเทศไทย บริษัทที่ใช้ ERP Software ขนาดใหญ่ส่วนใหญได้รับอิทธิพลมาจาก บริษัทคู่ค้าที่เป็นลูกค้าหลักใช้อยู่ ไม่ว่าจะเป็นอุตสาหกรรม Harddisk , Automobile หรือธุกิจที่ต้องพึงพา บริษัทขนาดใหญ่

Opensorce ERP เป็นทางออกที่ธุรกิจ ขนาดกลางและขนาดเล็กในประเทศ จะสามารถได้ใช้ระบบ ERP ที่มีฟังค์ชั่น การใช้งานเทียบเท่ากับ ERP ขนาดใหญ่จากต่างประเทศ และเหมาะสมกับขนาดขององค์กร

7-Jul-2008 เริ่มต้น พัฒนา THAI SME ERP เพื่ออิสรภาพของคนไทย


นภดล