本文是筆者用來記錄 FreeBSD 安裝 PostgreSQL 的筆記,文中有提到為了增加 PostgreSQL 的 max_connections 數目,而調整了 FreeBSD 系統的 /etc/sysctl.conf & /boot/loader.conf 兩個檔案。如果你只是想安裝 PostgreSQL 玩玩,而不需要調整 max_connections 數目,你可以忽略修改上述兩個檔案的內容。 1.修改 FreeBSD 系統參數 修改 /etc/sysctl.conf 增加以下指令 修改 /boot/loader.conf 增加以下指令 2.安裝 PostgreSQL 安裝 libxml2 模組 安裝 libxslt 模組 安裝 XML for PostgreSQL 安裝 adminpack 3.修改 /etc/rc.conf 增加以下指令,以便開機自動執行 PostgreSQL postgresql_enable=”YES” 4.初始 PostgreSQL 資料庫 mkdir /pgdb chown pgsql:pgsql /pgdb su -l pgsql -c “initdb -D /pgdb -E utf8″ 5.修改 /pgdb/postgresql.conf 以便符合實際系統運作需求,這邊大家可以斟酌調整 6.修改 /pgdb/pg_hba.conf 以便可以透過網路連接該 PostgreSQL 伺服器。 7.啟動 PostgreSQL 8.建立預設使用者 帳號名稱:postgres 9.啟用其他相關外掛套件 啟用 adminpack 啟用 XML 支援 for PostgreSQL 完成以上步驟,基本上你的 PostgreSQL 應該就可以正常運作了。
kern.ipc.shmmax=134217728
kern.ipc.shmall=32768
kern.ipc.semmap=256
kern.ipc.semmni=256
kern.ipc.semmns=512
kern.ipc.semmnu=256
cd /usr/ports/databases/postgresql82-server
make install
cd /usr/ports/textproc/libxml2
make install
cd /usr/ports/textproc/libxslt
make install
cd /usr/ports/databases/postgresql82-server/work/postgresql-8.2.5/contrib/xml2
gmake install
cd /usr/ports/databases/postgresql82-server/work/postgresql-8.2.5/contrib/adminpack
gmake install
# optional
postgresql_data=”/pgdb”
postgresql_flags=”-w -s -m fast”
postgresql_initdb_flags=”–encoding=utf-8 –lc-collate=C”
postgresql_class=”default”
建立放置 PostgreSQL 資料庫檔案的目錄,同時修改該資料匣權限,改完權限後便初始化 PostgreSQL 資料庫
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
# “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
/usr/local/etc/rc.d/postgresql start
su -l pgsql -c “createuser -P”
su -l pgsql -c “psql -U postgres postgres < /usr/local/share/postgresql/contrib/adminpack.sql”
su -l pgsql -c “psql -U postgres postgres < /usr/local/share/postgresql/contrib/pgxml.sql”