PostgreSQL安装

前端之家收集整理的这篇文章主要介绍了PostgreSQL安装前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

#下载

访问https://www.postgresql.org/download/点击左侧的‘source'进行下载,一般选择bz2的安装包。

#安装相关软件包

yum install -y zlib-devel

yum install -y readline-devel

#安装Postgresql

tar -xvf postgresql-9.5.6.tar.bz2

cd postgresql-9.5.6

./configure --prefix=/usr/local/pgsql9.5.6--enable-thread-safety --with-perl --with-python

make

make install

ln -s /usr/local/pgsql9.5.6 /usr/local/pgsql

#安装contrib下的工具

cd postgresql-9.5.6/contrib

make

make install

export PATH=$PATH:/usr/local/pgsql/bin

export LD_LIBRARY_PATH=/usr/local/pgsql/lib

#让以上设置对所有用户生效

vi /etc/profile

在最后添加

export PATH=$PATH:/usr/local/pgsql/bin

exportLD_LIBRARY_PATH=/usr/local/pgsql/lib:$LD_LIBRARY_PATH

cd /data/server

mkdir pgdata

export PGDATA=/data/server/pgdata

[root@pc2 server]# initdb

initdb: cannot be run as root

Please log in (using,e.g.,"su")as the (unprivileged) user that will

own the server process.

#新建普通用户,初始化数据库

useradd postgres

cd /data/server

chown -R postgres:postgres pgdata

su - postgres

export PGDATA=/data/server/pgdata

initdb

#启动数据库

pg_ctl -D /data/server/pgdata start

#登录数据库测试

[postgres@pc2 ~]$ psql

psql (9.5.6)

Type "help" for help.

postgres-# \l

List ofdatabases

Name | Owner| Encoding | Collate |Ctype | Access privileges

-----------+----------+----------+-------------+-------------+-----------------------

postgres| postgres | UTF8 |en_US.UTF-8 | en_US.UTF-8 |

template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |=c/postgres +

| || | | postgres=CTc/postgres

template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |=c/postgres +

| | | | | postgres=CTc/postgres

(3 rows)

--本篇文章参考自《Postgresql 修炼之道:从小工到专家》

猜你在找的Postgre SQL相关文章