当前位置:  数据库>其它
本页文章导读:
    ▪在VMware Server 2.0.2 上安装 Oracle 10g RAC 手把手详解      192.168.8.241 192.168.8.242 192.168.8.248 192.168.8.249 rac1->export LANG=en_US.UTF-8 vi /etc/sysconfig/network-scripts/ifcfg-eth0 vi /etc/sysconfig/network-scripts/ifcfg-eth1 [root@rac2 ~]# more /etc/sysconfig/network-scripts/ifcfg-eth0 # Advan.........
    ▪C语言连接mysql数据库      操作系统是Linux,需要mysql客户端软件开发库libmysqlclient,这个函数库是mysql的组成部分之一。 一般头文件都在/usr/include/mysql路径下,库文件都在/usr/lib/mysql路径下。 如果没有需要安装mysql-devel.........
    ▪[原创]在Oracle 10g,Number、Char和Varchar2类型作为主键,查询效率分析      背景     在实际项目中,设计数据库表的主键生成机制有多种选择:Sequence、产品自增长、表自增长、UUID、复合主键。从主键单纯性和查询简单性考虑,首先不建议使用复合主键。从数.........

[1]在VMware Server 2.0.2 上安装 Oracle 10g RAC 手把手详解
    来源: 互联网  发布时间: 2013-11-07
192.168.8.241
192.168.8.242
192.168.8.248
192.168.8.249


rac1->export LANG=en_US.UTF-8


vi /etc/sysconfig/network-scripts/ifcfg-eth0
vi /etc/sysconfig/network-scripts/ifcfg-eth1
[root@rac2 ~]# more /etc/sysconfig/network-scripts/ifcfg-eth0
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth0
BOOTPROTO=none
IPADDR=192.168.8.242
ONBOOT=yes
HWADDR=00:0c:29:98:38:5a
NETMASK=255.255.255.0
GATEWAY=192.168.8.1
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
You have new mail in /var/spool/mail/root


service network restart


[root@rac1 ~]# vi /etc/hosts
127.0.0.1       localhost
192.168.8.241   rac1.oracle.com         rac1
192.168.8.248   rac1-vip.oracle.com     rac1-vip
10.10.10.241    rac1-priv.oracle.com    rac1-priv
192.168.8.242   rac2.oracle.com         rac2
192.168.8.249   rac2-vip.oracle.com     rac2-vip
10.10.10.242    rac2-priv.oracle.com    rac2-priv


[root@rac2 ~]# vi /etc/hosts
127.0.0.1       localhost
192.168.8.241   rac1.oracle.com         rac1
192.168.8.248   rac1-vip.oracle.com     rac1-vip
10.10.10.241    rac1-priv.oracle.com    rac1-priv
192.168.8.242   rac2.oracle.com         rac2
192.168.8.249   rac2-vip.oracle.com     rac2-vip
10.10.10.242    rac2-priv.oracle.com    rac2-priv




rac1->mkdir ~/.ssh
rac1->chmod 700 ~/.ssh
rac1->ssh-keygen -t rsa
rac1->ssh-keygen -t dsa


rac2->mkdir ~/.ssh
rac2->chmod 700 ~/.ssh
rac2->ssh-keygen -t rsa
rac2->ssh-keygen -t dsa


rac2->cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
rac2->cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
rac2->ssh rac1 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys 
rac2->ssh rac1 cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys 
rac2->scp ~/.ssh/authorized_keys rac1:~/.ssh/authorized_keys 
oracle@rac1's password: 
authorized_keys                               100% 2032     2.0KB/s  
 00:00




rac1->ssh rac2 date
rac1->ssh rac2-priv date
rac1->ssh rac2.oracle.com date
rac1->ssh rac2-priv.oracle.com date
rac1->ssh rac1.oracle.com
rac1->ssh rac1
rac1->ssh rac1-priv.oracle.com
rac1->ssh rac1-priv


rac2->ssh rac1.oracle.com date
rac2->ssh rac1-priv.oracle.com date
rac2->ssh rac1 date
rac2->ssh rac1-priv date
rac2->ssh rac2.oracle.com
rac2->ssh rac2
rac2->ssh rac2-priv.oracle.com
rac2->ssh rac2-priv




