2009年6月29日星期一

The v2 patch 之 InnoDB

  • Innodb_dict_size - number of bytes used for the InnoDB dictionary
  • Innodb_have_atomic_builtins - indicates whether InnoDB uses atomic memory operations in place of pthreads synchronization functions
  • Innodb_heap_enabled - indicates whether the InnoDB malloc heap was enabled -- see Bug38531
  • Innodb_long_lock_wait - set when there is a long lock wait on an internal lock. These usually indicate an InnoDB bug. They also occur because the adaptive hash latch is not always released when it should be (such as during an external sort).
  • Innodb_long_lock_waits - incremented once for each internal long lock wait
  • Innodb_os_read_requests - from SHOW INNODB STATUS
  • Innodb_os_write_requests - from SHOW INNODB STATUS
  • Innodb_os_pages_read - from SHOW INNODB STATUS
  • Innodb_os_pages_written - from SHOW INNODB STATUS
  • Innodb_os_read_time - from SHOW INNODB STATUS
  • Innodb_os_write_time - from SHOW INNODB STATUS
  • Innodb_time_per_read - milliseconds per read
  • Innodb_time_per_write - milliseconds per write
  • Innodb_deadlocks - application deadlocks, detected automatically
  • Innodb_transaction_count - from SHOW INNODB STATUS
  • Innodb_transaction_purge_count - from SHOW INNODB STATUS
  • Innodb_transaction_purge_lag - count of work to be done by the InnoDB purge thread, see InnodbLag
  • Innodb_active_transactions - from SHOW INNODB STATUS
  • Innodb_summed_transaction_age - from SHOW INNODB STATUS
  • Innodb_longest_transaction_age - from SHOW INNODB STATUS
  • Innodb_lock_wait_timeouts - count of lock wait timeouts
  • Innodb_lock_waiters - from SHOW INNODB STATUS
  • Innodb_summed_lock_wait_time - from SHOW INNODB STATUS
  • Innodb_longest_lock_wait - from SHOW INNODB STATUS
  • Innodb_pending_normal_aio_reads - from SHOW INNODB STATUS
  • Innodb_pending_normal_aio_writes - from SHOW INNODB STATUS
  • Innodb_pending_ibuf_aio_reads - from SHOW INNODB STATUS
  • Innodb_pending_log_ios - from SHOW INNODB STATUS
  • Innodb_pending_sync_ios - from SHOW INNODB STATUS
  • Innodb_os_reads - from SHOW INNODB STATUS
  • Innodb_os_writes - from SHOW INNODB STATUS
  • Innodb_os_fsyncs - from SHOW INNODB STATUS
  • Innodb_ibuf_inserts - from SHOW INNODB STATUS
  • Innodb_ibuf_size - counts work to be done by the insert buffer, see InnodbLag
  • Innodb_ibuf_merged_recs - from SHOW INNODB STATUS
  • Innodb_ibuf_merges - from SHOW INNODB STATUS
  • Innodb_log_ios_done - from SHOW INNODB STATUS
  • Innodb_buffer_pool_hit_rate - from SHOW INNODB STATUS


mysql> show variables like 'INNODB%';
+----------------------------------+-------------------------------------------------------------------+
| Variable_name | Value |
+----------------------------------+-------------------------------------------------------------------+
| innodb_additional_mem_pool_size | 2097152 |
| innodb_autoextend_increment | 8 |
| innodb_buffer_pool_awe_mem_mb | 0 |
| innodb_buffer_pool_size | 16777216 |
| innodb_checksums | ON |
| innodb_clear_replication_status | OFF |
| innodb_commit_concurrency | 0 |
| innodb_concurrency_tickets | 500 |
| innodb_confirm_checksum_on_write | OFF |
| innodb_crash_if_init_fails | OFF |
| innodb_data_file_path | ibdata1:2000M;ibdata2:2000M;ibdata3:2000M:ibdata4:100M:autoextend |
| innodb_data_home_dir | /usr/local/mysql5037/var/ |
| innodb_disallow_writes | OFF |
| innodb_doublewrite | ON |
| innodb_extra_dirty_writes | ON |
| innodb_fast_shutdown | 1 |
| innodb_file_io_threads | 4 |
| innodb_file_per_table | ON |
| innodb_flush_log_at_trx_commit | 1 |
| innodb_flush_method | |
| innodb_force_recovery | 0 |
| innodb_io_capacity | 100 |
| innodb_lock_wait_timeout | 50 |
| innodb_locks_unsafe_for_binlog | OFF |
| innodb_log_arch_dir | |
| innodb_log_archive | OFF |
| innodb_log_buffer_size | 8388608 |
| innodb_log_file_size | 5242880 |
| innodb_log_files_in_group | 2 |
| innodb_log_group_home_dir | |
| innodb_max_dirty_pages_pct | 90 |
| innodb_max_purge_lag | 0 |
| innodb_mirrored_log_groups | 1 |
| innodb_open_files | 300 |
| innodb_rollback_on_timeout | OFF |
| innodb_support_xa | ON |
| innodb_sync_spin_loops | 20 |
| innodb_table_locks | ON |
| innodb_thread_concurrency | 8 |
| innodb_thread_sleep_delay | 10000 |
| innodb_read_io_threads | 1 |
| innodb_write_io_threads | 1 |
| innodb_max_merged_io | 64 |
| innodb_status_update_interval | 0 |
+----------------------------------+-------------------------------------------------------------------+
44 rows in set (0.00 sec)

The v2 patch 之 SemiSyncReplication

引自:http://code.google.com/p/google-mysql-tools/wiki/SemiSyncReplicationDesign
半同步复制:
原理图概要:
改变了传统的复制协议(tcp/ip)
改变了commit的方式:至少一个副本已经确认得到更改后进行commit,基本可以 保证数据的一致性,主从服务器都要设定,目前仅对innodb有效
parameters:
  • rpl_semi_sync_enabled configures a master to use semi-sync replication.
  • rpl_semi_sync_slave_enabled configures a slave to use semi-sync replication. The IO thread must be restarted for this to take effect.
  • rpl_semi_sync_timeout is the timeout in milliseconds for the master
mysql> show variables like 'rpl_semi_sync_enabled';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| rpl_semi_sync_enabled | 0 |
+-----------------------+-------+
1 row in set (0.01 sec)

mysql> show variables like 'rpl_semi_sync_slave_enabled';
+-----------------------------+-------+
| Variable_name | Value |
+-----------------------------+-------+
| rpl_semi_sync_slave_enabled | 0 |
+-----------------------------+-------+
1 row in set (0.01 sec)

mysql> show variables like 'rpl_semi_sync_timeout';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| rpl_semi_sync_timeout | 10 |
+-----------------------+-------+
1 row in set (0.00 sec)

mysql> show status like 'rpl%';
+-------------------------------------+-------+
| Variable_name | Value |
+-------------------------------------+-------+
| Rpl_semi_sync_clients | 0 |
| Rpl_semi_sync_net_avg_wait_time(us) | 0 |
| Rpl_semi_sync_net_wait_time | 0 |
| Rpl_semi_sync_net_waits | 0 |
| Rpl_semi_sync_no_times | 0 |
| Rpl_semi_sync_no_tx | 0 |
| Rpl_semi_sync_status | 0 |
| Rpl_semi_sync_slave_status | 0 |
| Rpl_semi_sync_timefunc_failures | 0 |
| Rpl_semi_sync_tx_avg_wait_time(us) | 0 |
| Rpl_semi_sync_tx_wait_time | 0 |
| Rpl_semi_sync_tx_waits | 0 |
| Rpl_semi_sync_wait_pos_backtraverse | 0 |
| Rpl_semi_sync_wait_sessions | 0 |
| Rpl_semi_sync_yes_tx | 0 |
| Rpl_status | NULL |
| Rpl_transaction_support | OFF |
+-------------------------------------+-------+
17 rows in set (0.00 sec)

