1.下载源码介质
下载地址:
源码下载地址: https://www.postgresql.org/ftp/source/
二进制下载地址:https://www.enterprisedb.com/download-postgresql-binaries
2.安装依赖包
yum install readline
yum install gcc
yum -y install -y readline-devel
yum install zlib-devel
3.二进制安装
[root@localhost soft]#mkdir -p /opt/postgresql-11.6
[root@localhost soft]#./configure --prefix=/opt/postgresql-11.6
[root@localhost soft]#make
[root@localhost soft]#make install
4.创建相应的用户
[root@localhost opt]# groupadd postgres
[root@localhost opt]# useradd -g postgres postgres
5.创建数据及日志目录,并做相应授权
[root@localhost soft]#mkdir -p /opt/postgresql-11.6/{data,log}
[root@localhost soft]#chown -R postgres:postgres /opt/postgresql-11.6
6.初始化数据库
#su - postgres
[postgres@localhost bin]$ cd /opt/postgresql-11.6/bin
[postgres@localhost bin]$ ./initdb -D /opt/postgresql-11.6/data/
7.启动数据库
[postgres@localhost bin]$ cd /opt/postgresql-11.6/bin
[postgres@localhost bin]$./pg_ctl -D /opt/postgresql-11.6/data/ -l logfile start
8.登陆使用
[postgres@localhost bin]$cd /opt/postgresql-11.6/bin
[postgres@localhost bin]$ ./psql
psql (11.6)
Type "help" for help.
postgres=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
9.设置环境变量
[postgres@localhost ~]$ 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/.local/bin:$HOME/bin:/opt/postgresql-11.6/bin
export PATH
原文:https://www.cnblogs.com/hxlasky/p/12187660.html