PostgreSQL8.x版本的安装已经非常的简单了。EnterpriseDB制作了一键安装的版本,包括FreeBSD/Linux/Mac OS X/Solaris/Windows平台都有。不过即使使用源码编译,也非常的简单。各个版本的源码可以点这里下载。
创建os用户
#useradd -g dba postgres #su - postgres
编译
$tar -zxvf postgresql-8.4.2.tar.gz $cd postgresql-8.4.2 $./configure --prefix=/OPT/postgresql --enable-profiling --with-blocksize=8 --with-wal-blocksize=8 $make && make install
其中with-blocksize指定数据块大小,默认8k,with-wal-blocksize指定日志块大小,默认也是8k。更多编译配置选项,可以通过./configure -help查看。
初始化database,注意PostgreSQL在服务端不支持GBK编码。
$cd /opt/postgresql/bin $ ./initdb --encoding=utf8 -D /opt/postgresql/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 en_US.UTF-8. The default text search configuration will be set to "english". creating directory /opt/postgresql/data ... ok creating subdirectories ... ok selecting default max_connections ... 100 selecting default shared_buffers ... 32MB creating configuration files ... ok creating template1 database in /opt/postgresql/data/base/1 ... ok initializing pg_authid ... ok initializing dependencies ... ok creating system views ... ok loading system objects' descriptions ... ok creating conversions ... ok creating dictionaries ... ok setting privileges on built-in objects ... ok creating information schema ... ok vacuuming database template1 ... ok copying template1 to template0 ... ok copying template1 to postgres ... ok WARNING: enabling "trust" authentication for local connections You can change this by editing pg_hba.conf or using the -A option the next time you run initdb. Success. You can now start the database server using: ./postgres -D /opt/postgresql/data or ./pg_ctl -D /opt/postgresql/data -l logfile start
初始化完成后,会在 /opt/postgresql/data目录生成数据库的文件,至此,软件安装完毕,数据库创建完毕。
启动数据库
./pg_ctl -D /opt/postgresql/data/ -l /opt/postgresql/log/alert.log start
启动后,可以发现PostgreSQL实例一共运行了5个进程
$ ps -ef | grep postgres postgres 17572 1 0 16:41 pts/2 00:00:00 /opt/postgresql/bin/postgres -D /opt/postgresql/data postgres 17574 17572 0 16:41 ? 00:00:00 postgres: writer process postgres 17575 17572 0 16:41 ? 00:00:00 postgres: wal writer process postgres 17576 17572 0 16:41 ? 00:00:00 postgres: autovacuum launcher process postgres 17577 17572 0 16:41 ? 00:00:00 postgres: stats collector process postgres 18679 20791 0 16:47 pts/2 00:00:00 grep postgres
其中wal writer process是日志写进程。