The v2 patch 之 SqlChanges

杀死idle线程

KILL IF_IDLE can be used to kill a connection but only if it is idle.

MAX_QUERIES_PER_MINUTE can be used in place of MAX_QUERIES_PER_HOUR. This version of MySQL enforces query limits per minute rather than per hour and the value stored in the MySQL privilege table is the rate per minute.

CREATE MAPPED USER 'foo' ROLE 'bar' and
DROP MAPPED USER 'foo'
support mapped users. See
MysqlRoles for more details.

SHOW PROCESSLIST WITH ROLES and
SHOW USER_STATISTICS WITH ROLES use the role name rather than the user name in results..

有用的用户表状态监控 UserTableMonitoring

  • SHOW USER_STATISTICS
  • SHOW TABLE_STATISTICS
  • SHOW INDEX_STATISTICS
  • SHOW CLIENT_STATISTICS
  • FLUSH TABLE_STATISTICS
  • FLUSH INDEX_STATISTICS
  • FLUSH CLIENT_STATISTICS

    MysqlRateLimiting
  • MAKE USER 'foo' DELAYED 1000
  • MAKE CLIENT '10.0.0.1' DELAYED 2000
  • SHOW DELAYED USER
  • SHOW DELAYED CLIENT

SHOW INNODB LOCKS provides more details on InnoDB lock holders and waiters.

FLUSH SLOW QUERY LOGS rotates the slow query log.

MAKE MASTER REVOKE SESSION disconnects all sessions but the current one and prevents future connections from all users unless they have SUPER, REPL_CLIENT or REPL_SLAVE privileges. MAKE MASTER GRANT SESSION undoes this.


mysql> SHOW TABLE_STATISTICS;
+--------------+-----------+--------------+-------------------------+--------+
| Table | Rows_read | Rows_changed | Rows_changed_x_#indexes | Engine |
+--------------+-----------+--------------+-------------------------+--------+
| ETL.Customer | 0 | 2 | 2 | InnoDB |
| mysql.db | 2 | 0 | 0 | MyISAM |
| ETL.Mer | 8 | 1 | 1 | MyISAM |
| mysql.user | 6 | 0 | 0 | MyISAM |
+--------------+-----------+--------------+-------------------------+--------+
4 rows in set (0.00 sec)

mysql> SHOW USER_STATISTICS\G
*************************** 1. row ***************************
User: root
Total_connections: 1
Concurrent_connections: 1
Connected_time: 923
Busy_time: 0
Cpu_time: 0
Bytes_received: 0
Bytes_sent: 352
Binlog_bytes_written: 0
Rows_fetched: 1
Rows_updated: 0
Table_rows_read: 0
Select_commands: 1
Update_commands: 0
Other_commands: 1
Commit_transactions: 0
Rollback_transactions: 0
Denied_connections: 0
Lost_connections: 0
Access_denied: 0
Empty_queries: 0




google-mysql-tools - The v2 patch

install:
498 wget http://downloads.mysql.com/archives/mysql-5.0/mysql-5.0.37.tar.gz
499 mv mysql-5.0.37.tar.gz mysql
500 cd mysql/
502 md5sum mysql-5.0.37.tar.gz

508 gunzip all.v2-mysql-5.0.37.patch.gz
517 cd mysql-5.0.37
518 patch -p1 < ../all.v2-mysql-5.0.37.patch
521 ./configure --prefix=/usr/local/mysql5037
522 make
523 make install
534 cp my.cnf /etc/my.cnf
526 cd /usr/local/mysql5037/
530 bin/mysql_install_db --user=mysql
531 chown -R mysql var 532
chgrp -R mysql . 533

netstat -ultn 535
bin/mysqld_safe --user=mysql &


后来对每个新功能做一介绍

看看mysql Enterprise Monitor tool


想自己开发的朋友,很值得学习参考下

2009年6月19日星期五

一不小心,中了磁碟机病毒(Dummycom)

相信大家都对这个有所耳闻了,有着“病毒之王”的称号,

今天被我遇上了,真是可遇不可求,呵
360下载磁碟机病毒(Dummycom)专杀工具,搞定

2009年6月12日星期五

sqlplus 基本操作 一

1 以 SYS AS SYSDBA 用户身份连接至数据库并关闭数据库。
SQL> CONNECT / AS SYSDBA
Connected.
SQL> SHUTDOWN IMMEDIATE

2 关闭数据库后,从PFILE 中创建 SPFILE。将 SPFILE以 spfileSID.ora 文件
名格式存放在目录$HOME/ADMIN/PFILE 中。使用例程名称来代替SID。从
$HOME/ADMIN/PFILE 目录中的PFILE创建 SPFILE。
SQL> CONNECT / AS SYSDBA
Connected to an idle instance.
SQL> CREATE SPFILE='$HOME/ADMIN/PFILE/spfile$ORACLE_SID.ora'
2 FROM PFILE='$HOME/ADMIN/PFILE/init$ORACLE_SID.ora';

3.从操作系统查看 SPFILE。
SQL> !strings $HOME/ADMIN/PFILE/spfile$ORACLE_SID.ora or
SQL> !more $HOME/ADMIN/PFILE/spfile$ORACLE_SID.ora

4 以 SYS AS SYSDBA 用户身份连接,然后使用 SPFILE 启动数据库。
SQL> CONNECT / AS SYSDBA
Connected to an idle instance.
SQL> STARTUP

2009年6月11日星期四

oracle第一课

Oracle 数据库的物理结构包括控制文件、数据文件和重做日志文件

Oracle 服务器的组件:
Oracle 进程、 Oracle 数据库

Oracle 进程:
用户进程,服务器进程,后台进程
必备后台进程:DBWR,LGWR,PMON,SMON,CKPT,ARCH

数据库层次结构:数据库 表空间 段 区 块

2009年6月10日星期三

登录不能载入libnnz11.so

安装11g,由于没按手册中一步步操作,自己手动简单设置了下,安装后,登录有问题

解决如下:
$ sqlplus ‘/as sysdba’
sqlplus: error while loading shared libraries: /u01/app/oracle/product/11.1.0/db_1/lib/libnnz11.so: cannot restore segment prot after reloc: Permission denied

The reason is that SELinux is running in “enforcing” mode.

You can check it on file /etc/pam.d/login

Oracle development has recommended the following workaround while they correct the problem:

Switch SELinux from the default “Enforcing” mode that it is running in, to the “Permissive” mode.

Commands, as root:
======================
getenforce (returns “Enforcing”)
setenforce 0
getenforce (returns “Permissive”)

This allows SELinux to continue running, and logging denial messages, but SELinux will not actually deny any operations. Once Development has resolved this issue, you can (and should) return SELinux to the default “Enforcing” mode as follows:

Commands, as root:
======================
setenforce 1
getenforce (returns “Enforcing”)

Oracle 10g 静默安装

引用于http://hi.baidu.com/songdeyouxiang/blog/item/49b97b4edc95f53eaec3ab29.html


