`
hehaibo
  • 浏览: 410208 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
社区版块
存档分类
最新评论

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/
[root@oplinux postgresql-8.4.10]# cd /usr/hehaibo/pgsql/
[root@oplinux pgsql]# ls
bin  include  lib  share

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

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

初始化数据库
[postgres@oplinux 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参数
[postgres@oplinux data]$ 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
创建成功。

运行并创建数据库
[postgres@oplinux bin]$ ./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
[postgres@oplinux bin]$ ./createdb test

进入数据库
[postgres@oplinux bin]$ psql test
psql (8.4.10)
Type "help" for help.

test=# select * from test;
id
----
  1
(1 row)
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics