<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Latest topics for the forum "Database"]]></title>
		<link>https://forum.andowson.com/forums/show/12.page</link>
		<description><![CDATA[The newest discussed topics in the forum "Database"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>升級PostgreSQL 9.4到PostgreSQL 12</title>
				<description><![CDATA[ [size=18]升級PostgreSQL 9.4到PostgreSQL 12[/size] 
<br>
<br>
0.前言 
<br>
因CentOS 6.10已經EOL，故我已將其透過[url=https://docs.oracle.com/zh-tw/solutions/migrate-centos-ora-linux/index.html]script[/url]轉換成Oracle Linux 6.10 
<br>
<br>
目前[url=https://yum.postgresql.org/rpmchart/]yum.postgresql.org[/url]網站上面對RHEL/CentOS/Oracle Linux 6只有支援到PostgreSQL 12，沒有到PostgreSQL 13，因此以升級到PostgreSQL 12為目標 
<br>
<br>
本文是以Oracle Linux 6.10 x86_64上面原安裝PostgreSQL 9.4作為說明，預設執行身分為root，如需切換帳號為postgres，會以su - postgres開始 
<br>
<br>
警語: 升級資料庫有其風險，本文為作者自行實測心得，照作不保證一定可以成功或沒有其他未知風險，讀者應先於測試環境驗證新版資料庫對應用程式的相容性，並備妥資料庫備份還原步驟，以防萬一失敗時可以回到原先狀態。 
<br>
<br>
1.安裝新版的PostgreSQL 
<br>
1.1 安裝新版的PostgreSQL yum repository 
<br>
先開啟網頁到[url]https://www.postgresql.org/download/linux/redhat/[/url]，在Select platform找到目前使用的作業系統版本，例如Red Hat Enterprise, CentOS, Scientific or Oracle version 6，有個Copy script 
<br>
[code]cd /root/setup/database 
<br>
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-6-x86_64/pgdg-redhat-repo-latest.noarch.rpm[/code] 
<br>
<br>
1.2 安裝PostgreSQL新版的套件 
<br>
安裝新版的套件(必須安裝postgresql12-contrib套件才會有pg_upgrade) 
<br>
[code]sudo yum install -y postgresql12-server postgresql12-contrib[/code] 
<br>
<br>
2.升級前置動作 
<br>
2.1初始化新版PostgreSQL資料庫 
<br>
[code]sudo service postgresql-12 initdb[/code] 
<br>
<br>
2.2檢查是否成功建立資料庫所需目錄 
<br>
[code]ls /var/lib/pgsql/12/ 
<br>
cat /var/lib/pgsql/12/pgstartup.log[/code] 
<br>
<br>
<br>
3.停止網頁服務 
<br>
[code]sudo service tomcat stop[/code] 
<br>
<br>
注意/etc/crontab中有無設定定期檢查Tomcat是否有在跑的tomcat_monitor，有的話先註解掉該排程作業，以免系統又自己將Tomcat服務帶起來 
<br>
<br>
4.開始升級資料庫 
<br>
4.1.備份舊的資料 
<br>
執行pg_dumpall(建議使用新版的PostgreSQL目錄下的pg_dumpall) 
<br>
[code]su - postgres 
<br>
mkdir /tmp/pgsql 
<br>
/usr/pgsql-12/bin/pg_dumpall &gt; /tmp/pgsql/db.out 
<br>
exit[/code] 
<br>
4.2 關閉資料庫 
<br>
[code]sudo service postgresql-9.4 stop[/code] 
<br>
<br>
4.3 備份檔案系統 
<br>
切換身分為postgres(再多備份一次檔案系統) 
<br>
[code]su - postgres 
<br>
cp -pr /var/lib/pgsql/9.4 /tmp/pgsql/[/code] 
<br>
<br>
4.4 執行升版前的檢查pg_upgrade --check 
<br>
執行pg_upgrade(注意要使用新版的PostgreSQL目錄下的pg_upgrade) 
<br>
[code]/usr/pgsql-12/bin/pg_upgrade -b /usr/pgsql-9.4/bin -B /usr/pgsql-12/bin -d /var/lib/pgsql/9.4/data -D /var/lib/pgsql/12/data --check[/code] 
<br>
<br>
4.5 進行真正的升級動作，執行pg_upgrade 
<br>
[code]/usr/pgsql-12/bin/pg_upgrade -v -b /usr/pgsql-9.4/bin/ -B /usr/pgsql-12/bin/ -d /var/lib/pgsql/9.4/data -D /var/lib/pgsql/12/data[/code] 
<br>
<br>
最後看到下面這些畫面就完成了 
<br>
[code]Upgrade Complete 
<br>
---------------- 
<br>
Optimizer statistics are not transferred by pg_upgrade so, 
<br>
once you start the new server, consider running: 
<br>
 ./analyze_new_cluster.sh 
<br>
<br>
Running this script will delete the old cluster's data files: 
<br>
 ./delete_old_cluster.sh 
<br>
-bash-4.1$[/code] 
<br>
<br>
<br>
4.6 調整設定檔: pg_hba.conf, postgresql.conf 
<br>
可能新版會有新增一些參數，我們用diff比較一下差異，再把舊版修改的地方依據需要反映到新的版本去 
<br>
[code]diff /var/lib/pgsql/9.4/data/pg_hba.conf /var/lib/pgsql/12/data/pg_hba.conf 
<br>
vi /var/lib/pgsql/12/data/pg_hba.conf[/code] 
<br>
例如，我把local的peer改成trust，host的ident改成md5，有關replication的部分都先mark掉: 
<br>
[code] 
<br>
# TYPE DATABASE USER ADDRESS METHOD 
<br>
<br>
# "local" is for Unix domain socket connections only 
<br>
local all all trust 
<br>
# IPv4 local connections: 
<br>
host all all 127.0.0.1/32 md5 
<br>
# IPv6 local connections: 
<br>
host all all ::1/128 md5 
<br>
# Allow replication connections from localhost, by a user with the 
<br>
# replication privilege. 
<br>
#local replication all peer 
<br>
#host replication all 127.0.0.1/32 ident 
<br>
#host replication all ::1/128 ident[/code] 
<br>
postgresql.conf可能新版會有新增一些參數，我們用diff比較一下差異，再把舊版修改的地方依據需要反映到新的版本去 
<br>
[code]diff /var/lib/pgsql/9.4/data/postgresql.conf /var/lib/pgsql/12/data/postgresql.conf[/code] 
<br>
<br>
例如，我修改了: 
<br>
effective_cache_size = 256MB 
<br>
<br>
退出postgres 
<br>
[code]exit[/code] 
<br>
<br>
5.啟動新版的PostgreSQL服務 
<br>
[code]sudo chkconfig postgresql-12 on 
<br>
sudo service postgresql-12 start[/code] 
<br>
[code][root@www ~]# sudo service postgresql-12 start 
<br>
正在啟動 postgresql-12 服務： [ 確定 ][/code] 
<br>
<br>
6.升級後的優化作業 
<br>
[code]su - postgres 
<br>
./analyze_new_cluster.sh[/code] 
<br>
<br>
[code][root@www ~]# su - postgres 
<br>
-bash-4.1$ ./analyze_new_cluster.sh 
<br>
This script will generate minimal optimizer statistics rapidly 
<br>
so your system is usable, and then gather statistics twice more 
<br>
with increasing accuracy. When it is done, your system will 
<br>
have the default level of optimizer statistics. 
<br>
<br>
If you have used ALTER TABLE to modify the statistics target for 
<br>
any tables, you might want to remove them and restore them after 
<br>
running this script because they will delay fast statistics generation. 
<br>
<br>
If you would like default statistics as quickly as possible, cancel 
<br>
this script and run: 
<br>
 "/usr/pgsql-12/bin/vacuumdb" --all --analyze-only 
<br>
<br>
.... 
<br>
<br>
Done 
<br>
-bash-4.1$[/code] 
<br>
退出postgres 
<br>
[code]exit[/code] 
<br>
<br>
7.啟動網頁服務 
<br>
[code]sudo service tomcat start[/code] 
<br>
<br>
7.1 測試網頁服務是否正常 
<br>
<br>
8. 升級後的清理作業 
<br>
8.1 刪除舊的資料庫存放區 
<br>
[code]su - postgres 
<br>
./delete_old_cluster.sh[/code] 
<br>
<br>
<br>
8.2 移除舊版的PostgreSQL套件 
<br>
[code]yum remove postgresql94*[/code] 
<br>
<br>
<br>
8.3 刪除/tmp/pgsql目錄下的備份檔 
<br>
[code]rm -rf /tmp/pgsql[/code] 
<br>
<br>
[選擇性作業]8.4 重新啟用排程/etc/crontab中的tomcat_monitor 
<br>
<br>
至此就完成了PostgreSQL 12的升版作業]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/780/1554.page</guid>
				<link>https://forum.andowson.com/posts/preList/780/1554.page</link>
				<pubDate><![CDATA[Tue, 21 Sep 2021 03:48:54]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>升級PostgreSQL 9.3到PostgreSQL 9.4 </title>
				<description><![CDATA[ 本文是以CentOS 6.6 x86_64上面原安裝PostgreSQL 9.3作為說明，預設執行身分為root，如需切換為postgres，會以su - postgres開始 
<br>
<br>
 1.安裝新版的PostgreSQL 
<br>
 1.1 安裝新版的PostgreSQL repository 
<br>
 先開啟網頁到[url]http://yum.postgresql.org/[/url]，在Available PostgreSQL Releases點選我們要升級的版本的連結，這裡應該是9.4，然後找到目前使用的作業系統版本，例如CentOS 6 - x86_64，在這個連結上按滑鼠右鍵複製連結，取得URL，回到PuTTY視窗 
<br>
[code]cd /root/setup/database 
<br>
yum install -y http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-1.noarch.rpm[/code] 
<br>
<br>
 1.2 安裝PostgreSQL新版的套件 
<br>
 先找出之前安裝了那些套件: rpm -qa | grep postgresql93 
<br>
[code][root@www database]# rpm -qa | grep postgresql93 
<br>
postgresql93-9.3.6-1PGDG.rhel6.x86_64 
<br>
postgresql93-libs-9.3.6-1PGDG.rhel6.x86_64 
<br>
postgresql93-server-9.3.6-1PGDG.rhel6.x86_64 
<br>
postgresql93-contrib-9.3.6-1PGDG.rhel6.x86_64[/code] 
<br>
<br>
 安裝新版的套件(必須安裝postgresql94-contrib套件才會有pg_upgrade) 
<br>
[code]yum install postgresql94-server postgresql94-libs postgresql94 postgresql94-contrib[/code] 
<br>
<br>
<br>
 2.升級前置動作 
<br>
 2.1初始化新版PostgreSQL資料庫 
<br>
[code]/etc/init.d/postgresql-9.4 initdb[/code] 
<br>
<br>
<br>
 2.2檢查是否成功建立資料庫所需目錄 
<br>
[code]ls /var/lib/pgsql/9.4/ 
<br>
cat /var/lib/pgsql/9.4/pgstartup.log[/code] 
<br>
<br>
<br>
 3.停止網頁服務 
<br>
[code]service tomcat stop[/code] 
<br>
<br>
 注意/etc/crontab中有無設定定期檢查Tomcat是否有在跑的tomcat_monitor，有的話先註解掉該排程作業，以免系統又自己將Tomcat服務帶起來 
<br>
<br>
 4.開始升級資料庫 
<br>
 4.1.備份舊的資料 
<br>
[code]su - postgres 
<br>
mkdir /tmp/pgsql 
<br>
pg_dumpall &gt; /tmp/pgsql/db.out 
<br>
exit [/code] 
<br>
 4.2 關閉資料庫 
<br>
[code]service postgresql-9.3 stop[/code] 
<br>
<br>
 4.3 備份檔案系統 
<br>
 切換身分為postgres(再多備份一次檔案系統) 
<br>
[code]su - postgres 
<br>
cp -pr /var/lib/pgsql/9.3 /tmp/pgsql/[/code] 
<br>
<br>
 4.4 執行升版前的檢查pg_upgrade --check 
<br>
 執行pg_upgrade(注意要使用新版的PostgreSQL目錄下的pg_upgrade) 
<br>
[code]/usr/pgsql-9.4/bin/pg_upgrade -b /usr/pgsql-9.3/bin -B /usr/pgsql-9.4/bin -d /var/lib/pgsql/9.3/data -D /var/lib/pgsql/9.4/data --check[/code] 
<br>
<br>
 4.5 進行真正的升級動作，執行pg_upgrade 
<br>
[code]/usr/pgsql-9.4/bin/pg_upgrade -v -b /usr/pgsql-9.3/bin/ -B /usr/pgsql-9.4/bin/ -d /var/lib/pgsql/9.3/data -D /var/lib/pgsql/9.4/data[/code] 
<br>
<br>
 最後看到下面這些畫面就完成了 
<br>
[code]reating script to analyze new cluster ok 
<br>
Creating script to delete old cluster ok 
<br>
<br>
Upgrade Complete 
<br>
---------------- 
<br>
Optimizer statistics are not transferred by pg_upgrade so, 
<br>
once you start the new server, consider running: 
<br>
 analyze_new_cluster.sh 
<br>
<br>
Running this script will delete the old cluster's data files: 
<br>
 delete_old_cluster.sh 
<br>
-bash-4.1$ 
<br>
[/code] 
<br>
<br>
 4.6 調整設定檔: pg_hba.conf, postgresql.conf 
<br>
可能新版會有新增一些參數，我們用diff比較一下差異，再把舊版修改的地方依據需要反映到新的版本去 
<br>
[code]diff /var/lib/pgsql/9.3/data/pg_hba.conf /var/lib/pgsql/9.4/data/pg_hba.conf 
<br>
vi /var/lib/pgsql/9.4/data/pg_hba.conf[/code] 
<br>
<br>
 postgresql.conf可能新版會有新增一些參數，我們用diff比較一下差異，再把舊版修改的地方依據需要反映到新的版本去 
<br>
[code]diff /var/lib/pgsql/9.3/data/postgresql.conf /var/lib/pgsql/9.4/data/postgresql.conf[/code] 
<br>
<br>
 例如，我修改了: 
<br>
 [code]effective_cache_size = 256MB [/code] 
<br>
<br>
 退出postgres 
<br>
[code]exit[/code] 
<br>
<br>
 5.啟動新版的PostgreSQL服務 
<br>
[code]service postgresql-9.4 start[/code] 
<br>
[root@www database]# service postgresql-9.4 start 
<br>
正在啟動 postgresql-9.4 服務： [ 確定 ] 
<br>
<br>
 6.升級後的優化作業 
<br>
[code]su - postgres 
<br>
./analyze_new_cluster.sh 
<br>
<br>
[root@www database]# su - postgres 
<br>
-bash-4.1$ ./analyze_new_cluster.sh 
<br>
This script will generate minimal optimizer statistics rapidly 
<br>
so your system is usable, and then gather statistics twice more 
<br>
with increasing accuracy. When it is done, your system will 
<br>
have the default level of optimizer statistics. 
<br>
<br>
If you have used ALTER TABLE to modify the statistics target for 
<br>
any tables, you might want to remove them and restore them after 
<br>
running this script because they will delay fast statistics generation. 
<br>
<br>
If you would like default statistics as quickly as possible, cancel 
<br>
this script and run: 
<br>
 "/usr/pgsql-9.4/bin/vacuumdb" --all --analyze-only 
<br>
<br>
vacuumdb: vacuuming database "jforum" 
<br>
Generating minimal optimizer statistics (1 target) 
<br>
vacuumdb: vacuuming database "postgres" 
<br>
Generating minimal optimizer statistics (1 target) 
<br>
vacuumdb: vacuuming database "template1" 
<br>
Generating minimal optimizer statistics (1 target) 
<br>
vacuumdb: vacuuming database "jforum" 
<br>
Generating medium optimizer statistics (10 targets) 
<br>
vacuumdb: vacuuming database "postgres" 
<br>
Generating medium optimizer statistics (10 targets) 
<br>
vacuumdb: vacuuming database "template1" 
<br>
Generating default (full) optimizer statistics 
<br>
vacuumdb: vacuuming database "jforum" 
<br>
Generating default (full) optimizer statistics 
<br>
vacuumdb: vacuuming database "postgres" 
<br>
Generating default (full) optimizer statistics 
<br>
vacuumdb: vacuuming database "template1" 
<br>
<br>
Done 
<br>
-bash-4.1$ 
<br>
[/code] 
<br>
<br>
 7.啟動網頁服務 
<br>
[code]service tomcat start[/code] 
<br>
<br>
 7.1 測試網頁服務是否正常 
<br>
<br>
 8. 升級後的清理作業 
<br>
 8.1 刪除舊的資料庫存放區 
<br>
[code]su - postgres 
<br>
./delete_old_cluster.sh[/code] 
<br>
<br>
<br>
 8.2 移除舊版的PostgreSQL套件 
<br>
[code]yum remove postgresql93* pgdg-centos93[/code] 
<br>
<br>
<br>
 8.3 刪除/tmp/pgsql目錄下的備份檔 
<br>
[code]rm -rf /tmp/pgsql[/code] 
<br>
<br>
<br>
 [選擇性作業]8.4 重新啟用排程/etc/crontab中的tomcat_monitor 
<br>
<br>
 至此就完成了PostgreSQL 9.4的升版作業]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/636/1329.page</guid>
				<link>https://forum.andowson.com/posts/preList/636/1329.page</link>
				<pubDate><![CDATA[Thu, 16 Jul 2015 00:16:05]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>升級PostgreSQL 9.2 到PostgreSQL 9.3</title>
				<description><![CDATA[ 升級PostgreSQL 9.2 到PostgreSQL 9.3 
<br>
<br>
本文是以CentOS 6.5 x86_64上面原安裝PostgreSQL 9.2作為說明，預設執行身分為root，如需切換為postgres，會以su - postgres開始 
<br>
<br>
1.備份舊的資料 
<br>
[code]su - postgres 
<br>
mkdir /tmp/pgsql 
<br>
pg_dumpall &gt; /tmp/pgsql/db.out 
<br>
cp -pr /var/lib/pgsql/9.2 /tmp/pgsql/ 
<br>
exit 
<br>
[/code] 
<br>
2.安裝新版的PostgreSQL 
<br>
2.1 安裝新版的PostgreSQL repository 
<br>
到[url]http://yum.postgresql.org/[/url] 先點要升級的版本，如9.3，然後找到目前使用的作業系統版本，例如CentOS 6 - x86_64 
<br>
[code]cd /root/setup/database 
<br>
wget http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-1.noarch.rpm 
<br>
rpm -ivh ./pgdg-centos93-9.3-1.noarch.rpm 
<br>
[/code] 
<br>
2.2 安裝PostgreSQL新版的套件 
<br>
可以先找出之前安裝了那些套件: rpm -qa | grep postgresql92 
<br>
[code] 
<br>
[root@www database]# rpm -qa | grep postgresql92 
<br>
postgresql92-libs-9.2.9-1PGDG.rhel6.x86_64 
<br>
postgresql92-9.2.9-1PGDG.rhel6.x86_64 
<br>
postgresql92-server-9.2.9-1PGDG.rhel6.x86_64 
<br>
[/code] 
<br>
安裝新版的套件(必須安裝postgresql93-contrib套件才會有pg_upgrade) 
<br>
[code] 
<br>
yum install postgresql93-server postgresql93-libs postgresql93 postgresql93-contrib 
<br>
[/code] 
<br>
3.升級前置動作 
<br>
3.1修改新版PostgreSQL啟動檔的Port 
<br>
因為舊版的還在run，新版PostgreSQL預設的啟動port先改為5433 
<br>
編輯/etc/init.d/postgresql-9.3檔案，將 
<br>
[code]PGPORT=5432[/code] 
<br>
改為 
<br>
[code]PGPORT=5433[/code] 
<br>
<br>
3.2初始化新版PostgreSQL資料庫 
<br>
[code]/etc/init.d/postgresql-9.3 initdb[/code] 
<br>
<br>
3.3檢查是否成功建立資料庫所需目錄 
<br>
[code]ls /var/lib/pgsql/9.3/ 
<br>
cat /var/lib/pgsql/9.3/pgstartup.log[/code] 
<br>
<br>
3.4停止網頁服務 
<br>
[code]service tomcat stop[/code] 
<br>
注意/etc/crontab中有無設定定期檢查Tomcat是否有在跑的tomcat_monitor，有的話先註解掉該排程作業，以免系統又自己將Tomcat服務帶起來 
<br>
<br>
4.開始升級資料庫 
<br>
4.1 關閉資料庫 
<br>
[code]service postgresql-9.2 stop[/code] 
<br>
<br>
4.2 執行pg_upgrade 
<br>
切換身分為postgres(再多備份一次檔案系統) 
<br>
[code]su - postgres 
<br>
cp -pr /var/lib/pgsql/9.2 /tmp/pgsql/[/code] 
<br>
<br>
執行pg_upgrade(注意要使用新版的PostgreSQL目錄下的pg_upgrade) 
<br>
[code]/usr/pgsql-9.3/bin/pg_upgrade -v -b /usr/pgsql-9.2/bin/ -B /usr/pgsql-9.3/bin/ -d /var/lib/pgsql/9.2/data/ -D /var/lib/pgsql/9.3/data/[/code] 
<br>
最後看到下面這些畫面就完成了 
<br>
[code] 
<br>
Creating script to analyze new cluster ok 
<br>
Creating script to delete old cluster ok 
<br>
<br>
Upgrade Complete 
<br>
---------------- 
<br>
Optimizer statistics are not transferred by pg_upgrade so, 
<br>
once you start the new server, consider running: 
<br>
 analyze_new_cluster.sh 
<br>
<br>
Running this script will delete the old cluster's data files: 
<br>
 delete_old_cluster.sh 
<br>
-bash-4.1$ 
<br>
[/code] 
<br>
4.3 調整設定檔: pg_hba.conf, postgresql.conf 
<br>
pg_hba.conf通常可以直接複製過去就好: 
<br>
[code] 
<br>
diff /var/lib/pgsql/9.2/data/pg_hba.conf /var/lib/pgsql/9.3/data/pg_hba.conf 
<br>
cp -p /var/lib/pgsql/9.2/data/pg_hba.conf /var/lib/pgsql/9.3/data/pg_hba.conf 
<br>
[/code] 
<br>
postgresql.conf可能新版會有新增一些參數，我們用diff比較一下差異，再把舊版修改的地方依據需要反映到新的版本去 
<br>
[code] 
<br>
diff /var/lib/pgsql/9.2/data/postgresql.conf /var/lib/pgsql/9.3/data/postgresql.conf[/code] 
<br>
例如，我修改了: 
<br>
effective_cache_size = 256MB 
<br>
<br>
4.4 修改/etc/init.d/postgresql-9.3 
<br>
退出postgres 
<br>
[code]exit[/code] 
<br>
將 
<br>
[code]PGPORT=5433[/code] 
<br>
改回 
<br>
[code]PGPORT=5432[/code] 
<br>
<br>
5.啟動新版的PostgreSQL服務 
<br>
[code]service postgresql-9.3 start[/code] 
<br>
<br>
6.升級後的優化作業 
<br>
[code]su - postgres 
<br>
./analyze_new_cluster.sh[/code] 
<br>
[code] 
<br>
-bash-4.1$ ./analyze_new_cluster.sh 
<br>
This script will generate minimal optimizer statistics rapidly 
<br>
so your system is usable, and then gather statistics twice more 
<br>
with increasing accuracy. When it is done, your system will 
<br>
have the default level of optimizer statistics. 
<br>
<br>
If you have used ALTER TABLE to modify the statistics target for 
<br>
any tables, you might want to remove them and restore them after 
<br>
running this script because they will delay fast statistics generation. 
<br>
<br>
If you would like default statistics as quickly as possible, cancel 
<br>
this script and run: 
<br>
 "/usr/pgsql-9.3/bin/vacuumdb" --all --analyze-only 
<br>
<br>
Generating minimal optimizer statistics (1 target) 
<br>
-------------------------------------------------- 
<br>
vacuumdb: vacuuming database "jforum" 
<br>
vacuumdb: vacuuming database "postgres" 
<br>
vacuumdb: vacuuming database "template1" 
<br>
<br>
The server is now available with minimal optimizer statistics. 
<br>
Query performance will be optimal once this script completes. 
<br>
<br>
Generating medium optimizer statistics (3 targets) 
<br>
--------------------------------------------------- 
<br>
vacuumdb: vacuuming database "jforum" 
<br>
vacuumdb: vacuuming database "postgres" 
<br>
vacuumdb: vacuuming database "template1" 
<br>
<br>
<br>
Generating default (full) optimizer statistics (100 targets?) 
<br>
------------------------------------------------------------- 
<br>
vacuumdb: vacuuming database "jforum" 
<br>
vacuumdb: vacuuming database "postgres" 
<br>
vacuumdb: vacuuming database "template1" 
<br>
<br>
<br>
Done 
<br>
-bash-4.1$ 
<br>
[/code] 
<br>
7.啟動網頁服務 
<br>
[code]service tomcat start[/code] 
<br>
7.1 測試網頁服務是否正常 
<br>
<br>
8. 升級後的清理作業 
<br>
8.1 刪除舊的資料庫存放區 
<br>
[code]su - postgres 
<br>
./delete_old_cluster.sh 
<br>
[/code] 
<br>
8.2 移除舊版的PostgreSQL套件 
<br>
[code]yum remove postgresql92-server postgresql92-libs postgresql92 pgdg-centos92[/code] 
<br>
<br>
8.3 刪除/tmp/pgsql目錄下的備份檔 
<br>
[code]rm -rf /tmp/pgsql[/code] 
<br>
<br>
[選擇性作業]8.4 重新啟用排程/etc/crontab中的tomcat_monitor 
<br>
<br>
至此就完成了PostgreSQL 9.3的升版作業。 
<br>
<br>
參考資料: 
<br>
[url]http://www.uptimemadeeasy.com/databases/upgrade-postgresql/[/url] 
<br>]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/628/1317.page</guid>
				<link>https://forum.andowson.com/posts/preList/628/1317.page</link>
				<pubDate><![CDATA[Sat, 23 Aug 2014 16:51:15]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>PostgreSQL如何查詢某個table的結構</title>
				<description><![CDATA[ 在Oracle中有個desc tablename的指令，可以在SQL命令模式顯示出表格的結構，而在PostgreSQL中也有對應的功能，就是\d tablename，或是用\d+ tablename來獲得更多資訊。 
<br>
<br>
<br>
參考資料: 
<br>
[url]http://stackoverflow.com/questions/109325/postgresql-describe-table[/url] 
<br>
[url]http://www.faqs.org/docs/ppbook/c4890.htm[/url]]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/558/1153.page</guid>
				<link>https://forum.andowson.com/posts/preList/558/1153.page</link>
				<pubDate><![CDATA[Wed, 5 Oct 2011 08:00:31]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>Upgrade PostgreSQL 8.1 to PostgreSQL 8.4 on CentOS 5.5</title>
				<description><![CDATA[ CentOS 5.5支援到PostgreSQL 8.4資料庫，先前的資料庫版本是8.1，由於只能有一版存在，必須移除舊版才行，整個升級過程大致如下： 
<br>
<br>
1.建立備份用的目錄 
<br>
[code]# mkdir /pgbak 
<br>
# chown postgres:postgres /pgbak/[/code] 
<br>
2.備份舊的資料 
<br>
[code]# su - postgres 
<br>
$ pg_dumpall --globals-only &gt; /pgbak/globals.sql 
<br>
$ psql -l 
<br>
$ pg_dump --create --oids --format=c --verbose --file=/pgbak/dbX dbX 
<br>
$ exit[/code] 
<br>
dbX就是您資料庫的名稱(用psql -l指令可以找出有哪些資料庫) 
<br>
<br>
3.停止PostgreSQL資料庫服務 
<br>
[code]# /etc/init.d/postgresql stop[/code] 
<br>
4.將舊的目錄備份起來 
<br>
[code]# mv /var/lib/pgsql/data /pgbak[/code] 
<br>
5.移除舊的postgresql 8.1套件 
<br>
[code]# yum remove postgresql*[/code] 
<br>
( :!: 注意相關性會移除httpd, mod_ssl等) 
<br>
6.安裝新的postgresql84套件 
<br>
[code]# yum install postgresql84-server[/code] 
<br>
7.初始資料庫 
<br>
[code]service postgresql initdb[/code] 
<br>
8.啟動資料庫 
<br>
[code]# chkconfig postgresql on 
<br>
# service postgresql start[/code] 
<br>
9.復原資料 
<br>
[code]# su - postgres 
<br>
$ psql -f /pgbak/globals.sql 
<br>
$ pg_restore --create -d postgres /pgbak/dbX 
<br>
$ exit[/code] 
<br>
10.參考/pgbak/data目錄下的檔案，修改/var/lib/pgsql/data/postgresql.conf和pg_hba.conf等設定檔 
<br>
再重新啟動一次postgresql 
<br>
[code]#service postgresql restart[/code] 
<br>
<br>
11.安裝回被移除的套件 
<br>
[code]# yum install httpd mod_ssl[/code] 
<br>
12.使用備份的設定檔 
<br>
[code]# mv /etc/httpd/conf/httpd.conf /tmp/. 
<br>
# mv /etc/httpd/conf/httpd.conf.rpmsave /etc/httpd/conf/httpd.conf 
<br>
# mv /etc/httpd/conf.d/proxy_ajp.conf /tmp/. 
<br>
# mv /etc/httpd/conf.d/proxy_ajp.conf.rpmsave /etc/httpd/conf.d/proxy_ajp.conf 
<br>
# mv /etc/httpd/conf.d/ssl.conf /tmp/. 
<br>
# mv /etc/httpd/conf.d/ssl.conf.rpmsave /etc/httpd/conf.d/ssl.conf[/code] 
<br>
<br>
參考資料： 
<br>
http://blog.lystor.org.ua/2010/05/upgrading-postgresql-81-to-84-centos-55.html 
<br>
<br>
http://www.postgresonline.com/journal/archives/144-An-almost-idiots-guide-to-Install-and-Upgrade-to-PostgreSQL-8.4-with-Yum.html]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/476/986.page</guid>
				<link>https://forum.andowson.com/posts/preList/476/986.page</link>
				<pubDate><![CDATA[Sat, 2 Apr 2011 21:50:02]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>回覆:在ACCESS 2007裡面的VBA一個問題？</title>
				<description><![CDATA[ 假設您已經把所有的資料由一個csv檔案匯入到Access 2007中的一個table (table name是test)，然後依據欄位ID的值之不同，將所有ID相同之紀錄分別插入(Insert)到相同的資料表，不同的ID則放到不同的資料表中(table name為三位數字，由001開始，依序遞增）。由於不知道資料表可能有多少個，所以採用由程式動態建立。參考範例程式如下： 
<br>
<br>
[code] 
<br>
import java.sql.Connection; 
<br>
import java.sql.DriverManager; 
<br>
import java.sql.PreparedStatement; 
<br>
import java.sql.ResultSet; 
<br>
import java.sql.ResultSetMetaData; 
<br>
import java.sql.SQLException; 
<br>
import java.sql.Statement; 
<br>
import java.sql.Timestamp; 
<br>
<br>
public class DBAccess { 
<br>
<br>
 /** 
<br>
 * @param args 
<br>
 */ 
<br>
 public static void main(String[] args) { 
<br>
 try { 
<br>
 // Connect to database 
<br>
 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
<br>
 String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:/test/Database1.accdb"; 
<br>
 Connection conn = DriverManager.getConnection(url, "", ""); 
<br>
 // Fetch data from table 
<br>
 PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM test"); 
<br>
 ResultSet rs = pstmt.executeQuery(); 
<br>
 ResultSetMetaData rsmd = rs.getMetaData(); 
<br>
 int i = 0; 
<br>
 String oldID = ""; 
<br>
 String tableName = ""; 
<br>
 while (rs.next()) { 
<br>
 // Fetch a record 
<br>
 String ID = rs.getString("ID"); 
<br>
 Timestamp diagnoseDate = rs.getTimestamp("看診日期"); 
<br>
 String pulseCondition = rs.getString("脈象"); 
<br>
 int segment = rs.getInt("段"); 
<br>
 String chiefComplaint = rs.getString("主訴"); 
<br>
 String disease = rs.getString("病名"); 
<br>
 String prescription = rs.getString("配方"); 
<br>
 // Change tableName if ID change 
<br>
 if (!oldID.equals(ID)) { 
<br>
 i++; 
<br>
 oldID = ID; 
<br>
 tableName = String.format("%03d", i); 
<br>
 System.out.println(tableName); 
<br>
 Statement stmt = conn.createStatement(); 
<br>
 try { 
<br>
 // We may need to run this program several times 
<br>
 stmt.execute("DROP TABLE " + tableName); 
<br>
 } catch (SQLException se) { 
<br>
 // Just ignore the table does not exist exception 
<br>
 } 
<br>
 stmt.execute("CREATE TABLE " + tableName + " ([ID] CHAR(10), [看診日期] DATETIME, [脈象] TEXT, [段] INTEGER, [主訴] TEXT, [病名] TEXT, [配方] TEXT)"); 
<br>
 for (int j = 1; j &lt; rsmd.getColumnCount(); j++) { 
<br>
 System.out.print(rsmd.getColumnName(j) + "_"); 
<br>
 } 
<br>
 System.out.println(rsmd.getColumnName(rsmd.getColumnCount())); 
<br>
 } 
<br>
 // Store each record into new table 
<br>
 String sql = "INSERT INTO " + tableName + " ([ID], [看診日期], [脈象], [段], [主訴], [病名], [配方]) VALUES(?, ?, ?, ?, ?, ?, ?)"; 
<br>
 PreparedStatement pstmt2 = conn.prepareStatement(sql); 
<br>
 pstmt2.setString(1, ID); 
<br>
 pstmt2.setTimestamp(2, diagnoseDate); 
<br>
 pstmt2.setString(3, pulseCondition); 
<br>
 pstmt2.setInt(4, segment); 
<br>
 pstmt2.setString(5, chiefComplaint); 
<br>
 pstmt2.setString(6, disease); 
<br>
 pstmt2.setString(7, prescription); 
<br>
 pstmt2.executeUpdate(); 
<br>
 } 
<br>
 rs.close(); 
<br>
 pstmt.close(); 
<br>
 conn.close(); 
<br>
 } catch (Exception e) { 
<br>
 System.err.println("Got an exception!"); 
<br>
 System.err.println(e.getMessage()); 
<br>
 } 
<br>
 } 
<br>
<br>
} 
<br>
[/code] 
<br>
<br>
參考資料： 
<br>
http://msdn.microsoft.com/en-us/library/bb208866%28v=office.12%29.aspx]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/468/969.page</guid>
				<link>https://forum.andowson.com/posts/preList/468/969.page</link>
				<pubDate><![CDATA[Fri, 21 Jan 2011 12:17:58]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>[參考]15個實用的PostgreSQL指令(15 Practical PostgreSQL Database Administration Commands)</title>
				<description><![CDATA[ [url=http://www.thegeekstuff.com/2009/04/15-practical-postgresql-database-adminstration-commands/#more-446]15 Practical PostgreSQL Database Administration Commands[/url]]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/441/906.page</guid>
				<link>https://forum.andowson.com/posts/preList/441/906.page</link>
				<pubDate><![CDATA[Sun, 10 Oct 2010 11:01:41]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>Deploy PostgreSQL HA with NAS + Heartbeat</title>
				<description><![CDATA[ 這是一個比較單純的作法，用兩部機器當作DB Server，後面去掛載一個NAS的分享目錄，然後把資料庫的檔案放到NAS去。由Heartbeat來自動切換Active和Standby角色。 
<br>
<br>
參考資料 
<br>
http://momjian.us/main/writings/pgsql/replication.pdf]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/428/868.page</guid>
				<link>https://forum.andowson.com/posts/preList/428/868.page</link>
				<pubDate><![CDATA[Thu, 1 Jul 2010 13:26:08]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>備份及移植含有BLOB欄位之Oracle資料庫的好工具PL/SQL Developer</title>
				<description><![CDATA[ 最近一個JForum討論區的案子要結案，需要將資料庫整個備份出來交給業主。因為資料庫是使用Oracle，而JForum在三個table上包含了BLOB這種資料型態，所以之前試了很久，都沒辦法很輕易的將資料庫備份出來，並還原回去。後來問了一下同事，他之前也處理過這樣的問題，所以他就提供了一個工具給我，[url=http://www.allroundautomations.com/plsqldev.html]PL/SQL Developer[/url]，然後利用它的Export tables及Import tables功能，很輕鬆而且快速地就將資料庫備份又還原到另一個資料庫去了，只差sequence還沒過去而已，而sequence這個問題也很容易解決，只需要把目前的資料庫的sequence之DDL轉出來，然後修改一下，再放到新的資料庫上執行一下重新建立就可以了。 
<br>
<br>
軟體可由下面網址下載（30天完整功能免費試用版） 
<br>
http://allroundautomations.swmirror.com/plsqldev802.exe]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/410/797.page</guid>
				<link>https://forum.andowson.com/posts/preList/410/797.page</link>
				<pubDate><![CDATA[Mon, 29 Mar 2010 19:13:42]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>PostgreSQL Shared Database Hosting參考文件</title>
				<description><![CDATA[ [url]http://wiki.postgresql.org/wiki/Shared_Database_Hosting[/url]]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/311/583.page</guid>
				<link>https://forum.andowson.com/posts/preList/311/583.page</link>
				<pubDate><![CDATA[Sun, 5 Apr 2009 15:30:09]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>日期之年月日拆解及補0</title>
				<description><![CDATA[ [code]cast(datepart(yyyy, birthday) as varchar)+'年'+right('00'+cast(datepart(mm, birthday) as varchar), 2)+'月'+right('00'+cast(datepart(dd, birthday) as varchar), 2)+'日' as birthday_string[/code] 
<br>
<br>
[code]datepart(yyyy, birthday) AS birth_year, right('00'+cast(datepart(mm, birthday) as varchar), 2) AS birth_month, 
<br>
right('00'+cast(datepart(dd, birthday) as varchar), 2) AS birth_day[/code]]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/310/580.page</guid>
				<link>https://forum.andowson.com/posts/preList/310/580.page</link>
				<pubDate><![CDATA[Thu, 2 Apr 2009 22:16:47]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>PostgreSQL Performance &amp; Configuration參考文件</title>
				<description><![CDATA[ Tuning Your PostgreSQL Server 
<br>
[url]http://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server[/url] 
<br>
<br>
Performance Tuning PostgreSQL 
<br>
[url]http://www.revsys.com/writings/postgresql-performance.html[/url] 
<br>]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/300/558.page</guid>
				<link>https://forum.andowson.com/posts/preList/300/558.page</link>
				<pubDate><![CDATA[Tue, 20 Jan 2009 22:57:44]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>如何查詢PostgreSQL資料庫的大小</title>
				<description><![CDATA[ 使用PostgreSQL資料庫一段時間後，想瞭解一下資料庫目前的大小，可以透過以下的指令來查詢： 
<br>
 :arrow: PostgreSQL 8.1以後的版本： 
<br>
[code=sql]psql db_name -- db_name can be any database 
<br>
<br>
SELECT pg_database.datname, 
<br>
pg_size_pretty(pg_database_size(pg_database.datname)) AS size 
<br>
FROM pg_database; 
<br>
[/code] 
<br>
顯示的結果類似如下： 
<br>
datname | size 
<br>
-----------+--------- 
<br>
 postgres | 3537 kB 
<br>
 support | 99 MB 
<br>
 jtrac | 8497 kB 
<br>
 template1 | 3480 kB 
<br>
 template0 | 3480 kB 
<br>
<br>
注意事項：pg_database_size()需PostgreSQL 8.1以上才有支援 
<br>
<br>
 :arrow: PostgreSQL7.4以前的版本 
<br>
因每個資料庫都有一個oid，而每個oid都有一個對應的目錄名稱，先用下面的指令找出資料庫的oid 
<br>
[code]psql db_name -- db_name can be any database 
<br>
<br>
select oid,datname from pg_database;[/code] 
<br>
 oid | datname 
<br>
--------+---------------- 
<br>
 1 | template1 
<br>
 17141 | template0 
<br>
 20744 | forum 
<br>
 474667 | jtrac 
<br>
 498681 | trac_onlinemsg 
<br>
 499009 | trac_webmail 
<br>
 509099 | olat 
<br>
 511373 | testdb 
<br>
 514460 | roller 
<br>
<br>
然後切換目錄到/var/lib/pgsql/data/base下 
<br>
cd /var/lib/pgsql/data/base 
<br>
使用du --si來取得使用硬碟空間的大小 
<br>
-bash-3.00$ du --si 
<br>
4.7M ./511373==&gt;testdb 
<br>
5.3M ./474667==&gt;trac 
<br>
4.7M ./1==&gt;template1 
<br>
5.8M ./498681==&gt;trac_onlinemsg 
<br>
31M ./514460==&gt;roller 
<br>
7.2M ./509099==&gt;olat 
<br>
5.9M ./499009==&gt;trac_webmail 
<br>
4.1k ./20744/pgsql_tmp 
<br>
131M ./20744==&gt;forum 
<br>
4.6M ./17141==&gt;template0 
<br>
<br>
參考資料： 
<br>
http://mi.nws.noaa.gov/oh/hrl/hseb/postgreSQL/Creating_Database.doc]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/293/540.page</guid>
				<link>https://forum.andowson.com/posts/preList/293/540.page</link>
				<pubDate><![CDATA[Sat, 20 Dec 2008 14:04:51]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>如何最佳化PostgreSQL資料庫大小</title>
				<description><![CDATA[ 這篇文章寫得不錯，[url=http://www.linuxinsight.com/optimize_postgresql_database_size.html]How to optimize PostgreSQL database size[/url] 
<br>
作者比較了三種縮小資料庫佔用硬碟空間的方法（衡量指標是耗用時間跟佔用硬碟空間大小） 
<br>
vacuumdb/reindexdb: 190min - 1990MB 
<br>
reindexdb/vacuumdb/reindexdb: 105min - 1990MB 
<br>
dump/dropdb/createdb/restore: 20min - 1685MB 
<br>
最後看起來應該是採用第三種方法比較快速有效，不過這三種方法都需要先將資料庫先離線才行。 
<br>]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/292/539.page</guid>
				<link>https://forum.andowson.com/posts/preList/292/539.page</link>
				<pubDate><![CDATA[Sat, 20 Dec 2008 13:19:42]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>解決SQL Server 2005 Express本機無法連線1433 port</title>
				<description><![CDATA[ 為了測試方便，我將Tomcat 6.0.18和SQL Server 2005 Express安裝在同一部主機，按照習慣下載了[url=http://www.microsoft.com/downloads/details.aspx?displaylang=zh-tw&amp;FamilyID=c47053eb-3b64-4794-950d-81e1ec91c1ba]Microsoft SQL Server 2005 JDBC Driver 1.2[/url]，解壓縮後將jar檔放在Tomcat 6的lib目錄下，設定相關的JDBC設定後，卻出現TCP/IP 連線被拒的錯誤訊息: 
<br>
[quote]com.microsoft.sqlserver.jdbc.SQLServerException: 連接到主機 的 TCP/IP 連接已經失敗。 java.net.ConnectException: Connection[/quote] 
<br>
<br>
經由同事分享經驗告知解法如下： 
<br>
將SQLEXPRESS的通訊協定之TCP/IP設定調整一下，應該要啟用，如果有顯示啟用，再點右鍵進入內容 
<br>
[img]http://sites.google.com/site/andowson/_/rsrc/1222268706397/Home/sql2005_protocol.jpg[/img] 
<br>
在最底下的IPALL的TCP通訊埠輸入port值為1433 
<br>
[img]http://sites.google.com/site/andowson/_/rsrc/1222268747047/Home/sql2005_tcp_port.jpg[/img] 
<br>
重新啟動SQL Server Express即可 
<br>
[img]http://sites.google.com/site/andowson/_/rsrc/1222268732738/Home/sql2005_restart.jpg[/img] 
<br>
<br>]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/275/485.page</guid>
				<link>https://forum.andowson.com/posts/preList/275/485.page</link>
				<pubDate><![CDATA[Wed, 24 Sep 2008 23:25:51]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
	</channel>
</rss>