[root@rac1 ~]# rpm -qa|grep ocfs
ocfs2-2.6.18-128.el5xen-1.2.9-1.el5
ocfs2-2.6.18-128.el5-1.2.9-1.el5
ocfs2console-1.2.7-1.el5
ocfs2-2.6.18-128.el5debug-1.2.9-1.el5
ocfs2-tools-devel-1.2.7-1.el5
ocfs2-2.6.18-128.el5PAE-1.2.9-1.el5
ocfs2-tools-1.2.7-1.el5


[root@rac2 ~]# rpm -qa | grep ocfs
ocfs2-2.6.18-128.el5xen-1.2.9-1.el5
ocfs2-2.6.18-128.el5-1.2.9-1.el5
ocfs2console-1.2.7-1.el5
ocfs2-2.6.18-128.el5debug-1.2.9-1.el5
ocfs2-tools-devel-1.2.7-1.el5
ocfs2-2.6.18-128.el5PAE-1.2.9-1.el5
ocfs2-tools-1.2.7-1.el5




配置cluster file system


ocfs2console




rac1->more /etc/ocfs2/cluster.conf 
node:
        ip_port = 7777
        ip_address = 192.168.8.241
        number = 0
        name = rac1
        cluster = ocfs2


node:
        ip_port = 7777
        ip_address = 192.168.8.242
        number = 1
        name = rac2
        cluster = ocfs2


ocfs2console 传输配置文件
[root@rac2 ~]# more /etc/ocfs2/cluster.conf 
node:
        ip_port = 7777
        ip_address = 192.168.8.241
        number = 0
        name = rac1
        cluster = ocfs2


node:
        ip_port = 7777
        ip_address = 192.168.8.242
        number = 1
        name = rac2
        cluster = ocfs2


cluster:
        node_count = 2
        name = ocfs2






cluster:
        node_count = 2
        name = ocfs2




[root@rac1 ~]# /etc/init.d/o2cb unload
[root@rac2 ~]# /etc/init.d/o2cb unload


配置心跳
[root@rac1 ~]# /etc/init.d/o2cb configure
[root@rac2 ~]# /etc/init.d/o2cb configure
[root@rac1 ~]# /etc/init.d/o2cb status
Module "configfs": Loaded
Filesystem "configfs": Mounted
Module "ocfs2_nodemanager": Loaded
Module "ocfs2_dlm": Loaded
Module "ocfs2_dlmfs": Loaded
Filesystem "ocfs2_dlmfs": Mounted
Checking O2CB cluster ocfs2: Online
  Heartbeat dead threshold: 1200
  Network idle timeout: 30000
  Network keepalive delay: 2000
  Network reconnect delay: 2000
Checking O2CB heartbeat: Not active
[root@rac2 ~]#  /etc/init.d/o2cb status
Module "configfs": Loaded
Filesystem "configfs": Mounted
Module "ocfs2_nodemanager": Loaded
Module "ocfs2_dlm": Loaded
Module "ocfs2_dlmfs": Loaded
Filesystem "ocfs2_dlmfs": Mounted
Checking O2CB cluster ocfs2: Online
  Heartbeat dead threshold: 1200
  Network idle timeout: 30000
  Network keepalive delay: 2000
  Network reconnect delay: 2000
Checking O2CB heartbeat: Not active


[root@rac1 ~]# fdisk -l
Disk /dev/sdb: 536 MB, 536870912 bytes
64 heads, 32 sectors/track, 512 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes


ocfs2console 格式化 /dev/sdb


挂载
[root@rac1 ~]# mount -t ocfs2 -o datavolume,nointr /dev/sdb1 /ocfs
[root@rac2 ~]# mount -t ocfs2 -o datavolume,nointr /dev/sdb1 /ocfs


[root@rac1 ~]# vi /etc/fstab
[root@rac2 ~]# vi /etc/fstab 
/dev/sdb1               /ocfs           ocfs2   _netdev,datavolume,nointr 0 0


[root@rac1 ~]# df -h
[root@rac2 ~]# df -h
[root@rac1 ~]# cd /ocfs
[root@rac1 ocfs]# ll
total 1
drwxr-xr-x 2 root root 1024 Aug 12 00:51 lost+found


