安泰信息

2008年08月21日

当当网购书:通过oracle连接sqlserver数据库

归档在: DB — JACKEYJ @ 4:31 PM

在Oracle里同时能访问SQL Server里默认的pubs和Northwind两个数据库。

可参考最初写的通过异构服务链接oracle 和sql server 数据库服务器。当当网购书

1、在安装了ORACLE9i Standard Edition或者ORACLE9i EntERPrise Edition的Windows机器上(IP:192.168.0.1),
   产品要选了透明网关(Oracle Transparent Gateway)里要访问Microsoft SQL Server数据库.

$ORACLE9I_HOME\tg4msql\admin下新写initpubs.ora和initnorthwind.ora配置文件
initpubs.ora内容如下:
HS_FDS_CONNECT_INFO=”SERVER=sqlserver_hostname;DATABASE=pubs”
HS_DB_NAME=pubs
HS_FDS_TRACE_LEVEL=OFF
HS_FDS_RECOVERY_ACCOUNT=RECOVER
HS_FDS_RECOVERY_PWD=RECOVER

initnorthwind.ora内容如下:
HS_FDS_CONNECT_INFO=”SERVER=sqlserver_hostname;DATABASE=Northwind”
HS_DB_NAME=Northwind
HS_FDS_TRACE_LEVEL=OFF
HS_FDS_RECOVERY_ACCOUNT=RECOVER
HS_FDS_RECOVERY_PWD=RECOVER

(蓝色字的部分可以根据具体要访问的SQL Server数据库的情况而修改)

$ORACLE9I_HOME\network\admin 下listener.ora内容如下:

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.1)(PORT = 1521))
      )
    )
  )

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = test9)
      (ORACLE_HOME = d:\oracle\ora92)
      (SID_NAME = test9)
    )
    (SID_DESC=
      (SID_NAME=pubs)
      (ORACLE_HOME=d:\Oracle\Ora92)
      (PROGRAM=tg4msql)
    )
    (SID_DESC=
      (SID_NAME=northwind)
      (ORACLE_HOME=d:\Oracle\Ora92)
      (PROGRAM=tg4msql)
    )
  )

重启动这台做gateway的Windows机器上(IP:192.168.0.1)TNSListener服务.

(凡是按此步骤新增可访问的SQL Server数据库时,TNSListener服务都要重启动)当当网购书

2、ORACLE8I,ORACLE9I的服务器端配置tnsnames.ora, 添加下面的内容:

pubs =
  (DESCRIPTION =
  (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SID = pubs)
    )
    (HS = pubs)
   )
 
northwind =
  (DESCRIPTION =
  (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SID = northwind)
    )
    (HS = northwind)
   ) 
 
   保存tnsnames.ora后,在命令行下
 
   tnsping pubs
   tnsping northwind
 
出现类似提示,即为成功
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)
(PORT = 1521))) (CONNECT_DATA = (SID = pubs)) (HS = pubs))
OK(20毫秒)
 
   Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)
(PORT = 1521))) (CONNECT_DATA = (SID = northwind)) (HS = northwind))
OK(20毫秒)

设置数据库参数global_names=false。

设置global_names=false不要求建立的数据库链接和目的数据库的全局名称一致。
global_names=true则要求, 多少有些不方便。

oracle9i和oracle8i都可以在DBA用户下用SQL命令改变global_names参数

alter system set global_names=false;

建立公有的数据库链接:

create public database link pubs connect to testuser identified by testuser_pwd using ‘pubs’;

create public database link northwind connect to testuser identified by testuser_pwd using ‘northwind’;

(假设SQL Server下pubs和northwind已有足够权限的用户登录testuser,密码为testuser_pwd)

访问SQL Server下数据库里的数据:

select * from stores@pubs;
…… ……

select * from region@northwind;
……  ……

使用sql *plus copy命令从本地数据库复制暑假到MS SQL SERVER中:

copy from scott/tiger@myoracle  insert   EMP@pubs  using  select * from EMP

3、使用时的注意事项当当网购书

ORACLE通过访问SQL Server的数据库链接时,用select * 的时候字段名是用双引号引起来的。

2008年05月30日

Oracle 10g R2 在 x86_64位 CentOS 4.4 系统上的安装-2

归档在: Linux, DB — JACKEYJ @ 5:04 PM

Oracle 10g R2 在 x86_64位 CentOS 4.4 系统上的安装

前提:配置Yum服务,当os上没有对应的依赖包时,可以使用Yum服务添加相应的依赖包。
1、log in system as root.
uname -a
Linux oracle10gsvr 2.6.16.29-xenU-hosting-3.0.0 #3 SMP Fri Jan 12 14:00:48 CST 2007 x86_64 x86_64 x86_64 GNU/Linux

2、硬件需求:1GB以上内存,硬盘空间最好2G以上,/tmp至少400MB以上。
3、安装以下包:

