自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

DBUtil教程之?dāng)?shù)據(jù)庫集群備份

運(yùn)維 數(shù)據(jù)庫運(yùn)維 數(shù)據(jù)庫
在現(xiàn)在系統(tǒng)中,海量數(shù)據(jù)成為軟件工程師要面對(duì)的主要問題。很多人都把數(shù)據(jù)庫優(yōu)化集中在編程和數(shù)據(jù)庫的結(jié)構(gòu),再構(gòu)建一些索引和視圖,但是在編程和表結(jié)構(gòu)都到了極致的時(shí)候,數(shù)據(jù)庫優(yōu)化該何去何從。

在現(xiàn)在系統(tǒng)中,海量數(shù)據(jù)成為軟件工程師要面對(duì)的主要問題。很多人都把數(shù)據(jù)庫優(yōu)化集中在編程和數(shù)據(jù)庫的結(jié)構(gòu),再構(gòu)建一些索引和視圖,但是在編程和表結(jié)構(gòu)都到了極致的時(shí)候,數(shù)據(jù)庫優(yōu)化該何去何從。

Oracle公司現(xiàn)在有一個(gè)比較熱門的數(shù)據(jù)庫集群技術(shù),叫做rac。rac應(yīng)該是現(xiàn)在數(shù)據(jù)庫集群中最優(yōu)化和最熱門的技術(shù)。但是只是局限于同類型和同構(gòu)數(shù)據(jù)庫上面。

RAC是一個(gè)負(fù)載均衡的代表,它的集群主要是面對(duì)不是大而復(fù)雜的數(shù)據(jù)庫查詢,而是面對(duì)大量的連接。但是如果我們面對(duì)是一個(gè)異類異構(gòu)數(shù)據(jù)庫怎么解決。

近年來,有一種比較熱門的數(shù)據(jù)庫進(jìn)入我們生活,列式數(shù)據(jù)庫。它是一個(gè)高查詢性能,低插入性能的數(shù)據(jù)庫?,F(xiàn)在主要代表是sybaseiq,主要開源的 列式數(shù)據(jù)庫有monetdb 。但是列式數(shù)據(jù)庫問題很多,主要是插入慢、數(shù)據(jù)庫不穩(wěn)定、數(shù)據(jù)庫傳統(tǒng)語法支持不強(qiáng)、穩(wěn)定性低、線程低和擴(kuò)展性低。但是達(dá)到幾百萬行以上數(shù)據(jù)以后,列式數(shù)據(jù) 庫的查詢速度是mysql的10倍以上。

在一個(gè)大型系統(tǒng)中,行式和列式數(shù)據(jù)庫優(yōu)勢(shì)互補(bǔ),合理使用成為開發(fā)人員必須關(guān)心的問題。我們今天的集群也是主要面對(duì)這個(gè)問題。

集群原理:

在dbutil的集群中,我們是用了一個(gè)行式數(shù)據(jù)庫和若干個(gè)列式數(shù)據(jù)庫組成,每次更新數(shù)據(jù)的時(shí)候,我們是用廣播模式,把增刪改數(shù)據(jù)通過廣播模式,群 體更新所有的數(shù)據(jù)。當(dāng)查詢數(shù)據(jù)時(shí)候,我們會(huì)通過連接池模式,找出最少人使用的數(shù)據(jù),查詢數(shù)據(jù)。并且可以設(shè)置每天定時(shí)同步數(shù)據(jù),把存放在行式數(shù)據(jù)的數(shù)據(jù),定 時(shí)同步到所有的節(jié)點(diǎn)。

配置方法:

在我們之前幾個(gè)文章簡(jiǎn)單見過DBUtil的使用,配置方法和之前的教程大同小異。

1.配置xml

  1. <!-- 集群測(cè)試數(shù)據(jù)庫 --> 
  2.     <Resource jndi="jdbc/Cluster1" driverClass="com.mysql.jdbc.Driver" 
  3.         dbUserName="root" dbPassWord="root" 
  4.         jdbcUrl="jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8" 
  5.         initSize="2" minPoolSize="1" maxPoolSize="10" maxStatements="50" 
  6.         maxIdleTime="60" /> 
  7.     <Resource jndi="jdbc/Cluster2" driverClass="com.mysql.jdbc.Driver" 
  8.         dbUserName="root" dbPassWord="root" 
  9.         jdbcUrl="jdbc:mysql://127.0.0.1:3306/test2?useUnicode=true&characterEncoding=utf-8" 
  10.         initSize="2" minPoolSize="1" maxPoolSize="10" maxStatements="50" 
  11.         maxIdleTime="60" /> 
  12.     <!-- 集群 --> 
  13.     <Cluster jndiCluster="jdbc/Cluster" mainDB="jdbc/Cluster1" 
  14.         synchronous="off" synchronousTime="00:00" protect="on"> 
  15.         <Resource jndi="jdbc/Cluster1" /> 
  16.         <Resource jndi="jdbc/Cluster2" /> 
  17.     </Cluster> 

 

