August 29,2005
DataBase Administrator
Postgresql 8.0.3 在 RedHat 上的設定

Postgresql安裝
# useradd postgres
# tar zxvf postgresql-xxxx.tar.gz
# chown -R postgres.postgres postgresql-xxxx
# cd postgresql-xxxx
#./configure --prefix=/usr/local/pgsql --enable-multibyte=MULE_INTERNAL
# make
# make install
在/etc/profile內加入
PATH=$PATH:/usr/local/pgsql/bin
MANPATH=$MANPATH:/usr/local/pgsql/man
export PATH MANPATH
LD_LIBRARY_PATH=/usr/local/pgsql/lib
export LD_LIBRARY_PATH
在內加入
在/home/postgres/.bash_profile 加入
PGLIB="/usr/local/pgsql/lib"
PGDATA="/usr/local/pgsql/data"
PGBIN="/usr/local/pgsql/bin"
PGLOG="/usr/local/pgsql/log"
PGCLIENTENCODING='BIG5'
export PGLIB PGDATA PGBIN PGLOG PGCLIENTENCODING
# chown -R postgres.postgres /usr/local/pgsql
# su - postgres
# initdb -E MULE_INTERNAL
# postmaster -i -S
# createuser sa(當pgsql系統問你sa是否可以建立db及user都選yes)
# createdb -E EUC_TW test
# psql test
test=# set client_encoding to 'big5';
test=# alter user sa with password '你想要的密碼';
test=# \q
在Linux OS環境下用 root 來useradd sa
並且passwd sa(密碼我是設定跟在pgsql內的sa的密碼一樣)
# vi /home/sa/.bash_profile
內加入
PGLIB="/usr/local/pgsql/lib"
PGDATA="/usr/local/pgsql/data"
PGBIN="/usr/local/pgsql/bin"
PGLOG="/usr/local/pgsql/log"
PGCLIENTENCODING='BIG5'
export PGLIB PGDATA PGBIN PGLOG PGCLIENTENCODING
然後vi /etc/rc.d/rc.local
內加入
#start pgsql when OS reboot (這行是註解,底下才是內容)
POSTGRESDIR=/usr/local/pgsql
if [ -x $POSTGRESDIR/bin/postmaster -a -d $POSTGRESDIR/data ];then
rm -f /tmp/s.PGSQL.5432
su - postgres -c "postmaster -i -S"
echo -n 'postmaster'
fi
# useradd postgres
# tar zxvf postgresql-xxxx.tar.gz
# chown -R postgres.postgres postgresql-xxxx
# cd postgresql-xxxx
#./configure --prefix=/usr/local/pgsql --enable-multibyte=MULE_INTERNAL
# make
# make install
在/etc/profile內加入
PATH=$PATH:/usr/local/pgsql/bin
MANPATH=$MANPATH:/usr/local/pgsql/man
export PATH MANPATH
LD_LIBRARY_PATH=/usr/local/pgsql/lib
export LD_LIBRARY_PATH
在內加入
在/home/postgres/.bash_profile 加入
PGLIB="/usr/local/pgsql/lib"
PGDATA="/usr/local/pgsql/data"
PGBIN="/usr/local/pgsql/bin"
PGLOG="/usr/local/pgsql/log"
PGCLIENTENCODING='BIG5'
export PGLIB PGDATA PGBIN PGLOG PGCLIENTENCODING
# chown -R postgres.postgres /usr/local/pgsql
# su - postgres
# initdb -E MULE_INTERNAL
# postmaster -i -S
# createuser sa(當pgsql系統問你sa是否可以建立db及user都選yes)
# createdb -E EUC_TW test
# psql test
test=# set client_encoding to 'big5';
test=# alter user sa with password '你想要的密碼';
test=# \q
在Linux OS環境下用 root 來useradd sa
並且passwd sa(密碼我是設定跟在pgsql內的sa的密碼一樣)
# vi /home/sa/.bash_profile
內加入
PGLIB="/usr/local/pgsql/lib"
PGDATA="/usr/local/pgsql/data"
PGBIN="/usr/local/pgsql/bin"
PGLOG="/usr/local/pgsql/log"
PGCLIENTENCODING='BIG5'
export PGLIB PGDATA PGBIN PGLOG PGCLIENTENCODING
然後vi /etc/rc.d/rc.local
內加入
#start pgsql when OS reboot (這行是註解,底下才是內容)
POSTGRESDIR=/usr/local/pgsql
if [ -x $POSTGRESDIR/bin/postmaster -a -d $POSTGRESDIR/data ];then
rm -f /tmp/s.PGSQL.5432
su - postgres -c "postmaster -i -S"
echo -n 'postmaster'
fi
引用URL
http://cgi.blog.roodo.com/trackback/424406
回應文章 
針對 open source 的資料庫做一些比較(Mysql vs Postgresql)
Mysql 在台灣的市場佔有率會比 postgresql 還會有更多choic
其原因如下
1.會去使用mysql這套 open source database 大多數的作業系統多事base on window系統 , 但是在postpgsq之前在7.0** 的版本只提供Unix or other open source platform (redhat , freebsd)上, 所以會對pgsql 比較生疏 , 但是經由postresql 但是在8.0*** 1版本已後也有提供 other version for window
platform , 而在 proformce 也不會比 mysql 還差 , 相對的 mysql 跟postgres 8.0*** 這兩種不同的差別上有很打不同
1.1 postgres can use transation 這個 function ,trigger else....
1.2 postgres can create view
1.3 else.....
1.4more information provide by postgesq website
http://www.postgresql.org/
version
Mysql 在台灣的市場佔有率會比 postgresql 還會有更多choic
其原因如下
1.會去使用mysql這套 open source database 大多數的作業系統多事base on window系統 , 但是在postpgsq之前在7.0** 的版本只提供Unix or other open source platform (redhat , freebsd)上, 所以會對pgsql 比較生疏 , 但是經由postresql 但是在8.0*** 1版本已後也有提供 other version for window
platform , 而在 proformce 也不會比 mysql 還差 , 相對的 mysql 跟postgres 8.0*** 這兩種不同的差別上有很打不同
1.1 postgres can use transation 這個 function ,trigger else....
1.2 postgres can create view
1.3 else.....
1.4more information provide by postgesq website
http://www.postgresql.org/
version
Posted by javanull
at August 31,2005 00:53
在jdbc裡要怎樣知道某一個database 所以table 的資料
用Query比較簡便。
SQL Server:
select * from Sysobjects where TYPE in ('U','V')
U=User's table
V=View
補充一下:
Oracle的作法:
select * from all_tables 查詢所有的資料表
select * from all_views 查詢所有的檢示表
透過 Connection getMetaData() method 可取得 DatabaseMetaData,
DatabaseMetaData 可取得許多與整個 Database 相關的資訊,
1234567
DatabaseMetaData dbMeta = con.getMetaData();
ResultSet rs = dbMeta.getTables(null, null, null, new String[]{"TABLE"});
// 如果你連 view 都要取出來,可用 new String[]{"TABLE", "VIEW"}
while (rs.next()) {
String tableName = rs.getString("TABLE_NAME");
}
用Query比較簡便。
SQL Server:
select * from Sysobjects where TYPE in ('U','V')
U=User's table
V=View
補充一下:
Oracle的作法:
select * from all_tables 查詢所有的資料表
select * from all_views 查詢所有的檢示表
透過 Connection getMetaData() method 可取得 DatabaseMetaData,
DatabaseMetaData 可取得許多與整個 Database 相關的資訊,
1234567
DatabaseMetaData dbMeta = con.getMetaData();
ResultSet rs = dbMeta.getTables(null, null, null, new String[]{"TABLE"});
// 如果你連 view 都要取出來,可用 new String[]{"TABLE", "VIEW"}
while (rs.next()) {
String tableName = rs.getString("TABLE_NAME");
}
Posted by Roger
at September 6,2005 15:01
For mssql only
CREATE TABLE [example] (
[counterID] [int] IDENTITY (1, 1) NOT NULL ,
[alphaID] AS ('A' + convert(varchar,[counterID]))
)
Everytime you enter in a new record, the [alphaID] column will be A##
CREATE TABLE [example] (
[counterID] [int] IDENTITY (1, 1) NOT NULL ,
[alphaID] AS ('A' + convert(varchar,[counterID]))
)
Everytime you enter in a new record, the [alphaID] column will be A##
Posted by roger
at September 29,2005 23:37