31 January 2011

LINUX - netstat

1. Using Netstat to Count TCP Connection States
netstat -an|awk '/tcp/ {print $6}'|sort|uniq -c

2. List TCP/UDP and it's PID
netstat -tuvnap

APACHE - Redirect http requests to https

First make sure Apache is configured for HTTPS connection and necessary SSL certificates are installed.

No non-ssl access i.e. only accept https connections

Now open httpd.conf or .htaccess file (mod_rewrite not required):
# vi httpd.conf

Append following line :
Redirect permanent / https://mail.nixcraft.com/

Any request made to http://mail.nixcraft.com will goto https://mail.nixcraft.com/

Save and close the file. Restart the Apache:
# systemctl restart httpd

LINUX - How to Tell 32 or 64-bit?

# getconf LONG_BIT

25 January 2011

LINUX - Determine number of CPU cores

# cat /proc/cpuinfo | egrep “physical\ id|core\ id”




physical id : 0
core id : 1
cpu cores : 2

If you have two CPUs in cpuinfo with the same physical id and core id, than – hyperthreading! When you have all CPUs with different physical ids, than you have SMP, and when you have CPUs with one physical id and different core ids – you have one multicore CPU. And so on…

22 January 2011

PostgreSQL - Migrating from Oracle to Postgres Using ora2pg

# tar xzf ora2pg-7.x.tar.gz
# cd ora2pg-7.x/
# perl Makefile.PL
# make && make install

# perl -MCPAN -e 'install DBI'

# export ORACLE_HOME
# export LD_LIBRARY_PATH=$ORACLE_HOME/lib
# perl -MCPAN -e 'install DBD::Oracle'

Edit /etc/ora2pg/ora2pg.conf to modify ORACLE_HOST ORACLE_USER ORACLE_PASSWORD

LINUX - Loading data into database table

Example: To load username from /etc/passwd into a database table.

awk -F: '{print $1}' /etc/passwd > passwd_txt

cat passwd_txt | while read username; do echo "insert into {TABLE} (USERNAME,GROUPNAME,PRIORITY) values (""'$username'"", 'acct', 0);" >> users.sql; done;

LINUX - awk

To print single column from a text file
#awk -F: '{print $1}' /etc/passwd

To print multiple columns from a text file
# awk -F: '{print $1,$7}' /etc/passwd

20 January 2011

ORACLE - Data Pump Export (expdp) and Data Pump Import (impdp)


Data Pump Export (expdp) and Data Pump Import (impdp) are server-based rather than client-based as is the case for the original export (exp) and import (imp). Because of this, dump files, log files, and sql files are accessed relative to the server-based directory paths. Data Pump requires that directory objects mapped to a file system directory be specified in the invocation of the data pump import or export.

It for this reason and for convenience that a directory object be created before using the data pump export or import utilities. For example to create a directory object named expdp_dir located at /u01/backup/exports enter the following sql statement:

SQL> create directory expdp_dir as '/u01/backup/exports';

then grant read and write permissions to the users who will be performing the data pump export and import.

SQL> grant read,write on directory expdp_dir to system, user1, user2, user3;


Invoking Data Pump Export

You can invoke the data pump export using a command line. Export parameters can be specified directly in the command line.

Full Export Mode

A full export is specified using the FULL parameter. In a full database export, the entire database is unloaded. This mode requires that you have the EXP_FULL_DATABASE role. Example :

$ expdp system/ DIRECTORY=expdp_dir DUMPFILE=expfull.dmp FULL=y LOGFILE=expfull.og

Schema Export Mode

The schema export mode is invoked using the SCHEMAS parameter. If you have no EXP_FULL_DATABASE role, you can only export your own schema. If you have EXP_FULL_DATABASE role, you can export several schemas in one go. Optionally, you can include the system privilege grants as well.

$ expdp hr/hr DIRECTORY=expdp_dir DUMPFILE=schema_exp.dmp SCHEMAS=hr,sh,oe

Table Export Mode

This export mode is specified using the TABLES parameter. In this mode, only the specified tables, partitions and their dependents are exported. If you do not have the EXP_FULL_DATABASE role, you can export only tables in your own schema. You can only specify tables in the same schema.

$ expdp hr/hr DIRECTORY=expdp_dir DUMPFILE=tables_exp.dmp TABLES=employees,jobs,departments

Invoking Data Pump Import

The data pump import can be invoked in the command line. The export parameters can be specified directly in the command line.

Full Import Mode

The full import mode loads the entire contents of the source (export) dump file to the target database. However, you must have been granted the IMP_FULL_DATABASE role on the target database. The data pump import is invoked using the impdp command in the command line with the FULL parameter specified in the same command line.

$ impdp system/ DIRECTORY=expdp_dir DUMPFILE=expfull.dmp FULL=y LOGFILE=impfull.og

Schema Import Mode

The schema import mode is invoked using the SCHEMAS parameter. Only the contents of the specified schemas are load into the target database. The source dump file can be a full, schema-mode, table, or tablespace mode export files. If you have a IMP_FULL_DATABASE role, you can specify a list of schemas to load into the target database.

$ impdp hr/hr DIRECTORY=expdp_dir DUMPFILE=expfull.dmp SCHEMAS=hr,sh,oe

Table Import Mode

This export mode is specified using the TABLES parameter. In this mode, only the specified tables, partitions and their dependents are exported. If you do not have the EXP_FULL_DATABASE role, you can import only tables in your own schema.

$ impdp hr/hr DIRECTORY=expdp_dir DUMPFILE=expfull.dmp TABLES=employees,jobs,departments

Schema Import Mode to a different User

impdp user/password@DB directory=EXPORT_BACKUP_DIR dumpfile=DMPFILE.dmp remap_schema=:

The new user will be created automatically.
Once done, change password for the new user.

Ex.
impdp user/password@DB directory=EXPORT_BACKUP_DIR dumpfile=DMPFILE.dmp schemas=user remap_schema=user:new_user

ORACLE - exp and imp User Schema Without Data


I want to take the structure of my database, but not the data. Is it possible in any way? I do this all the time in some of my systems. This is a great way to get the DDL of your database objects so that you can re-create a view or stored procedure without having to perform an incomplete restore. I use Oracle's export and import utilities for this activity. The trick is to export without any data. The ROWS=N parameter will tell exp to not include any rows. So I have a nightly script which performs the following:

$ exp userid=system file=full_ddl.dmp rows=n