Oracle 10g 静默安装

Oracle 10G数据库静默安装的实践过程记录及经验总结(linux平台)2007-12-11 20:12本文是作者进行Oracle数据库静默安装的实践过程记录及经验总结。其中10g的静默安装实践是在RHEL AS3U4上进行.(安装测试过不下10次,如果你有问题肯定是你的问题)

使用这种方法安装数据库可以在ssh,telnet命令行界面就可以安装,而不需要OUI界面,并且不需要人去修改任何的配置文件。

1. 静默安装Oracle数据库10g篇
以下是在Linux系统上静默安装Oracle数据库10g的实践过程,主要分为以下两个步骤:

l Step 1.静默安装Oracle数据库10g软件

l Step 2.静默安装Oracle数据库

1.1 Step 1.静默安装Oracle数据库10g软件
1.1.1 使用OUI录制响应文件,记录安装过程

执行以下命令,然后在OUI中根据提示执行安装数据库软件的操作

$./runInstaller –record –destinationFile /tmp/install_database.rsp

注意:

(1)录制过程中选择只安装数据库软件不创建数据库

(2)当安装界面到达最后一步时选择cancel

1.1.2 回放响应文件静默安装Oracle数据库软件

(1)执行以下命令静默安装Oracle数据库软件

$./runInstaller –silent –responseFile /tmp/install_database.rsp

(2)安装完成后执行以下脚本

#. $ORACLE_BASE/oraInventory/orainstRoot.sh

#. $ORACLE_HOME/root.sh

(3)可选参数:

详见website/content/DB/Packaging/ISV_Deployment_Packaging.pdf

举例:$./runInstaller –silent –force -ignoreSysprereqs ORACLE_HOME=/oracle ORACLE_HOME_NAME=OHOME_1 –responseFile /tmp/install_database.rsp

1.1.3 静默卸载Oracle数据库软件

执行以下命令静默卸载Oracle数据库软件

$./runInstaller –silent –deinstall –removeallfiles –removeAllPatches “REMOVE_HOMES={$ORACLE_HOME}” –responseFile /tmp/install_database.rsp

1.2 Step 2.静默安装Oracle数据库
1.2.1 用DBCA创建一个种子数据库――ISV实际需要使用的数据库

(1) 创建初始数据库的时候选择Custom Database模板

(2) 建议使用File System存储机制

(3) 数据文件的存放地点建议选择

Use Oracle-Managed Files

Database Area: {ORACLE_BASE}/oradata

(4) 内存建议选择Custom,指定SGA和PGA大小

(5) 字符集根据实际需要设定

(6) 数据库创建选项里面选择Create Database

(7) 创建应用程序需要的表空间和用户,导入初始数据

1.2.2 用DBCA根据种子数据库创建一个模板

(1) 启动DBCA,选择Manage Templates

(2) 按照提示创建一个模板

1.2.3 将Oracle DB安装盘里面response目录下的dbca.rsp拷贝到本机上

1.2.4 修改dbca.rsp文件,将模板名和DB名添加进去

GDBNAME=medi

SID= media3

TEMPLATENAME=

如果需要使用Oracle Enterprise Manager,则还需要修改以下参数如下:

EMCONFIGURATION=”LOCAL”

SYSMANPASSWORD=”password”

DBSNMPPASSWORD=”password”

1.2.5 执行以下命令使用DBCA根据模板创建新数据库

$./dbca –silent –createdatabase –responseFile /home/oracle/embed/dbca.rsp

建议直接写.ora文件配置listener

------------------Install.sh

#!/bin/bash
echo
date
ORACLE_HOME_NAME=OraDb10g
echo
printf "请输入安装盘目录位置 [/home/oracle/Disk1]:"
read DISK_DRIVE
DISK_DRIVE=${DISK_DRIVE:=/home/oracle/Disk1}
echo
echo "设置oracle初始化参数..."
echo "export ORACLE_SID=huashusp" >> /home/oracle/.bash_profile
echo "export PATH=$PATH:$ORACLE_HOME/bin" >> /home/oracle/.bash_profile
. .bash_profile
echo
printf "请输入Oracle10G 响应文件的地址.[/home/oracle]:"
read response
response=${response:=/home/oracle}
echo
$DISK_DRIVE/runInstaller -silent -force -responseFile $response/media32.rsp &
if [ $? == 0 ]; then
echo ""
echo "数据库安装成功!请接下来在root用户下执行root.sh脚本"
exit
else
echo "数据库安装失败!"
exit
fi
echo
---------------------------------------DBCA.sh

#!/bin/bash
echo
printf "开始安装DBCA,请输入响应文件的位置[/home/oracle]:"
read response
response=${response:=/home/oracle}
cp huashu* $ORACLE_HOME/assistants/dbca/templates/
. .bash_profile
dbca -silent -createdatabase -responseFile $response/dbca.rsp &
if [ $? == 0 ]; then
lsnrctl start
echo "DBCA安装成功!"
sqlplus /nolog < alter.sql
echo "media32用户成功已经激活。"
exit
else
echo "DBCA安装失败!"
exit
fi
echo "请在root用户下执行tomcat.sh脚本安装应用。"


------------------------------alter.sql
conn / as sysdba
alter user media32 identified by media32 account unlock;
alter user sys identified by java123 account unlock;
exit;



//////////////////////////////////////////////////////////
---- Step 1. 准备文件

1). 拷贝文件 10201_database_linux32.zip 到 /oracle目录下;

2). 解压(可用鼠标右击解压,或用口令, cd /oracle)
[root@lym oracle]# uzip 10201_database_linux32.zip

3). 在/etc目录下创建一个名为 oraInst.loc 的文件,文件中的内容(两行代码)如下:
inventory_loc=ORACLE_BASE/oraInventory
inst_group= oinstall

4). 输入下面的命令在oraInst.loc文件上设置合适的拥有者,组和权限:
[root@lym oracle]# chown oracle:oinstall oraInst.loc
[root@lym oracle]# chmod 664 oraInst.loc
//////////////////////////////////////////////////////////
---- Step 2 检查硬件需求
1). 查看系统物理内存,以下输出可以看出,有1G的内存,内存最低要求256M。
[root@lym oracle]# grep MemTotal /proc/meminfo
MemTotal: 1035400 kB

2). 查看交换空间大小,以下输出可以看出,有2G的交换空间,交换空间的最优设置与你物理内存大小相关,详细说明请参考安装文档
[root@lym oracle]# grep SwapTotal /proc/meminfo
SwapTotal: 2096440 kB

3). 查看可用物理内存和交换空间
[root@lym oracle]# free
total used free shared buffers cached
Mem: 1035400 1019716 15684 0 10152 815440
-/+ buffers/cache: 194124 841276
Swap: 2096440 108 2096332

4). 查看挂载的临时分区空间情况
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hda3 8823460 4068908 4299112 49% /

--客户端安装有四种安装模式供选择,各种安装模式的功能及其占用磁盘空间请见安装文档,
--我选择“Administrator”,占用空间为:820 MB,以适应sb1机器的使用要求!

5). 查看处理器类型,看是否适合安装此软件
[root@lym oracle]# grep "model name" /proc/cpuinfo
model name : Intel(R) Celeron(R) CPU 1.70GHz

/////////////////////////////////////////////////////////////////////
---- Step 3 检查软件需求

1). 查看Linux版本
[root@lym oracle]# cat /etc/issue
Red Hat Enterprise Linux Server release 5 (Tikanga)
Kernel \r on an \m

