DB/PostgreSQL

새로운 DB를 구축

swhwang 2016. 5. 4. 01:33

2010-12-17 09:00:02.361 JST [][][] LOG:  received fast shutdown request
2010-12-17 09:00:02.361 JST [][][] LOG:  shutting down
2010-12-17 09:00:04.461 JST [][][] LOG:  database system is shut down
2010-12-17 09:00:04.506 JST [][][] LOG:  logger shutting down
2010-12-17 11:20:40.521 JST [][][] LOG:  database system was shut down at 2010-12-17 09:00:04 JST
2010-12-17 11:20:40.521 JST [][][] LOG:  could not open file "pg_xlog/00000005000004D5000000F7" (log file 1237, segment 247): No such file or directory
2010-12-17 11:20:40.521 JST [][][] LOG:  invalid primary checkpoint record
2010-12-17 11:20:40.521 JST [][][] LOG:  could not open file "pg_xlog/00000005000004D5000000F7" (log file 1237, segment 247): No such file or directory
2010-12-17 11:20:40.521 JST [][][] LOG:  invalid secondary checkpoint record
2010-12-17 11:20:40.521 JST [][][] PANIC:  could not locate a valid checkpoint record
2010-12-17 11:20:40.521 JST [][][] LOG:  startup process (PID 6357) was terminated by signal 6
2010-12-17 11:20:40.521 JST [][][] LOG:  aborting startup due to startup process failure
2010-12-17 11:20:40.541 JST [][][] LOG:  logger shutting down

----------

/usr/local/postgresql/bin/pg_resetxlog -f /usr/local/postgresql/data -l 0x1,0x4D5,0x0F8

Transaction log reset



cp -p ./PG_VERSION base/23451/PG_VERSION

[root@gp_db3 data]# cp -p ./PG_VERSION base/23451/PG_VERSION
[root@gp_db3 data]# /usr/local/postgresql/bin/psql -h localhost -U interdev selfydb
psql: FATAL:  could not open relation 1663/23451/2610: No such file or directory




----------
メンテ作業中にatgames07 baseバックアップ

-----

cd /mnt/xfs/dump

/usr/local/postgresql-9.0.1/bin/psql -h localhost -p 5432 -U postgres -c "select pg_switch_xlog();"  >>/home/interdev/obatemp/db_restore.log 2>&1
sleep 5;
/usr/local/postgresql-9.0.1/bin/psql -h localhost -p 5432 -U postgres -c "select pg_start_backup('for replication');"  >>/home/interdev/obatemp/db_restore.log 2>&1
sleep 5;
#cd /usr/local/postgresql
cd /mnt/xfs
date  >>/home/interdev/obatemp/db_restore.log 2>&1
sleep 5;
time ionice -c2 -n7 nice -n19 tar czf data_`date +%Y%m%d`.tar.gz data  >>/home/interdev/obatemp/db_restore.log 2>&1
sleep 5;
/usr/local/postgresql-9.0.1/bin/psql -h localhost -p 5432 -U postgres -c "select pg_stop_backup();" >>/home/interdev/obatemp/db_restore.log 2>&1
sleep 5;
date  >>/home/interdev/obatemp/db_restore.log 2>&1 

(データ転送)
スレーブに転送
time ionice -c2 -n7 nice -n19 rsync --bwlimit=61440 --progress /mnt/xfs/data_`date +%Y%m%d`.tar.gz interdev@172.19.1.33:/var/atgames/




----------
本番環境へインストール・・・12/14実施済み
(対象:qzent, qzgame1, qzgame2, qzgame3, qzgame5, qzmana, qzweb1, qzweb2, qzreserve, gifap1, gifap2, gp_mngap1)

----------
scp -pr interdev@172.16.5.3:/usr/local/httpd/conf /usr/local/httpd/

scp -pr interdev@172.16.5.3:/usr/local/tomcat/conf/server.xml /usr/local/tomcat/conf/server.xml

umount /var/atgames/mail1
umount /var/atgames/mail2
umount /var/atgames/webdl1
umount /var/atgames/webdl2
umount /var/atgames/image2/avatar
umount /var/atgames/webdl
umount /var/atgames/gdwebdl

#nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames interdev@172.16.5.8:/var/atgames/

nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames \
-e "/var/atgames/mail1"     \
-e "/var/atgames/mail2"     \
-e "/var/atgames/webdl1"    \
-e "/var/atgames/webdl2"    \
-e "/var/atgames/gdwebdl"   \
-e "/var/atgames/webdl"     \
-e "/var/atgames/image2/avatar" \
-e "/var/atgames/clothes2" \
interdev@172.16.5.8:/var/atgames/