[root@rac1 ocfs]# mkdir cluster
[root@rac1 ocfs]# chown -R oracle:dba /ocfs
[root@rac2 soft]# cd /ocfs
[root@rac2 ocfs]# ll
total 2
drwxr-xr-x 2 oracle dba 1024 Aug 12 01:00 cluster
drwxr-xr-x 2 oracle dba 1024 Aug 12 00:51 lost+found


rac1->cd /soft
rac1->ll
total 12
drwxrwxrwx 9 oracle oinstall 4096 Jun  3 12:14 clusterware
drwxrwxrwx 6 oracle oinstall 4096 Jul  3  2005 database
drwxr-xr-x 3 root   root     4096 Nov 22  2009 rac


rac1->more ~/.bash_profile
rac2->more ~/.bash_profile


PATH=$PATH:$HOME/bin


export PS1="`/bin/hostname -s`->"
export EDITOR=vim
export ORACLE_SID=devdb1
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export ORA_CRS_HOME=$ORACLE_BASE/product/10.2.0/crs_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib


export PATH=$ORACLE_HOME/bin:$ORA_CRS_HOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/
usr/X11R6/bin
umask 022
export LANG=en_US.UTF-8




rac1->export LANG=en
rac1->cd /soft
rac1->cd clusterware/
rac1->pwd
/soft/clusterware
rac1->ll
total 36
drwxrwxrwx 2 oracle oinstall 4096 Jun  3 12:10 cluvfy
drwxrwxrwx 6 oracle oinstall 4096 Jun  3 12:10 doc
drwxrwxrwx 4 oracle oinstall 4096 Jun  3 12:10 install
drwxrwxrwx 2 oracle oinstall 4096 Jun  3 12:10 response
drwxrwxrwx 2 oracle oinstall 4096 Jun  3 12:10 rpm
-rwxrwxrwx 1 oracle oinstall 1328 Jun  3 12:10 runInstaller
drwxrwxrwx 9 oracle oinstall 4096 Jun  3 12:14 stage
drwxrwxrwx 2 oracle oinstall 4096 Jun  3 12:14 upgrade
-rwxrwxrwx 1 oracle oinstall 3445 Jun  3 12:14 welcome.html




ocr disk:/ocfs/cluster/ocr
vote disk:/ocfs/cluster/votingdisk




[root@rac1 ~]# /u01/app/oracle/oraInventory/orainstRoot.sh
[root@rac2 ~]# /u01/app/oracle/oraInventory/orainstRoot.sh


[root@rac1 ~]# cd /u01/app/oracle/product/10.2.0/crs_1/bin
[root@rac1 bin]# ls -l vipca
-rwxr-xr-x 1 oracle oinstall 5014 Aug 12 02:01 vipca
[root@rac1 bin]# vi vipca
unset LD_ASSUME_KERNEL


[root@rac1 bin]# vim srvctl
unset LD_ASSUME_KERNEL


[root@rac2 bin]# vi vipca
unset LD_ASSUME_KERNEL


[root@rac2 bin]# vim srvctl
unset LD_ASSUME_KERNEL




