small note on postgresql

|**|

postgresql postgres 003

postmaster

start of postgresql server

バックグラウンドで サーバーを 起動させる

$ cd
$ pwd
/home/postgres
$ postmaster -D /usr/local/pgsql/data >logfile001 2>&1 &
[1] 518
$ cat logfile001 
bash: postmaster: command not found

command が 無いいうてはります なんで?

$ ls /usr/local/pgsql/bin/
clusterdb*   dropdb*    initdb*          pg_ctl*        pg_restore*  reindexdb*
createdb*    droplang*  ipcclean*        pg_dump*       postgres*    vacuumdb*
createlang*  dropuser*  pg_config*       pg_dumpall*    postmaster@
createuser*  ecpg*      pg_controldata*  pg_resetxlog*  psql*
$ ls -l /usr/local/pgsql/bin/postmaster 
lrwxrwxrwx    1 postgres postgres   8 12月 19日  13:30 /usr/local/pgsql/bin/postmaster -> postgres*
$ rm logfile001 
$ /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data >logfile002 2>&1 &
[1] 539
$ ps aux | grep postmaster | grep -v grep
postgres   441  0.0  1.0 16244 2772 pts/0    S    15:12   0:00 postmaster -D /us

動いてる動いてる動いてまっせ さて 止めるのは どうすんねん?

stop of postgresql server

$ pg_ctl stop
bash: pg_ctl: command not found
$ /usr/local/pgsql/bin/pg_ctl stop
pg_ctl: no database directory specified and environment variable PGDATA unset
Try "pg_ctl --help" for more information.
$ /usr/local/pgsql/bin/pg_ctl stop -D /usr/local/pgsql/data
waiting for postmaster to shut down.... done
postmaster stopped
[1]+  Done   /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data >logfile002 2>&1
$ cat logfile002 
LOG:  database system was shut down at 2005-12-20 10:09:52 JST
LOG:  checkpoint record is at 0/33A6AC
LOG:  redo record is at 0/33A6AC; undo record is at 0/0; shutdown TRUE
LOG:  next transaction ID: 565; next OID: 10794
LOG:  next MultiXactId: 1; next MultiXactOffset: 0
LOG:  database system is ready
LOG:  transaction ID wrap limit is 2147484146, limited by database "postgres"
LOG:  received smart shutdown request
LOG:  shutting down
LOG:  database system is shut down
$ ps aux | grep postmaster
postgres   627  0.0  0.2  2480  740 pts/0    S    14:00   0:00 grep postmaster

取り敢えず 起動停止は 出来るようだしかしながら 一々 なんとか かんとか /bin 何何 は あまり 良い方法では おまへんな?

Edit .bashrc at /home/postgres of postgres

$ cp .bashrc .bashrc_bf_postgresql
$ vi .bashrc
$ diff -s .bashrc .bashrc_bf_postgresql 
180,186c180
< # 2005年12月20日 (火) 14:54:54 JST add below 5 lines /* 数勘定が 出来ないの? 6行 ちゃう? */
< PATH="$PATH":/usr/local/pgsql/bin
<  export POSTGRES_HOME=/usr/local/pgsql
<  export PGLIB=$POSTGRES_HOME/lib
<  export PGDATA=$POSTGRES_HOME/data
<  export MANPATH="$MANPATH":$POSTGRES_HOME/man
<  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH":$PGLIB
---
> 
$ source .bashrc

Again start and stop

$ rm logfile002 
$ postmaster -D /usr/local/pgsql/data >logfile001 2>&1 &
[2] 713
$ ps aux | grep postmaster
postgres   713  0.1  1.0 16244 2772 pts/0    S    15:01   0:00 postmaster -D /us
postgres   719  0.0  0.2  2480  744 pts/0    S    15:02   0:00 grep postmaster
$ ps aux | grep postmaster | grep -v grep
postgres   713  0.0  1.0 16244 2772 pts/0    S    15:01   0:00 postmaster -D /us
$ /usr/local/pgsql/bin/pg_ctl stop -D /usr/local/pgsql/data
waiting for postmaster to shut down.... done
postmaster stopped
[2]-  Done                    postmaster -D /usr/local/pgsql/data >logfile001 2>&1
$ ps aux | grep postmaster
postgres   729  0.0  0.2  2480  744 pts/0    S    15:05   0:00 grep postmaster

重要 これは postgresql を 使う ユー ザーは 全て対応 しておく 必要が あるようですな 今回は これのみとしておき ましょう。

./configure
gmake
su
gmake install
adduser postgres
mkdir /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data  
/usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data >logfile 2>&1 & /* 今回これみの */
/usr/local/pgsql/bin/pg_ctl stop -D /usr/local/pgsql/data /* おまけ */
/usr/local/pgsql/bin/createdb test
/usr/local/pgsql/bin/psql test

これで サーバーの 起動停止が 出来た事に なります

にゃんたろう 拝!

2005年12月21日 (水) 23:12:31 JST 作成

|**|


small note on postgresql

Copyright © 2004.-2007. nyantarou All Rights Reserved.