binutils-2.15.92.0.2-10.EL4
compat-db-4.1.25-9
control-center-2.8.0-12
gcc-3.4.3-9.EL4
gcc-c++-3.4.3-9.EL4
glibc-2.3.4-2
glibc-common-2.3.4-2
gnome-libs-1.4.1.2.90-44.1
libstdc++-3.4.3-9.EL4
libstdc++-devel-3.4.3-9.EL4
make-3.80-5
xorg-x11-libs.i386
xorg-x11-deprecated-libs.i386
libaio.i386
libaio.x86_64
libaio-devel.x86_64
libgcc.i386
libgcc.x86_64

可以用:”rpm -qa –queryformat “%{NAME}-%{VERSION}.%{RELEASE} (%{ARCH})\n” | grep ${要查看的包}” 进行包的查看

4、在/etc/hosts中给你的域名主机取别名为主机名前缀。
5、创建用户组oinstall,用户oracle(属于oinstall)。

/usr/sbin/groupadd oinstall
/usr/sbin/useradd -g oinstall oracle
/usr/sbin/groupadd oinstall
groupadd dba
groupadd asadmin
usermod  -g oinstall -G dba,asadmin oracle
6、passwd oracle
7、vi /etc/sysctl.conf加入以下内容:

kernel.shmall = 2097152
kernel.shmmax = 2147483648
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 = 1048576
net.core.rmem_max = 1048576
net.core.wmem_default = 262144
net.core.wmem_max = 262144

然后执行/sbin/sysctl -p

8、修改oracle用户的环境变量

su - oracle
vi  .bash_profile 添加:
export ORACLE_SID=orcl10g
export ORACLE_BASE=/infolab/oracle10g
export ORACLE_HOME=/infolab/oracle10g/product/10.2.0/db_1
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/lib32:$LD_LIBRARY_PATH

9、下载oracle的安装程序,如果是*.cpio.gz文件,运行如下命令:

gzip –decompress ${下载的文件}
cpio -idmv < ${解压后的cpio文件}

10、进入解压后的oracle安装文件目录下的response目录,复制enterprise.rsp文件并保存一份备份文件。随后按照文档中的提示内容进行相应的"“调整备用
11、退出response目录,在解压后的安装目录中,运行:”./runInstaller -silent -responseFile ${当前目录}/response/standard.rsp”
注意,在standard.rsp文件中我们不在安装过程中创建DB,只安装程序文件。

[oracle@oracle10gsvr database]$ ./runInstaller -silent -responseFile /tmp/standard.rsp

12、随后系统进入相关的安装状态,过程中,可能会出现一些问题,需要查看系统相关提示进行rpm包的安装后,运行安装目录下bin目录中的relink all进行新安装文件的链接。
13、如果系统出现问题,可以手工进行网络服务的配置和监听。
$ORACLE_HOME/bin/netca /silent /responsefile /local_dir/netca.rsp
14、手动创建DB
[oracle@oracle10gsvr database]$ dbca -silent -cloneTemplate -responseFile /infolab/src/database/response/dbca.rsp
Copying database files
1% complete
100% complete
Look at the log file “/infolab/oracle10g/product/10.2.0/db_1/cfgtoollogs/dbca/orcl10g/orcl10g.log” for further details.
15、 添加tnsname 别名
[oracle@oracle10gsvr database]$ vi /infolab/oracle10g/product/10.2.0/db_1/network/admin/tnsnames.ora

加入下列内容:

orcl10g =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(PROTOCOL=tcp)
(HOST=10.10.31.180)
(PORT=1521)
)
)

(CONNECT_DATA =
(SID = orcl10g)
)
)

15、系统安装完毕后的验证:
输入: sqlplus “/ as sysdba” 后,如果系统没有任何错误信息,且”netstat -antp | grep 1521″后有相应的记录,表明数据库安装成功,且服务正常。

16、创建自启动文件

vi /etc/init.d/oracledb

内容:

#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.

ORA_HOME=/infowarelab/oracle10g/product/10.2.0/db_1
ORA_OWNER=oracle

if [ ! -f $ORA_HOME/bin/dbstart ]
then
echo “Oracle startup: cannot start”
exit
fi

case “$1″ in
’start’)
# Start the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
su - $ORA_OWNER -c “$ORA_HOME/bin/dbstart $ORA_HOME”
;;
’stop’)
# Stop the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
su - $ORA_OWNER -c “$ORA_HOME/bin/dbshut $ORA_HOME”
;;
esac
#################################################

Note:

This script can only stop Oracle Net listener for which a password has not been set. In addition, if the listener name is not the default name, LISTENER, then you must specify the listener name in the stop and start commands:
$ORACLE_HOME/bin/lsnrctl {start &brvbarstop} listener_name

17、Change the group of the dbora file to the OSDBA group (typically dba), and set the permissions to 750:

# chgrp dba oracledb
# chmod 750 oracledb

18、Create symbolic links to the dbora script in the appropriate run-level script directories as follows:

Platform Symbolic Links Commands

Linux
# ln -s /etc/init.d/oracledb /etc/rc.d/rc3.d/K01oracledb
# ln -s /etc/init.d/oracledb /etc/rc.d/rc3.d/S99oracledb
# ln -s /etc/init.d/oracledb /etc/rc.d/rc5.d/K01oracledb
# ln -s /etc/init.d/oracledb /etc/rc.d/rc5.d/S99oracledb