[root@rac1 bin]# /u01/app/oracle/product/10.2.0/crs_1/root.sh
[r
    
[2]C语言连接mysql数据库
    来源: 互联网  发布时间: 2013-11-07
操作系统是Linux,需要mysql客户端软件开发库libmysqlclient,这个函数库是mysql的组成部分之一。
一般头文件都在/usr/include/mysql路径下,库文件都在/usr/lib/mysql路径下。
如果没有需要安装mysql-devel包(mysql-devel-5.1.47-4.el6.i686.rpm)
[**@**]# rpm -ivh mysql-devel-5.1.47-4.el6.i686.rpm
安装完成后可以去那两个路径下看看有没有,如果没有就查找一下
[**@**]# find / -name mysql.h
[**@**]# find / -name mysqlclient
看一下路径在哪里。


安装完成后,就可以编译连接C源程序了。


[**@**]# gcc -I/usr/include/mysql -L/usr/lib/mysql -lmysqlclient *.c
编译成功即可运行。


解释下:
gcc GNU C/C++编译器
-I指定头文件所在路径(大写i)
-L 指定库文件所在路径
-l 与所需要的动态链接库链接起来(小写L)
这么长的编译命令一般都在make文件里面写了


关于动态链接库可以添加一个环境变量
[**@**]# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usrlib/mysql

不过一劳永逸的办法是:将这句话LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usrlib/mysql添加在.bashrc里面


最后源码:

#include <stdio.h>
#include <mysql.h>

int main(int argc, char *argv[])
{
  int i;
  MYSQL *conn;        // connection to MySQL server
  MYSQL_RES *result;  // result of SELECT query
  MYSQL_ROW row;      // one record (row) of SELECT query

  // connect to MySQL
  conn = mysql_init(NULL);
  // mysql_options(conn, MYSQL_READ_DEFAULT_GROUP, "myclient");
  if(mysql_real_connect(
        conn, "localhost", "root", "uranus", //此处更改用户名密码
        "mylibrary", 0, NULL, 0) == NULL) {
      fprintf(stderr, "sorry, no database connection ...\n");
      return 1;
    }

  // only if utf8 output is needed
  mysql_query(conn, "SET NAMES 'utf8'");

  // retrieve list of all publishers in mylibrary
  const char *sql="SELECT COUNT(titleID), publName \
                   FROM publishers, titles \
                   WHERE publishers.publID = titles.publID  \
                   GROUP BY publishers.publID \
                   ORDER BY publName";
  if(mysql_query(conn, sql)) {
    fprintf(stderr, "%s\n", mysql_error(conn));
    fprintf(stderr, "Fehlernummer %i\n", mysql_errno(conn));
    fprintf(stderr, "%s\n", sql);
    return 1;
  }

  // process results
  result = mysql_store_result(conn);
  if(result==NULL) {
    if(mysql_error(conn))
      fprintf(stderr, "%s\n", mysql_error(conn));
    else
      fprintf(stderr, "%s\n", "unknown error\n");
    return 1;
  }
  printf("%i records found\n", (int)mysql_num_rows(result));

  // loop through all found rows
  while((row = mysql_fetch_row(result)) != NULL) {
    for(i=0; i < mysql_num_fields(result); i++) {
      if(row[i] == NULL)
        printf("[NULL]\t");
      else
        printf("%s\t", row[i]);
    }
    printf("\n");
  }

  // de-allocate memory of result, close connection
  mysql_free_result(result);
  mysql_close(conn);
  return 0;
}



作者:hnzmdzcm 发表于2013-2-5 11:51:29 原文链接
阅读:0 评论:0 查看评论

    
[3][原创]在Oracle 10g,Number、Char和Varchar2类型作为主键,查询效率分析
    来源: 互联网  发布时间: 2013-11-07
背景
    在实际项目中,设计数据库表的主键生成机制有多种选择:Sequence、产品自增长、表自增长、UUID、复合主键。从主键单纯性和查询简单性考虑,首先不建议使用复合主键。从数据表重建和数据迁移的方便性考虑,首选UUID,但使用UUID就必须使用字符类型字段,有担心字符类型主键的查询效率远不及数字类型主键。另外,有观点指出,对Varchar2类型字段建立索引,查询时,不使用该索引。在网上搜索相关的文章后,没有可信证据,所以,自力更生,寻找验证方案。

方案设计
    建三张相同结构的表,分别使用Number、Char和Varchar2类型作为主键(Number类型主键值用Sequence的方式生成,Char和Varchar2类型主键值用GUID类生成),此次仅测试数据库的性能,所以,一切操作仅使用SQL和PLSQL完成。执行以下操作,并记录执行时间:
    1 每张表录入100万条记录。
    2 按主键排序,抽取第一个50万个记录的主键,执行主键查询。

建表
-- Number类型主键
create table b2c_pk_number
(
  id number(15),
  name varchar2(32)
) tablespace ecsdata2;
alter table b2c_pk_number 
  add constraint pk_pk_number primary key (id)
    using index tablespace ecsindex2;
-- Char类型主键
create table b2c_pk_char
(
  id char(32),
  name varchar2(32)
) tablespace ecsdata2;
alter table b2c_pk_char 
  add constraint pk_pk_char primary key (id)
    using index tablespace ecsindex2;
-- Varchar2类型主键
create table b2c_pk_varchar2
(
  id varchar2(32),
  name varchar2(32)
) tablespace ecsdata2;
alter table b2c_pk_varchar2
  add constraint pk_pk_varchar2 primary key (id)
    using index tablespace ecsindex2;

插入100万条记录
--  Number类型主键
declare
  v_total number := 1000000;
  v_starttime timestamp;
  v_endtime timestamp; 
begin
  v_starttime := systimestamp;
  for idx in 1 .. v_total
  loop
    insert into b2c_pk_number(id,name) values(idx, sys_guid());
    
    -- 每1万提交一次
    if( mod(idx, 10000) = 0) then
      -- dbms_output.put_line(idx);
      commit;
    end if;
  end loop;
  
  v_endtime := systimestamp;
  
  dbms_output.put_line(v_endtime - v_starttime);
end;
-- Char类型主键
declare
  v_total number := 1000000;
  v_starttime timestamp;
  v_endtime timestamp; 
begin
  v_starttime := systimestamp;
  for idx in 1 .. v_total
  loop
    insert into b2c_pk_char(id,name) values(sys_guid(), sys_guid());
    
    -- 每1万提交一次
    if( mod(idx, 10000) = 0) then
      -- dbms_output.put_line(idx);
      commit;
    end if;
  end loop;
  
  v_endtime := systimestamp;
  
  dbms_output.put_line(v_endtime - v_starttime);
end;
-- Varchar2类型主键
declare
  v_total number := 1000000;
  v_starttime timestamp;
  v_endtime timestamp; 
begin
  v_starttime := systimestamp;
  for idx in 1 .. v_total
  loop
    insert into b2c_pk_varchar2(id,name) values(sys_guid(), sys_guid());
    
    -- 每1万提交一次
    if( mod(idx, 10000) = 0) then
      -- dbms_output.put_line(idx);
      commit;
    end if;
  end loop;
  
  v_endtime := systimestamp;
  
  dbms_output.put_line(v_endtime - v_starttime);
end;
结果
 
Number类型主键
Char类型主键
Varchar2类型主键
执行时间(单位:秒) 71.516642000 93.747191000 97.184995000

修正
    考虑到,Number类型主键的新增记录少调用了一次sys_guid(),而且,在实际系统中,会用到Sequence。所以,做出以下调整:
1 创建Sequence
create sequence seq_pk_number;
2 将b2c_pk_number表清空
truncate table b2c_pk_number;
3 修改新增记录的plsql,重新执行。
declare
  v_total number := 1000000;
  v_starttime timestamp;
  v_endtime timestamp; 
begin
  v_starttime := systimestamp;
  for idx in 1 .. v_total
  loop
    insert into b2c_pk_number(id,name) values(seq_pk_number.nextval, sys_guid());
    
    -- 每1万提交一次
    if( mod(idx, 10000) = 0) then
      -- dbms_output.put_line(idx);
      commit;
    end if;
  end loop;
  
  v_endtime := systimestamp;
  
  dbms_output.put_line(v_endtime - v_starttime);
end;
修正后结果
 
Number类型主键
Char类型主键
Varchar2类型主键
执行时间(单位:秒) 78.962285000 93.747191000 97.184995000

对第50W条记录进行查询100W次的总时间
-- Number类型主键
declare
  v_total number := 1000000;
  v_starttime timestamp;
  v_endtime timestamp; 
begin
  v_starttime := systimestamp;
  for idx in 1 .. v_total
  loop
      execute immediate 'select * from b2c_pk_number where id = 500000';
  end loop;
  
  v_endtime := systimestamp;
  
  dbms_output.put_line(v_endtime - v_starttime);
end;
-- Char类型主键
select * from (select t.*, row_number() over(order by id) rn from b2c_pk_char t ) where rn = 500000;
declare
  v_total number := 1000000;
  v_starttime timestamp;
  v_endtime timestamp; 
begin
  v_starttime := systimestamp;
  for idx in 1 .. v_total
  loop
      execute immediate 'select * from b2c_pk_char where id = ''D4F1204D823F706BE0440018FE2DB7D7''';
  end loop;
  
  v_endtime := systimestamp;
  
  dbms_output.put_line(v_endtime - v_starttime);
end;
    
最新技术文章:
 




特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3