配置xml也是首先配置2個(gè)數(shù)據(jù)庫節(jié)點(diǎn),然后加入集群。

  • jndiCluster:是集群的唯一標(biāo)識(shí)符
  • mainDB:集群的主數(shù)據(jù)庫,建議用mysql數(shù)據(jù)庫
  • synchronous:同步數(shù)據(jù)
  • synchronousTime:同步時(shí)間
  • protect:保護(hù)模式(查詢數(shù)據(jù),不用主數(shù)據(jù)庫,只是獲取集群數(shù)據(jù)庫的數(shù)據(jù))

2.更新數(shù)據(jù)

  1. package com.shine.DBUtil; 
  2.  
  3. import com.shine.DBUtil.manage.DBManager; 
  4. import com.shine.DBUtil.utils.ClusterList; 
  5.  
  6. public class ClusterUpdateExample { 
  7.  
  8.     /** 
  9.      * 集群更新例子 
  10.      *  
  11.      * @param args 
  12.      */ 
  13.     public static void main(String[] args) { 
  14.         System.out.println("ClusterUpdateExample..."); 
  15.         DBUtil 
  16.                 .getInstance() 
  17.                 .init( 
  18.                         "E:\\workspace\\JavaFramework2.5\\src\\com\\shine\\DBUtil\\config\\dbXml.xml"); 
  19.  
  20.         ClusterList list = DBManager.getInstance() 
  21.                 .getClusterConnectionNameList("jdbc/Cluster"); 
  22.         System.out.println("主數(shù)據(jù)庫為:" + list.getMainDB()); 
  23.         String sql = "insert into test1(test) value('test')"
  24.         DBUtil.getInstance().executeClusterUpdate("jdbc/Cluster", sql); 
  25.  
  26.     } 
  27.  

3.查詢數(shù)據(jù)

  1. package com.shine.DBUtil; 
  2.  
  3. import com.shine.DBUtil.model.DBModel; 
  4.  
  5. public class ClusterSelectExample { 
  6.  
  7.     /** 
  8.      * 集群查詢 
  9.      *  
  10.      * @param args 
  11.      */ 
  12.     public static void main(String[] args) { 
  13.         System.out.println("ClusterSelectExample..."); 
  14.         DBUtil 
  15.                 .getInstance() 
  16.                 .init( 
  17.                         "E:\\workspace\\JavaFramework2.5\\src\\com\\shine\\DBUtil\\config\\dbXml.xml"); 
  18.  
  19.         String sql = "select * from test1"
  20.         String clusterJndi = "jdbc/Cluster"
  21.         DBModel dbmodel1 = DBUtil.getInstance().executeClusterQuery( 
  22.                 clusterJndi, sql); 
  23.  
  24.         DBModel dbmodel2 = DBUtil.getInstance().executeClusterQuery( 
  25.                 clusterJndi, sql); 
  26.  
  27.     } 
  28.  

實(shí)際上集群數(shù)據(jù)庫的同步最好是不要選擇定時(shí)同步,除非特殊需要,因?yàn)槿绻玫綌?shù)據(jù)庫集群,必然會(huì)有海量的數(shù)據(jù)。而DBUtil的定時(shí)同步是整庫同步,使用者應(yīng)該根據(jù)業(yè)務(wù)邏輯分表,部分同步比較實(shí)際。

原文鏈接:http://blog.csdn.net/arjick/article/details/6758872

【編輯推薦】

  1. DataReader鏈接關(guān)閉解惑篇
  2. 詳解MySQL如何鏈接遠(yuǎn)程SQL
  3. 詳解SQL Server如何鏈接遠(yuǎn)程MySQL
  4. 為什么要關(guān)閉數(shù)據(jù)庫連接,能不能不要啊
  5. SQL語句相關(guān)概念及練習(xí)之基礎(chǔ)篇
責(zé)任編輯:艾婧 來源: arjick的專欄
相關(guān)推薦

2011-08-10 15:46:29

數(shù)據(jù)庫

2011-04-07 10:50:47

數(shù)據(jù)庫編程注釋規(guī)范

2021-05-17 06:57:34

SQLServer數(shù)據(jù)庫

2011-04-07 10:29:21

數(shù)據(jù)庫編程書寫規(guī)范

2011-08-23 17:33:00

SQLAndroid

2010-06-17 13:24:38

SQL Server教

2009-10-26 09:04:35

VB.NET數(shù)據(jù)庫基礎(chǔ)

2011-03-30 13:57:41

MySQL數(shù)據(jù)庫自動(dòng)備份

2011-05-17 15:02:15

ORACLE數(shù)據(jù)庫備份

2011-03-31 14:34:46

cactimysql備份

2010-08-27 09:59:51

SQL Server

2011-08-24 10:45:23

Oracle數(shù)據(jù)庫進(jìn)程從屬進(jìn)程

2009-11-20 14:08:39

Oracle數(shù)據(jù)庫備份

2011-03-24 09:07:11

SQL Server數(shù)備份

2019-03-01 13:40:01

MySQL數(shù)據(jù)庫備份案例

2009-06-24 13:07:44

Android數(shù)據(jù)庫

2011-03-24 16:46:44

微軟Excel數(shù)據(jù)庫

2010-06-04 09:58:03

MySQL數(shù)據(jù)庫備份

2010-06-07 14:09:12

mysqldump備份

2019-12-13 10:31:45

數(shù)據(jù)庫SQLMySQL
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)