달력

4

« 2024/4 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
2008. 3. 29. 10:38

MySQL Federated Table DB2008. 3. 29. 10:38

오라클의 db link와 유사한 기능을 제공

federeated table은 transaction이 지원되지 않는다.

grant all privileges on *.* to dbUserId@'ip' identified by 'pwd' with grant option;
flush privileges;

CREATE TABLE IF NOT EXISTS tableName (
table description
) ENGINE=FEDERATED DEFAULT CHARSET=utf8 CONNECTION='mysql://userId:pwd@hostname:3306/dbname/tableName'

슬레이브 쪽에, 레플리케이션을 하고자하는 테이블/디비를 설정하거나, 반대로 레플리케이션을 하지 않을 테이블/디비를 my.cnf에 명시해주시면 됩니다.

replicate-ignore-db=indexmessage

replicate-ignore-table=gaiabbs.indexmessage

http://dev.mysql.com/doc/refman/5.0/en/replication-options.html

:
Posted by codetemplate
2008. 3. 20. 01:12

dbcp connection이 자꾸 끊어 질 때 DB2008. 3. 20. 01:12

http://kwon37xi.egloos.com/2472081

testOnBorrow를 유력한 후보로 생각했는데, 이 녀석은 default가 true이다. 그래서 제외

그리고 maxWait는 풀에 가용한 컨넥션이 없을 때 exception을 던지기 전에 풀에 반환되는 컨넥션을 기다리는 최대 millisecond이다. 디폴트는 무한대이다.

정답으로 보이는 설정은 위의 url에 설명된 바와 같다.

timeBetweenEvictionRunsMillis(-1)

The number of milliseconds to sleep between runs of the idle object evictor thread. When non-positive, no idle object evictor thread will be run.

numTestsPerEvictionRun(3)

The number of objects to examine during each run of the idle object evictor thread (if any).

minEvictableIdleTimeMillis(1000 * 60 * 30)

The minimum amount of time an object may sit idle in the pool before it is eligable for eviction by the idle object evictor (if any).

:
Posted by codetemplate
2008. 3. 20. 01:11

MySQL Commands DB2008. 3. 20. 01:11

my.conf 사용하기

bin/safe_mysqld --defaults-extra-file=/opt/mysql-5.0.51a-osx10.5-x86/my.cnf --user=root

사용자 추가하기

grant all privileges on *.* to userId@'ip.%' identified by 'password' with grant option; flush privileges;

리플리케이션 상태보기

Read_Master_Log_Pos와 Exec_Master_Log_Pos의 차이가 없어야 함

dump/import

  • /usr/local/mysql/bin/mysqldump --user=userId database --default-character-set=utf8 > xx.sql
  • /usr/local/mysql/bin/mysql --user=userId database [optional_table_name] < xx.sql

uptime 보기

./mysqladmin status -ppassword

커맨드 누적 횟수 보기

mysql> show status like 'Com_%';

프로세스 개수 보기

./mysqladmin -uroot processlist | wc -l
:
Posted by codetemplate
2008. 3. 15. 01:02

MySQL Cluster DB2008. 3. 15. 01:02

mgt node

data node 관리

ndb_mgm 데몬

클러스터 내의 모든 노드 리스트 및 관리

api(sql) node

비즈니스 데이터

어플리케이션 API 호출 처리

data(ndb) node

클러스터링을 위한 데이터

DDL에서 engine을 NDBCLUSTER로 지덩해야

kldp mysql clsuter v4

정합성 테스트

한쪽에서 insert / select

다른 쪽에서 select / insert / select

다른 쪽에서 select

부하 테스트

non cluster single node 성능

cluster 성능

레퍼런스 사이트 ???

:
Posted by codetemplate
2008. 3. 13. 13:24

MySQL Master/Slave Connection DB2008. 3. 13. 13:24

Using Master/Slave Replication with ReplicationConnection

http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-replication-connection.html

springframework의 declarative txn. mgt.에서 readOnly=true를 주면 setReadOnly 메소드를 사용하지 않을까 ???

2008/03/13 이렇게 시도해 보니 진짜 생각한 대로 동작했다. 그런데 테스트할 때 문제가 있었다. AbstractTransactionalXXXTest를 상속 받은 경우에는 항상 rollback 되기 때문에 transaction aspect이 동작하지 않는 것 같다. 그래서 readOnly transactional method에서 CUD를 해도 exception이 발생하지 않았다. 그래서 AbstractJUnit4SpringContextTests를 사용했다.

이제 해 볼 것은 readOnly 메소드에서 transactional method를 호출할 때 제대로 master/slave로 호출이 분배되는지 확인하는 것이다.

이건 안된다.

