Showing posts with label instantClient. Show all posts
Showing posts with label instantClient. Show all posts

Thursday, April 15, 2010

Learn to install SQL*Plus(Instant Client) or Learn More...

Installation PHP + OCI8, we have to use Instant Client Package(Basic) and Instant Client Package(SDK). but If we need to use SQL*Plus to test something by connection to Oracle Database. We have to use Instant Client Package(Basic) and Instant Client Package(SQL*Plus).
$ unzip oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64.zip
Archive: oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64.zip
inflating: instantclient_11_2/BASIC_README
inflating: instantclient_11_2/adrci
inflating: instantclient_11_2/genezi
inflating: instantclient_11_2/libclntsh.so.11.1
inflating: instantclient_11_2/libnnz11.so
inflating: instantclient_11_2/libocci.so.11.1
inflating: instantclient_11_2/libociei.so
inflating: instantclient_11_2/libocijdbc11.so
inflating: instantclient_11_2/ojdbc5.jar
inflating: instantclient_11_2/ojdbc6.jar
inflating: instantclient_11_2/xstreams.jar

$ unzip oracle-instantclient11.2-sqlplus-11.2.0.1.0-1.x86_64.zip
Archive: oracle-instantclient11.2-sqlplus-11.2.0.1.0-1.x86_64.zip
inflating: instantclient_11_2/SQLPLUS_README
inflating: instantclient_11_2/glogin.sql
inflating: instantclient_11_2/libsqlplus.so
inflating: instantclient_11_2/libsqlplusic.so
inflating: instantclient_11_2/sqlplus

$ cd instantclient_11_2
$ ./sqlplus
./sqlplus: error while loading shared libraries: libsqlplus.so: cannot open shared object file: No such file or directory
We learned to install SQL*Plus(Instant Client) and we were learning to make it work, then checked "libsqlplus.so" shared library file.
$ ls -l libsqlplus.so
-r-xr-xr-x 1 oracle oinstall 1470768 Aug 15 2009 libsqlplus.so
then used "ldd" to help.
ldd prints the shared libraries required by each program or shared library specified on the command line.
$ ldd sqlplus
libsqlplus.so => not found
libclntsh.so.11.1 => not found
libnnz11.so => not found
libdl.so.2 => /lib64/libdl.so.2 (0x0000003fc1f00000)
libm.so.6 => /lib64/tls/libm.so.6 (0x0000003fc1d00000)
libpthread.so.0 => /lib64/tls/libpthread.so.0 (0x0000003fc2100000)
libnsl.so.1 => /lib64/libnsl.so.1 (0x0000003fc9400000)
libc.so.6 => /lib64/tls/libc.so.6 (0x0000003fc1a00000)
/lib64/ld-linux-x86-64.so.2 (0x0000003fc1600000)
"sqlplus" command could not load shared libraries. checked all shared libraries = "not found"
$ ls -l libsqlplus.so libclntsh.so.11.1 libnnz11.so
-rwxrwxr-x 1 oracle oinstall 48797739 Aug 15 2009 libclntsh.so.11.1
-r-xr-xr-x 1 oracle oinstall 7899997 Aug 15 2009 libnnz11.so
-r-xr-xr-x 1 oracle oinstall 1470768 Aug 15 2009 libsqlplus.so

$ pwd
/opt/instantclient_11_2
then used LD_LIBRARY_PATH environment variable.
The environment variable LD_LIBRARY_PATH is a colon-separated set of directories where libraries should be searched for first, before the standard set of directories.
$ export LD_LIBRARY_PATH=/opt/instantclient_11_2:$LD_LIBRARY_PATH