The resulting export dump file will contain all of the DDL to re-create your database objects, but the dump file will not be terribly large since no data was included in the export.

When I need to see the contents, I use the import utility with the SHOW=Y parameter to see the DDL, similar to the following:

$ imp userid=system file=full_ddl.dmp show=y log=create_ddl.sql full=y


I log the output to a file and the file will contain all of the CREATE and ALTER statements necessary to re-create the database objects. If you do not want to see all objects in the database, then you can use other imp parameters to limit your output. For instance, to see just the SCOTT.EMP table, use the following:

$ imp userid=system file=full_ddl.dmp show=y log=create_emp.sql tables=scott.emp

The imp utility will skip all other objects in the dump file. The resulting log file will need some slight text editing to get the correct command.

Finally, the INDEXFILE parameter is much more readable than SHOW=Y for the imp utility. However, the INDEXFILE parameter will only show the CREATE TABLE and CREATE INDEX statements. If you need to see CREATE VIEW or CREATE PROCEDURES statements, the only option is the SHOW=Y parameter.


$ imp userid=system full=Y file=full_ddl.dmp indexfile=aa.sql


ORACLE - Resize Temporary Tablespace


The procedures above document how to drop a temporary tablespace that is not the default temporary tablespace for the database. You will know fairly quickly if the tablespace is a default temporary tablespace when you are greeted with the following exception:

SQL> DROP TABLESPACE temp;
drop tablespace temp
*
ERROR at line 1:
ORA-12906: cannot drop default temporary tablespace

In cases where the temporary tablespace you want to resize (using the drop/recreate method) is the default temporary tablespace for the database, you have several more steps to perform, all documented below. The first step you need to perform is create another temporary tablespace (lets call it TEMP2). The next step would be to remove the temporary tablespace you want to resize from being the default temporary tablespace (in our example, this will be a tablespace named TEMP) by making TEMP2 the default. Drop / recreate the TEMP tablespace to the size you want. Finally, make the newly created TEMP tablespace your default temporary tablespace for the database and drop the TEMP2 tablespace. A full example session is provided below:

SQL> CREATE TEMPORARY TABLESPACE temp2
2 TEMPFILE '/u02/oradata/TESTDB/temp2_01.dbf' SIZE 5M REUSE
3 AUTOEXTEND ON NEXT 1M MAXSIZE unlimited
4 EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M;

Tablespace created.


SQL> ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp2;

Database altered.


SQL> DROP TABLESPACE temp INCLUDING CONTENTS AND DATAFILES;

Tablespace dropped.

SQL> CREATE TEMPORARY TABLESPACE temp
2 TEMPFILE '/u02/oradata/TESTDB/temp01.dbf' SIZE 500M REUSE
3 AUTOEXTEND ON NEXT 100M MAXSIZE unlimited
4 EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M;

Tablespace created.


SQL> ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp;

Database altered.


SQL> DROP TABLESPACE temp2 INCLUDING CONTENTS AND DATAFILES;

Tablespace dropped.

ORACLE - View user (schema) and its corresponding tablespace


column username format A12 word_wrapped
column default_tablespace format A20 word_wrapped
column temporary_tablespace format A20 word_wrapped
column created heading format A12
select username ,default_tablespace ,temporary_tablespace ,created from dba_users
where username like '{USERNAME}%';

ORACLE To show User Schema Size


column "Total MB" format 99,999,999
SELECT owner, round(sum(bytes) / 1048576) "Total MB"
FROM dba_segments
GROUP BY owner

ORACLE Tablespace Size

column "Tablespace" format a13
column "Used MB" format 99,999,999
column "Free MB" format 99,999,999
column "Total MB" format 99,999,999
select
fs.tablespace_name "Tablespace",
(df.totalspace - fs.freespace) "Used MB",
fs.freespace "Free MB",
df.totalspace "Total MB",
round(100 * (fs.freespace / df.totalspace)) "Pct. Free",
round((100 * (df.totalspace - fs.freespace)) / df.totalspace) "Pct. Used" from
(select
tablespace_name,
round(sum(bytes) / 1048576) TotalSpace
from
dba_data_files
group by
tablespace_name
) df,
(select
tablespace_name,
round(sum(bytes) / 1048576) FreeSpace
from
dba_free_space
group by
tablespace_name
) fs
where
df.tablespace_name = fs.tablespace_name;

ORACLE SQL How to change user or system password

$ sqlplus "/ as sysdba"

SQL> show user

USER is "SYS"

SQL> passw system
Changing password for system
New password:
Retype new password:
Password changed
SQL> quit

ORACLE SQL View Database Information

select NAME,
CREATED,
LOG_MODE,
CHECKPOINT_CHANGE#,
ARCHIVE_CHANGE#
from v$database;

ORACLE SQL View Product and Version

select BANNER product_versions
from v$version;

ORACLE SQL View Sessions with PID


