centos 下 PostgreSql安装

来源:互联网 发布:linux启动mysql 编辑:程序博客网 时间:2024/05/21 06:37

centos 下 PostgreSql安装

1.下载

wget https://ftp.postgresql.org/pub/source/v9.2.0/postgresql-9.2.0.tar.gz

2.解压文件

tar zxvf

3.编译:

./configure --prefix=/usr/local/pgsql --without-readline --without-zlib

4.安装:

make && make install

5. 添加用户

5.1 创建postgres用户

  adduser postgres

5.2 修改postgres密码

   passwd postgres

6. 切换到postgres用户

  su postgres 或者 su - postgres

7. 编辑~/.bash_profile文件

vi ~/.bash_profile- export PATH- export PATH=/usr/local/pgsql/bin:$PATH- export PGDATA=/usr/local/pgsql/data- export MANPATH=$MANPATH:/usr/local/pgsql/man- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/pgsql/lib

8.初始化:

- mkdir /usr/local/pgsql/data- chown postgres /usr/local/pgsql/data- su - postgres- /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data- /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data > logfile 2>&1 &- /usr/local/pgsql/bin/createdb test- /usr/local/pgsql/bin/psql test

9.创建数据库库文件的存储目录,个体postgres赋予权限

#chown postgres.postgres data#touch /var/log/pgsql.log#chown postgres.postgres /var/log/pgsql.log

9.初始化数据并设置locale

initdb -E UTF-8 -D /usr/local/pgsql/data --locale=zh_CN.UTF-8

10.启动数据库:

/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l /var/log/pgsql.log start 或者 pg_ctl start pa_ctl stop

连接数据库:

psql -h 127.0.0.1 -d postgres -U postgres

11、配置监听地址和端口:

vi /usr/local/pgsql/data/postgresql.conf

取消以下两行的注释

  listen_addresses = '*'  port = 5432

12、允许远程连接:

添加

vi /usr/local/pgsql/data/pg_hba.conf  host all all 192.168.1.0/24 md5

客户端连接PostgreSQL

13、防火墙

systemctl start firewalld  启动防火墙firewall-cmd --zone=public --add-port=5432/tcp --permanentfirewall-cmd --reloadfirewall-cmd --zone=public --list-ports

以上为主要步骤,lz亲自实验并ok

主要参考:

http://blog.chinaunix.net/uid-20874246-id-3330495.html
http://blog.csdn.net/liuzongxi/article/details/46381111
http://www.wit-x.com/?p=193

原创粉丝点击