2). 查看内核版本
[root@lym oracle]# uname -a
Linux lym.oracle.com 2.6.18-8.el5 #1 SMP Fri Jan 26 14:15:21 EST 2007 i686 i686 i386 GNU/Linux

3). 检测及安装需要安装的系统软件包
[root@lym Server]# rpm -ivh glibc-headers-2.5-12.i386.rpm
[root@lym Server]# rpm -ivh glibc-devel-2.5-12.i386.rpm
[root@lym Server]# rpm -ivh libgomp-4.1.1-52.el5.i386.rpm
[root@lym Server]# rpm -ivh gcc-4.1.1-52.el5.i386.rpm
[root@lym Server]# rpm -ivh libstdc++-devel-4.1.1-52.el5.i386.rpm
[root@lym Server]# rpm -ivh gcc-c++-4.1.1-52.el5.i386.rpm
[root@lym Server]# rpm -ivh make-3.81-1.1.i386.rpm
[root@lym Server]# rpm -ivh libXp-1.0.0-8.i386.rpm
[root@lym Server]# rpm -ivh openmotif-2.3.0-0.3.el5.i386.rpm
[root@lym Server]# rpm -ivh setarch-2.0-1.1.i386.rpm
[root@lym Server]# rpm -ivh compat-db-4.2.52-5.1.i386.rpm
[root@lym Server]# rpm -ivh compat-gcc-34-3.4.6-4.i386.rpm

[root@lym Server]# rpm -ivh compat-gcc-34-c++-3.4.6-4.i386.rpm

[root@lym Server]# rpm -ivh compat-libstdc++-33-3.2.3-61.i386.rpm

/////////////////////////////////////////////////////////////////////
---- Step 4 配置内核及其他参数
1). vi /etc/sysctl.conf --加入以下11行代码(并将原来的# kernel.shmmax和kernel.shmall这两行参数屏蔽)
kernel.shmall = 2097152

kernel.shmmax = 2147483648

kernel.shmmni = 4096

# semaphores: semmsl, semmns, semopm, semmni

kernel.sem = 250 32000 100 128

fs.file-max = 65536

net.ipv4.ip_local_port_range = 1024 65000

net.core.rmem_default=262144

net.core.rmem_max=262144

net.core.wmem_default=262144

net.core.wmem_max=262144

2). 执行以下命令使以上参数修改生效
[root@lym Server]# /sbin/sysctl -p

3). vi /etc/security/limits.conf --加入以下四行代码
* soft nproc 2047

* hard nproc 16384

* soft nofile 1024

* hard nofile 65536

4). vi /etc/pam.d/login --加入下面一行代码
session required /lib/security/pam_limits.so

5). vi /etc/selinux/config --(禁用SELINUX,安装完后可再还原成原值) 将SELINUX设置为
SELINUX=disabled

////////////////////////////////////////////////////////////
---- Step 5. 添加用户组和用户,并为oracle用户设置密码

[root@lym Server]# groupadd oinstall
[root@lym Server]# groupadd dba
[root@lym Server]# groupadd oper
[root@lym Server]# useradd -g oinstall -G dba oracle
[root@lym Server]# passwd oracle
Changing password for user oracle.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

/////////////////////////////////////////////////////////////
---- Step 6. 创建安装Oracle的文件夹,并设置其相应权限给Oracle用户。
[root@lym Server]# mkdir -p /u01/app/oracle/product/10.2.0/db_1

[root@lym Server]# chown -R oracle.oinstall /u01

[root@lym Server]# chmod 775 /u01

/////////////////////////////////////////////////////////////
---- Step 7. 伪装操作系统版本,使安装Oracle时,通过操作系统验证。
vi /etc/redhat-release --(可保存此文件的副本在某位置,以便安装完成后,复原此文件)
--将这文件中的内容( Red Hat Enterprise Linux Server release 5 (Tikanga) )
替换为如下代码:
redhat-4

/////////////////////////////////////////////////////////////
---- Step 8. Oracle 10g 默认不支持中文
安装时将 /etc/sysconfig/i18n 中的 LANG改为 en 即可

/////////////////////////////////////////////////////////////
---- Step 9. 设置Oracle环境变量(可根据你的需要作适当更改)
[root@lym Server]# vi /home/oracle/.bash_profile --加入内容如下
# Oracle Settings
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR

ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1; export ORACLE_HOME
ORACLE_SID=TSH1; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH

LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/jre:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH

if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi

////////////////////////////////////////////////////////////
---- Step 10. 注销root用户,并登录oracle用户,在/home/oracle目录下建立一个名为enterprise01.rsp的文件,里面的具体内容如下 (参考/oracle/database/response目录下面的enterprise.rsp文件,该目录下有三个文件 enterprise.rsp(企业版静默安装文件),standard.rsp(标准版静默安装文件)和custom.rsp(客户版静默安装文件),另外还有其他三个静默安装文件)。

RESPONSEFILE_VERSION=2.2.1.0.0
FROM_LOCATION="../stage/products.xml"
ORACLE_HOME="/u01/app/oracle/product/10.2.0/db_1/"
ORACLE_HOME_NAME="OraDb10g_home1"
TOPLEVEL_COMPONENT={"oracle.server","10.2.0.1.0"}
DEINSTALL_LIST={"oracle.server","10.2.0.1.0"}
SHOW_SPLASH_SCREEN=false
SHOW_WELCOME_PAGE=false
SHOW_COMPONENT_LOCATIONS_PAGE=false
SHOW_CUSTOM_TREE_PAGE=false
SHOW_SUMMARY_PAGE=false
SHOW_INSTALL_PROGRESS_PAGE=false
SHOW_REQUIRED_CONFIG_TOOL_PAGE=false
SHOW_CONFIG_TOOL_PAGE=false
SHOW_RELEASE_NOTES=false
SHOW_ROOTSH_CONFIRMATION=false
SHOW_END_SESSION_PAGE=false
SHOW_EXIT_CONFIRMATION=false
NEXT_SESSION=false
NEXT_SESSION_ON_FAIL=false
SHOW_DEINSTALL_CONFIRMATION=false
SHOW_DEINSTALL_PROGRESS=false
ACCEPT_LICENSE_AGREEMENT=true
COMPONENT_LANGUAGES={"en"}
CLUSTER_NODES=
INSTALL_TYPE="EE"
s_nameForDBAGrp=dba
s_nameForOPERGrp=dba
b_oneClick=false
SHOW_DATABASE_CONFIGURATION_PAGE=false
b_createStarterDB=false

///////////////////////////////////////////////////////////////////
---- Step 11. 开始安装
[oracle@lym ~]$ cd /oracle/database
[oracle@lym database]$ ./runInstaller -silent -responseFile /home/oracle/enterprise01.rsp

-------安装时终端输出类似如文件"安装过程中的终端显示2.txt"中的内容--------
-------请您耐心等待,可先去喝杯荼!---------

//////////////////////////////////////////////////////////////////
---- Step 12. 以root用户运行安装后环境所需脚本(千万主意:要以root用户去执行这两个脚本,执行后一个脚本时,回车一下就可以了)
[root@lym ~]# sh /u01/app/oracle/oraInventory/orainstRoot.sh
[root@lym ~]# sh /u01/app/oracle/product/10.2.0/db_1/root.sh

---- Step 测试看能否进sqlplus----
[oracle@lym ~]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on Thu May 22 00:25:56 2008

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