set echo off;
set termout on;
set linesize 80;
set pagesize 60;
set newpage 0;
set heading off;
select 'Sessions on database '||substr(name,1,8) from v$database;
set heading on;
select
substr(a.spid,1,9) pid,
substr(b.sid,1,5) sid,
substr(b.serial#,1,5) ser#,
substr(b.machine,1,6) box,
substr(b.username,1,10) username,
substr(b.osuser,1,8) os_user,
substr(b.program,1,30) program
from v$session b, v$process a where
b.paddr = a.addr
and type='USER'
order by spid;

ORACLE Table Replication

OEM
1. Extract Table Schema (base on show SQL in OEM)
2. drop table {table} cascade;
3. alter table {table_new} RENAME TO {table}

SQL
1. create table {table_new} as select * from {table} where 1=2;
2. create unique index {index} on {table_new} (“uludo_key”) tablespace app_data;
3. drop table {table} cascade;
4. alter table {table_new} rename to {table};


ORACLE SQL View Database Files

select 'Archived Log Directory' "Filename",
value "Location"
from v$parameter
where name = 'log_archive_dest'
UNION
select 'Control Files' "Filename",
value "Location"
from v$parameter
where name = 'control_files'
UNION
select 'Datafile' "Filename",
name "Location"
from v$datafile
UNION
select 'LogFile Member' "Filename",
member "Location"
from v$logfile;

ORACLE Installing Oracle 11g on RHEL5 (32 and 64-bit)

Minimum hardware requirements:


32-bit (x86)


x86 compatible CPU
1 GB RAM
10 GB available disk space (3.5 GB for the Oracle software + 1.5 GB for the database + 3 GB for OEL5 + 2 GB swap)
64-bit (x86_64)


x86_64 compatible CPU
1 GB RAM
10.5 GB available disk space (4 GB for the Oracle software + 1.5 GB for the database + 3 GB for OEL5 + 2 GB swap)
Note: Both Linux and Oracle must be installed for the same architecture. 32-bit Oracle will only run on 32-bit Linux and 64-bit Oracle will only run on 64-bit Linux.




32-bit (x86) Installations
--------------------------
Required kernel version: 2.6.18 This kernel, or any of the kernels supplied in updates, works with Oracle Database 11g Release 1 .


Check your kernel version by running the following command:


uname -r


Ex:
# uname -r
2.6.18-8.el5
Required package versions (or later):


compat-libstdc++-33-3.2.3-61
elfutils-libelf-0.125-3.el5
elfutils-libelf-devel-0.125-3.el5
glibc-2.5-12
glibc-devel-2.5-12
glibc-common-2.5-12
gcc-4.1.1-52.el5
gcc-c++-4.1.1-52.el5
kernel-headers
libgcc-4.1.1-52.el5
libaio-0.3.106-3.2
libaio-devel-0.3.106-3.2
libstdc++-4.1.1-52.el5
libstdc++-devel-4.1.1-52.el5
unixODBC-2.2.11-7.1
unixODBC-devel-2.2.11-7.1
sysstat-7.0.0-3.el5
binutils-2.17.50.0.6-2.el5
make-3.81-1.1
If you've performed a "default RPMs" install as suggested by Oracle, there are still some required packages that must be installed:
compat-libstdc++-33
elfutils-libelf-devel
glibc-devel-2.5
gcc
gcc-c++
libaio-devel
libstdc++-devel
unixODBC
unixODBC-devel
sysstat
To install the remaining packages, mount the Oracle Enterprise Linux media and move to the directory containing the RPMs.


Some required packages are dependent upon other packages, so the dependant packages must be installed as well. Login as root and run the following commands to install the remaining required packages and their dependent packages. (Warning: packages often move from disk to disk across different releases.)


Mount CD 2


cd cd_mount_point/Server


rpm -ivh elfutils-libelf-devel* glibc-devel-2* glibc-headers-2* gcc-4* libgomp-4* gcc-c++-4* libstdc++-devel-4*


Ex:
# rpm -ivh elfutils-libelf-devel* glibc-devel-2* glibc-headers-2* gcc-4* libgomp-4* gcc-c++-4* libstdc++-devel-4*
warning: compat-libstdc++-33-3.2.3-61.i386.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159
Preparing... ########################################### [100%]
1:libgomp ########################################### [ 25%]
2:glibc-headers ########################################### [ 33%]
3:glibc-devel ########################################### [ 42%]
4:gcc ########################################### [ 50%]
5:gcc-c++ ########################################### [ 58%]
6:elfutils-libelf-devel-s########################################### [ 92%]
7:elfutils-libelf-devel ########################################### [100%]
8:libstdc++-devel-4 ########################################### [100%]


Mount CD 3


cd cd_mount_point/Server


rpm -ivh compat-libstdc++-33* libaio-devel* sysstat* unixODBC*


Ex:
# rpm -ivh compat-libstdc++-33* libaio-devel* sysstat* unixODBC*
warning: sysstat-7.0.0-3.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159
Preparing... ########################################### [100%]
1:unixODBC ########################################### [ 8%]
2:libaio-devel ########################################### [ 75%]
3:compat-libstdc++-33 ########################################### [ 83%]
4:sysstat ########################################### [100%]


To verify that the required packages have been installed on your system, run the following command:


rpm -q compat-libstdc++-33 elfutils-libelf-devel glibc-devel-2.5 gcc gcc-c++ libaio-devel libstdc++-devel \
unixODBC unixODBC-devel sysstat binutils elfutils-libelf glibc glibc-common libaio libgcc libstdc++ make


Ex:
# rpm -q compat-libstdc++-33 elfutils-libelf-devel glibc-devel-2.5 gcc gcc-c++ libaio-devel libstdc++-devel \
> unixODBC unixODBC-devel sysstat binutils elfutils-libelf glibc glibc-common libaio libgcc libstdc++ make
compat-libstdc++-33-3.2.3-61
elfutils-libelf-devel-0.125-3.el5
glibc-devel-2.5-12
gcc-4.1.1-52.el5
gcc-c++-4.1.1-52.el5
libaio-devel-0.3.106-3.2
libstdc++-devel-4.1.1-52.el5
unixODBC-2.2.11-7.1
unixODBC-devel-2.2.11-7.1
sysstat-7.0.0-3.el5
binutils-2.17.50.0.6-2.el5
elfutils-libelf-0.125-3.el5
glibc-2.5-12
glibc-common-2.5-12
libaio-0.3.106-3.2
libgcc-4.1.1-52.el5
libstdc++-4.1.1-52.el5
make-3.81-1.1
64-bit (x86_64) Installations
-----------------------------


Required kernel version: 2.6.18 This kernel, or any of the kernels supplied in updates, works with Oracle Database 11g Release 1 .


Check your kernel version by running the following command:


uname -rm


Ex:
# uname -rm
2.6.18-8.el5 x86_64
Required package versions (or later):


binutils-2.17.50.0.6
compat-libstdc++-33-3.2.3
compat-libstdc++-33-3.2.3 (32 bit)
elfutils-libelf-0.125
elfutils-libelf-devel-0.125
gcc-4.1.1
gcc-c++-4.1.1
glibc-2.5-12
glibc-2.5-12 (32 bit)
glibc-common-2.5
glibc-devel-2.5
glibc-devel-2.5-12 (32 bit)
libaio-0.3.106
libaio-0.3.106 (32 bit)
libaio-devel-0.3.106
libgcc-4.1.1
libgcc-4.1.1 (32 bit)
libstdc++-4.1.1
libstdc++-4.1.1 (32 bit)
libstdc++-devel 4.1.1
make-3.81
sysstat-7.0.0
Note that there are a number of packages where both the 64-bit and 32-bit RPMs must be installed. Fortunately, both are provided on the 64-bit Linux installation media.
If you've performed a "default RPMs" install as suggested by Oracle, there are still some required packages that must be installed:


compat-libstdc++-33-3.2.3
compat-libstdc++-33-3.2.3 (32 bit)
elfutils-libelf-devel-0.125
gcc-4.1.1
gcc-c++-4.1.1
glibc-devel-2.5
glibc-devel-2.5-12 (32 bit)
libaio-devel-0.3.106
libstdc++-devel 4.1.1
sysstat-7.0.0
To install the remaining packages, mount the Oracle Enterprise Linux media and move to the directory containing the RPMs.


Some required packages are dependent upon other packages, so the dependant packages must be installed as well. Login as root and run the following commands to install the remaining required packages and their dependent packages:


Mount CD 2


mount -t iso9660 -r /dev/cdrom /media
cd /media/Server


rpm -ivh elfutils-libelf-devel*.x86_64.rpm glibc-devel-2* gcc-4*.x86_64.rpm gcc-c++-4*.x86_64.rpm libstdc++-devel-4*.x86_64.rpm glibc-headers*.x86_64.rpm libgomp*.x86_64.rpm


Ex:
# rpm -ivh elfutils-libelf-devel*.x86_64.rpm glibc-devel-2* gcc-4*.x86_64.rpm gcc-c++-4*.x86_64.rpm libstdc++-devel-4*.x86_64.rpm glibc-headers*.x86_64.rpm libgomp*.x86_64.rpm
warning: elfutils-libelf-devel-0.125-3.el5.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159
Preparing... ########################################### [100%]
1:glibc-headers ########################################### [ 11%]
2:glibc-devel ########################################### [ 22%]
3:libgomp ########################################### [ 33%]
4:gcc ########################################### [ 44%]
5:libstdc++-devel ########################################### [ 56%]
6:gcc-c++ ########################################### [ 67%]
7:glibc-devel ########################################### [ 78%]
8:elfutils-libelf-devel-s########################################### [ 89%]
9:elfutils-libelf-devel ########################################### [100%]


cd /
eject


Mount CD 3


mount -t iso9660 -r /dev/cdrom /media
cd /media/Server


rpm -ivh compat-libstdc++-33* libaio-devel*.x86_64.rpm


Ex:
# rpm -ivh compat-libstdc++-33* libaio-devel*.x86_64.rpm
warning: compat-libstdc++-33-3.2.3-61.i386.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159
Preparing... ########################################### [100%]
1:libaio-devel ########################################### [ 33%]
2:compat-libstdc++-33 ########################################### [ 67%]
3:compat-libstdc++-33 ########################################### [100%]


cd /
eject


Mount CD 4


mount -t iso9660 -r /dev/cdrom /media
cd /media/Server


rpm -ivh sysstat*


Ex:
# rpm -ivh sysstat*
warning: sysstat-7.0.0-3.el5.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159
Preparing... ########################################### [100%]
1:sysstat ########################################### [100%]


To verify that the required packages have been installed on your system, run the following command:


rpm -q --queryformat "%{NAME}-%{VERSION}-%{RELEASE} (%{ARCH})\n" binutils \
compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc \
glibc-common glibc-devel-2.5 libaio libaio-devel libgcc libstdc++ libstdc++-devel \
make sysstat


Ex:
# rpm -q --queryformat "%{NAME}-%{VERSION}-%{RELEASE} (%{ARCH})\n" binutils \
> compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc \
> glibc-common glibc-devel-2.5 libaio libaio-devel libgcc libstdc++ libstdc++-devel \
> make sysstat
binutils-2.17.50.0.6-2.el5 (x86_64)
compat-libstdc++-33-3.2.3-61 (i386)
compat-libstdc++-33-3.2.3-61 (x86_64)
elfutils-libelf-0.125-3.el5 (x86_64)
elfutils-libelf-devel-0.125-3.el5 (x86_64)
gcc-4.1.1-52.el5 (x86_64)
gcc-c++-4.1.1-52.el5 (x86_64)
glibc-2.5-12 (i686)
glibc-2.5-12 (x86_64)
glibc-common-2.5-12 (x86_64)
glibc-devel-2.5-12 (x86_64)
glibc-devel-2.5-12 (i386)
libaio-0.3.106-3.2 (x86_64)
libaio-0.3.106-3.2 (i386)
libaio-devel-0.3.106-3.2 (x86_64)
libgcc-4.1.1-52.el5 (x86_64)
libgcc-4.1.1-52.el5 (i386)
libstdc++-4.1.1-52.el5 (x86_64)
libstdc++-4.1.1-52.el5 (i386)
libstdc++-devel-4.1.1-52.el5 (x86_64)
make-3.81-1.1 (x86_64)
sysstat-7.0.0-3.el5 (x86_64)
Part II: Configuring Linux for Oracle


Now that the Linux software is installed, you need to configure it for Oracle. This section walks through the steps required to configure Linux for Oracle Database 11g Release 1.


Create the Oracle Groups and User Account


Next, create the Linux groups and user account that will be used to install and maintain the Oracle Database 11g Release 1 software. The user account will be called oracle, and the groups will be oinstall and dba. Execute the following commands as root:


/usr/sbin/groupadd oinstall
/usr/sbin/groupadd dba
/usr/sbin/useradd -m -g oinstall -G dba oracle
id oracle


Ex:
# /usr/sbin/groupadd oinstall
# /usr/sbin/groupadd dba
# /usr/sbin/useradd -m -g oinstall -G dba oracle
# id oracle
uid=501(oracle) gid=502(oinstall) groups=502(oinstall),503(dba)


Set the password on the oracle account:


passwd oracle


Ex:
# passwd oracle
Changing password for user oracle.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.


Create Directories


Now create directories to store the Oracle Database 11g Release 1 software and the database files. This guide adheres to the Optimal Flexible Architecture (OFA) for the naming conventions used in creating the directory structure. For more information on OFA standards, see Appendix D of the Oracle Database Installation Guide 11g Release 1 (11.1) for Linux.


The following assumes that the directories are being created in the root filesystem. This is done for the sake of simplicity and is not recommended as a general practice. These directories would normally be created as separate filesystems.


Issue the following commands as root:


mkdir -p /u01/app/oracle
chown -R oracle:oinstall /u01/app
chmod -R 775 /u01/app
Configuring the Linux Kernel Parameters


Oracle Database 11g Release 1 requires the kernel parameter settings shown below. The values given are minimums, so if your system uses a larger value, don't change it. Linux allows modification of most kernel parameters while the system is up and running, so there's no need to reboot the system after making kernel parameter changes.


kernel.shmall = 2097152
kernel.shmmax = 536870912
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default=4194304
net.core.wmem_default=262144
net.core.rmem_max=4194304
net.core.wmem_max=262144


Note that OEL 5 already has values defined for kernel.shmall and kernel.shmmax. Use the default values if they are the same or larger than the required values.


If you're following along and have just installed Linux, the kernel parameters will all be at their default values and you can just cut and paste the following commands while logged in as root.


cat >> /etc/sysctl.conf <
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default=4194304
net.core.wmem_default=262144
net.core.rmem_max=4194304
net.core.wmem_max=262144
EOF
/sbin/sysctl -p


Ex:
# cat >> /etc/sysctl.conf <
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default=262144
> kernel.shmmni = 4096
> kernel.sem = 250 32000 100 128
> fs.file-max = 65536
> net.ipv4.ip_local_port_range = 1024 65000
> net.core.rmem_default=4194304
> net.core.wmem_default=262144
> net.core.rmem_max=4194304
> net.core.wmem_max=262144
> EOF
# /sbin/sysctl -p
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 4294967295
kernel.shmall = 268435456
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default = 4194304
net.core.wmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_max = 262144
Run the following commands as root to verify your settings:


/sbin/sysctl -a | grep shm
/sbin/sysctl -a | grep sem
/sbin/sysctl -a | grep file-max
/sbin/sysctl -a | grep ip_local_port_range
/sbin/sysctl -a | grep rmem_default
/sbin/sysctl -a | grep rmem_max
/sbin/sysctl -a | grep wmem_default
/sbin/sysctl -a | grep wmem_max


Ex:
# /sbin/sysctl -a | grep shm
kernel.shmmni = 4096
kernel.shmall = 268435456
kernel.shmmax = 4294967295
kernel.shm-use-bigpages = 0
# /sbin/sysctl -a | grep sem
kernel.sem = 250 32000 100 128
# /sbin/sysctl -a | grep file-max
fs.file-max = 65536
# /sbin/sysctl -a | grep ip_local_port_range
net.ipv4.ip_local_port_range = 1024 65000
# /sbin/sysctl -a | grep rmem_default
net.core.rmem_default = 4194304
# /sbin/sysctl -a | grep rmem_max
net.core.rmem_max = 4194304
# /sbin/sysctl -a | grep wmem_default
net.core.wmem_default = 262144
# /sbin/sysctl -a | grep wmem_max
net.core.wmem_max = 262144


Setting shell limits for the oracle user


Oracle recommends setting limits on the number of processes and open files each Linux account may use. To make these changes, cut and paste the following commands as root:


cat >> /etc/security/limits.conf <
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
EOF


cat >> /etc/pam.d/login <
session required pam_limits.so
EOF


Change the default profile for bash and ksh as well as the default login script for cshell.


cat >> /etc/profile <
if [ \$USER = "oracle" ]; then
if [ \$SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
umask 022
fi
EOF


cat >> /etc/csh.login <
if ( \$USER == "oracle" ) then
limit maxproc 16384
limit descriptors 65536
umask 022
endif
EOF


Part III: Installing Oracle
Oracle Database 11g Release 1 can be downloaded from OTN. Oracle offers a development and testing license free of charge. However, no support is provided and the license does not permit production use. A full description of the license agreement is available on OTN.


The easiest way to make the Oracle Database 11g Release 1 distribution media available on your server is to download them directly to the server.


Use the graphical login to log in as oracle.


Create a directory to contain the Oracle Database 11g Release 1 distribution:


mkdir 11gR1_db


To download Oracle Database 11g Release 1 from OTN, point your browser to the Oracle Database Download Page. Read the OTN License agreement. If you agree with the restrictions and the license agreement, click on Accept License Agreement.


Click on the Linux x86 link (32-bit) or Linux x86-64 link (64-bit) and save the file in the directory you created for this purpose (11gR1_db)—if you have not already logged in to OTN, you may be prompted to do so at this point.


Unzip and extract the file.


cd 11gR1_db
For 32-bit
unzip linux_11gR1_database.zip
For 64-bit
unzip linux.x64_11gR1_database.zip


Install the Software and Create a Database


Log in using the oracle account.


Change directory to the directory containing the Oracle Database 11g Release 1 software.
Ex:
$ cd $HOME/11gR1_db/database


Start the Oracle Universal Installer.


$ ./runInstaller


Select Installation Method
Select Basic Installation
Oracle Base Location: /u01/app/oracle
Oracle Home Location: /u01/app/oracle/product/11.1.0/db_1
Installation Type: Enterprise Edition (3.3GB)
UNIX DBA Group: dba
Make sure Create Starter Database is checked
Global Database Name: demo1
Enter the Database Password and Confirm Password
Click on Next
Specify Inventory Directory and Credentials
Inventory Directory: /u01/app/oraInventory
Operating System group name: oinstall
Click on Next
Product-specific Prerequisite Checks
If you've been following the steps in this guide, all the checks should pass without difficulty. You may receive a warning related to swap file size if the default partition layout was used during OEL5 installation. This may be safely ignored . If one or more checks fail, correct the problem before proceeding.
Click on Next
Oracle Configuration Manager Registration
Leave this disabled for the demo and click on Next
Summary
A summary of the products being installed is presented.
Click on Install.
Install
Installation progress is displayed
Configuration Assistants
The Oracle Net, Oracle Database, and iSQL*Plus configuration assistants will run automatically
Take note of the information presented in the Database Configuration Assistant pop-up window and click on OK.
Execute Configuration Scripts
At the end of the installation, a pop up window will appear indicating scripts that need to be run as root. Login as root and run the indicated scripts.
Click on OK when finished.
End of Installation
Make note of the URLs presented in the summary, and click on Exit when ready.
Congratulations! Your new Oracle Database 11g Release 1 database is up and ready for use.
Part IV: Configuring Storage
The database we created in Part III used a single filesystem for disk storage. However, there are several other ways to configure storage for an Oracle database.


This section explores other methods of configuring disk storage for a database. In particular, it describes creating an additional filesystem and using Automatic Storage Management (ASM).


Partition the Disks


In order to use either file systems or ASM, you must have unused disk partitions available. This section describes how to create the partitions that will be used for new file systems and for ASM.


WARNING: Improperly partitioning a disk is one of the surest and fastest ways to wipe out everything on your hard disk. If you are unsure how to proceed, stop and get help, or you will risk losing data.


This example uses /dev/sda (an empty disk with no existing partitions) to create a single partition for the entire disk.


Ex:
# fdisk /dev/sda


The number of cylinders for this disk is set to 30401.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)


Command (m for help): p


Disk /dev/sda: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes


Device Boot Start End Blocks Id System


Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-30401, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-30401, default 30401):
Using default value 30401