-----
drwxrwxrwx  37 interdev interdev    4096 10月  8 13:16 .
drwxr-xr-x  21 root     root        4096  3月 18  2008 ..
drwxr-xr-x   2 interdev interdev    4096  7月 25 16:16 ap
drwxrwxr-x   6 interdev interdev    4096 10月 19 12:12 asp
-rwxr-xr-x   1 interdev interdev     347  7月  1  2009 chg_html.sh
drwxrwxr-x  36 interdev interdev    4096 12月 14 14:03 clothes2
-rw-rw-r--   1 interdev interdev     332  8月  1  2006 credit_cancel.sh
-rw-rw-r--   1 interdev interdev    2403  8月  1  2006 credit_cancel.txt
drwxrwxr-x   3 interdev interdev    4096  5月  7  2008 diary
-rwxrwxr-x   1 interdev interdev     767  3月 30  2010 event_creator_html_for_it.sh
drwxrwxr-x   3 interdev pegasus     4096  8月 20  2009 gdwebdl
drwxrwxrwx   3 interdev interdev    4096  6月 17  2008 image2
-rwxrwxr-x   1 interdev interdev    6408  6月  8  2010 info_creator_html_for_it.sh
drwxrwxr-x   2 interdev interdev   36864 12月 17 01:18 ipAddress
drwxr-xr-x   4 interdev interdev    4096  6月 23  2009 logs
drwxrwxrwx  10 interdev interdev   36864  5月 26  2010 mail1
drwxrwxrwx   6 interdev interdev    4096  6月 11  2009 mail2
-rwxrwxr-x   1 interdev interdev    2751  6月 28 15:34 makeShopRanking.sh
-rwxrwxr-x   1 interdev interdev     234  6月 30  2009 makeShopTop.sh
-rwx------   1 interdev interdev     270  8月 22  2008 makeSubInfo.sh
-rwxr-xr-x   1 interdev interdev     282  8月 27 17:57 make_enquete.sh
-rwxr-xr-x   1 interdev interdev    1696  7月  7  2009 make_static.sh
drwxrwxr-x   2 interdev interdev    4096  6月 30  2009 make_static_090630
-r-xr-xr-x   1 interdev interdev     732  5月 23  2010 make_submenu.sh
-rwxrwxr-x   1 interdev interdev     422  3月 30  2010 make_top.sh
-rw-rw-r--   1 interdev interdev     228  8月  1  2006 md5.sh
drwxrwxr-x   2 interdev interdev    4096 10月 22 19:12 medal
drwxrwxr-x   2 interdev interdev    4096  5月 22  2007 outflash
drwxr-xr-x   2 interdev interdev   24576 12月 16 20:09 passwordChange
drwxr-xr-x   2 interdev interdev   40960 12月 17 00:00 petitcoin
drwxrwxr-x   2 interdev interdev   28672 12月 13 08:00 pointcooperation
drwxr-xr-x   2 interdev interdev    4096  9月 10 13:20 searchINFO
drwxrwxr-x   2 interdev interdev  151552  3月 30  2010 searchInfo
drwxrwxr-x   2 interdev interdev   65536 12月 17 00:18 settlement
drwxrwxr-x   2 interdev interdev    4096  4月 12  2010 sh
-rwxrwxr-x   1 interdev interdev     650  6月 28 15:21 shop_ranking_creator_html.sh
-rw-rw-r--   1 interdev interdev    4054  7月  2  2009 sub_menu.html
-rw-rw-r--   1 interdev interdev    8369  4月  2  2008 submenu.html
-rw-rw-r--   1 interdev interdev    8677  6月 30  2009 top3_lu.html
drwxrwxrwx   2 interdev interdev    4096  5月 25  2006 toyap1
drwxrwxrwx   2 interdev interdev    4096  5月 25  2006 toyap2
drwxrwxrwx   2 interdev interdev    4096  5月 25  2006 toyap3
drwxrwxrwx   2 interdev interdev    4096  5月 25  2006 toyap4
drwxrwxrwx   2 interdev interdev    4096  5月 25  2006 toyap5
drwxrwxrwx   2 interdev interdev    4096  5月 25  2006 toyap6
drwxrwxr-x   3 interdev interdev 1359872 12月 17 13:04 uniquelogin
drwxrwxr-x   2 interdev interdev   28672 12月 17 00:00 userIDCheck
drwxr-xr-x   3 interdev interdev   12288 12月 17 07:45 user_affiliate
drwxrwxrwx  12 interdev pegasus      127  5月 28  2010 webdl
drwxrwxr-x  77 interdev interdev    4096 12月 13 18:12 webdl1
drwxrwxr-x  78 interdev interdev    4096 12月 13 18:12 webdl2
drwxrwxrwx   2 interdev interdev    4096  6月 13  2006 webdl3
drwxrwxrwx   2 interdev interdev    4096  6月 13  2006 webdl4
-rw-rw-r--   1 interdev interdev     630  5月 23  2010 wget_clothrank.log
-rw-rw-r--   1 interdev interdev     622  5月 23  2010 wget_event.log
-rw-rw-r--   1 interdev interdev     233  5月 23  2010 wget_info.log
-rw-rw-r--   1 interdev interdev     437  5月 23  2010 wget_osusumecircle.log
-rw-rw-r--   1 interdev interdev     525  7月  2  2009 wget_submenu.log
-rw-rw-r--   1 interdev interdev     424  6月 30  2009 wget_top3_lu.log
drwxrwxr-x   3 interdev interdev    4096  8月 23  2006 www


nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/ap                 interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/asp                interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/clothes2           interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/diary              interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/ipAddress          interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/logs               interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/make_static_090630 interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/medal              interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/outflash           interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/passwordChange     interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/petitcoin          interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/pointcooperation   interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/searchINFO         interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/searchInfo         interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/settlement         interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/sh                 interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/toyap1             interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/toyap2             interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/toyap3             interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/toyap4             interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/toyap5             interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/toyap6             interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/uniquelogin        interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/userIDCheck        interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/user_affiliate     interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/webdl3             interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/webdl4             interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/www                interdev@172.16.5.8:/var/atgames/

nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/chg_html.sh interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/credit_cancel.sh interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/credit_cancel.txt interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/event_creator_html_for_it.sh interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/info_creator_html_for_it.sh interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/makeShopRanking.sh interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/makeShopTop.sh interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/makeSubInfo.sh interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/make_enquete.sh interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/make_static.sh interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/make_submenu.sh interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/make_top.sh interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/md5.sh interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/shop_ranking_creator_html.sh interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/sub_menu.html interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/submenu.html interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/top3_lu.html interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/wget_clothrank.log interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/wget_event.log interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/wget_info.log interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/wget_osusumecircle.log interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/wget_submenu.log interdev@172.16.5.8:/var/atgames/
nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/wget_top3_lu.log interdev@172.16.5.8:/var/atgames/



#nice -n19 rsync -ltr --bwlimit=100000 --progress /var/atgames/clothes2 interdev@172.16.5.8:/var/atgames/

