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
[[email protected] 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
#登录数据库测试
[[email protected] ~]$ 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 修炼之道:从小工到专家》