Archive

Archive for the ‘Database’ Category

Backup methodology

January 9, 2012 Leave a comment

1. Full backup

A whole backup

2.Differential backup

Backup different from the full backup

eg. 0=0, 1=0+1, 2=0+2, 3=0+3, 4=0+4, 5=0+5, 6=0+6

3. Incremental backup

Backup increment from previous day

eg. 0=0, 1=0+1, 2=1+2, 3=2+3, 4=3+4, 5=4+5, 6=5+6

PS:

0 — Sunday full

1 — Sunday

2 — Tuesday

3 — Wendesday

4 — Thursday

5 — Friday

6 — Saturday

 

Categories: Database

Install Oracle11g R2 for Oracle Solaris 11 on x86-64 (64-Bit)

January 1, 2012 Leave a comment

1. Logging In to the System as root

— X window is needed

2.  Checking the Hardware Requirements

2.1 Memory Requirements

  • At least 256 MB of physical RAM.
  • To view physical memory size

# prtconf | grep “Memory size”

  • RAM & SWAP relationship
RAM Swap Space
Between 0 MB and 256 MB 3 times the size of RAM
Between 256 MB and 512 MB 2 times the size of RAM
Between 512 MB and 2 GB 1.5 times the size of RAM
Between 2 GB and 16 GB Equal to the size of RAM
More than 16 GB 16 GB
  • To view SWAP size

# swap -s

  • To view available SWAP

# sar -r 5

2.2 System architecture

# isainfo -kv

2.3 Disk Space Requirements

  • The minimum disk space requirement for a client install in the /tmpdirectory is 180 MB.To determine the amount of disk space available in the /tmpdirectory, enter the following command:
    # df -h /tmp
  • To determine the amount of free disk space available, enter the following command:
    # df -h
    Installation Type Requirement for Software Files
    Instant Client 220 MB
    Administrator 1.7 GB
    Runtime 1.4 GB

3. Checking the Software Requirements

3.1 Operating System Requirements

Have to be 5.10 or 5.11

# uname -r

3.2 Package and Patch Requirements

Verifying Packages

To determine whether the required packages are installed, enter commands similar to the following:

# pkginfo -i SUNWarc SUNWbtool SUNWhea SUNWlibC SUNWlibms SUNWsprot 
  SUNWtoo SUNWi1of SUNWi1cs SUNWi15cs SUNWxwfnt

Verifying Operating System Patches

To determine whether an operating system patch is installed, enter a command similar to the following:

# /usr/sbin/patchadd -p | grep patch_number(without version number)

For example, to determine if any version of the 119963 patch is installed, use the following command:

# /usr/sbin/patchadd -p | grep 119963

If an operating system patch is not installed, then download it from the My Oracle Support Web site and install it:

https://support.oracle.com/

3.3 Compiler Requirements

Oracle Solaris Studio 12 (C and C++ 5.9) is supported with Pro*C/C++, Oracle Call Interface, Oracle C++ Call Interface, and Oracle XML Developer’s Kit (XDK) for Oracle Database 11g Release 2.

3.4 Additional Software Requirements

3.4.1 Oracle JDBC/OCI Drivers

JDK 7, JDK 6 or JDK

4. Creating Required Operating System Group and User

The following local operating system groups and users are required if you are installing Oracle Database:

  • The Oracle Inventory group (typically, oinstall)
  • The Oracle software owner (typically, oracle)

To determine whether these group and user exist, and if necessary, to create them, follow these steps:

  1. To determine whether the oinstallgroup exists, enter the following command:
    # more /var/opt/oracle/oraInst.loc

    If the output of this command shows the oinstall group name, then the group exists.

    If the oraInst.loc file exists, then the output from this command is similar to the following:

    inventory_loc=/u01/app/oracle/oraInventory
    inst_group=oinstall

    The inst_group parameter shows the name of the Oracle Inventory group, oinstall.

  2. If necessary, enter the following commands to create the oinstallgroup:
    # /usr/sbin/groupadd oinstall
  3. To determine whether the oracleuser exists and belongs to the correct groups, enter the following command:
    # id -a oracle

    If the oracle user exists, this command displays information about the groups to which the user belongs. The output should be similar to the following, indicating that oinstall is the primary group and dba is a secondary group:

    uid=440(oracle) gid=200(oinstall) groups=201(dba),202(oper)
  4. If necessary, complete one of the following actions:
    • If the oracle user exists, but its primary group is not oinstall or it is not a member of the dbagroup, then enter the following command:
      # /usr/sbin/usermod -g oinstall -G dba oracle
    • If the oracleuser does not exist, enter the following command to create it:
      # /usr/sbin/useradd -m -g oinstall [-G dba] oracle

      This command creates the oracle user and specifies oinstall as the primary group and dba as an optional secondary group.

  5. Enter the following command to set the password of the oracleuser:
    # passwd oracle