nice -n19 rsync -ltr --bwlimit=100000 --progress /usr/local/tomcat/webapps/*.war interdev@172.16.5.8:/usr/local/tomcat/webapps/



15 *  *  *  *   interdev /var/atgames/make_static.sh 1> /dev/null
#15,35,55 *  *  *  *   interdev /var/atgames/make_static.sh 1> /dev/null
#30 *  *  *  *   root /var/atgames/make_static.sh 1> /dev/null
59 23 1 4 * interdev /var/atgames/chg_html.sh 1> /dev/null
#4,9,14,19,24,29,34,39,44,49,54,59 * * * * interdev /var/atgames/diary/OutsideBlogUptake.sh 1> /dev/null
#ショップトップに表示されるランキング静的ページ生成用
5 * * * * interdev /var/atgames/shop_ranking_creator_html.sh 1> /dev/null
#販売物イベント(最新情報)の静的ページ生成用
#0 1 * * * interdev /var/atgames/event_creator_html_for_it.sh 1> /dev/null
#お知らせの静的ページ生成用
#0 1 * * * interdev /var/atgames/info_creator_html_for_it.sh 1> /dev/null

#tomcat log gzip
#55 5 * * *   interdev /var/atgames/sh/tomcatlog_gzip.sh >/dev/null 2>&1

#user affiliate batch (log file -> database)
10 6 * * * interdev /var/atgames/user_affiliate/batch/dump_user_affiliate_log.sh 1> /dev/null 2>&1

---

[interdev@gp_ap3 ~]$ df -h
Filesystem          サイズ  使用  残り 使用% マウント位置
/dev/md2               66G   53G  9.8G  85% /
/dev/md0               99M   13M   81M  14% /boot
none                  3.9G     0  3.9G   0% /dev/shm
124.39.15.13:/var/atgames/mail
                       71G   37G   31G  55% /var/atgames/mail1
124.39.15.14:/var/atgames/mail
                       71G   35G   33G  52% /var/atgames/mail2
172.16.2.1:/var/atgames/image1
                       62G   45G   14G  78% /var/atgames/webdl1
172.16.2.2:/var/atgames/image1
                       62G   24G   35G  42% /var/atgames/webdl2
172.16.8.5:/var/atgames/gdwebdl
                      388G  304G   64G  83% /var/atgames/gdwebdl
172.16.11.30:/var/atgames/webdl
                      265G  161G  105G  61% /var/atgames/webdl
172.16.11.30:/var/atgames/image2/avatar
                      265G  161G  105G  61% /var/atgames/image2/avatar

mount -a


-----

【新しいアイテムのDB(atgames07)を構築】

cd /usr/local/src

wget http://wwwmaster.postgresql.org/redir/311/h/source/v9.0.2/postgresql-9.0.2.tar.gz
wget http://wwwmaster.postgresql.org/redir/311/h/source/v9.0.2/postgresql-9.0.2.tar.gz.md5

md5sum postgresql-9.0.2.tar.gz
cat postgresql-9.0.2.tar.gz.md5


tar xzf postgresql-9.0.2.tar.gz

cd postgresql-9.0.2

./configure --prefix=/usr/local/postgresql-9.0.2

make

su

make install


/usr/sbin/groupadd -g 5432 postgres
/usr/sbin/useradd -g 5432 -u 5432 -c 'DBAdmin' -d /home/postgres -m -s /bin/bash postgres
chown -R postgres.postgres postgresql-9.0.2

(createdb)

dataの作成

#cp -p /etc/rc.d/init.d/gp_postgres /etc/rc.d/init.d/gp_postgres9

#vi /etc/rc.d/init.d/gp_postgres9



mkdir -p /var/log/pgsql9
chown postgres.postgres /var/log/pgsql9

-----(以下、やらない)-----
su - postgres
/usr/local/postgresql/bin/initdb --pgdata=/usr/local/postgresql/data

cd /usr/local/postgresql/data

cp -p pg_hba.conf     pg_hba.conf.`date +%Y%m%d`.org
cp -p pg_ident.conf   pg_ident.conf.`date +%Y%m%d`.org
cp -p postgresql.conf postgresql.conf.`date +%Y%m%d`.org
-----(以上、やらない)-----

コピーしたものを展開する
su - postgres
cd /usr/local/postgresql

ln -s /mnt/xfs/data data
cd /usr/local/postgresql/data

ln -s /var/log/pgsql9 pg_log

---------
(slave用のconfファイルを設定する)

cp -p PG_VERSION      PG_VERSION.`date +%Y%m%d`
cp -p pg_hba.conf     pg_hba.conf.`date +%Y%m%d`
cp -p pg_ident.conf   pg_ident.conf.`date +%Y%m%d`
cp -p postgresql.conf postgresql.conf.`date +%Y%m%d`
cp -p postmaster.opts postmaster.opts.`date +%Y%m%d`
cp -p recovery.conf   recovery.conf.`date +%Y%m%d`

tar xzf pg9slave_conf.tar.gz

-----

scp -p interdev@172.19.1.41:/etc/rc.d/init.d/gp_postgres /etc/rc.d/init.d/gp_postgres



(アーカイブ用ディレクトリの作成)

mkdir -p /var/atgames/db/pg_standby/archive41 /var/atgames/db/pg_standby/archive42

chown -R interdev.interdev /var/atgames
chown -R postgres.postgres /var/atgames/db/pg_standby


exit

#cp -p /usr/local/postgresql/data/pg_hba.conf /usr/local/postgresql9/data/pg_hba.conf
#su - postgres
#cd /usr/local/postgresql9/data

su - postgres

cd /usr/local/postgresql/data

ln -s /var/log/pgsql9 pg_log
-----

scp -p interdev@172.19.1.33:/etc/rc.d/init.d/gp_postgres /etc/rc.d/init.d/gp_postgres

(各種コンフィグレーションのコピー) db40と35からのコピー
tar czf ../`hostname`_conf.tar.gz pg_hba.conf pg_ident.conf postgresql.conf

tar czf ../`hostname`_conf.tar.gz pg_hba.conf pg_ident.conf postgresql.conf recovery.conf

scp -p interdev@172.19.1.40:/usr/local/postgresql9/gp_db40_conf.tar.gz .

scp -p interdev@172.19.1.35:/usr/local/postgresql9/gp_db35_conf.tar.gz .