readOnly 메소드가 transactional 메소드를 호출하면 read only connection에서 데이터를 변경하려고 시도했다고 exception을 발생시킨다.

Load Balancing JDBC Pool (lbpool)

http://code.tailrank.com/lbpool

예제)
1. replication.properties

replication.driverClassName=com.mysql.jdbc.ReplicationDriver
replication.url=jdbc:mysql://master-ip,slave-ip-1, slave-ip-2/dbname?autoReconnect=true
jdbc.username=xxx
jdbc.password=yyy

2. applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">

<context:property-placeholder
location="classpath:replication.properties" />

<tx:annotation-driven transaction-manager="transactionManager" />

<context:component-scan base-package="net" />

<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${replication.driverClassName}"
p:url="${replication.url}" p:username="${jdbc.username}"
p:password="${jdbc.password}" />

<bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"
p:configLocation="classpath:sqlMap-config.xml"
p:dataSource-ref="dataSource" />

<bean id="sqlMapClientTemplate"
class="org.springframework.orm.ibatis.SqlMapClientTemplate"
p:sqlMapClient-ref="sqlMapClient" />

<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref="dataSource" />

<bean id="someDao"
class="net.SomeDaoImpl"
p:sqlMapClientTemplate-ref="sqlMapClientTemplate" />
</beans>

3. ManageArticleServiceImpl

@Service
@Transactional(readOnly=true)
public class ManageArticleServiceImpl implements ManageArticleService {
@Autowired
private SomeDao SomeDao;

@Autowired
private CountService countService;

@Transactional(readOnly=false, propagation = Propagation.REQUIRED)
public Article getArticle(Long articleId) {
Article article = someDao.find(articleId);

countService.read(article);

return article;
}
}

4. CountServiceImpl

@Service
@Transactional(readOnly=true)
public class CountServiceImpl implements CountService {
@Autowired
private SomeDao someDao;

@Transactional(readOnly=false, propagation = Propagation.REQUIRED)
public void read(Article article) {
article.read();
someDao.update(article);
}
}

:
Posted by codetemplate
2006. 11. 15. 17:19

mysql row level lock DB2006. 11. 15. 17:19

4.1.3 innodb나 5.1 이상에서 가능

SELECT * FROM t WHERE i = 1 LOCK IN SHARE MODE;

Rows are locked during updates using indexes. For example,
update tab set col1=3 where col2=17;

will lock the entire table unless col2 is indexed (in which case, only rows where col2=17 will be locked).

:
Posted by codetemplate
2006. 10. 30. 19:55

Oracle data를 csv로 덤프하는 방법 DB2006. 10. 30. 19:55

    1  #!/bin/ksh
    2
    3  for tableName in `cat table.lst`
    4  do
    5          echo "set echo off" > t1.sql
    6          echo "set heading off" >> t1.sql
    7          echo "set pagesize 0" >> t1.sql
    8          echo "set verify off" >> t1.sql
    9          echo "set feedback off" >> t1.sql
   10          echo "set linesize 130" >> t1.sql
   11          echo "set trimspool on" >> t1.sql
   12          echo "define tableName=$tableName" >> t1.sql
   13          echo "spool t2.sql" >> t1.sql
   14          echo "select 'set echo off' from dual;" >> t1.sql
   15          echo "select 'set heading off' from dual;" >> t1.sql
   16          echo "select 'set pagesize 0' from dual;" >> t1.sql
   17          echo "select 'set verify off' from dual;" >> t1.sql
   18          echo "select 'set feedback off' from dual;" >> t1.sql
   19          echo "select 'set linesize 130' from dual;" >> t1.sql
   20          echo "select 'set trimspool on' from dual;" >> t1.sql
   21          echo "select 'spool &tableName.csv' from dual;" >> t1.sql
   22          echo "select 'select ' from sys.dual;" >> t1.sql
   23          echo "select decode(column_id,1,column_name, '||'',''||'||column_name)" >> t1.sql
   24          echo "from   sys.dba_tab_columns" >> t1.sql
   25          echo "where  table_name = '&tableName'" >> t1.sql
   26          echo "order by column_id;" >> t1.sql
   27          echo "select 'from &tableName;'" >> t1.sql
   28          echo "from   sys.dual;" >> t1.sql
   29          echo "select 'spool off' from dual;" >> t1.sql
   30          echo "spool off" >> t1.sql
   31 
   32          sqlplus -S vep/rkaus60 < t1.sql
   33
   34          sqlplus -S vep/rkaus60 < t2.sql
   35  done

:
Posted by codetemplate
2006. 10. 30. 19:17

오라클에서 escape 문자 사용법 DB2006. 10. 30. 19:17

set escape '\'

insert into <table_name>
values('s\&p');
:
Posted by codetemplate