$ ldd sqlplus
libsqlplus.so => /opt/instantclient_11_2/libsqlplus.so (0x0000002a95557000)
libclntsh.so.11.1 => /opt/instantclient_11_2/libclntsh.so.11.1 (0x0000002a9573f000)
libnnz11.so => /opt/instantclient_11_2/libnnz11.so (0x0000002a97c6f000)
libdl.so.2 => /lib64/libdl.so.2 (0x0000003fc1f00000)
libm.so.6 => /lib64/tls/libm.so.6 (0x0000003fc1d00000)
libpthread.so.0 => /lib64/tls/libpthread.so.0 (0x0000003fc2100000)
libnsl.so.1 => /lib64/libnsl.so.1 (0x0000003fc9400000)
libc.so.6 => /lib64/tls/libc.so.6 (0x0000003fc1a00000)
libaio.so.1 => /usr/lib64/libaio.so.1 (0x0000003fc1800000)
/lib64/ld-linux-x86-64.so.2 (0x0000003fc1600000)
"sqlplus" command could load all shares libraries.
$ ./sqlplus

SQL*Plus: Release 11.2.0.1.0 Production on Thu Apr 15 20:58:18 2010

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Enter user-name:
We can use SQL*Plus(Instant Client), we learned to make it work (learned to fix and use shell command). so We learned more...

However, If we need to make it work faster... and don't necessary to learn more... (just need it work). After unzip file:
$ pwd
/opt/instantclient_11_2
$ export TNS_ADMIN=/opt/instantclient_11_2
$ export LD_LIBRARY_PATH=/opt/instantclient_11_2:$LD_LIBRARY_PATH
$ export PATH=$PATH:/opt/instantclient_11_2
$ sqlplus user/pwd@DB

SQL*Plus: Release 11.2.0.1.0 Production on Thu Apr 15 21:50:53 2010

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options

SQL>
TNS_ADMIN environment is the directory containing the tnsnames.ora file.

Reference(To Learn More):
Oracle Database Instant Client
SQL*Plus Instant Client
Linux Shared Libraries
Filesystem Hierarchy Standard

/lib : Essential shared libraries and kernel modules
Purpose:
The /lib directory contains those shared library images needed to boot the system and run the commands in the root filesystem, ie. by binaries in /bin and /sbin.

/usr/lib : Libraries for programming and packages
Purpose:
/usr/lib includes object files, libraries, and internal binaries that are not intended to be executed directly by users or shell scripts.
Applications may use a single subdirectory under /usr/lib. If an application uses a subdirectory, all architecture-dependent data exclusively used by the application must be placed within that subdirectory.

Wednesday, April 01, 2009

How to install HTTP Server + PHP + InstantClient


1. Softwares.

- HTTP Server http://httpd.apache.org/
httpd-2.2.11.tar.gz

- PHP http://www.php.net/downloads.php
php-5.2.9.tar.gz (oci8 1.2.5)

- OCI8 (if need new OCI8 version) http://pecl.php.net/package/oci8/download/
oci8-1.3.5.tgz

- InstantClient http://www.oracle.com/technology/software/tech/oci/instantclient/index.html
basic-11.1.0.70-linux-x86_64.zip
sdk-11.1.0.7.0-linux-x86_64.zip

2. Install Softwares. 
- InstantClient (on /oracle/instantclient_11_1 PATH)
$ mkdir /oracle

$ cd /oracle

$ unzip SOURCE/basic-11.1.0.70-linux-x86_64.zip
Archive: SOURCE/basic-11.1.0.70-linux-x86_64.zip
inflating:
instantclient_11_1/BASIC_README
.
.
.

$ unzip SOURCE/sdk-11.1.0.7.0-linux-x86_64.zip
Archive: SOURCE/sdk-11.1.0.7.0-linux-x86_64.zip
creating:
instantclient_11_1/sdk/
.
.
.

$ ls
instantclient_11_1

$ cd instantclient_11_1

###make link soft file ###

$ ln -s libclntsh.so.11.1 libclntsh.so

$ ln -s libocci.so.11.1 libocci.so

- Install HTTP Server (Increase DEFAULT_SERVER_LIMIT > 256)
$ cd SOURCE

$ tar zxvf httpd-2.2.11.tar.gz
httpd-2.2.11/
.
.
.

$ cd httpd-2.2.11