Command (m for help): w
The partition table has been altered!


Calling ioctl() to re-read partition table.
Syncing disks.
Now verify the new partition:


Ex:
# fdisk -l /dev/sda


Disk /dev/sda: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes


Device Boot Start End Blocks Id System
/dev/sda1 1 30401 244196001 83 Linux
Repeat the above steps for each disk to be partitioned. The following section on Filesystems uses a single disk partition, /dev/sda1. The ASM example uses two disks: /dev/sda1 and /dev/sdb1.
Filesystems


Filesystems are the most widely used means of storing data file, redo logs, and control files for Oracle databases. Filesystems are easy to implement and require no third-party software to administer.


In most cases, filesystems are created during the initial installation of Linux. However, there are times when a new filesystem must be created after the initial installation, such as when a new disk drive is being installed.


This section describes building a new filesystem and using it in an Oracle database. Unless otherwise noted, all commands must be run as root.


Create the Filesystem


Use ext3 to create this new filesystem. Other filesystems work just as well, but ext3 offers the fastest recovery time in the event of a system crash.


Ex:
# mke2fs -j /dev/sda1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
30539776 inodes, 61049000 blocks
3052450 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
1864 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872


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


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


Create the Mount Point


A filesystem must have a mount point, which is simply an empty directory where the new filesystem "attaches" to the system's directory tree. Mount points should be given names consistent with the Oracle Flexible Architecture (OFA) standard. For more information on OFA standards, see Appendix D of the Oracle Database Installation Guide 11g Release 1 (11.1) for Linux.


