大家可以利用BSD的Ports 来安装。
FBSD# cd /usr/ports/databases/postgresql7
(如果没更新Ports 的话,这个PostgreSQL是7.3.2,更新后是7.3.3)
FBSD# make install
…..
片刻就安装完成。
但我更趋向于自己编译安装,可以定制目录的。
1、下载PostgreSQL包
FBSD# fetch ftp://ftp3.ca.postgresql.org/pub ... gresql-7.3.3.tar.gz
(大家可以到 http://www.postgresql.org/mirrors-ftp.html 那里选择一个快的Mirror下载)
Receiving postgresql-7.3.3.tar.gz (11210071 bytes): 100% (ETA 00:00)
11210071 bytes transferred in 165.6 seconds (66.12 kBps)
FBSD# tar zxvf postgresql-7.3.3.tar.gz
FBSD# ls –lA
drwxr-xr-x 6 70 70 512 May 25 05:36 postgresql-7.3.3
-rw-r--r-- 1 root wheel 11210071 May 25 05:36 postgresql-7.3.3.tar.gz
FBSD# cd postgresql-7.3.3
FBSD# ./configure
(其实这的configure 可以加参数,但是我觉得它默认安装就已经满足了我初探要求了)
FBSD# gmake
….
All of PostgreSQL successfully made. Ready to install.
(make 成功)
FBSD# su (要有root的权限)
FBSD# gmake install
……
Please check the following URL for a listing of the current user-support
mailing lists: http://www.ca.postgresql.org/users-lounge/index.html#maillist
All of the mailing lists are currently archived and viewable at: http://archives.postgresql.org/
And, so that we have an idea of who is using what, please connect to the
following registration URL: http://www.pgsql.com/register/submit.php
Thank you for choosing PostgreSQL, the most advanced open source database
engine.
(其实现在PostgreSQL已经安装完毕)
FBSD# pw useradd postgres -d /usr/local/pgsql/data
(为PostgreSQL 添加启动用户postgres ,各系统的添加可能不一样。)
FBSD# mkdir /usr/local/pgsql/data
(添加PostgreSQL的数据库目录)
FBSD# chown postgres /usr/local/pgsql/data
(将data 目录所属人改为postgres 的)
FBSD# su - postgres
(改变用户)
$
(变成普通用户后,状态符变成$了)
$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale C.
Fixing permissions on existing directory /usr/local/pgsql/data... ok
creating directory /usr/local/pgsql/data/base... ok
creating directory /usr/local/pgsql/data/global... ok
creating directory /usr/local/pgsql/data/pg_xlog... ok
creating directory /usr/local/pgsql/data/pg_clog... ok
creating template1 database in /usr/local/pgsql/data/base/1... ok
creating configuration files... ok
initializing pg_shadow... ok
enabling unlimited row size for system tables... ok
initializing pg_depend... ok
creating system views... ok
loading pg_description... ok
creating conversions... ok
setting privileges on built-in objects... ok
vacuuming database template1... ok
copying template1 to template0... ok
Success. You can now start the database server using:
/usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data
or
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
$
(安装数据库)
$ cd /usr/local/pgsql/data
$ /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
(启动PostgreSQL数据库)
$ /usr/local/pgsql/bin/createdb test
CREATE DATABASE
(建立数据库test)
2、使用
下面大家可以一步一步接触PostgreSQL了。
$ /usr/local/pgsql/bin/psql test
Welcome to psql 7.3.3, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit
test=#
(大家看到=#状态符了吗?现在你可以输入以下命令看看)
test=# SELECT version();
version
---------------------------------------------------------------------
PostgreSQL 7.3.3 on i386-unknown-freebsd4.8, compiled by GCC 2.95.4
(1 row)
(哈哈……安装调试完成!)
想help 吗?输入\?
想退出?输入\q