Wednesday, May 13, 2009

ERROR: pgsenna2: sen_index_update failed

postgres.conf
・ludia.max_n_sort_result = 100000
・ludia.enable_seqscan = on
・ludia_sen_index_flags = 31
・ludia.max_n_index_cache = 16
・ludia.initial_n_segments = 3000

setting up with big value initial_n_segments it will pass error

postgresql order by count

select count(*), u.user_id
from aaa up
join user u
on u.user_id=up.user_id
where accepted=1
group by user_id
having count(*)>1
order by 1

Tuesday, May 12, 2009

PHP smarty submenu

Here are the code
The PHP code is:
$menu=array();
$query="SELECT * FROM domenii WHERE parentid=0";
$resursa=$obj->query($query);
while($row=$obj->fetcharray($resursa)){
$query1="SELECT * FROM domenii WHERE parentid=".$row['id'];
$resursa1=$obj->query($query1);
if($obj->numrows($resursa1)>0){
$submenu=array();
while($row1=$obj->fetcharray($resursa1)){
$submenu[]=array('type'=>$row1['type'],
'id'=>$row1['id'],
'nume'=>$row1['nume'],
'title'=>str_replace(' ','-', $row1['nume']));
}
}else{$submenu='0';}

$menu[]=array('type'=>$row['type'],
'id'=>$row['id'],
'nume'=>$row['nume'],
'title'=>str_replace(' ','-', $row['nume']),
'submenu'=>$submenu);
}

$obj->assign('menu', $menu);

The HTML (with smarty) code:




Compact it like this:

