星期二, 十月 07, 2008

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=134217728kern.ipc.shmall=32768kern.ipc.semmap=256
修改 /boot/loader.conf 增加以下指令kern.ipc.semmni=256kern.ipc.semmns=512kern.ipc.semmnu=256
2.安装 PostgreSQLcd /usr/ports/databases/postgresql83-servermake install
安装 libxml2 模块cd /usr/ports/textproc/libxml2make install
安装 libxslt 模块cd /usr/ports/textproc/libxsltmake install
安装 XML for PostgreSQLcd /usr/ports/databases/postgresql83-server/work/postgresql-8.3.3/contrib/xml2gmake install
安装 adminpackcd /usr/ports/databases/postgresql83-server/work/postgresql-8.3.3/contrib/adminpackgmake install
3.修改 /etc/rc.conf 增加以下指令,以便开机自动执行 PostgreSQL
postgresql_enable=”YES”# optionalpostgresql_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’ // 标准输出 loglog_directory = ‘pg_log’log_filename = ‘postgresql-%Y-%m-%d_%H%M%S.log’log_rotation_age = 1dlog_rotation_size = 10MBclient_min_messages = noticelog_min_messages = noticelog_error_verbosity = defaultlog_min_error_statement = errorlog_duration = onlog_line_prefix = ‘%u %d %h %i’log_statement = ‘mod’stats_start_collector = onstats_row_level = on
6.修改 /pgdb/pg_hba.conf 以便可以透过网络连接该 PostgreSQL 服务器。# “local” is for Unix domain socket connections onlylocal all all trust# IPv4 local connections:host all all 127.0.0.1/32 trusthost all all 10.3.1.21/32 trusthost all all 10.3.1.22/32 trusthost all all 10.3.1.23/32 trusthost all all 10.1.1.0/32 trusthost all all 10.2.1.0/24 md5# IPv6 local connections:host all all ::1/128 md5host all smart_teacher 10.3.1.0/24 md5host all postgres 10.3.1.0/24 md5host 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.启用其它相关外挂套件
启用 adminpacksu -l pgsql -c “psql -U postgres postgres < /usr/local/share/postgresql/contrib/adminpack.sql”
启用 XML 支援 for PostgreSQLsu -l pgsql -c “psql -U postgres postgres < /usr/local/share/postgresql/contrib/pgxml.sql”
完成以上步骤,基本上你的 PostgreSQL 应该就可以正常运作了。
— 2008/08/13 新增 —
PostgreSQL 安装时修改 Makefile 档案,可以解决 xslt_process 无法安装的问题
找到底下设定
CONFIGURE_ARGS+=–with-libraries=${LOCALBASE}/lib \–with-includes=${LOCALBASE}/include \–enable-thread-safety \–with-docdir=${DOCSDIR} \–with-libxslt \–with-libxml增加红色的部份

0 评论: