[iyunv@node1 ~]# yum -y install pgdg-centos96-9.6-3.noarch.rpm #yum源安装
[iyunv@node1 ~]# yum -y install postgresql-server #安装postgreesql
#安装生成的文件
[iyunv@node1 ~]# rpm -ql postgresql-server
/etc/pam.d/postgresql
/usr/bin/initdb
/usr/bin/pg_basebackup
/usr/bin/pg_controldata
/usr/bin/pg_ctl
/usr/bin/pg_receivexlog
/usr/bin/pg_resetxlog
/usr/bin/postgres
/usr/bin/postgresql-check-db-dir
/usr/bin/postgresql-setup
/usr/bin/postmaster
/usr/lib/systemd/system/postgresql.service
/usr/lib/tmpfiles.d/postgresql.conf
/var/lib/pgsql
/var/lib/pgsql/.bash_profile
/var/lib/pgsql/backups
/var/lib/pgsql/data
/var/run/postgresql、
#启动postgresql
#直接启动会报错:
[iyunv@node1 ~]# systemctl start postgresql.service
Job for postgresql.service failed because the control process exited with error code. See "systemctl status postgresql.service" and "journalctl -xe" for details.
#上面是提示数据库还没有初始化,所以我们先初始化一下
postgresql-setup initdb
Initializing database ... OK #提示初始化成功
#重新启动Postgresql
[iyunv@node1 ~]# systemctl start postgresql.service
[iyunv@node1 ~]# netstat -tnlp
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 1512/postgres
tcp6 0 0 ::1:5432 :::* LISTEN 1512/postgres
#查看运行状态
[iyunv@node1 ~]# systemctl status postgresql.service
● postgresql.service - PostgreSQL database server
Active: active (running) since Sat 2016-11-26 22:49:07 CST; 1min 33s ago
#切换到操作系统下的“postgres”用户,登录数据库
[iyunv@node1 ~]# su - postgres
-bash-4.2$ psql
psql (9.2.15)
Type "help" for help.
postgres=# help
You are using psql, the command-line interface to PostgreSQL.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
#到此为止,基本安装已经完成。