Because the /u01 directory was created in Part I, this example uses /u02.


Ex:
# mkdir /u02


Add the New Filesystem to /etc/fstab


So that the new filesystem will be mounted automatically when the system boots, you need to add a line to the /etc/fstab file that describes the new filesystem and where to mount it. Add a line similar to the one below to /etc/fstab, using a text editor.


/dev/sda1 /u02 ext3 defaults 1 2


Mount the New Filesystem


Mounting the filesystem makes it available for use. Until the filesystem is mounted, files cannot be stored in it. Use the following commands to mount the filesystem and verify that it is available.


mount /u02
df -h /u02


Ex:
# mount /u02
# df -h /u02
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 230G 188M 218G 1% /u02


Create Oracle Directories and Set Permissions


Now create a directory to store your Oracle database files. The directory name used in the example follows the OFA standard naming convention for a database with ORACLE_SID=demo1.


mkdir -p /u02/app/oracle/oradata/demo1
chown -R oracle:oinstall /u02/app
chmod -R 775 /u02/app


Create a New Tablespace in the New Filesystem


The new filesystem is ready for use. Next you create a new tablespace in the filesystem to store your database objects. Connect to the database as the SYSTEM user, and execute the CREATE TABLESPACE statement, specifying the data file in the new filesystem.


Ex:
$ sqlplus


SQL*Plus: Release 11.1.0.6.0 - Production on Sun Nov 4 15:19:00 2007


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


Enter user-name: system
Enter password:


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


SQL> create tablespace data1
2 datafile '/u01/app/oracle/oradata/demo1/data1_01.dbf' size 100m
3 extent management local
4 segment space management auto;


Tablespace created.
Now you can use the new tablespace to store database objects such as tables and indexes.


Ex:
SQL> create table demotab (id number(5) not null primary key,
2 name varchar2(50) not null,
3 amount number(9,2))
4 tablespace data1;
Table created.
Automatic Storage Management (ASM)
ASM is a disk storage option that provides the services of a filesystem, logical volume manager, and software RAID in a platform-independent manner. ASM can stripe and mirror your disks, allow disks to be added or removed while the database is under load, and automatically balance I/O to remove "hot spots." It also supports direct and asynchronous I/O and implements the Oracle Data Manager API (simplified I/O system call interface) introduced in Oracle9i.


ASM is not a general-purpose filesystem and can be used only for Oracle database related files. Files in ASM can be created and named automatically by the database (by use of the Oracle Managed Files feature) or manually by the DBA. ASM files are not accessible using operating system commands such as ls, cp, and dd. To manage ASM files, use Oracle Enterprise Manager or other Oracle provided methods.


ASM is implemented as a separate Oracle instance that must be running if other databases are to be able to access it. Memory requirements for ASM are light: only 64 MB for most systems.


Installing ASM


ASM can use a variety of storage types including raw partitions, RAID LUNs, and NFS files. For Linux systems, Oracle provides a custom device driver known as ASMLib, which is recommended for most ASM installations on Linux. ASMLib is available for free download from OTN. This section walks through the process of configuring a simple ASM instance using ASMLib 2.0 and building a database that uses ASM for disk storage.


Determine Which Version of ASMLib You Need


ASMLib 2.0 is delivered as a set of three RPM packages.


oracleasmlib-2.0 - the ASM libraries
oracleasm-support-2.0 - utilities needed to administer ASMLib
oracleasm - a kernel module for the ASM library that is specific to each kernel
Each Linux distribution has its own set of ASMLib 2.0 packages (OEL 5 uses the same RPMs as Red Hat Enterprise Linux 5 AS). Within each distribution, each kernel version has a corresponding oracleasm package. The following paragraphs describe how to determine which set of packages you need.
First, determine which kernel you are using by logging in as root and running the following command:


uname -rm


Ex:
# uname -rm
2.6.18-8.el5 i686


The example shows that this is a 2.6.18 kernel, patch level 8, for Enterprise Linux 5 on 32-bit x86 compatible hardware (i686).


Use this information to find the correct ASMLib packages on OTN:


Point your Web browser to http://www.oracle.com/technology/tech/linux/asmlib/index.html
Select the link for your version of Linux (OEL5 users may use the Red Hat Enterprise Linux 5 AS link).
Download the oracleasmlib and oracleasm-support packages for your version of Linux. The files are grouped by architecture (AMD64 / Intel em64t for x86_64, IA64 for Itanium, and IA32 for x86). At the top of each section is a Library and Tools heading. Download both of the files under this heading - these are the support utilities and ASM libraries (oracleasm-support and oracleasmlib, respectively).
Next, download the oracleasm package corresponding to your kernel. In the example above, the oracleasm-2.6.18-8.el5-2.0.4-1.el5.i686.rpm package was used. Note that there are two or three drivers listed under most of the kernel versions. For example:


Drivers for kernel 2.6.18-8.el5


* oracleasm-2.6.18-8.el5xen-2.0.4-1.el5.i686.rpm
* oracleasm-2.6.18-8.el5PAE-2.0.4-1.el5.i686.rpm
* oracleasm-2.6.18-8.el5-2.0.4-1.el5.i686.rpm


Choose only one of these. In this example, there are drivers for Xen (virtual machine architecture), PAE (for 32-bit systems with more than 4GB RAM), and the "standard" 32-bit kernel.
Next, install the packages by executing the following command as root:


rpm -Uvh oracleasm-kernel_version-asmlib_version.cpu_type.rpm \
oracleasmlib-asmlib_version.cpu_type.rpm \
oracleasm-support-asmlib_version.cpu_type.rpm


Ex:
# rpm -Uvh oracleasm-2.6.18-8.el5-2.0.4-1.el5.i686.rpm \
> oracleasm-support-2.0.4-1.el5.i386.rpm \
oracleasmlib-2.0.3-1.el5.i386.rpm
Preparing... ########################################### [100%]
1:oracleasm-support ########################################### [ 33%]
2:oracleasm-2.6.18-8.el5 ########################################### [ 67%]
3:oracleasmlib ########################################### [100%]
Configuring ASMLib


Before using ASMLib, you must run a configuration script to prepare the driver. Run the following command as root, and answer the prompts as shown in the example below.


# /etc/init.d/oracleasm configure
Configuring the Oracle ASM library driver.


This will configure the on-boot properties of the Oracle ASM library
driver. The following questions will determine whether the driver is
loaded on boot and what permissions it will have. The current values
will be shown in brackets ('[]'). Hitting without typing an
answer will keep that current value. Ctrl-C will abort.


Default user to own the driver interface []: oracle
Default group to own the driver interface []: dba
Start Oracle ASM library driver on boot (y/n) [n]: y
Fix permissions of Oracle ASM disks on boot (y/n) [y]: y
Writing Oracle ASM library driver configuration: [ OK ]
Loading module "oracleasm": [ OK ]
Mounting ASMlib driver filesystem: [ OK ]
Scanning system for ASM disks: [ OK ]
Next you tell the ASM driver which disks you want it to use. Oracle recommends that each disk contain a single partition for the entire disk. See Partitioning the Disks at the beginning of this section for an example of creating disk partitions.


Mark disks for use by ASMLib by running the following command as root:


/etc/init.d/oracleasm createdisk DISK_NAME device_name


Tip: Enter the DISK_NAME in UPPERCASE letters.


Ex:
# /etc/init.d/oracleasm createdisk VOL1 /dev/sda1
Marking disk "/dev/sdb1" as an ASM disk: [ OK ]
# /etc/init.d/oracleasm createdisk VOL2 /dev/sdb1
Marking disk "/dev/sdb1" as an ASM disk: [ OK ]
Verify that ASMLib has marked the disks:
# /etc/init.d/oracleasm listdisks
VOL1
VOL2




Create the ASM Instance


ASM runs as a separate Oracle instance which can be created and configured using the Oracle Universal Installer. Now that ASMLib is installed and the disks are marked for use, you can create an ASM instance.


Log in as oracle and start runInstaller:


$ ./runInstaller


Select Installation Method
Select Advanced Installation
Click on Next
Specify Inventory Directory and Credentials
Inventory Directory: /u01/app/oraInventory
Operating System group name: oinstall
Click on Next
Select Installation Type
Select Enterprise Edition
Click on Next
Install Location
Oracle Base: /u01/app/oracle
Name: OraDB11gASM
Path: /u01/app/oracle/product/11.1.0/asm
Note:Oracle recommends using a different ORACLE_HOME for ASM than the ORACLE_HOME used for the database for ease of administration.
Click on Next
Product-specific Prerequisite Checks
If you've been following the steps in this guide, all the checks should pass without difficulty. If one or more checks fail, correct the problem before proceeding.
Click on Next
Select Configuration Option
Select Configure Automatic Storage Management (ASM)
Enter the ASM SYS password and confirm
Click on Next
Configure Automatic Storage Management
Disk Group Name: DATA
Redundancy
- High mirrors data twice.
- Normal mirrors data once. This is the default.
- External does not mirror data within ASM. This is typically used if an external RAID array is providing redundancy.
Add Disks
The disks you configured for use with ASMLib are listed as Candidate Disks. Select each disk you wish to include in the disk group.
Click on Next
Privileged Operating System Groups
Database Administrator (OSDBA) Group: dba
Database Operator (OSOPER) Group: dba
ASM administrator (OSASM) Group: dba
Click on Next
Oracle Configuration Manager Registration
Leave this disabled for the demo
Click on Next
Summary
A summary of the products being installed is presented.
Click on Install.
Install
Installation progress is displayed
Execute Configuration Scripts
At the end of the installation, a pop up window will appear indicating scripts that need to be run as root. Login as root and run the indicated scripts.
Click on OK when finished.
Configuration Assistants
The Oracle Net, Oracle Database, and iSQL*Plus configuration assistants will run automatically
End of Installation
Cick on Exit
Congratulations! Your new Oracle ASM Instance is up and ready for use.


Create the Database


Once the ASM instance has been created, create a database that uses ASM for storage:


Log in as oracle and start runInstaller:


$ ./runInstaller