其他自动启动的方法:
1) /etc/rc.local add lines
su - oracle -c “dbstart”
su - oracle -c “lsnrctl start”

2) use chkconfig
chkconfig –add oracledb
chkconfig –level 3 oracledb on

问题列表:

安装完成后一直有问题,
su oracle
dbstart
提示:
“Failed to auto-start Oracle Net Listene using /ade/vikrkuma_new/oracle/bin/tnslsnr”
解决办法:

To solve this problem please follow the steps.

Step 1 Edit $ORACLE_HOME/bin/dbstart
Step 2 Goto line 78
Step 3 Replace the line with
ORACLE_HOME_LISTNER=$ORACLE_HOME
Step 4 Save and exit the editor.
Step 5 Now reexecute the dbstart

见:http://forums.oracle.com/forums/thread.jspa?messageID=1094708

2008年05月29日

oracle dbstart执行失败问题

归档在: Linux, DB — JACKEYJ @ 8:49 PM

SQL>
/infowarelab/oracle10g/product/10.2.0/db_1/bin/dbstart: Database instance “orcl10g” warm started.

/infowarelab/oracle10g/product/10.2.0/db_1/bin/dbstart: Starting up database “orcl10g”
Thu May 29 20:21:17 CST 2008

SQL*Plus: Release 10.2.0.1.0 - Production on Thu May 29 20:21:18 2008

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

SQL> ERROR:
ORA-01031: insufficient privileges

SQL> ORA-01031: insufficient privileges
SQL>

(更多…)

oracle 10g r2 dbstart无法启动

归档在: Linux, DB — JACKEYJ @ 7:05 PM

安装完成后一直有问题,
su oracle
dbstart
提示:
“Failed to auto-start Oracle Net Listene using /ade/vikrkuma_new/oracle/bin/tnslsnr”
解决办法:

To solve this problem please follow the steps.

Step 1 Edit $ORACLE_HOME/bin/dbstart
Step 2 Goto line 78
Step 3 Replace the line with
ORACLE_HOME_LISTNER=$ORACLE_HOME
Step 4 Save and exit the editor.
Step 5 Now reexecute the dbstart

见:http://forums.oracle.com/forums/thread.jspa?messageID=1094708

Oracle 10g R2 在 x86_64位 CentOS 4.4 系统上的安装

归档在: Linux, DB — JACKEYJ @ 2:56 PM

Oracle 10g R2 x86_64 CentOS 4.4 系统上的安装

前提:配置Yum服务,当os上没有对应的依赖包时,可以使用Yum服务添加相应的依赖包。
1
log in system as root.

uname -a

Linux oracle10gsvr 2.6.16.29-xenU-hosting-3.0.0 #3 SMP Fri Jan 12 14:00:48 CST 2007 x86_64 x86_64 x86_64 GNU/Linux


2
、硬件需求:1GB以上内存,硬盘空间最好2G以上,/tmp至少400MB以上。
3
、安装以下包:

binutils-2.15.92.0.2-10.EL4
compat-db-4.1.25-9
control-center-2.8.0-12
gcc-3.4.3-9.EL4
gcc-c++-3.4.3-9.EL4
glibc-2.3.4-2
glibc-common-2.3.4-2
gnome-libs-1.4.1.2.90-44.1
libstdc++-3.4.3-9.EL4
libstdc++-devel-3.4.3-9.EL4
make-3.80-5
xorg-x11-libs.i386
xorg-x11-deprecated-libs.i386
libaio.i386
libaio.x86_64
libaio-devel.x86_64
libgcc.i386
libgcc.x86_64

可以用:“rpm -qa –queryformat “%{NAME}-%{VERSION}.%{RELEASE} (%{ARCH})\n” | grep ${要查看的包}” 进行包的查看


4
、在/etc/hosts中给你的域名主机取别名为主机名前缀。
5
、创建用户组oinstall,用户oracle(属于oinstall)

/usr/sbin/groupadd oinstall
/usr/sbin/useradd -g oinstall oracle

  groupadd dba

  groupadd asadmin

usermod  -g oinstall -G dba,asadmin oracle6passwd oracle
7
vi /etc/sysctl.conf加入以下内容:

kernel.shmall = 2097152
kernel.shmmax = 2147483648
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 = 1048576
net.core.rmem_max = 1048576
net.core.wmem_default = 262144
net.core.wmem_max = 262144

然后执行/sbin/sysctl –p


8
、修改oracle用户的环境变量

su - oracle
vi  .bash_profile 添加:
export ORACLE_SID=${
计划的数据库服务名}
export ORACLE_BASE=${
计划存放数据库db文件的地方,如存储}
export ORACLE_HOME=${oracle
安装后的运行目录}
export PATH=$ORACLE_HOME/bin:$PATH
export NLS_LANG=”UTF-8″ #
字符集设置,可以根据实际想要的情况,进行调整
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/lib32:$LD_LIBRARY_PATH

9、下载oracle的安装程序,如果是*.cpio.gz文件,运行如下命令:

gzip –decompress ${下载的文件}
cpio -idmv < ${
解压后的cpio文件}

10、进入解压后的oracle安装文件目录下的response目录,复制enterprise.rsp文件并保存一份备份文件。随后按照文档中的提示内容进行相应的“”调整备用
11
、退出response目录,在解压后的安装目录中,运行:“./runInstaller -silent -responseFile ${当前目录}/response/enterprise.rsp”

 

[oracle@oracle10gsvr database]$ ./runInstaller -silent -responseFile /tmp/standard.rsp


12
、随后系统进入相关的安装状态,过程中,可能会出现一些问题,需要查看系统相关提示进行rpm包的安装后,运行安装目录下bin目录中的relink all进行新安装文件的链接。
13
、如果系统出现问题,可以手工进行网络服务的配置和监听。

$ORACLE_HOME/bin/netca /silent /responsefile /local_dir/netca.rsp

14、手动创建DB

[oracle@oracle10gsvr database]$ dbca -silent -cloneTemplate -responseFile /infolab/src/database/response/dbca.rsp

Copying database files

1% complete

100% complete

Look at the log file “/infolab/oracle10g/product/10.2.0/db_1/cfgtoollogs/dbca/orcl10g/orcl10g.log” for further details.

15 添加tnsname 别名

[oracle@oracle10gsvr database]$ vi /infolab/oracle10g/product/10.2.0/db_1/network/admin/tnsnames.ora

 

加入下列内容:

 

orcl10g =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS =

                (PROTOCOL=tcp)

                (HOST=10.10.31.180)

                (PORT=1521)

        )

    )

   

    (CONNECT_DATA =

      (SID = orcl10g)

    )

  )


14
、系统安装完毕后的验证:
输入: sqlplus “/ as sysdba” 后,如果系统没有任何错误信息,且“netstat -antp | grep 1521″后有相应的记录,表明数据库安装成功,且服务正常。

 

 

 

在安装过程中可能会遇到一下java命令无法运行的情况,请检查依赖的包是否已经全部安装。一般是在创建oracle程序的时候没有问题,而是到dbca创建db的时候过不去。遇到这样的情况可以执行最后一段重新创建db即可。

如果第一遍出错的话,想重新安装,只需要把原来的安装目录rm掉就可以了。

祝你好运!

2007年09月28日

Client does not support authentication protocol

归档在: 未分类, Linux, DB — JACKEYJ @ 10:23 PM

B.1.2.3. Client does not support authentication protocol

MySQL 5.0 uses an authentication protocol based on a password hashing algorithm that is incompatible with that used by older (pre-4.1) clients. If you upgrade the server from 4.0, attempts to connect to it with an older client may fail with the following message:

shell> mysql
Client does not support authentication protocol requested
by server; consider upgrading MySQL client