SQL>

至此Oracle的产品已经安装完成,可是目前为止我们还没有建立数据库。
由于没有X界面无法启动dbca ,所以不能用dbca来帮我们建立数据库。这时候你可能会想到用create database 语句来建立数据库,可是语法实在是繁琐,并且还要运行许多的
oracle脚本 。

此时,我们可以利用oracle提供的种子数据库还原一个数据库出来(详细见以下操作)
假设我们要建立的数据库的名称为TSH1(这个名称跟你安装前设置的环境变量中的ORACLE_SID相一致)。
-----------------------------------------------------------------------------
---------利用oracle提供的种子数据库还原一个数据库出来 的详细步骤---------------
///////////////////////////////////////////////////////////////////////////
---- Step 1. 建立我们所需的目录,并刷新授权。
[root@lym Server]# mkdir -p /u01/app/oracle/admin/TSH1/{a,b,u}dump
[root@lym Server]# mkdir -p /u01/app/oracle/oradata/TSH1
[root@lym Server]# chown -R oracle.oinstall /u01

[root@lym Server]# chmod 775 /u01
--你可以在oracle用户下,看刷新授权前后,权限的变化(比较如下)。
[oracle@lym oracle]$ ls -l --刷新授权前/uo1/oracle/oracle下面各文件的权限
total 16
drwxr-xr-x 3 root root 4096 May 22 06:24 admin
drwxr-xr-x 3 root root 4096 May 22 06:25 oradata
drwxr-xr-x 6 oracle oinstall 4096 May 22 06:19 oraInventory
drwxr-xr-x 3 oracle oinstall 4096 May 22 06:08 product
[oracle@lym oracle]$ ls -l ----刷新授权后/uo1/oracle/oracle下面各文件的权限
total 16
drwxr-xr-x 3 oracle oinstall 4096 May 22 06:24 admin
drwxr-xr-x 3 oracle oinstall 4096 May 22 06:25 oradata
drwxr-xr-x 6 oracle oinstall 4096 May 22 06:19 oraInventory
drwxr-xr-x 3 oracle oinstall 4096 May 22 06:08 product

/////////////////////////////////////////////////////////////////////////////
---- Step 2. 找到oracle为种子数据库提供的控制文件并copy至/u01/app/oracle/oradata/TSH1目录下(在Oracle用户下操作)。
[oracle@lym oracle]$ cd /u01/app/oracle/product/10.2.0/db_1/assistants/dbca/templates/
[oracle@lym templates]$ cp Seed_Database.ctl /u01/app/oracle/oradata/TSH1

////////////////////////////////////////////////////////////////////////////
---- Step 3. 建立pfile文件(在Oracle用户下操作)。
[oracle@lym templates]$ cd /u01/app/oracle/product/10.2.0/db_1/dbs
[oracle@lym templates]$ vi initTSH1.ora --输入以下三行并保存退出
*.db_name=SEEDDATA
control_files='/u01/app/oracle/oradata/TSH1/Seed_Database.ctl'
compatible=10.2.0.1.0

----注:因为Seed_Database.ctl控制文件中记录的db_name为SEEDDATA,所以第一行的设置如此。
/////////////////////////////////////////////////////////////////////////////
---- Step 4. 启动数据库到mount状态,并使用默认的参数建立spfile文件;然后重新启动数据库并更改sga_max_size,sga_target参数的值;然后再次重新启动数据库(具体操作如下)。
[oracle@lym dbs]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Thu May 22 06:56:19 2008

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

Connected to an idle instance.

SQL> startup mount
ORACLE instance started.

Total System Global Area 113246208 bytes
Fixed Size 1218004 bytes
Variable Size 58722860 bytes
Database Buffers 50331648 bytes
Redo Buffers 2973696 bytes
Database mounted.
SQL> create spfile from pfile;

File created.

SQL> shutdown immediate
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area 113246208 bytes
Fixed Size 1218004 bytes
Variable Size 58722860 bytes
Database Buffers 50331648 bytes
Redo Buffers 2973696 bytes
Database mounted.
SQL> alter system set sga_max_size=200M scope=spfile;

System altered.

SQL> alter system set sga_target=160M scope=spfile;

System altered.

SQL> shutdown immediate
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area 209715200 bytes
Fixed Size 1218580 bytes
Variable Size 100665324 bytes
Database Buffers 104857600 bytes
Redo Buffers 2973696 bytes
Database mounted.
SQL>

///////////////////////////////////////////////////////////////////////////
---- Step 5. 用rman连接数据库
[oracle@lym ~]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Thu May 22 07:22:51 2008

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

connected to target database: SEEDDATA (DBID=3891038516, not open)

RMAN> list backup;

using target database control file instead of recovery catalog

List of Backup Sets
===================

BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
1 Full 89.23M DISK 00:00:36 30-JUN-05
BP Key: 1 Status: AVAILABLE Compressed: YES Tag:
Piece Name: /ade/aime_10.2_lnx_push/oracle/oradata/Seed_Database.dfb
List of Datafiles in backup set 1
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 446074 30-JUN-05 /ade/aime_10.2_lnx_push/oracle/oradata/seeddata/system01.dbf
2 Full 446074 30-JUN-05 /ade/aime_10.2_lnx_push/oracle/oradata/seeddata/undotbs01.dbf
3 Full 446074 30-JUN-05 /ade/aime_10.2_lnx_push/oracle/oradata/seeddata/sysaux01.dbf
4 Full 446074 30-JUN-05 /ade/aime_10.2_lnx_push/oracle/oradata/seeddata/users01.dbf

RMAN>

----可以看到,我们可以利用/ade/aime_10.2_lnx_push/oracle/oradata/Seed_Database.dfb这个备份集来还原数据库。
但是很明显我们系统中并没有这样一个文件/ade/aime_10.2_lnx_push/oracle/oradata /Seed_Database.dfb ,但是查找发现路径/u01/app/oracle/product/10.2.0/db_1/assistants/dbca/templates下有 Seed_Database.dfb文件 。

----此明有两种方法解决此问题,一个是建立一个软链接/ade/aime_10.2_lnx_push/oracle/oradata /Seed_Database.dfb 指向 /u01/app/oracle/product/10.2.0/db_1/assistants/dbca/templates/Seed_Database.dfb 。另一个是创建目录/ade/aime_10.2_lnx_push/oracle/oradata/
并将Seed_Database.dfb copy至其下 。

-- 这里,我们使用第二种方法(具体操作如下):
[root@lym ~]# mkdir -p /ade/aime_10.2_lnx_push/oracle/oradata/
[root@lym ~]# chown -R oracle.oinstall /ade
[root@lym ~]# chmod 775 /ade
[root@lym ~]# su - oracle
[oracle@lym ~]$ cd /u01/app/oracle/product/10.2.0/db_1/assistants/dbca/templates
[oracle@lym templates]$ cp Seed_Database.dfb /ade/aime_10.2_lnx_push/oracle/oradata/
[oracle@lym templates]$