###Increase default server limit of prefork > 256###

$ vi server/mpm/prefork/prefork.c
#define DEFAULT_SERVER_LIMIT 256 => #define DEFAULT_SERVER_LIMIT 1024
$ ./configure --prefix=/usr/local/apache --with-config-file-path=/usr/local/apache/conf --enable-ssl

$ make

$ su

# make install

- Install PHP (new oci8)
$ cd SOURCE

$ tar zxvf oci8-1.3.5.tgz
.
.
.

$ tar zxvf php-5.2.9.tar.gz
php-5.2.9/
.
.
.

$ cd php-5.2.9

###change to use new oci8###

$ mv ext/oci8 ext/oci8-old

$ mv ../oci8-1.3.5 ext/oci8

$ ./configure --prefix=/usr/local/apache --with-config-file-path=/usr/local/apache/conf \
--with-oci8=share,instantclient,/oracle/instantclient_11_1 --enable-sigchild \
--with-apxs2=/usr/local/apache/bin/apxs --disable-cli --disable-cgi

$ make

$ su

# make install

3. Configure HTTP Server and Etc.
- Add some Environments in /usr/local/apache/bin/apachectl file.
#
ARGV="$@"
#
export ORACLE_HOME=/oracle/instantclient_11_1
export NLS_LANG=AMERICAN_AMERICA.TH8TISASCII
export TNS_ADMIN=/oracle/instantclient_11_1

- Modified /usr/local/apache/conf/httpd.conf file to use .php type.

AddType application/x-httpd-php .php

- Modified Etc... on /usr/local/apache/conf/httpd.conf file.

Example:
ServerName server.domain.com
ServerAdmin admin@domain.com
User oracle
Group dba
.
.
.

- Harden Some... on HTTP Sever.
Example: (uncomment "Include conf/extra/httpd-default.conf" in /usr/local/apache/conf/httpd.conf file before)

ServerTokens Prod
ServerSignature Off
.
.
.

4. Create TNSNAME File (check "TNS_ADMIN" on HTTP Server before).
Example: /oracle/instantclient_11_1/tnsnames.ora (Because -> TNS_ADMIN=/oracle/instantclient_11_1)

DB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST =
db_host)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = DB)
)
)


5. Start HTTP Server(root).
# /usr/local/apache/bin/apachectl start


### write PHP connect Oracle DB and Test at /usr/local/apache/htdocs PATH (default)###

refer: http://docs.google.com/Doc?id=dhg2wncg_12ddc9f3tn

Monday, March 09, 2009

SQL*Plus 10.2.0.1 Hangs, When System Uptime Is Long Period of Time


Today, my colleague told me, Why I can't use "sqlplus" (Oracle client) on my application server connect your database, But I can use "tnsping"... And I'd ever connected!


I remoted on this server and found "sqlplus" hung ... and sqlplus used more CPU %

$ ps aux
USER       PID %CPU %MEM   VSZ  RSS TTY      STAT START   TIME COMMAND
oracle   12722 96.4  0.2 19560 4600 pts/5    R    15:36   0:06 sqlplus

So, found out on metalink... (338461.1)
SQL*Plus 10.2.0.1 Hangs, When System Uptime Is Long Period of Time (Linux x86)

Used "strace" :

$ strace sqlplus -V 2>&1 |less

execve("/oracle/10.2.0/client/bin/sqlplus", ["sqlplus", "-V"], [/* 31 vars */]) = 0
uname({sys="Linux", node="host01", ...})  = 0
brk(0)                                  = 0x804a000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
.
.
.
times(NULL)                             = -2138395754
times(NULL)                             = -2138395754
times(NULL)                             = -2138395754
times(NULL)                             = -2138395754
times(NULL)                             = -2138395754
times(NULL)                             = -2138395754
times(NULL)                             = -2138395754
times(NULL)                             = -2138395754
times(NULL)                             = -2138395754
times(NULL)                             = -2138395754
times(NULL)                             = -2138395754
times(NULL)                             = -2138395754
times(NULL)                             = -2138395754
times(NULL)                             = -2138395754
times(NULL)                             = -2138395754
times(NULL)                             = -2138395754
times(NULL)                             = -2138395754
times(NULL)                             = -2138395754
times(NULL)                             = -2138395754
times(NULL)                             = -2138395754
times(NULL)                             = -2138395754
times(NULL)                             = -2138395754
times(NULL)                             = -2138395754
It is looping on the times() function.


