数据库

 首页 > 数据库 > postgresql > FreeBSD系统安装 PostgreSQL 数据库

FreeBSD系统安装 PostgreSQL 数据库

分享到:
【字体:
导读:
         摘要:1.假设环境pgsql.home.net192.168.1.3255.255.255.0文中的port选项是本人喜好,不是预设值或建议值2.更新FreeBSD中的porttree$su-$portsnapfetchupdate$exit如果你从未用过portsnap,改为$su-$portsnapfetchextrac...

FreeBSD系统安装 PostgreSQL 数据库
1. 假设环境

pgsql.home.net 192.168.1.3 255.255.255.0

文中的 port 选项是本人喜好,不是预设值或建议值

2. 更新 FreeBSD 中的 port tree

$ su -
$ portsnap fetch update
$ exit

如果你从未用过 portsnap,改为

$ su -
$ portsnap fetch extract update
$ exit

3. 登入 pgsql.home.net 后从 port 安装 perl 5.10.1

系统默认用 perl 5.8.x,如果你想 postgres 用 perl 5.10.x,有两个方法
i) 编译 postgresql 之前先编译 perl 5.10
ii) 在 /etc/make.conf 加入一行 PERL_VERSION=5.10.1

我习惯先编译 perl 5.10

$ su -
$ cd /usr/ports/lang/perl5.10/
$ make config

┌────────────────────────────────────┐
│                 Options for perl-threaded 5.10.1              │
│  ──────────────────────────┐ │
│ │      [ ] DEBUGGING      Build with debugging support           │ │
│ │      [ ] GDBM           Build GDBM_File extension              │ │
│ │      [ ] PERL_MALLOC    Use Perl malloc                        │ │
│ │      [X] PERL_64BITINT  Use 64 bit integers (on i386)          │ │
│ │      [X] THREADS        Build threaded perl                    │ │
│ │      [ ] MULTIPLICITY   Use multiplicity                       │ │
│ │      [X] SUIDPERL       Build set-user-id suidperl binary      │ │
│ │      [X] SITECUSTOMIZE  Run-time customization of @INC         │ │
│ │      [X] USE_PERL       Rewrite links in /usr/bin              │ │

$ make
$ make install
$ exit

4. 在 pgsql.home.net 从 port 安装 postgreSQL 8.4.1

$ su -
$ cd /usr/ports/database/postgres84-server
$ make config

┌─────────────────────┐
│               Options for postgresql-server 8.4.1                  │
│ ┌────────────────────────┐ │
│ │[X] NLS               Use internationalized messages            │ │
│ │[ ] PAM               Build with PAM support (server only)      │ │
│ │[ ] LDAP              Build with LDAP authentication support    │ │
│ │[ ] MIT_KRB5          Build with MIT’s kerberos support         │ │
│ │[ ] HEIMDAL_KRB5      Builds with Heimdal kerberos support      │ │
│ │[ ] OPTIMIZED_CFLAGS  Builds with compiler optimizations (-O3)  │ │
│ │[X] XML               Build with XML data type (server)         │ │
│ │[X] TZDATA            Use internal timezone database (server)   │ │
│ │[ ] DEBUG             Builds with debugging symbols             │ │
│ │[X] INTDATE           Builds with 64-bit date/time type (server)│ │
│ │                            │ │

$ make
$ make install
$ exit

当编译 perl5.10 或 postgres 时,会自动跳进其他套件选项画面,
如 libiconv, m4, libxslt
我个人喜好的选择如下:

┌───────────────────────┐
│                   Options for libiconv 1.13.1                      │
│ ┌────────────────────────┐ │
│ │  [X] EXTRA_ENCODINGS  Include extra character sets             │ │
│ │  [X] EXTRA_PATCHES    Apply patches to fix CP932 add EUCJP-MS  │ │

┌─────────────────────────┐
│                     Options for m4 1.4.13,1          │
│ ┌───────────────────────────┐ │
│ │     [X] LIBSIGSEGV  Use libsigsegv for better diagnostics      │ │

┌─────────────────────────┐
│                    Options for libxslt 1.1.26                      │
│ ┌────────────────────────────┐ │
│ │         [X] MEM_DEBUG  Enable memory debugging                 │ │
│ │         [X] CRYPTO     Enable crypto support for exslt         │ │

安装 postgresql-contrib

$ su -
$ cd /usr/ports/databases/postgresql-contrib
$ make
$ make install
$ exit

安装 p5-postgresql-plperl

$ su -
$ cd /usr/ports/databases/p5-postgresql-plperl
$ make
$ make install
$ exit

4. 在 pgsql.home.net 修改 postgreSQL Database 预设为中文 locate

本人使用繁体中文,选用 zh_TW.UTF-8 的 locate。

请参考 postgresql 安装说明,它有提及如何改变 locate 的方法

$ pkg_info -D postgresql-server-8.4.1

我使用增加一个 login class 的方法,去改变 locate 值,步骤为
i) 修改 /etc/login.conf
ii) 修改 /etc/rc.conf

i)

$ su -
$ vi /etc/login.conf
$ exit

===========================
在档案中某空白地方增加以下描述
#——————-
# postgresql class
#——————-
pgsql:
:lang=zh_TW.UTF-8:
:setenv=LC_COLLATE=C:
:tc=default:

修改完 /etc/login.conf 必顺执行一次 cap_mkdb 使之生效

$ su -
$ cap_mkdb /etc/login.conf
$ exit

ii)

$ su -
$ vi /etc/rc.conf
$ exit

==========================
在档案中某空白地方增加以下描述
#———————-
# postgresql settings
#———————-
postgresql_enable=”YES”
postgresql_data=”/usr/local/pgsql/data”
postgresql_flags=”-w -s -m fast”
postgresql_initdb_flags=”?encoding=utf-8 ?lc-collate=C”
postgresql_class=”pgsql”