////////////////////////////////////////////////////////////////////////////
---- Step 6. 还原数据库(先在RMAN下执行如下命令)
run {
set newname for datafile '/ade/aime_10.2_lnx_push/oracle/oradata/seeddata/system01.dbf' to '/u01/app/oracle/oradata/TSH1/system01.dbf';
set newname for datafile '/ade/aime_10.2_lnx_push/oracle/oradata/seeddata/sysaux01.dbf' to '/u01/app/oracle/oradata/TSH1/sysaux01.dbf';
set newname for datafile '/ade/aime_10.2_lnx_push/oracle/oradata/seeddata/undotbs01.dbf' to '/u01/app/oracle/oradata/TSH1/undotbs01.dbf';
set newname for datafile '/ade/aime_10.2_lnx_push/oracle/oradata/seeddata/users01.dbf' to '/u01/app/oracle/oradata/TSH1/users01.dbf';
restore database;
switch datafile all;
}

-- 然后,执行如下命令可以看到我们所需要的数据文件都还原回来了,但是现在还缺少log file 。
我们现在打开数据库。
[oracle@lym templates]$ cd /u01/app/oracle/oradata/TSH1
[oracle@lym TSH1]$ ls
Seed_Database.ctl sysaux01.dbf system01.dbf undotbs01.dbf users01.dbf
[oracle@lym TSH1]$

-- 因为控制文件中记录的log file路径为 /ade/aime_10.2_lnx_push/oracle/oradata/seeddata 所以要先创建相应的目录并再次刷新其权限(具体操作如下)。
[root@lym ~]# mkdir -p /ade/aime_10.2_lnx_push/oracle/oradata/seeddata
[root@lym ~]# chown -R oracle.oinstall /ade
[root@lym ~]# chmod 775 /ade

-- 然后在sqlplus中执行如下命令:
[oracle@lym TSH1]$ sqlplus / as sysdba
SQL> alter database open resetlogs;

Database altered.

SQL>

-- 此时,在目录/ade/aime_10.2_lnx_push/oracle/oradata/seeddata 下创建了redo01.log,redo02.log,redo03.log,temp01.dbf文件。

-- 我们要更改这几个文件的路径,所以先将数据库关闭,然后cp /ade/aime_10.2_lnx_push/oracle/oradata/seeddata/× /u01/app/oracle/oradata/orcl/
启动数据库到mount状态,并更改日志和临时文件的路径(具体操作如下)
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>

[oracle@lym ~]$ cd /ade/aime_10.2_lnx_push/oracle/oradata/seeddata
[oracle@lym seeddata]$ cp redo01.log redo02.log redo03.log temp01.dbf /u01/app/oracle/oradata/TSH1/

-- 然后启动数据库到mount状态,并更改日志和临时文件的路径
SQL> startup mount;
ORACLE instance started.

Total System Global Area 209715200 bytes
Fixed Size 1218580 bytes
Variable Size 104859628 bytes
Database Buffers 100663296 bytes
Redo Buffers 2973696 bytes
Database mounted.
SQL> alter database rename file '/ade/aime_10.2_lnx_push/oracle/oradata/seeddata/redo01.log' to '/u01/app/oracle/oradata/TSH1/redo01.log';

Database altered.

SQL> alter database rename file '/ade/aime_10.2_lnx_push/oracle/oradata/seeddata/redo02.log' to '/u01/app/oracle/oradata/TSH1/redo02.log';

Database altered.

SQL> alter database rename file '/ade/aime_10.2_lnx_push/oracle/oradata/seeddata/redo03.log' to '/u01/app/oracle/oradata/TSH1/redo03.log';

Database altered.

SQL> alter database rename file '/ade/aime_10.2_lnx_push/oracle/oradata/seeddata/temp01.dbf' to '/u01/app/oracle/oradata/TSH1/temp01.dbf';

Database altered.

SQL> alter database open;

Database altered.

SQL>

-- 到此数据库已经建立,并且数据文件也放到了我们期待的地方。但是还有一个问题,就是数据库名称不是我们事先期待的。
SQL> show parameter name

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert string
db_name string SEEDDATA
db_unique_name string SEEDDATA
global_names boolean FALSE
instance_name string TSH1
lock_name_space string
log_file_name_convert string
service_names string SEEDDATA
SQL>

////////////////////////////////////////////////////////////////////////
下面我们将数据库名称SEEDDATA改成我们需要的TSH1 。注意此时仅仅更改参数文件的值是不行的,因为控制文件中同样也记录着数据库的名称。

-- Step 7. 更改数据库名称
-- 首先备份控制文件脚本(具体操作如下)
SQL> alter database backup controlfile to trace as '/tmp/ctl.txt';

Database altered.

SQL> create pfile from spfile;

File created.

SQL>

-- 然后将spfile文件(spfileTSH1.ora)删除,编辑pfile文件(initTSH1.ora)将db_name="SEEDDATA" 改成 db_name="TSH1"(具体操作如下)。
[oracle@lym dbs]$ cd /u01/app/oracle/product/10.2.0/db_1/dbs
[oracle@lym dbs]$ rm spfileTSH1.ora
[oracle@lym dbs]$ vi initTSH1.ora

-- 然后保存对initTSH1.ora的修改并退出。
-- 然后vi /home/oracle/ctl2.txt(参考/tmp/ctl.txt重建控制文件脚本),脚本的内容如下:

CREATE CONTROLFILE REUSE DATABASE "SEEDDATA" set database "TSH1" RESETLOGS NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/oradata/TSH1/redo01.log' SIZE 50M,
GROUP 2 '/u01/app/oracle/oradata/TSH1/redo02.log' SIZE 50M,
GROUP 3 '/u01/app/oracle/oradata/TSH1/redo03.log' SIZE 50M
DATAFILE
'/u01/app/oracle/oradata/TSH1/system01.dbf',
'/u01/app/oracle/oradata/TSH1/undotbs01.dbf',
'/u01/app/oracle/oradata/TSH1/sysaux01.dbf',
'/u01/app/oracle/oradata/TSH1/users01.dbf',
'/u01/app/oracle/oradata/TSH1/tt.dbf'
CHARACTER SET US7ASCII
;


-- 然后重新启动数据库到nomount状态,运行上面建立控制文件的脚本,然后打开数据库(具体操作如下) 。
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup nomount;
ORACLE instance started.

Total System Global Area 209715200 bytes
Fixed Size 1218580 bytes
Variable Size 104859628 bytes
Database Buffers 100663296 bytes
Redo Buffers 2973696 bytes
SQL> @/home/oracle/ctl2.txt

Control file created.

SQL> alter database open resetlogs;

Database altered.

SQL>

//////////////////////////////////////////////////////////////////////////
---- Step 8. 控制文件更名并实现冗余
[root@lym ~]# cd /u01/app/oracle/oradata/TSH1
[root@lym TSH1]# mv Seed_Database.ctl control01.ctl
[root@lym TSH1]# cp control01.ctl control02.ctl
[root@lym TSH1]# cp control01.ctl control03.ctl
[root@lym TSH1]# cd /u01/app/oracle/product/10.2.0/db_1/dbs
[root@lym dbs]# chown -R oracle.oinstall /u01
[root@lym dbs]# chmod 775 /u01

-- 修改参数文件initTSH1.ora(修改*.control_files这一行,其内容如下)
[root@lym dbs]# vi initTSH1.ora
*.control_files='/u01/app/oracle/oradata/TSH1/control01.ctl','/u01/app/oracle/oradata/TSH1/control02.ctl','/u01/app/oracle/oradata/TSH1/control03.ctl'

-- 重新启动数据库,大功告成!
SQL> startup
ORACLE instance started.

