Tsurugi PostgreSQLから接続

 

参考文献: 次世代高速オープンソースRDB Tsurugi (神林飛志 et al. 著)

https://itecnote.com/tecnote/r-git-clone-works-git-submodule-fails-permission-denied/
https://github.com/project-tsurugi/tsurugi_fdw/blob/master/README.md

OS: Ubuntu 22.04
PostgreSQL: 12

CPU: 2
memory : 8G

 


-- 1. Java11インストール

 

sudo apt -y update
sudo apt purge -y needrestart

sudo apt -y install openjdk-11-jdk

sudo sh -c "cat > /etc/profile.d/java.sh" <<'EOF'
export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which java)))))
export PATH=$PATH:$JAVA_HOME/bin
EOF

. /etc/profile.d/java.sh


java -version
javac -version

 

 

 

-- 2. tsurugi_fdwのビルド

-- 2.1 Install required packages

sudo apt -y install libreadline-dev zlib1g-dev curl
sudo apt -y install make gcc g++ git


-- 2.2 Build and Install PostgreSQL

curl -sL https://ftp.postgresql.org/pub/source/v12.4/postgresql-12.4.tar.bz2 | tar -xj
cd postgresql-12.4
./configure --prefix=$HOME/pgsql
make
make install

vim ~/.profile

export PG_HOME=$HOME/pgsql

export LD_LIBRARY_PATH=$PG_HOME/lib
export PATH=$PG_HOME/bin:$PATH

. ~/.profile

echo $PG_HOME
echo $LD_LIBRARY_PATH
echo $PATH

ls -l $PG_HOME
psql --version


-- 2.3 Clone tsurugi_fdw


cd contrib
git clone https://github.com/project-tsurugi/tsurugi_fdw.git
cd tsurugi_fdw
git submodule update --init


vim .git/config


[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = https://github.com/project-tsurugi/tsurugi_fdw.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[submodule "third_party/message-manager"]
        active = true
        url = https://github.com/project-tsurugi/message-manager.git
[submodule "third_party/metadata-manager"]
        active = true
        url = https://github.com/project-tsurugi/metadata-manager.git
[submodule "third_party/ogawayama"]
        active = true
        url = https://github.com/project-tsurugi/ogawayama.git
[submodule "third_party/takatori"]
        active = true
        url = https://github.com/project-tsurugi/takatori.git


git submodule update --init


-- 2.4 Build and Install tsurugi


cd
git clone https://github.com/project-tsurugi/tsurugidb.git


cd tsurugidb

git submodule update --init --recursive


vim ./.git/modules/message-manager/config

url = git@github.com:project-tsurugi/metadata-manager.git

url = https://github.com/project-tsurugi/metadata-manager.git


git submodule update --init --recursive

 

sudo ./apt-install.sh

mkdir -p $HOME/tsurugi

sudo ./install.sh --prefix=$HOME/tsurugi


-- 2.5 Build and Install tsurugi_fdw

 

vim ~/.profile

export PG_HOME=$HOME/pgsql
export TSURUGI_HOME=$HOME/tsurugi/tsurugi-snapshot-202311081350-1bbf38d

export LD_LIBRARY_PATH=$PG_HOME/lib:$TSURUGI_HOME/lib
export PATH=$PG_HOME/bin:$TSURUGI_HOME/bin:$PATH

. ~/.profile

echo $TSURUGI_HOME
echo $LD_LIBRARY_PATH
echo $PATH

ls -l $TSURUGI_HOME
tgctl status

 

cd $HOME/postgresql-12.4/contrib/tsurugi_fdw

※誤植ではなく、LDなしの環境変数が必要。

export LIBRARY_PATH=$PG_HOME/lib:$TSURUGI_HOME/lib
echo $LIBRARY_PATH

make
make install

 


-- 3. tsurugi_fdwのセットアップ


mkdir -p $HOME/pgsql/data
initdb -D $HOME/pgsql/data

vim $HOME/pgsql/data/postgresql.conf

shared_preload_libraries = 'tsurugi_fdw'


pg_ctl -D $HOME/pgsql/data -l logfile start


psql postgres < $HOME/postgresql-12.4/contrib/tsurugi_fdw/third_party/metadata-manager/sql/ddl.sql

 

psql postgres

create extension tsurugi_fdw;
\dx
\dew

create server tsurugidb foreign data wrapper tsurugi_fdw;

\des

\! mkdir -p $HOME/pgsql/tsurugi

create tablespace tsurugi location '/home/user01/pgsql/tsurugi';
\db

\q

pg_ctl -D $HOME/pgsql/data -l logfile stop

 

-- 4. 動作確認

起動はTsurugi → PostgreSQL


tgctl start
tgctl status
pg_ctl -D $HOME/pgsql/data -l logfile start

psql postgres

 

create table tab1(
col1 integer primary key,
col2 varchar(30) not null,
col3 integer
) tablespace tsurugi;

create foreign table tab1(
col1 integer,
col2 varchar(30) not null,
col3 integer
) server tsurugidb;

insert into tab1(col1,col2,col3) values(1,'A',1);
insert into tab1(col1,col2,col3) values(2,'B',2);
insert into tab1(col1,col2,col3) values(3,'C',3);

select * from tab1;

select tg_start_transaction('OCC');
insert into tab1(col1,col2,col3) values(4,'D',4);
select tg_show_transaction();
select tg_commit();
select tg_show_transaction();


select tg_set_transaction('LTX');
select tg_set_write_preserve('tab1');
select tg_start_transaction();
insert into tab1(col1,col2,col3) values(5,'E',5);
select tg_show_transaction();
select tg_commit();
select tg_show_transaction();


select tg_start_transaction('RTX');
select * from tab1;
select tg_commit();


create table tab2(
col1 integer primary key,
col2 varchar(30) not null,
col3 integer
);

\d

insert into tab2 select * from tab1 where col3 > 2;

select * from tab1;
select * from tab2;