There have been cases where problem occurs when uptime reaches 60 days and others as long as 248 days.

In addition to sqlplus, it has been reported that the netca and dbca tools also hang.


Solution from metalink...
Select one of the following two solutions:

1) Apply one-off patch available for 10.2.0.1.
   a. Download one-off patch off Metalink:
       Patch 4612267
       Description OCI CLIENT IS IN AN INFINITE LOOP WHEN MACHINE UPTIME HITS 248 DAYS
       Product CORE
       Release Oracle 10.2.0.1

   b. To apply patch on Instant Client install, please follow instructions documented in the OCI manual.
        You can find this in:

        under "Patching Instant Client Shared Libraries on Linux or UNIX".

2)  Apply Patchset 10.2.0.2  or higher. 
      According to Bug 4612267, this bug is fixed in version 11, and backported to 10.2.0.2 patchset.

Tuesday, July 22, 2008

PHP + OCI8 + instantClient

We need to install PHP support OCI8 1.3.X (this is new oci8 support 11g, that can create connection pool) with instantClient (download basic-11.1.0.6.0-linux-x86_64.zip + sdk-11.1.0.6.0-linux-x86_64.zip).

Assume:

1. Used Linux x86_64
2. Installed Apache2 HTTP at /usr/local/apache/ PATH.

After that We install PHP =>

Begin -> download instantClient + SDK and install:

$ mkdir /oracle
$ cd /oracle
$ unzip /tmp/basic-11.1.0.6.0-linux-x86_64.zip
Archive: /tmp/basic-11.1.0.6.0-linux-x86_64.zip
inflating: instantclient_11_1/BASIC_README
inflating: instantclient_11_1/adrci
inflating: instantclient_11_1/genezi
inflating: instantclient_11_1/libclntsh.so.11.1
inflating: instantclient_11_1/libnnz11.so
inflating: instantclient_11_1/libocci.so.11.1
inflating: instantclient_11_1/libociei.so
inflating: instantclient_11_1/libocijdbc11.so
inflating: instantclient_11_1/ojdbc5.jar
inflating: instantclient_11_1/ojdbc6.jar

$ unzip /tmp/sdk-11.1.0.6.0-linux-x86_64.zip
Archive: /tmp/sdk-11.1.0.6.0-linux-x86_64.zip
creating: instantclient_11_1/sdk/
creating: instantclient_11_1/sdk/include/
inflating: instantclient_11_1/sdk/include/occi.h
inflating: instantclient_11_1/sdk/include/occiCommon.h
inflating: instantclient_11_1/sdk/include/occiControl.h
inflating: instantclient_11_1/sdk/include/occiData.h
inflating: instantclient_11_1/sdk/include/occiObjects.h
inflating: instantclient_11_1/sdk/include/occiAQ.h
inflating: instantclient_11_1/sdk/include/oci.h
inflating: instantclient_11_1/sdk/include/oci1.h
inflating: instantclient_11_1/sdk/include/oci8dp.h
inflating: instantclient_11_1/sdk/include/ociap.h
inflating: instantclient_11_1/sdk/include/ociapr.h
inflating: instantclient_11_1/sdk/include/ocidef.h
inflating: instantclient_11_1/sdk/include/ocidem.h
inflating: instantclient_11_1/sdk/include/ocidfn.h
inflating: instantclient_11_1/sdk/include/ociextp.h
inflating: instantclient_11_1/sdk/include/ocikpr.h
inflating: instantclient_11_1/sdk/include/ocixmldb.h
inflating: instantclient_11_1/sdk/include/odci.h
inflating: instantclient_11_1/sdk/include/oratypes.h
inflating: instantclient_11_1/sdk/include/ori.h
inflating: instantclient_11_1/sdk/include/orid.h
inflating: instantclient_11_1/sdk/include/orl.h
inflating: instantclient_11_1/sdk/include/oro.h
inflating: instantclient_11_1/sdk/include/ort.h
inflating: instantclient_11_1/sdk/include/xa.h
inflating: instantclient_11_1/sdk/include/nzt.h
inflating: instantclient_11_1/sdk/include/nzerror.h
creating: instantclient_11_1/sdk/demo/
inflating: instantclient_11_1/sdk/demo/demo.mk
inflating: instantclient_11_1/sdk/demo/cdemo81.c
inflating: instantclient_11_1/sdk/demo/occidemo.sql
inflating: instantclient_11_1/sdk/demo/occidemod.sql
inflating: instantclient_11_1/sdk/demo/occidml.cpp
inflating: instantclient_11_1/sdk/demo/occiobj.cpp
inflating: instantclient_11_1/sdk/demo/occiobj.typ
inflating: instantclient_11_1/sdk/SDK_README
extracting: instantclient_11_1/sdk/ottclasses.zip
inflating: instantclient_11_1/sdk/ott

$ cd instantclient_11_1/

create link libraries:
$ ln -s libclntsh.so.11.1 libclntsh.so
$ ln -s libocci.so.11.1 libocci.so


Download PHP + new OCI8 (http://oss.oracle.com) and then patch OCI8 + install PHP with Apache2:

$ tar zxvf php-5.2.6.tar.gz
$ cd php-5.2.6/ext/
$ mv oci8 oci8-old
$ tar zxvf /tmp/oci8-1.3.x.tgz
$ ln -s oci8-1.3.x oci8
$ cd ..

$ export ORACLE_HOME=/oracle/instantclient_11_1/
$ pwd
/tmp/php-5.2.6

$ ./configure --prefix=/usr/local/apache --with-config-file-path=/usr/local/apache/conf \
--enable-sigchild --with-apxs2=/usr/local/apache/bin/apxs \
--with-oci8=share,instantclient,/oracle/instantclient_11_1/

$ make

$ su # use "root" user to install

$ make install

copy file (php.ini-dist or php.ini-recommended) for php.ini
$ cp php.ini-dist( or php.ini-recommended) /usr/local/apache/conf/php.ini

Add Type in httpd.conf file and start Apache2
.......
AddType application/x-httpd-php .php
.......

>>> create tnsnames.ora file "/oracle/instantclient_11_1/tnsnames.ora"

DB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = db_host)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = DB)
)
)

>>>

Anyway, before start apache, we should set ORACLE ENV:

- ORACLE_HOME
- ORACLE_SID
- LD_LIBRARY_PATH
- NLS_LANG
- TNS_ADMIN

The NLS_LANG and TNS_ADMIN variables are most likely to be required for Zend Core for Oracle. Zend Core for Oracle modifies apachectl and adds LD_LIBRARY_PATH. (This may not be required in a future version of Zend Core for Oracle if Oracle links the Instant Client differently).

This allows the Zend Core for Oracle GUI Console to be reused to start Apache. If you are using a tnsnames.ora fi le and specify network aliases for the connection string with Zend Core for Oracle, you may need to do something similar with TNS_ADMIN so the Zend Core for Oracle Console can restart Apache correctly. If you start Apache manually, set the environment in a calling script.

>>> This case we created "tnsnames.ora" file at /oracle/instantclient_11_1/ PATH, So

$ export TNS_ADMIN=/oracle/instantclient_11_1/

$ /usr/local/apache/bin/apachectl start

create Code to test PHP + Oracle =>

$c = oci_connect('username', 'password', 'db');

We can find out PHP + Oracle at http://www.oracle.com/technology/tech/php/index.html