RedHat Linux 安裝 PostgreSQL 8.4.2

下載並解包
$ tar zxvf postgresql-8.2.4.tar.gz
$ cd postgresql-8.2.4
配置
$ ./configure --prefix=/usr/local/pgsql-8.2.4
...
config.status: linking ./src/makefiles/Makefile.linux to src/Makefile.port
編譯
$ make
...
All of PostgreSQL successfully made. Ready to install.
測試
$ make check
...
=======================
All 103 tests passed.
=======================
安裝(root)
# su -
# groupadd postgresql
# useradd -g postgresql postgresql
# cd <安裝目錄>
# make install
...
PostgreSQL installation complete.
# cd /usr/local
# ln -s pgsql-8.2.4 pgsql
# mkdir /usr/local/pgsql/data
# cd /usr/local/pgsql
# chown postgresql.postgresql data
初始化數據庫目錄(postgresql)
# su - postgresql
$ cd /usr/local/pgsql/bin
設置locale爲C,並且template1編碼爲UNICODE,使數據庫支持中文
$ ./initdb --locale=C -E UNICODE -D ../data/
...
Success. You can now start the database server using:
./postgres -D ../data
or
./pg_ctl -D ../data -l logfile start
配置環境變量及日誌文件(root)
$ (^d)
# vi /etc/profile
PATH=/usr/local/pgsql/bin:$PATH
PGDATA=/usr/local/pgsql/data
使環境變量生效(或重啓操作系統)
# export PGDATA=/usr/local/pgsql/data
# touch /var/log/pgsql.log
# chown postgresql.postgresql /var/log/pgsql.log
修改配置文件(postgresql)
$ su - postgresql
$ cd /usr/local/pgsql/data
修改配置使監聽生效,取消以下兩行的註釋
$ vi postgresql.conf
listen_addresses = '*' # what IP address(es) to listen on;
port = 5432 # (change requires restart)

啓動數據庫(postgresql)
$ cd /usr/local/pgsql/bin
$ ./postmaster -D /usr/local/pgsql/data > /var/log/pgsql.log 2>&1 &
$ cat /var/log/psql.log
LOG: checkpoint record is at 0/42C424
LOG: redo record is at 0/42C424; undo record is at 0/0; shutdown TRUE
LOG: next transaction ID: 0/593; next OID: 10820
LOG: next MultiXactId: 1; next MultiXactOffset: 0
LOG: database system is ready
創建數據庫dm
$ ./createdb dm
CREATE DATABASE
創建用戶
$ ./createuser -A -D -E -P dm
Enter password for new role: 123456
Enter it again: 123456
Shall the new role be allowed to create more new roles? (y/n) y
CREATE ROLE
使用psql
$ ./psql -d dm -U dm
Welcome to psql 8.2.4, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit

dm=> \q

*在psql中若需要使用中文,先發送:
dm=> set client_encoding to 'gbk';

配置數據庫自啓動腳本(root)
$ (^d)
# cd /etc/rc.d/init.d
# cp (安裝目錄)/postgresql-8.2.4/contrib/start-script/linux postgresql
# chmod +x postgresql
# vi postgresql
prefix=/usr/local/pgsql
PGDATA="/usr/local/pgsql/data"
PGUSER=postgresql
PGLOG="/var/log/pgsql.log"
# chkconfig --add postgresql
重啓數據庫
# /etc/rc.d/init.d/postgresql restart
=== 配置完成 ===
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章