5. Creating Required Directories

To create the required directories and specify the correct owner, group, and permissions for them:

Note:

In the following procedure, replace /u01 and /u02 with the appropriate mount point directories that you identified in Step 3 previously.

  1. Enter the following command to create subdirectories in the mount point directory that you identified for the Oracle base directory:
    # mkdir -p /u01/app/oracle
  2. If you intend to use a second file system for the Oracle Database files, then create an oradata subdirectory in the mount point directory that you identified for the Oracle data file directory (shown as /u02in the examples):
    # mkdir /u02/oradata
  3. Change the owner and group of the directories that you created to the oracle user and the oinstallgroup:
    # chown -R oracle:oinstall /u01/app/oracle
    # chown -R oracle:oinstall /u02/oradata
  4. Change the permissions on the directories that you created to 775:
    # chmod -R 775 /u01/app/oracle
    # chmod -R 775 /u02/oradata

6. Configuring the oracle User’s Environment

You run Oracle Universal Installer from the oracle account. However, before you start Oracle Universal Installer, you must configure the environment of the oracle user. To configure the environment, you must:

  • Set the default file mode creation mask (umask) to 022 in the shell startup file.
  • Set the DISPLAY environment variable.

To set the oracle user’s environment:

  1. Start a new terminal session, for example, an X terminal (xterm).
  2. Enter the following command to ensure that X Window applications can display on this system:
    $ xhost fully_qualified_remote_host_name

    For example:

    $ xhost somehost.us.example.com
  3. If you are not logged in to the system where you want to install the software, then log in to that system as the oracle user.
  4. If you are not logged in as the oracle user, then switch user to oracle:
    $ su - oracle
  5. To determine the default shell for the oracleuser, enter the following command:
    $ echo $SHELL
  6. To run the shell startup script, enter one of the following commands:
    • Bash shell:
      $ . ./.bash_profile
    • Bourne or Korn shell:
      $ . ./.profile
    • C shell:
      % source ./.login
  7. If you are not installing the software on the local computer, then run the following command on the remote system to set the DISPLAYvariable:
    • Bourne, Bash or Korn shell:
      $ export DISPLAY=local_host:0.0
    • C shell:
      % setenv DISPLAY local_host:0.0

    In this example, local_host is the host name or IP address of the local computer to use to display Oracle Universal Installer.

    Run the following command on the remote system to check if the shell and the DISPLAY environmental variable are set correctly:

    echo $SHELL
    echo $DISPLAY

    Now to enable X applications, run the following commands on the local computer:

    $ xhost + fully_qualified_remote_host_name

    To verify that X applications display is set properly, run a X11 based program that comes with the operating system such as xclock:

    $ xclock

    In this example, you can find xclock at /usr/X11R6/bin/xclocks. If the DISPLAY variable is set properly, then you can see xclock on your computer screen.

    See Also:

    PC-X Server or operating system vendor documents for further assistance

  8. If you determined that the /tmp directory has less than 1 GB of free disk space, then identify a file system with at least 1 GB of free space and set the TMP and TMPDIRenvironment variables to specify a temporary directory on this file system:
    1. To determine the free disk space on each mounted file system use the following command:
      # df -h /tmp
    2. If necessary, enter commands similar to the following to create a temporary directory on the file system that you identified, and set the appropriate permissions on the directory:
      $ sudo mkdir /mount_point/tmp
      $ sudo chmod a+wr /mount_point/tmp
      # exit
    3. Enter commands similar to the following to set the TMP and TMPDIRenvironment variables:
      • Bourne, Bash, or Korn shell:
        $ TMP=/mount_point/tmp
        $ TMPDIR=/mount_point/tmp
        $ export TMP TMPDIR
      • C shell:
        % setenv TMP /mount_point/tmp
        % setenv TMPDIR /mount_point/tmp
  9. Enter commands similar to the following to set the ORACLE_BASE and ORACLE_SIDenvironment variables:
    • Bourne, Bash, or Korn shell:
      $ ORACLE_BASE=/u01/app/oracle
      $ ORACLE_SID=sales
      $ export ORACLE_BASE ORACLE_SID
    • C shell:
      % setenv ORACLE_BASE /u01/app/oracle
      % setenv ORACLE_SID sales

    In this example, /u01/app/oracle is the Oracle base directory that you created or identified earlier and sales is the database name (typically no more than five characters).

  10. Enter the following commands to ensure that the ORACLE_HOME and TNS_ADMINenvironment variables are not set:
    • Bourne, Bash, or Korn shell:
      $ unset ORACLE_HOME
      $ unset TNS_ADMIN
    • C shell:
      % unsetenv ORACLE_HOME
      % unsetenv TNS_ADMIN

    Note:

    If the ORACLE_HOME environment variable is set, then Oracle Universal Installer uses the value that it specifies as the default path for the Oracle home directory. However, if you set the ORACLE_BASE environment variable, then Oracle recommends that you unset the ORACLE_HOME environment variable and choose the default path suggested by Oracle Universal Installer.