Total System Global Area 209715200 bytes
Fixed Size 1218580 bytes
Variable Size 104859628 bytes
Database Buffers 100663296 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
SQL> show parameter name

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert string
db_name string TSH1
db_unique_name string TSH1
global_names boolean FALSE
instance_name string TSH1
lock_name_space string
log_file_name_convert string
service_names string TSH1
SQL> create user lym identified by lym;

User created.

SQL> grant resource to lym;

Grant succeeded.

SQL> grant create session to lym;

Grant succeeded.

SQL> conn lym/lym;
Connected.
SQL> select sysdate from dual;

SYSDATE
---------
22-MAY-08

SQL>

listener问题

[oracle@localhost bdump]$ sqlplus vincent/vincent@oracle
SQL*Plus: Release 10.2.0.1.0 - Production on Fri May 22 20:36:10 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
ERROR:
ORA-12541: TNS:no listener

[oracle@localhost ~]$ lsnrctl start
[oracle@localhost ~]$ sqlplus vincent/vincent@oracle

SQL*Plus: Release 10.2.0.1.0 - Production on Fri May 22 20:36:34 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor

[oracle@localhost ~]$ tnsping localhost
TNS Ping Utility for Linux: Version 10.2.0.1.0 - Production on 22-MAY-2009 20:37:37
Copyright (c) 1997, 2005, Oracle. All rights reserved.
Used parameter files:
/u01/app/oracle/oracle/product/10.2.0/db_1/network/admin/sqlnet.ora

Used EZCONNECT adapter to resolve the alias
Attempting to contact (DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=localhost.localdomain))(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))
OK (10 msec)

tcp 0 0 0.0.0.0:1521 0.0.0.0:* LISTEN


[oracle@localhost admin]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Fri May 22 20:43:47 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn vincent/vincent
Error accessing PRODUCT_USER_PROFILE
Warning: Product user profile information not loaded!
You may need to run PUPBLD.SQL as SYSTEM
Connected.
SQL>

$ sqlplus vincent/vincent登录不上

google:
/u01/app/oracle/oracle/product/10.2.0/db_1/network/admin
listener.ora

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle/oracle/product/10.2.0/db_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = billy)
(ORACLE_HOME = /u01/app/oracle/oracle/product/10.2.0/db_1)
(SID_NAME = billy)
)
)

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521))
)
)
//添加斜体字部分

重启oracle

可以用
$ sqlplus vincent/vincent登录

另注意上面有个
Error accessing PRODUCT_USER_PROFILE
引用
其实在实际意义上这只是个警告而已,并不是真正的错误,遇见这个提示,并不会影响我们正常使用sql*plus,也不会对数据库功能产生影响。

如果数据库是使用dbca创建的那么不用担心这个问题,通常是我们手动创建数据库的情况下,忘了执行一些脚本才导致出现这样的警告。 product_user_profile其实有非常强大的功能,这是system模式下的一个表,在此表中存在的数据能让客户端程式登入的时候检查是否 在命令的执行上有什么限制。基本上我们是以他来限制sql*plus这个客户端程式(目前似乎也只有这个程式才会去自动检查这张表:d)

解决:
[oracle@localhost admin]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Fri May 22 21:25:52 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn system/manager
//默认密码:要修改以sys登录,alter user system identified by yourpass;
Connected.
SQL> @/u01/app/oracle/oracle/product/10.2.0/db_1/sqlplus/admin/pupbld.sql

SQL> desc product_user_profile;
Name Null? Type
----------------------------------------- -------- ----------------------------
PRODUCT NOT NULL VARCHAR2(30)
USERID VARCHAR2(30)
ATTRIBUTE VARCHAR2(240)
SCOPE VARCHAR2(240)
NUMERIC_VALUE NUMBER(15,2)
CHAR_VALUE VARCHAR2(240)
DATE_VALUE DATE
LONG_VALUE LONG

再次尝试登录
[oracle@localhost admin]$ sqlplus vincent/vincent
SQL*Plus: Release 10.2.0.1.0 - Production on Fri May 22 21:26:27 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

--OK

手动创建oracle数据库

安装oracle时,只安装软件
---------------------------
创建密码验证文件
orapwd file=/u01/app/oracle/oracle/product/10.2.0/db_1/dbs/orapwbilly password=billy entries=10

创建初始化参数文件
[oracle@localhost dbs]$ pwd
/u01/app/oracle/oracle/product/10.2.0/db_1/dbs
cat initbilly.ora
billy.__db_cache_size=96468992
billy.__java_pool_size=4194304
billy.__large_pool_size=4194304
billy.__shared_pool_size=58720256
billy.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/billy/adump'
*.background_dump_dest='/u01/app/oracle/admin/billy/bdump'
*.compatible='10.2.0.1.0'
*.control_files='/u01/app/oracle/oradata/billy/control01.ctl','/u01/app/oracle/oradata/billy/control02.ctl'
*.core_dump_dest='/u01/app/oracle/admin/billy/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='billy'
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=2147483648
*.dispatchers='(PROTOCOL=TCP) (SERVICE=billyXDB)'
*.job_queue_processes=10
*.log_archive_format='%t_%s_%r.dbf'
*.open_cursors=300
*.pga_aggregate_target=16777216
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=167772160
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS2'
*.user_dump_dest='/u01/app/oracle/admin/billy/udump'

创建相应的目录:
mkdir -p /u01/app/oracle/oradata/billy
mkdir -p /u01/app/oracle/admin/billy
cd /u01/app/oracle/admin/billy
mkdir adump cdump udump bdump

设置SID及其他环境变量
export ORACLE_SID=billy

创建数据库
sqlplus /nolog
SQL> conn / as sysdba
SQL> startup pfile=$ORACLE_HOME/dbs/initbilly.ora nomount

注意:undo tablespace UNDOTBS2-->这个名字要和initbilly.ora中定义的一致
SQL>create database billy
maxinstances 4
maxloghistory 2
maxlogfiles 16
maxlogmembers 2
maxdatafiles 8
character set zhs16gbk
national character set al16utf16
datafile '/u01/app/oracle/oradata/billy/system.dbf' size 20m autoextend on next 1m maxsize unlimited
sysaux datafile '/u01/app/oracle/oradata/billy/sysaux.dbf' size 20m autoextend on next 1m maxsize unlimited
default temporary tablespace temp tempfile '/u01/app/oracle/oradata/billy/temp.dbf' size 20m extent management local uniform size 32k
undo tablespace UNDOTBS2 datafile '/u01/app/oracle/oradata/billy/UNDOTBS2.dbf' size 50m
logfile
group 1 ('/u01/app/oracle/oradata/billy/redo0101.dbf') size 10m,
group 2 ('/u01/app/oracle/oradata/billy/redo0201.dbf') size 10m;

或把创建命令放在一个文件里 @filename调用
在创建过程的日志记录在/u01/app/oracle/admin/billy/bdump/alert_billy.log文件

如果要删除数据库,方法:
1、DBCA
2、删除相应的目录
3、Oracle 10g命令drop database。
SQL> conn / as sysdba
SQL> startup pfile=$ORACLE_HOME/dbs/initbilly.ora nomount restrict exclusive mount;
SQL> drop database;.

创建数据库内部对象

SQL> @ ?/rdbms/admin/catalog.sql;
SQL> @ ?/rdbms/admin/catproc.sql;

以上在执行的时候,如想记录执行的LOG,可用
SQL> spool catproc.log
SQL> @ ?/rdbms/admin/catproc.sql;
SQL> spool off

