codeigniter / ci / oracle database.php 的設定方式 / utf8 / big5 粉難搞

$db['oci']['hostname'] = "//IP_ADDRESS/INSTANT_NAME";
$db['oci']['username'] = "USERNAME";
$db['oci']['password'] = "PASSWORD";
$db['oci']['database'] = "INSTANT_NAME";
$db['oci']['dbdriver'] = "oci8";
$db['oci']['dbprefix'] = "";
$db['oci']['pconnect'] = TRUE;
$db['oci']['db_debug'] = TRUE;
$db['oci']['cache_on'] = FALSE;
$db['oci']['cachedir'] = "";
$db['oci']['char_set'] = "utf8"; // database 是 UTF8
$db['oci']['char_set'] = "ZHT16BIG5"; // database 是 big5

$db['oci']['dbcollat'] = "utf8_general_ci";

記得 codeigniter 的 /system/database/drivers/oci8/oci8_driver.php 這個檔要改一下

2009.0303 補充, 若要連 oracle standby database.php 要改成這樣 用 service name ( 看那個 tnsnames.ora )

擷取-oracle-standby-ci

用 mysql-proxy 實踐 讀/寫 分離

起因是不想要動到舊的程式碼 , 若用 mysql-proxy 把讀寫分離出來 , 那舊的程式連接資料庫的 connect 段就不用改了 , 而且 mysql-proxy 官網還寫了不少好處:

– load balancing
– failover
– query analysis
– query filtering and modification
and many more.

首先要先建制一個 master/slave 的 mysql 架構 – 設定 mysql 成 master / slave 架構

在 gentoo 中 , 用 emerge –av mysql-proxy 把 目前版本 0.61 裝進來 , 然後 /etc/conf.d/mysql-proxy 的設定如下

# /etc/conf.d/mysql-proxy: config file for /etc/init.d/mysql-proxy

# location auf pidfile
PIDFILE="/var/run/mysql-proxy.pid"

# general options for mysql-proxy
OPTS="--proxy-lua-script=/root/tutorial-keepalive.lua
--proxy-backend-addresses=172.30.0.182:3306
--proxy-read-only-backend-addresses=172.30.0.183:3306
"
#OPTS="/root/mysql-proxy.lua"

# if you want mysql-proxy to depend on mysql, enable this:
#RC_NEED="mysql"

這邊的 tutorial-keepalive.lua 可以到 http://svn.mysql.com/svnpublic/mysql-proxy/trunk/examples/tutorial-keepalive.lua下載

參考 http://jan.kneschke.de/2007/8/1/mysql-proxy-learns-r-w-splitting

O’Reilly 有一些 lua 的 sample : http://www.oreillynet.com/pub/a/databases/2007/07/12/getting-started-with-mysql-proxy.html?page=4

MySQL 官網的 FAQ : http://dev.mysql.com/doc/refman/5.0/en/mysql-proxy-faq.html

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

在 January 30th, 2009 , MySQL Proxy 有新版了  from 0.6.1 to 0.7.0

http://jan.kneschke.de/2009/1/30/mysql-proxy-from-0-6-1-to-0-7-0

另外 Lua 是一種簡單/快速的 script language , mysql proxy snippets

最後看到有個問題 : “SPoF” , Sigle Point of Failure ….

sqlrelay client for php and C : install / settings / history / tunning 方法

2017-0920 update:

stable version = rudiments-0.32  + sqlrelay-0.39.4

./sqlrelay-0.39.4/src/api/php/.libs/libsql_relay.so.0.0.0

 

 

step1. 裝 sqlrelay 前要先裝 Rudiments 的 library , 現在抓 rudiments 0.32 版.

PATH="$PATH:/sbin" ldconfig -n /usr/local/firstworks/lib

Libraries have been installed in:
/usr/local/firstworks/lib

他有提到幾點

– add LIBDIR to the `LD_LIBRARY_PATH’ environment variable
during execution
– add LIBDIR to the `LD_RUN_PATH’ environment variable
during linking
– use the `-Wl,–rpath -Wl,LIBDIR’ linker flag
– have your system administrator add LIBDIR to `/etc/ld.so.conf’

—->解決 lib 問題 : ld.so.conf

step2. 裝 sqlrelay , 抓

  • wget http://downloads.sourceforge.net/sqlrelay/sqlrelay-0.40.tar.gz?modtime=1231398430&big_mirror=0
  • configure , make , make install
  • 檢查是否有 sql_relay.so : find / -name sql_relay.so -print
    /usr/lib/php5/lib/php/extensions/no-debug-non-zts-20060613/sql_relay.so
  • gentoo 在 /etc/php 下的兩個環境 : apache2-php5 , cli-php5 目錄 裡面的 ext , ext-active 都要有這個 file : sqlrelay.ini , 內容是
    extension=sql_relay.so
  • 找安裝程式把 libsqlrclientwrapper*so* 放在哪個目錄 , 再修改 /etc/ld.so.conf 加上這個目錄 , 改完要下 ldconfig –v 讓路徑生效

 

用 php code 測試 sqlrelay extension 是否 load 進來了

$a = get_loaded_extensions();

print_r( $a );

 

以下是 SQL Relay server 端的設定—–

Tuning SQL Relay –

http://sqlrelay.sourceforge.net/sqlrelay/tuning.html

這邊提到一些改善 SQL Relay 效能的方法, 不過這些方法也適用於一些 networked daemon 的 tunning

如 下 sysctl -a|grep timeout 看到

net.ipv4.tcp_fin_timeout = 60 設成 30 ,
echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout

tcp_tw_recycle , tcp_tw_reuse 這兩個 default 是 0 (關起來的) 設成 1 ,
echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse
echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle

——–
cat /etc/sysctl.conf
net.ipv4.ip_local_port_range = “1024 65535” —> 這個在 gentoo 好像無效
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1