注意 /etc/rc.conf 中的 postgresql_class 值是对应 /etc/login.conf 名称

4. 在 pgsql.home.net 初始化 postgres 系统资料库

$ su
$ /usr/local/etc/rc.d/postgresql initdb
$ exit

5. 初始化系统资料库后,便可以第一次启动 postgresql

$ su
$ /usr/local/etc/rc.d/postgresql start
$ exit

6. 使用 psql 修改 pgsql 的密码
在 FreeBSD port 的 postgresql,它的 superuser 叫 pgsql,并不是 postgres 初始化的资料库,pgsql 是没有密码,在 localhost 没有密码登入,任何人皆可以在 localhost 用 pgsql 登入 postgresql 为所欲为。因此,第一件事为 pgsql 设密码,使用 psql 便可

==================================
在 psql 画面输入命令修改密码然后离开 psql
———————————————————-

postgres=# password pgsql
postgres=#q

修改密码工作还有下半部份,便是修改 /usr/local/pgsql/data/pg_hba.conf

$ su -
$ cd /usr/local/pgsql/data
$ vi pg_hba.conf
$ exit

=============================================
把档案中的 trust 改为 md5,强迫 postgres 必须做密码登入
—————————————————————————-

# TYPE  DATABASE       USER     CIDR-ADDRESS          METHOD

# “local” is for Unix domain socket connections only
local   all            pgsql                          md5

# IPv4 local connections:
host    all            pgsql    127.0.0.1/32          md5
host    all            pgsql    192.168.1.3/32        md5
host    all            all      192.168.1.0/24        reject

# IPv6 local connections:
#host   all         all         ::1/128               trust

仔细的 pg_hba.conf 权限语法请自行参考官方资料

修改了 pgsql 的密码 和 pg_hba.conf 设定后,必须重新启动 postgresql

$ su -
$ /usr/local/etc/rc.d/postgresql restart
$ exit

成功了,现在登入 postgresql 必须要输入密码

6. FreeBSD postgresql periodic script
FreeBSD port 会安装了一个 periodic 在 /usr/local/etc/periodic/daily/502.pgsql
这个 periodic script 提供两个服务:

i)每天定时做 vacuumdb 一次
ii)每天定时做 pg_dump 一次

想启动这功能 要修改 /etc/periodic.conf
或 /etc/periodic.conf.local 二者选一,内容一样

$su -
$vi /etc/periodic.conf
$ exit

================
档案中增加以下内容
—————
# 502.pgsql
daily_pgsql_backup_enable=”YES” # do backup
daily_pgsql_vacuum_enable=”YES” # do vacuum

如果你只想做 vacuum 不做 pg_dump,内容如下
===============
档案中增加以下内容
—————
# 502.pgsql
daily_pgsql_backup_enable=”NO” # do backup
daily_pgsql_vacuum_enable=”YES” # do vacuum

由于 postgresql 已改变为加密登入,使用 periodic script 必需提供 password 给 periodic,否则会执行 vacuumdb pg_dump,失败。方法是建立一个密码 .pgpass 档案把 password 传给 periodic

.pgpass 档案必需放置在 postgresql daemon 的 $HOME 才可以配合 periodic 顺利执行

检察 postgresql 的 $HOME 在那里

$su -
$more /etc/passwd | grep PostgreSQL
$ exit

==============
我的查询结果如下
————————
pgsql:*:70:70::0:0:PostgreSQL Daemon:/usr/local/pgsql:/bin/sh

表示 postgresql 的 $HOME 在 /usr/local/pgsql 这里
因此把 .pgpass 放置在 /usr/local/pgsql 成为

/usr/local/pgsql/.pgpass

步骤如下:

$ su -
$ cd /usr/local/pgsql
$ touch .pgpass
$ chmod 600 .pgpass
$ chown pgsql:pgsql .pgpass
$ exit

修改 .pgpass 内容

$ su -
$ vi /usr/local/pgsql/.pgpass
$ exit

==============================================
.pgpass 格式有规范的,官方说明请看
http://www.postgresql.org/docs/8.4/interactive/libpq-pgpass.html
——————————————————————————
localhost:5432:*:pgsql:你的pgsql密码

最后一步,是修改 /usr/local/etc/periodic/daily/502.pgsql 使它懂得配对
正确的用户名和密码

$ su -
$ vi /usr/local/etc/periodic/daily/502.pgsql
$ exit

==================
把其中的两行参数修改
——————————

< 原本是 >
daily_pgsql_vacuum_args=”-z”
daily_pgsql_pgdump_args=”-b -F c”

< 修改为 >
daily_pgsql_vacuum_args=”-h localhost -U pgsql -z”
daily_pgsql_pgdump_args=”-h localhost -U pgsql -b -F c”

基本安装完成

FreeBSD系统安装 PostgreSQL 数据库
分享到:
PostgreSQL数据库的优势
PostgreSQL数据库的优势 PostgreSQL 是世界上可以获得的最先进的开放源码的数据库系统, 它提供了多版本并行控制,支持几乎所有 SQL 构件(包括子查询,事务和用户定 义类型和函数), 并且可以获得非常广阔范围的(开发)语言绑定 (包括 C,C++,Java,perl,tcl,和 python)。具体的优点特性如下: 1. PostgreSQL 的特性...
db2 和 postgresql在开发中的对比
db2 和 postgresql在开发中的对比   最近用了用DB2,写了点区分。不一定完全正确。但是能够看看两者区分。   1,数据定义语言(DDL)连同外围工具:   db2和postgresql的区分几乎为0,   具体区分是:(desc)   a、db2 varchar 在没有配置特别表空间的话,上限为32K,postgresql的varchar   ...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……