Select Installation Method
Select Advanced Installation
Click on Next
Select Installation Type
Select Enterprise Edition
Click on Next
Install Location
Oracle Base: /u01/app/oracle
Name: OraDb11g_home1
Path: /u01/app/oracle/product/11.1.0/db_1
Note:Oracle recommends using a different ORACLE_HOME for the database than the ORACLE_HOME used for ASM.
Click on Next
Product-specific Prerequisite Checks
If you've been following the steps in this guide, all the checks should pass without difficulty. If one or more checks fail, correct the problem before proceeding.
Click on Next
Select Configuration Option
Select Create a Database
Click on Next
Select Database Configuration
Select General Purpose
Click on Next
Specify Database Configuration Options
Enter the Global Database Name and SID
Click on Next
Specify Database Config Options
Accept the defaults or change as desired
Click on Next
Select Database Management Option
Select Use Database Control for Database Management
Click on Next
Specify Database Storage Option
Select Automatic Storage Management (ASM)
Click on Next
Specify Backup and Recovery Options
Select Do not enable Automated backups
Click on Next
Select ASM Disk Group
Select the DATA disk group created in the previous section
Click on Next
Specify Database Schema Passwords
Select Use the same password for all the accounts
Enter the password and confirm
Click on Next
Privileged Operating System Groups
Database Administrator (OSDBA) Group: dba
Database Operator (OSOPER) Group: dba
ASM administrator (OSASM) Group: dba
Click on Next
Oracle Configuration Manager Registration
Leave this disabled for the demo
Click on Next
Summary
A summary of the products being installed is presented.
Click on Install.
Configuration Assistants
The Oracle configuration assistants will run automatically
When the configuration is complete, a pop-up window will appear with information about the database. Make note of the URL and click on OK when ready.
Execute Configuration Scripts
At the end of the installation, a pop up window will appear indicating scripts that need to be run as root. Login as root and run the indicated scripts.
Click on OK when finished.
End of Installation
Click on Exit
Congratulations! Your new Oracle Database is up and ready for use.
Conclusion
Now that your database is up and running, you can begin exploring the many new features offered in Oracle Database 11g Release 1. A great place to start is with Oracle Enterprise Manager. If you're unsure where to begin, the Oracle Database Concepts 11g Release 1 and the 2-Day DBA guide will help familiarize you with your new database. OTN also has a number of guides designed to help you get the most out of Oracle Database 11g Release 1.


Appendix
Accessing the Database with SQL*Plus


Log into Linux as oracle. Set the environment.


Set the Oracle environment variables:


$ . oraenv
ORACLE_SID = [demo1] ? demo1
The Oracle base for ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1 is /u01/app/oracle


Run SQL*Plus:


$ sqlplus


SQL*Plus: Release 11.1.0.6.0 - Production on Sun Nov 4 23:56:47 2007


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


Enter user-name: / as sysdba


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


SQL>


Using Oracle Enterprise Manager 11g Database Control


In a Web browser, connect to the URL provided during the installation.


Ex:
https://ds1.orademo.org:1158/em (You may have to use the IP address instead of the host name if your database server isn’t in your DNS.)


User Name: SYSTEM
Password:
Connect As: Normal


Click on




Welcome to Oracle Enterprise Manager 11g Database Control.


Starting and Stopping Oracle Enterprise Manager Database Control:


$ emctl start dbconsole
$ emctl stop dbconsole


Starting and Stopping the Listener:


The listener accepts connection requests from clients and creates connections to the database once the credentials have been authenticated. Before you can use OEM, the listener must be up.


$ lsnrctl start
$ lsnrctl stop


Starting and Stopping the Database:


The easiest way to start and stop the database is from the OEM Console. To do that from the command line, use SQL*Plus while logged in as oracle, as follows:


Startup:


$ sqlplus


SQL*Plus: Release 11.1.0.6.0 - Production on Mon Nov 5 00:00:31 2007


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


Enter user-name: / as sysdba


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


SQL> startup
ORACLE instance started.


Total System Global Area 849530880 bytes
Fixed Size 1303216 bytes
Variable Size 377490768 bytes
Database Buffers 465567744 bytes
Redo Buffers 5169152 bytes
Database mounted.
Database opened.


SQL> exit


Shutdown:


$ sqlplus


SQL*Plus: Release 11.1.0.6.0 - Production on Mon Nov 5 00:00:31 2007


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


Enter user-name: / as sysdba


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


SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.


SQL> exit


PostgreSQL To Identify and Terminate Hang Query

ps -ef | grep postgres to list out all processes belong to postgres user.

Notice process id with "idle in transaction", this is the hanging query in PostgreSQL.
Issue following command to terminate the PostgreSQL process manually.

kill -9 {pid}

PostgreSQL Cannot Start DB Service

Postgres cannot be started up, a file in pg_xlog was deleted, filename 000000010000000100000077

Err shown in $PGDATA/pg_log

2010-12-30 15:59:04 MYT LOG: database system was interrupted; last known up at 2010-12-30 12:19:37 MYT
2010-12-30 15:59:04 MYT LOG: could not open file "pg_xlog/000000010000000100000077" (log file 1, segment 119): No such file or directory
2010-12-30 15:59:04 MYT LOG: invalid primary checkpoint record
2010-12-30 15:59:04 MYT LOG: could not open file "pg_xlog/000000010000000100000077" (log file 1, segment 119): No such file or directory
2010-12-30 15:59:04 MYT LOG: invalid secondary checkpoint record
2010-12-30 15:59:04 MYT PANIC: could not locate a valid checkpoint record
2010-12-30 15:59:04 MYT LOG: startup process (PID 15605) was terminated by signal 6: Aborted
2010-12-30 15:59:04 MYT LOG: aborting startup due to startup process failure


Solution:
/opt/Postgresql/8.4/bin/pg_resetxlog -f $PGDATA

PostgreSQL unixODBC Configuration

Create the following files:

----pgsql-driver.tpl----------------------------------
[PostgreSQL]
Description = PostgreSQL driver for Linux & Win32
Driver = /usr/lib64/libodbcpsql.so
Setup = /usr/lib64/libodbcpsqlS.so


----pgsql-dsn.tpl----------------------------------
[saga80d01]
Description = CP resources db
Driver = PostgreSQL
Trace = No
TraceFile = sql.log
Database = saga80d01
Servername = localhost
UserName = postgres
Password = postgres
Port = 5432
Protocol = 6.4
ReadOnly = No
RowVersioning = No
ShowSystemTables = No
ShowOidColumn = No
FakeOidIndex = No
ConnSettings =
ExtraSysTablePrefixes =



1. Make sure unixODBC is installed
2. Install a driver
- odbcinst -i -d -f pgsql-driver.tpl
3. Install a system DSN
- odbcinst -i -s -f pgsql-dsn.tpl -l
4. Test Connection
- isql -v

PostgreSQL Client Only Installation

./configure --prefix=/opt/Postgresql-8....
gmake -C src/bin install
gmake -C src/include install
gmake -C src/interfaces install
gmake -C doc install

APACHE - failed to start

[On] Red Hat Enterprise Linux Server release 7.4 (Maipo) Apache was not running and attempt to start the httpd service failed. The natural t...