To solve this problem, you should use one of the following approaches:

  • Upgrade all client programs to use a 4.1.1 or newer client library.
  • When connecting to the server with a pre-4.1 client program, use an account that still has a pre-4.1-style password.
  • Reset the password to pre-4.1 style for each user that needs to use a pre-4.1 client program. This can be done using the SET PASSWORD statement and the OLD_PASSWORD() function:
    mysql> SET PASSWORD FOR
    -> 'some_user‘@’some_host‘ = OLD_PASSWORD(’newpwd‘);

    Alternatively, use UPDATE and FLUSH PRIVILEGES:

    mysql> UPDATE mysql.user SET Password = OLD_PASSWORD('newpwd‘)
    -> WHERE Host = 'some_host‘ AND User = ‘some_user‘;
    mysql> FLUSH PRIVILEGES;

    Substitute the password you want to use for “newpwd” in the preceding examples. MySQL cannot tell you what the original password was, so you’ll need to pick a new one.

  • Tell the server to use the older password hashing algorithm:
    1. Start mysqld with the --old-passwords option.
    2. Assign an old-format password to each account that has had its password updated to the longer 4.1 format. You can identify these accounts with the following query:
      mysql> SELECT Host, User, Password FROM mysql.user
      -> WHERE LENGTH(Password) > 16;

      For each account record displayed by the query, use the Host and User values and assign a password using the OLD_PASSWORD() function and either SET PASSWORD or UPDATE, as described earlier.

Note

In older versions of PHP, the mysql extension does not support the authentication protocol in MySQL 4.1.1 and higher. This is true regardless of the PHP version being used. If you wish to use the mysql extension with MySQL 4.1 or newer, you may need to follow one of the options discussed above for configuring MySQL to work with old clients. The mysqli extension (stands for “MySQL, Improved”; added in PHP 5) is compatible with the improved password hashing employed in MySQL 4.1 and higher, and no special configuration of MySQL need be done to use this MySQL client library. For more information about the mysqli extension, see http://php.net/mysqli.

It may also be possible to compile the older mysql extension against the new MySQL client library. This is beyond the scope of this Manual; consult the PHP documentation for more information. You also be able to obtain assistance with these issues in our MySQL with PHP forum.

For additional background on password hashing and authentication, see Section 5.7.9, “Password Hashing as of MySQL 4.1”.

2007年08月29日

MySQL grant replication 问题

归档在: 未分类, DB — JACKEYJ @ 4:45 PM

当前环境配置Replicate_Ignore_DB=mysql

      测试发现,mysql在判断该语句是否忽略有问题,如果当前数据库是mysql,则所有语句都会忽略,它无法判断语句真实对哪个数据库操作。

      如果当前数据库不是”Mysql”,比方说是“mydb”,你执行use mydb,然后再执行相关Grant语句,则复制没有问题。

      以上问题不光是grant语句会有问题,所有的SQL语句都存在这个问题。应该是Mysql复制设计上的问题。

      暂时的解决方法是:

1   执行Grant语句的时候,两边都执行。

2   取消参数 Replicate_Ignore_DB=mysql

2007年06月22日

mysql install can not resolve hostname error

归档在: Linux, DB — JACKEYJ @ 9:14 AM

This section discusses issues that have been found to occur on Linux. The first few subsections describe general operating system-related issues, problems that can occur when using binary or source distributions, and post-installation issues. The remaining subsections discuss problems that occur with Linux on specific platforms.

Note that most of these problems occur on older versions of Linux. If you are running a recent version, you may see none of them.

The Linux-Intel binary and RPM releases of MySQL are configured for the highest possible speed. We are always trying to use the fastest stable compiler available.

The binary release is linked with -static, which means you do not normally need to worry about which version of the system libraries you have. You need not install LinuxThreads, either. A program linked with -static is slightly larger than a dynamically linked program, but also slightly faster (3-5%). However, one problem with a statically linked program is that you can’t use user-defined functions (UDFs). If you are going to write or use UDFs (this is something for C or C++ programmers only), you must compile MySQL yourself using dynamic linking.

A known issue with binary distributions is that on older Linux systems that use libc (such as Red Hat 4.x or Slackware), you get some (non-fatal) issues with hostname resolution. If your system uses libc rather than glibc2, you probably will encounter some difficulties with hostname resolution and getpwnam(). This happens because glibc (unfortunately) depends on some external libraries to implement hostname resolution and getpwent(), even when compiled with -static. These problems manifest themselves in two ways:

  • You may see the following error message when you run mysql_install_db:
    Sorry, the host ‘xxxx‘ could not be looked up
    

    You can deal with this by executing mysql_install_db –force, which does not execute the resolveip test in mysql_install_db. The downside is that you cannot use hostnames in the grant tables: except for localhost, you must use IP numbers instead. If you are using an old version of MySQL that does not support --force, you must manually remove the resolveip test in mysql_install using a text editor.

  • You also may see the following error when you try to run mysqld with the --user option:
    getpwnam: No such file or directory
    

    To work around this problem, start mysqld by using the su command rather than by specifying the --user option. This causes the system itself to change the user ID of the mysqld process so that mysqld need not do so.

Another solution, which solves both problems, is not to use a binary distribution. Obtain a MySQL source distribution (in RPM or tar.gz format) and install that instead.

On some Linux 2.2 versions, you may get the error Resource temporarily unavailable when clients make a great many new connections to a mysqld server over TCP/IP. The problem is that Linux has a delay between the time that you close a TCP/IP socket and the time that the system actually frees it. There is room for only a finite number of TCP/IP slots, so you encounter the resource-unavailable error if clients attempt too many new TCP/IP connections over a short period of time. For example, you may see the error when you run the MySQL test-connect benchmark over TCP/IP.

We have inquired about this problem a few times on different Linux mailing lists but have never been able to find a suitable resolution. The only known “fix” is for clients to use persistent connections, or, if you are running the database server and clients on the same machine, to use Unix socket file connections rather than TCP/IP connections.

This section does not apply to MySQL Enterprise Server users.

The following notes regarding glibc apply only to the situation when you build MySQL yourself. If you are running Linux on an x86 machine, in most cases it is much better for you to use our binary. We link our binaries against the best patched version of glibc we can find and with the best compiler options, in an attempt to make it suitable for a high-load server. For a typical user, even for setups with a lot of concurrent connections or tables exceeding the 2GB limit, our binary is the best choice in most cases. After reading the following text, if you are in doubt about what to do, try our binary first to determine whether it meets your needs. If you discover that it is not good enough, you may want to try your own build. In that case, we would appreciate a note about it so that we can build a better binary next time.

MySQL uses LinuxThreads on Linux. If you are using an old Linux version that doesn’t have glibc2, you must install LinuxThreads before trying to compile MySQL. You can obtain LinuxThreads from http://dev.mysql.com/downloads/os-linux.html.

Note that glibc versions before and including version 2.1.1 have a fatal bug in pthread_mutex_timedwait() handling, which is used when INSERT DELAYED statements are issued. We recommend that you not use INSERT DELAYED before upgrading glibc.

Note that Linux kernel and the LinuxThread library can by default handle a maximum of 1,024 threads. If you plan to have more than 1,000 concurrent connections, you need to make some changes to LinuxThreads, as follows:

  • Increase PTHREAD_THREADS_MAX in sysdeps/unix/sysv/linux/bits/local_lim.h to 4096 and decrease STACK_SIZE in linuxthreads/internals.h to 256KB. The paths are relative to the root of glibc. (Note that MySQL is not stable with 600-1000 connections if STACK_SIZE is the default of 2MB.)
  • Recompile LinuxThreads to produce a new libpthread.a library, and relink MySQL against it.

There is another issue that greatly hurts MySQL performance, especially on SMP systems. The mutex implementation in LinuxThreads in glibc 2.1 is very poor for programs with many threads that hold the mutex only for a short time. This produces a paradoxical result: If you link MySQL against an unmodified LinuxThreads, removing processors from an SMP actually improves MySQL performance in many cases. We have made a patch available for glibc 2.1.3 to correct this behavior (http://dev.mysql.com/Downloads/Linux/linuxthreads-2.1-patch).

With glibc 2.2.2, MySQL uses the adaptive mutex, which is much better than even the patched one in glibc 2.1.3. Be warned, however, that under some conditions, the current mutex code in glibc 2.2.2 overspins, which hurts MySQL performance. The likelihood that this condition occurs can be reduced by re-nicing the mysqld process to the highest priority. We have also been able to correct the overspin behavior with a patch, available at http://dev.mysql.com/Downloads/Linux/linuxthreads-2.2.2.patch. It combines the correction of overspin, maximum number of threads, and stack spacing all in one. You need to apply it in the linuxthreads directory with patch -p0 . We hope it is included in some form in future releases of glibc 2.2. In any case, if you link against glibc 2.2.2, you still need to correct STACK_SIZE and PTHREAD_THREADS_MAX. We hope that the defaults is corrected to some more acceptable values for high-load MySQL setup in the future, so that the commands needed to produce your own build can be reduced to ./configure; make; make install.

We recommend that you use these patches to build a special static version of libpthread.a and use it only for statically linking against MySQL. We know that these patches are safe for MySQL and significantly improve its performance, but we cannot say anything about their effects on other applications. If you link other applications that require LinuxThreads against the patched static version of the library, or build a patched shared version and install it on your system, you do so at your own risk.

If you experience any strange problems during the installation of MySQL, or with some common utilities hanging, it is very likely that they are either library or compiler related. If this is the case, using our binary resolves them.

If you link your own MySQL client programs, you may see the following error at runtime:

ld.so.1: fatal: libmysqlclient.so.#:
open failed: No such file or directory

This problem can be avoided by one of the following methods:

If you are using the Fujitsu compiler (fcc/FCC), you may have some problems compiling MySQL because the Linux header files are very gcc oriented. The following configure line should work with fcc/FCC:

CC=fcc CFLAGS="-O -K fast -K lib -K omitfp -Kpreex -D_GNU_SOURCE 
-DCONST=const -DNO_STRTOLL_PROTO" 
CXX=FCC CXXFLAGS="-O -K fast -K lib 
-K omitfp -K preex --no_exceptions --no_rtti -D_GNU_SOURCE 
-DCONST=const -Dalloca=__builtin_alloca -DNO_STRTOLL_PROTO 
'-D_EXTERN_INLINE=static __inline'" 
./configure 
--prefix=/usr/local/mysql --enable-assembler 
--with-mysqld-ldflags=-all-static --disable-shared 
--with-low-memory

mysql.server can be found in the support-files directory under the MySQL installation directory or in a MySQL source tree. You can install it as /etc/init.d/mysql for automatic MySQL startup and shutdown. See Section 2.4.15.2.2, “Starting and Stopping MySQL Automatically”.

If MySQL cannot open enough files or connections, it may be that you have not configured Linux to handle enough files.

In Linux 2.2 and onward, you can check the number of allocated file handles as follows:

shell> cat /proc/sys/fs/file-max
shell> cat /proc/sys/fs/dquot-max
shell> cat /proc/sys/fs/super-max

If you have more than 16MB of memory, you should add something like the following to your init scripts (for example, /etc/init.d/boot.local on SuSE Linux):

echo 65536 > /proc/sys/fs/file-max
echo 8192 > /proc/sys/fs/dquot-max
echo 1024 > /proc/sys/fs/super-max

You can also run the echo commands from the command line as root, but these settings are lost the next time your computer restarts.

Alternatively, you can set these parameters on startup by using the sysctl tool, which is used by many Linux distributions (including SuSE Linux 8.0 and later). Put the following values into a file named /etc/sysctl.conf:

# Increase some values for MySQL
fs.file-max = 65536
fs.dquot-max = 8192
fs.super-max = 1024

You should also add the following to /etc/my.cnf:

[mysqld_safe]
open-files-limit=8192

This should allow the server a limit of 8,192 for the combined number of connections and open files.

The STACK_SIZE constant in LinuxThreads controls the spacing of thread stacks in the address space. It needs to be large enough so that there is plenty of room for each individual thread stack, but small enough to keep the stack of some threads from running into the global mysqld data. Unfortunately, as we have experimentally discovered, the Linux implementation of mmap() successfully unmaps a mapped region if you ask it to map out an address currently in use, zeroing out the data on the entire page instead of returning an error. So, the safety of mysqld or any other threaded application depends on the “gentlemanly” behavior of the code that creates threads. The user must take measures to make sure that the number of running threads at any given time is sufficiently low for thread stacks to stay away from the global heap. With mysqld, you should enforce this behavior by setting a reasonable value for the max_connections variable.

If you build MySQL yourself, you can patch LinuxThreads for better stack use. See Section 2.4.18.1.3, “Linux Source Distribution Notes”. If you do not want to patch LinuxThreads, you should set max_connections to a value no higher than 500. It should be even less if you have a large key buffer, large heap tables, or some other things that make mysqld allocate a lot of memory, or if you are running a 2.2 kernel with a 2GB patch. If you are using our binary or RPM version, you can safely set max_connections at 1500, assuming no large key buffer or heap tables with lots of data. The more you reduce STACK_SIZE in LinuxThreads the more threads you can safely create. We recommend values between 128KB and 256KB.

If you use a lot of concurrent connections, you may suffer from a “feature” in the 2.2 kernel that attempts to prevent fork bomb attacks by penalizing a process for forking or cloning a child. This causes MySQL not to scale well as you increase the number of concurrent clients. On single-CPU systems, we have seen this manifest as very slow thread creation; it may take a long time to connect to MySQL (as long as one minute), and it may take just as long to shut it down. On multiple-CPU systems, we have observed a gradual drop in query speed as the number of clients increases. In the process of trying to find a solution, we have received a kernel patch from one of our users who claimed it helped for his site. This patch is available at http://dev.mysql.com/Downloads/Patches/linux-fork.patch. We have done rather extensive testing of this patch on both development and production systems. It has significantly improved MySQL performance without causing any problems and we recommend it to our users who still run high-load servers on 2.2 kernels.

This issue has been fixed in the 2.4 kernel, so if you are not satisfied with the current performance of your system, rather than patching your 2.2 kernel, it might be easier to upgrade to 2.4. On SMP systems, upgrading also gives you a nice SMP boost in addition to fixing the fairness bug.

We have tested MySQL on the 2.4 kernel on a two-CPU machine and found MySQL scales much better. There was virtually no slowdown on query throughput all the way up to 1,000 clients, and the MySQL scaling factor (computed as the ratio of maximum throughput to the throughput for one client) was 180%. We have observed similar results on a four-CPU system: Virtually no slowdown as the number of clients was increased up to 1,000, and a 300% scaling factor. Based on these results, for a high-load SMP server using a 2.2 kernel, we definitely recommend upgrading to the 2.4 kernel at this point.

We have discovered that it is essential to run the mysqld process with the highest possible priority on the 2.4 kernel to achieve maximum performance. This can be done by adding a renice -20 $$ command to mysqld_safe. In our testing on a four-CPU machine, increasing the priority resulted in a 60% throughput increase with 400 clients.

We are currently also trying to collect more information on how well MySQL performs with a 2.4 kernel on four-way and eight-way systems. If you have access such a system and have done some benchmarks, please send an email message to with the results. We will review them for inclusion in the manual.

If you see a dead mysqld server process with ps, this usually means that you have found a bug in MySQL or you have a corrupted table. See Section B.1.4.2, “What to Do If MySQL Keeps Crashing”.

To get a core dump on Linux if mysqld dies with a SIGSEGV signal, you can start mysqld with the --core-file option. Note that you also probably need to raise the core file size by adding ulimit -c 1000000 to mysqld_safe or starting mysqld_safe with --core-file-size=1000000. See Section 5.3.1, “mysqld_safe — MySQL Server Startup Script”.

MySQL requires libc 5.4.12 or newer. It is known to work with libc 5.4.46. glibc 2.0.6 and later should also work. There have been some problems with the glibc RPMs from Red Hat, so if you have problems, check whether there are any updates. The glibc 2.0.7-19 and 2.0.7-29 RPMs are known to work.

If you are using Red Hat 8.0 or a new glibc 2.2.x library, you may see mysqld die in gethostbyaddr(). This happens because the new glibc library requires a stack size greater than 128KB for this call. To fix the problem, start mysqld with the --thread-stack=192K option. (Use -O thread_stack=192K before MySQL 4.) This stack size is the default on MySQL 4.0.10 and above, so you should not see the problem.

If you are using gcc 3.0 and above to compile MySQL, you must install the libstdc++v3 library before compiling MySQL; if you don’t do this, you get an error about a missing __cxa_pure_virtual symbol during linking.

On some older Linux distributions, configure may produce an error like this:

Syntax error in sched.h. Change _P to __P in the
/usr/include/sched.h file.
See the Installation chapter in the Reference Manual.

Just do what the error message says. Add an extra underscore to the _P macro name that has only one underscore, and then try again.

You may get some warnings when compiling. Those shown here can be ignored:

mysqld.cc -o objs-thread/mysqld.o
mysqld.cc: In function `void init_signals()':
mysqld.cc:315: warning: assignment of negative value `-1' to
`long unsigned int'
mysqld.cc: In function `void * signal_hand(void *)':
mysqld.cc:346: warning: assignment of negative value `-1' to
`long unsigned int'

If mysqld always dumps core when it starts, the problem may be that you have an old /lib/libc.a. Try renaming it, and then remove sql/mysqld and do a new make install and try again. This problem has been reported on some Slackware installations.

If you get the following error when linking mysqld, it means that your libg++.a is not installed correctly:

/usr/lib/libc.a(putc.o): In function `_IO_putc':
putc.o(.text+0x0): multiple definition of `_IO_putc'

You can avoid using libg++.a by running configure like this:

shell> CXX=gcc ./configure

We have tested MySQL 5.0 on Alpha with our benchmarks and test suite, and it appears to work well.

We currently build the MySQL binary packages on SuSE Linux 7.0 for AXP, kernel 2.4.4-SMP, Compaq C compiler (V6.2-505) and Compaq C++ compiler (V6.3-006) on a Compaq DS20 machine with an Alpha EV6 processor.

You can find the preceding compilers at http://www.support.compaq.com/alpha-tools/. By using these compilers rather than gcc, we get about 9-14% better MySQL performance.

For MySQL on Alpha, we use the -arch generic flag to our compile options, which ensures that the binary runs on all Alpha processors. We also compile statically to avoid library problems. The configure command looks like this:

CC=ccc CFLAGS="-fast -arch generic" CXX=cxx 
CXXFLAGS="-fast -arch generic -noexceptions -nortti" 
./configure --prefix=/usr/local/mysql --disable-shared 
--with-extra-charsets=complex --enable-thread-safe-client 
--with-mysqld-ldflags=-non_shared --with-client-ldflags=-non_shared

If you want to use egcs, the following configure line worked for us:

CFLAGS="-O3 -fomit-frame-pointer" CXX=gcc 
CXXFLAGS="-O3 -fomit-frame-pointer -felide-constructors 
-fno-exceptions -fno-rtti" 
./configure --prefix=/usr/local/mysql --disable-shared

Some known problems when running MySQL on Linux-Alpha:

  • Debugging threaded applications like MySQL does not work with gdb 4.18. You should use gdb 5.1 instead.
  • If you try linking mysqld statically when using gcc, the resulting image dumps core at startup time. In other words, do not use --with-mysqld-ldflags=-all-static with gcc.

2007年04月14日

oracle10g for linux 自启动配置

归档在: Linux, DB — JACKEYJ @ 12:05 AM

1. 创建文件/etc/oratab,

需要注意的是:修改oraclehome/bin/dbstart中的oratab中的路径,此处修改为etc/oratab
#添加如下内容到/etc/oratab文件中,
#$ORACLE_SID是你的Oracle数据库的sid
#$ORACLE_HOME是你的Oracle数据库的Oracle_home
#Y表示要求在系统启动的时候启动Oracle数据库.N表示不要在系统启动的时候启动Oracle
$ORACLE_SID:$ORACLE_HOME:Y

2. 修改文件/etc/rc.local添加一下两行
##
## 关于su的具体命令参看linux的manual文档
##
su - oracle -c ‘dbstart’
su - oracle -c ‘lsnrctl start LISTENER’
su - oracle -c ’sqlplus /nolog < connect /as sysdba
startup'

3.环境变量设置:
编辑 /etc/profile或者写入oracle用户下的.bash_profile,因为系统起来的时候就已经切换到oracle用户

# Oracle Home
ORACLE_BASE=/zjant/oracle
export ORACLE_BASE
export ORACLE_SID=orcl
export ORACLE_HOME=$ORACLE_BASE/OraHome_1
export PATH=$PATH:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib

4.重启设备:

最后重启设备后即可.

2007年04月11日

oracle 10g xe on ubuntu TNS-12555: TNS:permission denied

归档在: 未分类, Linux, DB — JACKEYJ @ 2:33 PM

Starting /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/tnslsnr: please wait…

TNSLSNR for Linux: Version 10.2.0.1.0 - Production
System parameter file is /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/network/admin/listener.ora
Log messages written to /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/network/log/listener.log
Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_XE)))
TNS-12555: TNS:permission denied
TNS-12560: TNS:protocol adapter error
TNS-00525: Insufficient privilege for operation
Linux Error: 1: Operation not permitted

Listener failed to start. See the error message(s) above…

Logon as oracle and execute following commands:

cd /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin
strace -o /tmp/trc.log -f ./tnslsnr

Then execute following command and post the output:

egrep ‘open|read|stat|write|access|chmod’ /tmp/trc.log

OK try execute following command (as root):
rm -f /var/tmp/.oracle/*

Now log on as oracle and try to start listener again.

下一页 »

Powered by ZJANT