yuxing 发表于 2016-11-20 08:11:01

postgresql数据的安装简记录

1 postgresql 数据库的官方地址
http://www.postgresql.org
2 从官方下载源码包
wget http://ftp.postgresql.org/pub/source/v8.4.10/postgresql-8.4.10.tar.gz
3 解压源码包
tar zxvf postgresql-8.4.10.tar.gz
4 进入目录
cd postgresql-8.4.10
5 配置
./configure --prefix=/usr/hehaibo/pgsql
--prefix 选项指定安装目录
6 编译
make
7 安装
make install

进入目录
cd /usr/hehaibo/pgsql/
# cd /usr/hehaibo/pgsql/
# ls
binincludelibshare

创建数据库目录
mkdir data
增加一个用户组
# groupadd postgres
增加一个组
# useradd -g postgres postgres
# cd /usr/hehaibo/pgsql/
改变目录的所属的用户为postgres
# chown postgres:postgres data/
用postgres用户登录
# su postgres
#配置postgres用户的环境变量
注意这是用户的宿主目录 pwd查看当前目录
$ pwd
/home/postgres
#查看所有文件 -a 显示隐藏
$ ls -a
....bash_history.bash_logout.bash_profile.bashrc.psql_history.viminfo
$ vi .bash_profile
配置环境变量

# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
      . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin
PGLIB=/usr/hehaibo/pgsql/lib
PGDATA=/usr/hehaibo/pgsql/data/
PATH=$PATH:/usr/hehaibo/pgsql/bin/
export PATH

保存退出
是当前环境变量立即生效
$ source ./.bash_profile
打印环境变量PGDATA
$ echo $PGDATA
/usr/hehaibo/pgsql/data/

初始化数据库
$ initdb -D /usr/hehaibo/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 zh_CN.GBK.
initdb: locale zh_CN.GBK requires unsupported encoding GBK
Encoding GBK is not allowed as a server-side encoding.
Rerun initdb with a different locale selection.
#为什么要加 --loccale参数
$ initdb --locale=zh_CN -D /usr/hehaibo/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 zh_CN.
The default database encoding has accordingly been set to EUC_CN.
initdb: could not find suitable text search configuration for locale zh_CN
The default text search configuration will be set to "simple".


fixing permissions on existing directory /usr/hehaibo/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 32MB
creating configuration files ... ok
creating template1 database in /usr/hehaibo/pgsql/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 /usr/hehaibo/pgsql/data
or
    pg_ctl -D /usr/hehaibo/pgsql/data -l logfile start
创建成功。

运行并创建数据库
$ ./postmaster -D /usr/hehaibo/pgsql/data
LOG:database system was shut down at 2012-07-18 15:33:23 CST
LOG:autovacuum launcher started
LOG:database system is ready to accept connections
创建数据test
$ ./createdb test

进入数据库
$ psql test
psql (8.4.10)
Type "help" for help.

test=# select * from test;
id
----
1
(1 row)
页: [1]
查看完整版本: postgresql数据的安装简记录