下载链接: https://www.enterprisedb.com/download-postgresql-binaries

  1. 创建目录解压
    mkdir -p /opt/postgres && tar xf postgresql-10.12-1-linux-x64-binaries.tar.gz -C /opt/postgres/

2.创建用户并设置密码
useradd postgres && passwd postgres

3.创建postgres的数据目录并授权
mkdir -p /opt/postgres/pg_data && chown -R postgres:postgres /opt/postgres/pg_data

4.切换到postgres用户启动数据库,并初始化数据库
su - postgres && /opt/postgres/pgsql/bin/initdb -D /opt/postgres/pg_data/

5.启动数据库
/opt/postgres/pgsql/bin/pg_ctl -D /opt/postgres/pg_data/ -l logfile start

[postgres@linux-node1 ~]$ netstat -lnupt|grep 5432
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 127.0.0.1:5432 0.0.0.0: LISTEN 23546/postgres
tcp6 0 0 ::1:5432 :::
LISTEN 23546/postgres

6.登录数据库
[postgres@linux-node1 pgsql]$ ./bin/psql -h localhost -d postgres -U postgres -p 5432
\l 查看数据库列表 \q退出交互界面

7.停止数据库
/opt/postgres/pgsql/bin/pg_ctl -D /opt/postgres/pg_data/ stop