['main_link1'] => Array (
['key1'] => value
['key2'] => value
['submenus'] => Array (
['sublink1'] => Array ()
['sublink2'] => Array ()
)
['main_link2'] => Array (
['key1'] => value
['key2'] => value
['submenus'] => Array (
['sublink1'] => Array ()
['sublink2'] => Array ()
)

Tuesday, April 28, 2009

pgpool-II install and setting(インストールと設定)

pgpool-II 2.0.1のインストール in PostgreSQL 8.3.5

PostgreSQL

# : rootユーザ

$ : postgresユーザ


■pgpool-IIのDL / 展開、postgresユーザへの権限付与

DL先 : /usr/local/src/

展開先 : /usr/local/src/pgpool-II-2.0.1/

インスト先 : /usr/local/pgpool2/

# mkdir /usr/local/pgpool2

# chown postgres.postgres -R /usr/local/pgpool2/

# cd /usr/local/src/

# wget http://pgfoundry.org/frs/download.php/1521/pgpool-II-2.0.1.tar.gz

# tar -zxvf pgpool-II-2.0.1.tar.gz

# chown postgres.postgres -R /usr/local/src/pgpool-II-2.0.1/


■pgpool-IIのインストール(実行ユーザ:postgres)

# su - postgres

$ cd /usr/local/src/pgpool-II-2.0.1/

$ ./configure --prefix=/usr/local/pgpool2

$ make

$ make install



参考

* FrontPage - pgpool Wiki(pgpool-II/tutorial - pgpool Wiki)

Permalink | コメント(0) | トラックバック(0) | 15:32 このエントリーを含むブックマーク
レプリケーション in pgpool-II 2.0.1 / PostgreSQL 8.2.5 / CentOs5CommentsAdd StarCommentsAdd StarCommentsAdd Star

PostgreSQL

# : rootユーザ

$ : postgresユーザ


■ネットワークの設定

# vi /etc/hosts

-> 192.168.xxx.xx1 ecshopping-guide1.localdomain ecshopping-guide1

-> 192.168.xxx.xx2 ecshopping-guide2.localdomain ecshopping-guide2

※TAB区切り

hostname:ecshopping-guide1の場合

# vi /etc/sysconfig/network

-> #NETWORKING_IPV6=yes

-> HOSTNAME=ecshopping-guide1.localdomain


■PostgreSQLの設定

$ vi /usr/local/pgsql/data/postgresql.conf

-> listen_addresses = '*'

-> port = 5432        # default

$ vi /usr/local/pgsql/data/pg_hba.conf

-> local all all trust

-> host all postgres 192.168.xxx.0/24 trust

※半角スペース区切り

■pgpool-IIの設定

$ cp -p /usr/local/pgpool2/etc/pgpool.conf.sample /usr/local/pgpool2/etc/pgpool.conf

$ vi /usr/local/pgpool2/etc/pgpool.conf

-> listen_addresses = '*'

-> port = 9999       # default

-> replication_mode = true

-> load_balance_mode = true

-> enable_pool_hba = false # default

-> # データベースノードの設定(hostname:ecshopping-guide1)

-> backend_hostname0 = 'ecshopping-guide1'

-> backend_port0 = 5432

-> backend_weight0 = 1

-> # データベースノードの設定(hostname:ecshopping-guide1)

-> backend_hostname1 = 'ecshopping-guide1'

-> backend_port1 = 5432

-> backend_weight1 = 1


■レプリケーションの確認(pgbenchを使用)

$ cd /usr/local/src/postgresql-8.2.5/contrib/pgbench

$ make

$ make install

$ /usr/local/pgpool2/bin/pgpool -n &

$ /usr/local/pgsql/bin/createdb -p 9999 bench_replication

$ /usr/local/pgsql/bin/pgbench -i -p 9999 bench_replication


データベースノードに設定したサーバのPostgreSQLを確認。

List of databases
Name | Owner | Encoding
-------------------+----------+----------
bench_replication | postgres | UTF8       <- が、各PostgreSQLに追加されているはず



多分、いまは構成はこんなかんじ。

 ┌─────┐ ┌─────┐  ┌───────────┐
 │client  ├─┤pgpool-II ├─┬┤PostgreSQL(ecshopping-guide1:5432)│
 └─────┘ └─────┘ │└───────────┘
                 │┌───────────┐
                 └┤PostgreSQL(ecshopping-guide2:5432)│
                  └───────────┘



# 最初、レプリケーションされなかったのはPostgreSQLにユーザ作成していなかったから…。

http://www.ecshopping-guide.com

ludia 1.5.1 and senna (search fulltext) install and configure for postgresql(ludia とsenna インストールと設定)

LudiaはSennaを使ったPostgresSQL用の組み込み型全文検索インデックスエンジンです。
ダウンロード

下記サイトからダウンロード。

http://sourceforge.jp/projects/ludia/

Mecab、MeCab辞書、Sennaが含まれているludia-withdepsのパッケージをDLします。
インストール
解凍

$tar -zxvf ludia-withdeps-1.5.1.tar.gz
$cd ludia-1.51/deps

MeCabのインストール

分かち書き方式に形態素解析を利用しない場合は、 MeCab(と辞書)をインストールする必要はありません。その場合はSennaのインストールに進んでください。 (MeCabをインストールしない場合はSennaのインストールの際に、 --without-mecabオプションを指定する必要あり)

MeCabをインストールする場合は、アーカイブを展開し、以下の要領でビルドとインストールを行います。:

$ tar -zxvf mecab-0.97.tar.gz
$ cd mecab-0.97
$ ./configure --with-charset=utf8
$ make
$ su
# make install

MeCab辞書のインストール

アーカイブを展開し、以下の要領でビルドとインストールを行います。:

$ tar -zxvf mecab-ipadic-2.7.0-20070801.tar.gz
$ cd mecab-ipadic-2.7.0-20070801
$ ./configure --with-charset=utf8
$ make
$ su
# make install

Sennaのインストール

アーカイブを展開し、以下の要領でビルドとインストールを行います。:

$ tar -zxvf senna-1.13.tar.gz
$ cd senna-1.13
$ ./configure
$ make
$ su
# make install

MeCabをインストールしていない場合には、以下のように --without-mecab オプションの指定が必要

$ ./configure --without-mecab

Ludiaのインストール

アーカイブを展開し、以下の要領でビルドとインストールを行います。:

$ ./../../
$ ./configure
$ make
$ su
# make install

pg_configコマンド、senna-cfgコマンドのインストール先にPATHが設定されていない場合、以下のようにそれぞれのpathをconfigureオプションで指定してください。:

$ ./configure --with-pg-config=/usr/local/pgsql/bin/pg_config --with-senna-cfg=/usr/local/bin/senna-cfg

インデックスアクセスメソッドの登録

$ psql -f /usr/share/pgsql/pgsenna2.sql testdb -u

postgreSQLの設定ファイル編集

postgresql.confに下記の設定を追加

custom_variable_classes = 'ludia'
ludia.max_n_sort_result = 10000
ludia.enable_seqscan = on
ludia.seqscan_flags = 1
ludia.sen_index_flags = 31
ludia.max_n_index_cache = 16
ludia.initial_n_segments = 512

インデックスの作成

インデックス作成例:

CREATE INDEX student_fulltext_index_name
ON student
USING fulltext(studentname);

検索クエリ

SELECT * FROM student WHERE studentname %% 'もも';

Monday, April 27, 2009

postgresql log setting postgresql ログ 設定

syslogにログをはく

vi /usr/local/pgsql/data/postgresql.conf

log_destination = 'syslog'
log_statement = 'all'

syslogの設定にも追加

vi /etc/syslog.conf

local0.* /var/log/postgresql.log

syslog再起動

/etc/init.d/syslog restart

Saturday, April 25, 2009

perl pdf encode utf8 and shift_jis(japanese font)

#!/usr/bin/perl -w
use strict;
use PDF::API2;
my $pdf = PDF::API2->new;
$pdf = PDF::API2->open('/tmp/old.pdf');
my $page = $pdf->openpage(1);
my $gfx = $page->gfx;
#my $jfs = $pdf->cjkfont( 'KozGo', -encode=>'utf8' );
my $jfs = $pdf->cjkfont( 'KozGo', -encode=>'shiftjis' );
my $text = "T03 2007/1/23 どんなかんじでしょうかね";
$gfx->textlabel(30, 800, $jfs, 20, $text, -color=>'red');
$pdf->saveas("new_file.pdf");