7. Mounting the Product Disc

On most Oracle Solaris systems, the product disc mounts automatically when you insert it into the drive. If the disc does not mount automatically, then follow these steps to mount it:

  1. Switch user to root:
    $ su - root
  2. If necessary, enter a command similar to the following to eject the currently mounted disc, then remove it from the drive:
    # eject
  3. Insert the disc into the disc drive.
  4. To verify that the disc mounted automatically, enter a command similar to the following:
    # ls /dvd/dvd0
  5. If this command fails to display the contents of the disc, then enter a command similar to the following:
    # /usr/sbin/mount -r -F hsfs /dev/dsk/cxtydzs2 /dvd

    In this example, /dvd is the disc mount point directory and /dev/dsk/cxtydzs2 is the device name for the disc device, for example /dev/dsk/c0t6d0s2.

  6. If Oracle Universal Installer displays the Disk Location dialog box, then enter the disc mount point directory path. For example:
    • Disc mounted automatically:
      /dvd/dvd0
    • Disc mounted manually:
      /dvd
  7. For Database software installation:

unzip solaris.x64_11gR2_database_1of2.zip
unzip solaris.x64_11gR2_database_2of2.zip

8. Installing Oracle Database Client

After configuring the oracle user’s environment, start Oracle Universal Installer and install Oracle Database as follows:

To start Oracle Universal Installer, enter the following command:

$ /mount_point/db/runInstaller

9. Log in the Oracle

To become familiar with this release of Oracle Database, it is recommended that you complete the following tasks:

  • Log in to Oracle Enterprise Manager Database Control using a Web browser.Oracle Enterprise Manager Database Control is a Web-based application that you can use to manage a single Oracle Database installation. The default URL for Database Control is similar to the following:
    http://host.domain:1158/em/

    To log in, use the user name SYS and connect as SYSDBA. Use the password that you specified for this user during the Oracle Database 11g installation.

Refer to Oracle document link.
Categories: Oracle

Load text file into SQL Server

November 3, 2011 Leave a comment

Example:

BULK
INSERT Test
FROM 'c:testFile.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = 'n'
)
GO


==================== Syntax of BULK INSERT for T-SQL =======================

BULK INSERT
   [ database_name . [ schema_name ] . | schema_name . ] [ table_name | view_name ]
      FROM 'data_file'
     [ WITH
    (
   [ [ , ] BATCHSIZE = batch_size ]
   [ [ , ] CHECK_CONSTRAINTS ]
   [ [ , ] CODEPAGE = { 'ACP' | 'OEM' | 'RAW' | 'code_page' } ]
   [ [ , ] DATAFILETYPE =
      { 'char' | 'native'| 'widechar' | 'widenative' } ]
   [ [ , ] FIELDTERMINATOR = 'field_terminator' ]
   [ [ , ] FIRSTROW = first_row ]
   [ [ , ] FIRE_TRIGGERS ]
   [ [ , ] FORMATFILE = 'format_file_path' ]
   [ [ , ] KEEPIDENTITY ]
   [ [ , ] KEEPNULLS ]
   [ [ , ] KILOBYTES_PER_BATCH = kilobytes_per_batch ]
   [ [ , ] LASTROW = last_row ]
   [ [ , ] MAXERRORS = max_errors ]
   [ [ , ] ORDER ( { column [ ASC | DESC ] } [ ,...n ] ) ]
   [ [ , ] ROWS_PER_BATCH = rows_per_batch ]
   [ [ , ] ROWTERMINATOR = 'row_terminator' ]
   [ [ , ] TABLOCK ]
   [ [ , ] ERRORFILE = 'file_name' ]
    )]

Categories: Database, SQL Server

Install MySQL under CentOS via yum

October 2, 2011 Leave a comment

1. Install MySQL

#yum install mysql mysql-devel mysql-server

2. Set MySQL as a service and auto run with system

# chkconfig –add mysqld
# chkconfig –level 3 mysqld on

3. Set password for root — for first time only

# service mysqld start

# mysqladmin -u root password ‘new-password’

4. Test MySQL running

# mysql -u root -p

mysql> show databases;
+——————–+
         | Database           |
        +——————–+
         | information_schema |
         | mysql              |
         | test               |
        +——————–+
        3 rows in set (0.00 sec)

mysql> use test;
Database changed
mysql> show tables;
Empty set (0.00 sec)

Categories: CentOS, MySQL