集思博客

集思博客,(www.gisblogs.net)用心记录我的成长历程,留下技术的沉淀……

« JDK环境变量设置Ubuntu配置JAVA环境 »

FreeBSD 安裝 PostgreSQL 的筆記

本文是筆者用來記錄 FreeBSD 安裝 PostgreSQL 的筆記,文中有提到為了增加 PostgreSQL 的 max_connections 數目,而調整了 FreeBSD 系統的 /etc/sysctl.conf & /boot/loader.conf 兩個檔案。如果你只是想安裝 PostgreSQL 玩玩,而不需要調整 max_connections 數目,你可以忽略修改上述兩個檔案的內容。

1.修改 FreeBSD 系統參數

修改 /etc/sysctl.conf 增加以下指令
kern.ipc.shmmax=134217728
kern.ipc.shmall=32768
kern.ipc.semmap=256

修改 /boot/loader.conf 增加以下指令
kern.ipc.semmni=256
kern.ipc.semmns=512
kern.ipc.semmnu=256

2.安裝 PostgreSQL
cd /usr/ports/databases/postgresql82-server
make install

安裝 libxml2 模組
cd /usr/ports/textproc/libxml2
make install

安裝 libxslt 模組
cd /usr/ports/textproc/libxslt
make install

安裝 XML for PostgreSQL
cd /usr/ports/databases/postgresql82-server/work/postgresql-8.2.5/contrib/xml2
gmake install

安裝 adminpack
cd /usr/ports/databases/postgresql82-server/work/postgresql-8.2.5/contrib/adminpack
gmake install

3.修改 /etc/rc.conf 增加以下指令,以便開機自動執行 PostgreSQL

postgresql_enable=”YES”
# optional
postgresql_data=”/pgdb”
postgresql_flags=”-w -s -m fast”
postgresql_initdb_flags=”–encoding=utf-8 –lc-collate=C”
postgresql_class=”default”

4.初始 PostgreSQL 資料庫
建立放置 PostgreSQL 資料庫檔案的目錄,同時修改該資料匣權限,改完權限後便初始化 PostgreSQL 資料庫

mkdir /pgdb

chown pgsql:pgsql /pgdb

su -l pgsql -c “initdb -D /pgdb -E utf8″

5.修改 /pgdb/postgresql.conf 以便符合實際系統運作需求,這邊大家可以斟酌調整
listen_addresses = ‘*’ //聆聽其他主機連線訊號
max_connections = 200 //增加同時連線數量
#log_destination = ’syslog’ // 註解
log_destination = ’stderr’ // 標準輸出 log
log_directory = ‘pg_log’
log_filename = ‘postgresql-%Y-%m-%d_%H%M%S.log’
log_rotation_age = 1d
log_rotation_size = 10MB
client_min_messages = notice
log_min_messages = notice
log_error_verbosity = default
log_min_error_statement = error
log_duration = on
log_line_prefix = ‘%u %d %h %i’
log_statement = ‘mod’
stats_start_collector = on
stats_row_level = on

6.修改 /pgdb/pg_hba.conf 以便可以透過網路連接該 PostgreSQL 伺服器。
# “local” is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 10.3.1.21/32 trust
host all all 10.3.1.22/32 trust
host all all 10.3.1.23/32 trust
host all all 10.1.1.0/32 trust
host all all 10.2.1.0/24 md5
# IPv6 local connections:
host all all ::1/128 md5
host all smart_teacher 10.3.1.0/24 md5
host all postgres 10.3.1.0/24 md5
host all ischool 10.3.1.0/24 md5

7.啟動 PostgreSQL
/usr/local/etc/rc.d/postgresql start

8.建立預設使用者
su -l pgsql -c “createuser -P”

帳號名稱:postgres

9.啟用其他相關外掛套件

啟用 adminpack
su -l pgsql -c “psql -U postgres postgres < /usr/local/share/postgresql/contrib/adminpack.sql”

啟用 XML 支援 for PostgreSQL
su -l pgsql -c “psql -U postgres postgres < /usr/local/share/postgresql/contrib/pgxml.sql”

完成以上步驟,基本上你的 PostgreSQL 應該就可以正常運作了。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表

Powered By Z-Blog 1.8 Spirit Build 80605 Code detection by Codefense  theme by BokeZhuti

Copyright 2007-2008 集思博客 www.gisblogs.net 备案号:粤ICP备07051728号 联系QQ:6390514