(以上创建DATABASE时,创建的是系统表空间)
创建用户表空间
create tablespace users datafile '/u01/app/oracle/oradata/billy/users.dbf' size 50M uniform size 64k;

创建用户
create user vincent identified by vincent default tablespace users;
grant create session to vincent;
grant create table to vincent;
alter user vincent quota unlimited on users;
SQL> create table stu(
2 id int,
3 name varchar2(20));
Table created.

SQL> insert into stu values(1,'vincent');
1 row created.

SQL> commit;
Commit complete.

SQL> select * from stu;

ID NAME
---------- --------------------
1 vincent
1 row selected.

2009年6月9日星期二

oracle server mode--dedicated and shared

Oracle 服务器模式
前言:oracle进程包括background process,server process,user process ,others
类型:dedicated and shared
区别:专用模式: 每个user连接进来,oracle启动一个server process来处理请求,N个用户,N个server process
共享模式: 所有user连接进来,oracle只启动固定数理的server process 处理请求,主要用在 OLTP 业务中
switcher进程来决定哪个用户请求使用哪一个server procsee 进程

共享模式配置:
1. 设置 DISPATCHERS 参数
*.DISPATCHERS='(PROTOCOL=TCP)(SERVICE=SKYSH)(DISPATCHERS=2)(PROTOCOL=IPC)(DISPATCHERS=1)'
DISPATCHER

的端口是随机分配的,如果要固定每个 DISPATCHER 的端口,可以用一下方法:
使用不同端口:

*.DISPATCHERS='(ADDRESS=(PROTOCOL=TCP)(PORT=5000))(DISPATCHERS=1)','(ADDRESS=(PROTOCOL=TCP)(PORT=5001))(DISPATCHERS=1)'

使用相同端口:

*.dispatchers='(ADDRESS=(PROTOCOL=TCP)(PORT=5002))(SERVICE=SKYSHR)(DISPATCHERS=1)'

DISPATCHERS 只能用 alter system set DISPATCHERS 来临时添加删除 dispatcher,重启之后又恢复原值,且不能使用 scope 参数。

其中,SERVICE=SKYSH 参数可以不指定,如果不指定,则需要指定 service_names 和 instance_name 初始参数,当 instance 启动时,PMON 会动态将 SERVICE 或者 service_names 指定的值邦定到 LISTENER,并生成 dispatchers。

DISPATCHERS=2 如果不指定,那么默认值是 1。
PROTOCOL:当使用 Shared Server 连接时,必须通过 Oracle Net Services,即使客户端和数据库在同一台机子上,如果在 Windows NT 上,dispatchers 只能使用 TCP/IP 协议。

2.设置客户端 tnsnames.ora 文件:

SKY3 =

(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.123)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = SKYSH.heysky.net)
(SERVER = SHARED)
)
)

相关参数更改

1、DISPATCHERS参数
数据库启动时,启动的调度程序的数量
eg:
配置2个TCP/IP调度程序和3个IPC调度程序
DISPATCHERS = “(PRO=TCP)(DIS=2)(PRO=IPC)(DIS=3)”

使用ALTER命令修改DISPATCHERS参数
ALTER SYSTEM SET DISPATCHERS = “(PRO=TCP)(DIS=2)”

使用DISPATCHERS参数配置连接集储(connection pooling)
连接集储定义:自动断开空闲连接和使用空闲连接为连接请求提供服务
eg:
DISPATCHERS=”(PROTOCOL=tcp)(DISPATCHERS=1)(POOL=ON)(TICK=1)(CONNECTIONS=500)(SESSIONS=1000)”
解释:
POOL=ON 打开连接集储
TICK=1 一个连接在经过一个非活动性的10分钟增量后被看做空闲的
2、MAX_DISPATCHERS参数
ORACLE SHARED SERVER需要的最大调度程序数据

使用ALTER命令修改
ALTER SYSTEM SET MAX_DISPATCHERS=10

3、SHARED_SERVERS参数
ORACLE实例启动和保持最小shared server数量

使用ALTER命令修改
ALTER SYSTEM SET SHARED_SERVERS=10

4、SHARED_SERVER_SESSION参数
ORACLE实例预测shared server会话的总数量

使用ALTER命令修改
ALTER SYSTEM SET SHARED_SERVER_SESSION =10

5、MAX_SHARED_SERVERS参数
并发运行shared server的最大数量
视图V$SHARED_SERVER_MONITOR可以查看ORACLE实例启动以来的shared server数量

使用ALTER命令修改
ALTER SYSTEM SET MAX_SHARED_SERVERS=10

6、CIRCUITS参数
控制一个输入输出网络会话所预测的虚拟电路的总数量

使用ALTER命令修改
ALTER SYSTEM SET CIRCUITS=10


2009年6月8日星期一

Innodb备份--innobackup

此文不讨论冷备
也不讨论mysqldump逻辑备份

http://www.innodb.com/doc/hot_backup/manual.html#innobackup
一个perl脚本,还没仔细了解备份细节,过几天分析下脚本内容

查看帮助
$ perl ibbackup

Usage:
innobackup [--sleep=MS] [--compress[=LEVEL]] [--include=REGEXP] [--user=NAME]
[--password=WORD] [--port=PORT] [--socket=SOCKET] [--no-timestamp]
[--ibbackup=IBBACKUP-BINARY] [--slave-info]
[--databases=LIST] MY.CNF BACKUP-ROOT-DIR
innobackup --apply-log [--use-memory=MB] [--uncompress]
[--ibbackup=IBBACKUP-BINARY] MY.CNF BACKUP-DIR
innobackup --copy-back MY.CNF BACKUP-DIR

创建一个备份

$ perl innobackup /home/pekka/.my.cnf /backups




2009年6月7日星期日

数据库基础--ACID

ACID,指数据库事务正确执行的四个基本要素的缩写.包含:
原子性(Atomicity)、
一致性(Consistency)、
隔离性 (Isolation)、
持久性(Durability)。

一个支持事务(Transaction)的数据库系统,必需要具有这四种特性,否则在事务过程 (Transaction processing)当中无法保证数据的正确性,交易过程极可能达不到交易方的要求.
  原子性
  整个事务中的所有操作,对于其数据修改,要么全都执行,要么全都不执行。不可能停滞在中间某个环节。事务在执行过程中发生错误,会被回滚(Rollback)到事务开始前的状态,就像这个事务从来没有执行过一样。
  一致性
  在事务开始之前和事务结束以后,数据库的完整性约束没有被破坏。
  隔离性
  两个事务的执行是互不干扰的,一个事务不可能看到其他事务运行时,中间某一时刻的数据。
  持久性
  在事务完成以后,该事务所对数据库所作的更改便持久的保存在数据库之中,并不会被回滚。

目前主要有两种方式实现ACID:
第一种是Write ahead logging,也就是日志式的方式。
第二种是Shadow paging。

Innodb 架构 From MySQL Conference, April 2009


虽然在2006年的Conf上已经有人展示了INNODB的相关特性,但这次,由Heikki Tuuri,Calvin Sun二位来自Oracle的大师,向我们展示了更多关于innodb的内部结构及底层相关内容,非常棒!

基本特征

磁盘文件:
InnoDB数据库文件

InnoDB表空间(innodb_file_per_table)
file_name:file_size[:autoextend[:max:max_file_size]]

InnoDB 页/ extents
InnoDB 行 (row-locking)
InnoDB 索引
InnoDB日志文件

开通Blogger

今天在这里安个家了,以后常回来住,^_^ ……