官方YUM:
https://yum.postgresql.org/repopackages.php#pg10

服务器下载并安装需要的YUM:

下载:

[root@postgresql01 PostgreSQL]# wget https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-redhat10-10-2.noarch.rpm
--2018-07-23 14:36:16--  https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-redhat10-10-2.noarch.rpm
Resolving download.postgresql.org... 87.238.57.227, 174.143.35.246, 217.196.149.55, ...
Connecting to download.postgresql.org|87.238.57.227|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4688 (4.6K) [application/x-redhat-package-manager]
Saving to: “pgdg-redhat10-10-2.noarch.rpm”

100%[=======================================================================================>] 4,688       15.9K/s   in 0.3s    

2018-07-23 14:36:21 (15.9 KB/s) - “pgdg-redhat10-10-2.noarch.rpm” saved [4688/4688]

[root@postgresql01 PostgreSQL]# 
[root@postgresql01 PostgreSQL]# pwd
/software/PostgreSQL
[root@postgresql01 PostgreSQL]# ls -ltr
total 8
-rw-r--r-- 1 root root 4688 Feb 27 03:46 pgdg-redhat10-10-2.noarch.rpm
[root@postgresql01 PostgreSQL]# 

安装:

[root@postgresql01 PostgreSQL]# pwd
/software/PostgreSQL
[root@postgresql01 PostgreSQL]# ls -ltr
total 8
-rw-r--r-- 1 root root 4688 Feb 27 03:46 pgdg-redhat10-10-2.noarch.rpm
[root@postgresql01 PostgreSQL]# 
[root@postgresql01 PostgreSQL]# rpm -ivh pgdg-redhat10-10-2.noarch.rpm 
warning: pgdg-redhat10-10-2.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Preparing...                ########################################### [100%]
   1:pgdg-redhat10          ########################################### [100%]
[root@postgresql01 PostgreSQL]# 
[root@postgresql01 PostgreSQL]# rpm -ql pgdg-redhat10-10-2.noarch
/etc/pki/rpm-gpg
/etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-10
/etc/yum.repos.d/pgdg-10-redhat.repo
[root@postgresql01 PostgreSQL]# 

查看一下YUM源:

[root@postgresql01 PostgreSQL]# ls -ltr /etc/yum.repos.d/
total 12
-rw-r--r--  1 root root 1004 Sep 24  2017 pgdg-10-redhat.repo
-rw-r--r--. 1 root root  529 May 21 16:35 rhel-source.repo
-rw-r--r--. 1 root root  358 Jul 23 10:09 redhat.repo
[root@postgresql01 PostgreSQL]# 
[root@postgresql01 PostgreSQL]# cat /etc/yum.repos.d/pgdg-10-redhat.repo 
[pgdg10]
name=PostgreSQL 10 $releasever - $basearch
baseurl=https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-$releasever-$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-10

[pgdg10-source]
name=PostgreSQL 10 $releasever - $basearch - Source
failovermethod=priority
baseurl=https://download.postgresql.org/pub/repos/yum/srpms/10/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-10

[pgdg10-updates-testing]
name=PostgreSQL 10 $releasever - $basearch
baseurl=https://download.postgresql.org/pub/repos/yum/testing/10/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-10

[pgdg10-source-updates-testing]
name=PostgreSQL 10 $releasever - $basearch - Source
failovermethod=priority
baseurl=https://download.postgresql.org/pub/repos/yum/srpms/testing/10/redhat/rhel-$releasever-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-10

[root@postgresql01 PostgreSQL]# 

修改YUM缓存策略:

[root@postgresql01 PostgreSQL]# cat /etc/yum.conf 
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=3

#  This is the default, if you make this bigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
#  It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
[root@postgresql01 PostgreSQL]# 
[root@postgresql01 PostgreSQL]# sed -i '/keepcache/s/0/1/g' /etc/yum.conf 
[root@postgresql01 PostgreSQL]# 
[root@postgresql01 PostgreSQL]# cat /etc/yum.conf | grep --color keepcache
keepcache=1
[root@postgresql01 PostgreSQL]# 

刷新YUM源:

[root@postgresql01 PostgreSQL]# yum makecache
Loaded plugins: product-id, refresh-packagekit, search-disabled-repos, security, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
pgdg10                                                                                                    | 4.1 kB     00:00     
pgdg10/group_gz                                                                                           |  245 B     00:00     
pgdg10/filelists_db                                                                                       | 397 kB     00:03     
pgdg10/prestodelta                                                                                        |  13 kB     00:00     
pgdg10/primary_db                                                                                         | 171 kB     00:01     
pgdg10/other_db                                                                                           |  55 kB     00:00     
Metadata Cache Created
[root@postgresql01 PostgreSQL]# 
[root@postgresql01 PostgreSQL]# yum list | grep --color pgdg10
CGAL.x86_64                                   4.7-1.rhel6                 pgdg10
CGAL-debuginfo.x86_64                         4.7-1.rhel6                 pgdg10
CGAL-demos-source.x86_64                      4.7-1.rhel6                 pgdg10
CGAL-devel.x86_64                             4.7-1.rhel6                 pgdg10
MigrationWizard.noarch                        1.1-3.rhel6                 pgdg10
PyGreSQL.x86_64                               5.0.3-1.rhel6               pgdg10
PyGreSQL-debuginfo.x86_64                     5.0.3-1.rhel6               pgdg10
amcheck_next10.x86_64                         1.4-1.rhel6                 pgdg10
amcheck_next10-debuginfo.x86_64               1.4-1.rhel6                 pgdg10
apache-maven.noarch                           3.3.9-4.rhel6               pgdg10
barman.noarch                                 2.4-1.rhel6                 pgdg10
barman-cli.noarch                             1.2-1.rhel6                 pgdg10
bgw_replstatus10.x86_64                       1.0.1-1.rhel6               pgdg10
bgw_replstatus10-debuginfo.x86_64             1.0.1-1.rhel6               pgdg10
boxinfo.noarch                                1.4.0-1.rhel6               pgdg10
bucardo.noarch                                5.4.1-1.rhel6               pgdg10
check_postgres.noarch                         2.24.0-1.rhel6              pgdg10
citus_10.x86_64                               7.4.1-1.rhel6               pgdg10
citus_10-debuginfo.x86_64                     7.4.1-1.rhel6               pgdg10
citus_10-devel.x86_64                         7.4.1-1.rhel6               pgdg10
cstore_fdw_10.x86_64                          1.6.1-1.rhel6               pgdg10
cstore_fdw_10-debuginfo.x86_64                1.6.1-1.rhel6               pgdg10
cyanaudit10.noarch                            1.0.2-1.rhel6               pgdg10
emaj.x86_64                                   2.2.3-1.rhel6               pgdg10
gdal.x86_64                                   1.9.2-8.rhel6               pgdg10
gdal-debuginfo.x86_64                         1.9.2-8.rhel6               pgdg10
gdal-devel.x86_64                             1.9.2-8.rhel6               pgdg10
gdal-java.x86_64                              1.9.2-8.rhel6               pgdg10
gdal-libs.x86_64                              1.9.2-8.rhel6               pgdg10
gdal-perl.x86_64                              1.9.2-8.rhel6               pgdg10
gdal-python.x86_64                            1.9.2-8.rhel6               pgdg10
gdal-ruby.x86_64                              1.9.2-8.rhel6               pgdg10
geoip10.noarch                                0.2.4-1.rhel6               pgdg10
geos36.x86_64                                 3.6.2-3.1.rhel6             pgdg10
geos36-debuginfo.x86_64                       3.6.2-3.1.rhel6             pgdg10
geos36-devel.x86_64                           3.6.2-3.1.rhel6             pgdg10
geos36-python.x86_64                          3.6.2-3.1.rhel6             pgdg10
hdfs_fdw_10.x86_64                            2.0.3-1.rhel6               pgdg10
hdfs_fdw_10-debuginfo.x86_64                  2.0.3-1.rhel6               pgdg10
hll_10.x86_64                                 2.10.2-1.rhel6              pgdg10
hll_10-debuginfo.x86_64                       2.10.2-1.rhel6              pgdg10
hypopg_10.x86_64                              1.1.1-1.rhel6               pgdg10
hypopg_10-debuginfo.x86_64                    1.1.1-1.rhel6               pgdg10
ip4r10.x86_64                                 2.2-1.rhel6                 pgdg10
ip4r10-debuginfo.x86_64                       2.2-1.rhel6                 pgdg10
jsquery_10.x86_64                             1.0.1-1.rhel6               pgdg10
jsquery_10-debuginfo.x86_64                   1.0.1-1.rhel6               pgdg10
jsquery_10-devel.x86_64                       1.0.1-1.rhel6               pgdg10
libgeotiff.x86_64                             1.4.0-1.rhel6               pgdg10
libgeotiff-debuginfo.x86_64                   1.4.0-1.rhel6               pgdg10
libgeotiff-devel.x86_64                       1.4.0-1.rhel6               pgdg10
libmemcached.x86_64                           1.0.18-1.rhel6              pgdg10
libmemcached-debuginfo.x86_64                 1.0.18-1.rhel6              pgdg10
libmemcached-devel.x86_64                     1.0.18-1.rhel6              pgdg10
luapgsql.x86_64                               1.6.1-1.rhel6               pgdg10
mailchimp_fdw.x86_64                          0.3.1-2.rhel6               pgdg10
multicorn10.x86_64                            1.3.5-1.rhel6               pgdg10
multicorn10-debuginfo.x86_64                  1.3.5-1.rhel6               pgdg10
mysql_fdw_10.x86_64                           2.4.0-1.rhel6               pgdg10
mysql_fdw_10-debuginfo.x86_64                 2.4.0-1.rhel6               pgdg10
nagios-plugins-pgactivity.noarch              2.2-1                       pgdg10
ogdi.x86_64                                   3.2.0-4.rhel6               pgdg10
ogdi-debuginfo.x86_64                         3.2.0-4.rhel6               pgdg10
ogdi-devel.x86_64                             3.2.0-4.rhel6               pgdg10
ogdi-odbc.x86_64                              3.2.0-4.rhel6               pgdg10
ogdi-tcl.x86_64                               3.2.0-4.rhel6               pgdg10
ogr_fdw10.x86_64                              1.0.4-1.rhel6               pgdg10
ogr_fdw10-debuginfo.x86_64                    1.0.4-1.rhel6               pgdg10
ora2pg.noarch                                 18.2-1.rhel6                pgdg10
orafce10.x86_64                               3.6.1-1.rhel6               pgdg10
orafce10-debuginfo.x86_64                     3.6.1-1.rhel6               pgdg10
pagila10.noarch                               2.0.1-1.rhel6               pgdg10
pam-pgsql10.x86_64                            0.7.3.2-1.rhel6             pgdg10
pam-pgsql10-debuginfo.x86_64                  0.7.3.2-1.rhel6             pgdg10
pgFormatter.noarch                            3.0-1.rhel6                 pgdg10
pgMail.noarch                                 1.4-1.rhel6                 pgdg10
pg_activity.noarch                            1.4.0-1.rhel6               pgdg10
pg_back.noarch                                1.5-1.rhel6                 pgdg10
pg_bloat_check.noarch                         2.4.3-2.rhel6               pgdg10
pg_bulkload10.x86_64                          3.1.14-2.rhel6              pgdg10
pg_bulkload10-client.x86_64                   3.1.14-2.rhel6              pgdg10
pg_bulkload10-debuginfo.x86_64                3.1.14-1.rhel6              pgdg10
pg_catcheck10.x86_64                          1.1.0-1.rhel6               pgdg10
pg_catcheck10-debuginfo.x86_64                1.1.0-1.rhel6               pgdg10
pg_comparator10.x86_64                        2.2.5-1.rhel6               pgdg10
pg_comparator10-debuginfo.x86_64              2.2.5-1.rhel6               pgdg10
pg_fkpart10.noarch                            1.6.0-1.rhel6               pgdg10
pg_jobmon10.noarch                            1.3.3-1.rhel6               pgdg10
pg_partman10.x86_64                           3.2.0-1.rhel6               pgdg10
pg_partman10-debuginfo.x86_64                 3.2.0-1.rhel6               pgdg10
pg_pathman10.x86_64                           1.4.13-1.rhel6              pgdg10
pg_pathman10-debuginfo.x86_64                 1.4.13-1.rhel6              pgdg10
pg_qualstats10.x86_64                         1.0.4-1.rhel6               pgdg10
pg_qualstats10-debuginfo.x86_64               1.0.4-1.rhel6               pgdg10
pg_repack10.x86_64                            1.4.3-1.rhel6               pgdg10
pg_repack10-debuginfo.x86_64                  1.4.2-1.rhel6               pgdg10
pg_slotsync10.x86_64                          1.0-1.rhel6                 pgdg10
pg_slotsync10-debuginfo.x86_64                1.0-1.rhel6                 pgdg10
pg_stat_kcache10.x86_64                       2.0.3-1.rhel6               pgdg10
pg_stat_kcache10-debuginfo.x86_64             2.0.3-1.rhel6               pgdg10
pg_top10.x86_64                               3.7.0-5.rhel6               pgdg10
pg_top10-debuginfo.x86_64                     3.7.0-5.rhel6               pgdg10
pg_track_settings10.x86_64                    1.0.1-1.rhel6               pgdg10
pgadmin4-babel.noarch                         2.3.4-2.rhel6               pgdg10
pgadmin4-babel-doc.noarch                     2.3.4-2.rhel6               pgdg10
pgadmin4-python-Flask-Mail.noarch             0.9.1-3.rhel6               pgdg10
pgadmin4-python-babel.noarch                  2.3.4-1.rhel6               pgdg10
pgadmin4-python-backports.csv.noarch          1:1.0.5-2.rhel6             pgdg10
pgadmin4-python-beautifulsoup4.noarch         4.5.1-2.rhel6               pgdg10
pgadmin4-python-blinker.noarch                1.4-2.rhel6                 pgdg10
pgadmin4-python-crypto.x86_64                 2.6.1-14.rhel6              pgdg10
pgadmin4-python-crypto-debuginfo.x86_64       2.6.1-14.rhel6              pgdg10
pgadmin4-python-fixtures.noarch               3.0.0-4.rhel6               pgdg10
pgadmin4-python-flask.noarch                  1:0.11.1-7.rhel6            pgdg10
pgadmin4-python-flask-babel.noarch            0.11.1-3.rhel6              pgdg10
pgadmin4-python-flask-gravatar.noarch         0.4.2-2.rhel6               pgdg10
pgadmin4-python-flask-htmlmin.noarch          1.2-5.rhel6                 pgdg10
pgadmin4-python-flask-login.noarch            0.3.2-1.rhel6               pgdg10
pgadmin4-python-flask-migrate.noarch          2.0.4-1.rhel6               pgdg10
pgadmin4-python-flask-paranoid.noarch         0.1-1.rhel6                 pgdg10
pgadmin4-python-flask-principal.noarch        0.4.0-13.rhel6              pgdg10
pgadmin4-python-flask-sqlalchemy.noarch       2.1-6.rhel6                 pgdg10
pgadmin4-python-html5lib.noarch               1:1.0b3-1.rhel6             pgdg10
pgadmin4-python-htmlmin.noarch                0.1.10-7.gitcc611c3.rhel6   pgdg10
pgadmin4-python-itsdangerous.noarch           0.24-9.rhel6                pgdg10
pgadmin4-python-jinja2.noarch                 2.8-8.rhel6                 pgdg10
pgadmin4-python-mimeparse.noarch              1.5.2-2.rhel6               pgdg10
pgadmin4-python-passlib.noarch                1.6.2-3.rhel6               pgdg10
pgadmin4-python-pbr.noarch                    1.8.1-6.rhel6               pgdg10
pgadmin4-python-speaklater.noarch             1.3-2.rhel6                 pgdg10
pgadmin4-python-sqlalchemy.x86_64             1.0.14-2.rhel6              pgdg10
pgadmin4-python-sqlalchemy-debuginfo.x86_64   1.0.14-2.rhel6              pgdg10
pgadmin4-python-sqlparse.noarch               0.2.1-4.rhel6               pgdg10
pgadmin4-python-werkzeug.noarch               0.11.11-3.rhel6             pgdg10
pgadmin4-python-wtforms.noarch                2.1-2.rhel6                 pgdg10
pgadmin4-python3-Flask-Mail.noarch            0.9.1-4.rhel6               pgdg10
pgadmin4-python3-babel.noarch                 2.3.4-2.rhel6               pgdg10
pgadmin4-python3-backports.csv.noarch         1:1.0.5-3.rhel6             pgdg10
pgadmin4-python3-beautifulsoup4.noarch        4.5.1-3.rhel6               pgdg10
pgadmin4-python3-blinker.noarch               1.4-3.rhel6                 pgdg10
pgadmin4-python3-click.noarch                 6.7-8.rhel6                 pgdg10
pgadmin4-python3-crypto.x86_64                2.6.1-15.rhel6              pgdg10
pgadmin4-python3-crypto-debuginfo.x86_64      2.6.1-15.rhel6              pgdg10
pgadmin4-python3-dateutil.noarch              1:2.7.2-1.rhel6             pgdg10
pgadmin4-python3-dateutil-doc.noarch          1:2.7.2-1.rhel6             pgdg10
pgadmin4-python3-extras.noarch                1.0.0-2.rhel6               pgdg10
pgadmin4-python3-fixtures.noarch              3.0.0-5.rhel6               pgdg10
pgadmin4-python3-flask.noarch                 1:0.12.2-1.rhel6            pgdg10
pgadmin4-python3-flask-babel.noarch           0.11.1-4.rhel6              pgdg10
pgadmin4-python3-flask-babelex.noarch         0.9.3-1.rhel6               pgdg10
pgadmin4-python3-flask-gravatar.noarch        0.4.2-3.rhel6               pgdg10
pgadmin4-python3-flask-htmlmin.noarch         1.3.2-1.rhel6               pgdg10
pgadmin4-python3-flask-login.noarch           0.3.2-3.rhel6               pgdg10
pgadmin4-python3-flask-migrate.noarch         2.1.1-1.rhel6               pgdg10
pgadmin4-python3-flask-paranoid.noarch        0.2-1.rhel6                 pgdg10
pgadmin4-python3-flask-principal.noarch       0.4.0-14.rhel6              pgdg10
pgadmin4-python3-flask-security.noarch        3.0.0-1.rhel6               pgdg10
pgadmin4-python3-flask-sqlalchemy.noarch      2.3.2-1.rhel6               pgdg10
pgadmin4-python3-flask-wtf.noarch             0.14.2-1.rhel6              pgdg10
pgadmin4-python3-html5lib.noarch              1:1.0.1-1.rhel6             pgdg10
pgadmin4-python3-htmlmin.noarch               0.1.12-1.rhel6              pgdg10
pgadmin4-python3-itsdangerous.noarch          0.24-10.rhel6               pgdg10
pgadmin4-python3-jinja2.noarch                2.8-9.rhel6                 pgdg10
pgadmin4-python3-linecache2.noarch            1.0.0-14.rhel6              pgdg10
pgadmin4-python3-markupsafe.x86_64            0.23-13.rhel6               pgdg10
pgadmin4-python3-markupsafe-debuginfo.x86_64  0.23-13.rhel6               pgdg10
pgadmin4-python3-mimeparse.noarch             1.6.0-1.rhel6               pgdg10
pgadmin4-python3-passlib.noarch               1.7.1-1.rhel6               pgdg10
pgadmin4-python3-pbr.noarch                   3.1.1-1.rhel6               pgdg10
pgadmin4-python3-pyrsistent.x86_64            0.14.2-1.rhel6              pgdg10
pgadmin4-python3-pyrsistent-debuginfo.x86_64  0.14.2-1.rhel6              pgdg10
pgadmin4-python3-simplejson.x86_64            3.13.2-1.rhel6              pgdg10
pgadmin4-python3-simplejson-debuginfo.x86_64  3.13.2-1.rhel6              pgdg10
pgadmin4-python3-six.noarch                   1.11.0-3.rhel6              pgdg10
pgadmin4-python3-speaklater.noarch            1.3-3.rhel6                 pgdg10
pgadmin4-python3-sqlalchemy.x86_64            1.2.5-1.rhel6               pgdg10
pgadmin4-python3-sqlalchemy-debuginfo.x86_64  1.2.5-1.rhel6               pgdg10
pgadmin4-python3-sqlparse.noarch              0.2.4-1.rhel6               pgdg10
pgadmin4-python3-werkzeug.noarch              0.11.11-4.rhel6             pgdg10
pgadmin4-python3-wtforms.noarch               2.1-3.rhel6                 pgdg10
pgadmin4-pytz.noarch                          2018.3-1.rhel6              pgdg10
pgadmin4-v1.x86_64                            1.6-2.rhel6                 pgdg10
pgadmin4-v1-debuginfo.x86_64                  1.6-2.rhel6                 pgdg10
pgadmin4-v1-docs.noarch                       1.6-2.rhel6                 pgdg10
pgadmin4-v1-web.noarch                        1.6-2.rhel6                 pgdg10
pgadmin4-v2.x86_64                            2.1-1.rhel6                 pgdg10
pgadmin4-v2-docs.noarch                       2.1-1.rhel6                 pgdg10
pgadmin4-v2-web.noarch                        2.1-1.rhel6                 pgdg10
pgagent_10.x86_64                             3.4.0-10.rhel6              pgdg10
pgagent_10-debuginfo.x86_64                   3.4.0-10.rhel6              pgdg10
pgaudit12_10.x86_64                           1.2.0-1.rhel6               pgdg10
pgaudit12_10-debuginfo.x86_64                 1.2.0-1.rhel6               pgdg10
pgbackman.noarch                              1.1.0-1.rhel6               pgdg10
pgbackrest.noarch                             1.26-1.rhel6                pgdg10
pgbackrest.x86_64                             2.04-1.rhel6                pgdg10
pgbadger.noarch                               9.2-1.rhel6                 pgdg10
pgbconsole.x86_64                             0.1.1-1.rhel6               pgdg10
pgbconsole-debuginfo.x86_64                   0.1.1-1.rhel6               pgdg10
pgbconsole10.x86_64                           0.1.1-1.rhel6               pgdg10
pgbconsole10-debuginfo.x86_64                 0.1.1-1.rhel6               pgdg10
pgbouncer.x86_64                              1.8.1-1.rhel6               pgdg10
pgbouncer-debuginfo.x86_64                    1.8.1-1.rhel6               pgdg10
pgbson10.x86_64                               1.0.1-2.rhel6               pgdg10
pgbson10-debuginfo.x86_64                     1.0.1-2.rhel6               pgdg10
pgcenter.x86_64                               0.3.0-1.rhel6               pgdg10
pgcenter-debuginfo.x86_64                     0.3.0-1.rhel6               pgdg10
pgcluu.noarch                                 2.6-1.rhel6                 pgdg10
pgdg-centos10.noarch                          10-2                        pgdg10
pgdg-fedora10.noarch                          10-4                        pgdg10
pgdg-oraclelinux10.noarch                     10-2                        pgdg10
pgdg-sl10.noarch                              10-2                        pgdg10
pgexportdoc10.x86_64                          0.1.1-1.rhel6               pgdg10
pgexportdoc10-debuginfo.x86_64                0.1.1-1.rhel6               pgdg10
pgfincore10.x86_64                            1.1.2-2.rhel6               pgdg10
pgfincore10-debuginfo.x86_64                  1.1.2-2.rhel6               pgdg10
pgimportdoc10.x86_64                          0.1.2-1.rhel6               pgdg10
pgimportdoc10-debuginfo.x86_64                0.1.2-1.rhel6               pgdg10
pgmemcache-10.x86_64                          2.3.0-2.rhel6               pgdg10
pgmemcache-10-debuginfo.x86_64                2.3.0-2.rhel6               pgdg10
pgpool-II-10.x86_64                           3.7.4-1.rhel6               pgdg10
pgpool-II-10-debuginfo.x86_64                 3.7.4-1.rhel6               pgdg10
pgpool-II-10-devel.x86_64                     3.7.4-1.rhel6               pgdg10
pgpool-II-10-extensions.x86_64                3.7.4-1.rhel6               pgdg10
pgpoolAdmin.noarch                            3.6.0-2.rhel6               pgdg10
pgreplay10.x86_64                             1.3.0-1.rhel6               pgdg10
pgreplay10-debuginfo.x86_64                   1.3.0-1.rhel6               pgdg10
pgsphere10.x86_64                             1.1.1-4.rhel6               pgdg10
pgsphere10-debuginfo.x86_64                   1.1.1-4.rhel6               pgdg10
pgtap10.noarch                                0.98.0-2.rhel6              pgdg10
pgxnclient.x86_64                             1.2.1-2.rhel6               pgdg10
pitrery.noarch                                2.0-2.rhel6                 pgdg10
pldebugger10.x86_64                           1.0-1.rhel6                 pgdg10
pldebugger10-debuginfo.x86_64                 1.0-1.rhel6                 pgdg10
plpgsql_check_10.x86_64                       1.2.1-1.rhel6               pgdg10
plpgsql_check_10-debuginfo.x86_64             1.2.1-1.rhel6               pgdg10
plproxy10.x86_64                              2.8-1.rhel6                 pgdg10
plproxy10-debuginfo.x86_64                    2.8-1.rhel6                 pgdg10
plr10.x86_64                                  8.3.0.17-1.rhel6            pgdg10
plr10-debuginfo.x86_64                        8.3.0.17-1.rhel6            pgdg10
plsh10.x86_64                                 1.20171014-1.rhel6          pgdg10
plsh10-debuginfo.x86_64                       1.20171014-1.rhel6          pgdg10
postgis23_10.x86_64                           2.3.7-1.rhel6               pgdg10
postgis23_10-client.x86_64                    2.3.7-1.rhel6               pgdg10
postgis23_10-devel.x86_64                     2.3.7-1.rhel6               pgdg10
postgis23_10-docs.x86_64                      2.3.7-1.rhel6               pgdg10
postgis23_10-utils.x86_64                     2.3.7-1.rhel6               pgdg10
postgis24_10.x86_64                           2.4.4-1.rhel6               pgdg10
postgis24_10-client.x86_64                    2.4.4-1.rhel6               pgdg10
postgis24_10-debuginfo.x86_64                 2.4.1-1.rhel6               pgdg10
postgis24_10-devel.x86_64                     2.4.4-1.rhel6               pgdg10
postgis24_10-docs.x86_64                      2.4.4-1.rhel6               pgdg10
postgis24_10-utils.x86_64                     2.4.4-1.rhel6               pgdg10
postgresql-jdbc.noarch                        42.2.4-1.rhel6              pgdg10
postgresql-jdbc-javadoc.noarch                42.2.4-1.rhel6              pgdg10
postgresql10.x86_64                           10.4-1PGDG.rhel6            pgdg10
postgresql10-contrib.x86_64                   10.4-1PGDG.rhel6            pgdg10
postgresql10-debuginfo.x86_64                 10.4-1PGDG.rhel6            pgdg10
postgresql10-devel.x86_64                     10.4-1PGDG.rhel6            pgdg10
postgresql10-docs.x86_64                      10.4-1PGDG.rhel6            pgdg10
postgresql10-libs.x86_64                      10.4-1PGDG.rhel6            pgdg10
postgresql10-odbc.x86_64                      10.03.0000-1PGDG.rhel6      pgdg10
postgresql10-plperl.x86_64                    10.4-1PGDG.rhel6            pgdg10
postgresql10-plpython.x86_64                  10.4-1PGDG.rhel6            pgdg10
postgresql10-pltcl.x86_64                     10.4-1PGDG.rhel6            pgdg10
postgresql10-server.x86_64                    10.4-1PGDG.rhel6            pgdg10
postgresql10-tcl.x86_64                       2.4.0-1.rhel6               pgdg10
postgresql10-tcl-debuginfo.x86_64             2.3.1-1.rhel6               pgdg10
postgresql10-test.x86_64                      10.4-1PGDG.rhel6            pgdg10
powa_10.x86_64                                3.1.1-2.rhel6               pgdg10
powa_10-debuginfo.x86_64                      3.1.1-2.rhel6               pgdg10
powa_10-web.x86_64                            3.1.1-2.rhel6               pgdg10
prefix10.x86_64                               1.2.8-1.rhel6               pgdg10
prefix10-debuginfo.x86_64                     1.2.8-1.rhel6               pgdg10
proj49.x86_64                                 4.9.3-3.rhel6               pgdg10
proj49-debuginfo.x86_64                       4.9.3-3.rhel6               pgdg10
proj49-devel.x86_64                           4.9.3-3.rhel6               pgdg10
proj49-epsg.x86_64                            4.9.3-3.rhel6               pgdg10
proj49-nad.x86_64                             4.9.3-3.rhel6               pgdg10
proj49-static.x86_64                          4.9.3-3.rhel6               pgdg10
pspg.x86_64                                   1.1.0-1.rhel6               pgdg10
pspg-debuginfo.x86_64                         1.1.0-1.rhel6               pgdg10
python-ldap2pg.x86_64                         4.11-1.rhel6                pgdg10
python-ldap2pg-doc.x86_64                     4.11-1.rhel6                pgdg10
python-psycopg2.x86_64                        2.7.5-1.rhel6               pgdg10
python-psycopg2-debuginfo.x86_64              2.7.5-1.rhel6               pgdg10
python-psycopg2-doc.x86_64                    2.7.5-1.rhel6               pgdg10
python2-psycopg2-tests.x86_64                 2.7.5-1.rhel6               pgdg10
repmgr10.x86_64                               4.0.6-1.rhel6               pgdg10
repmgr10-debuginfo.x86_64                     4.0.6-1.rhel6               pgdg10
resource-agents-paf.noarch                    1.1.0-1.rhel6               pgdg10
rum_10.x86_64                                 1.1.0-1.rhel6               pgdg10
rum_10-debuginfo.x86_64                       1.1.0-1.rhel6               pgdg10
rum_10-devel.x86_64                           1.1.0-1.rhel6               pgdg10
slony1-10.x86_64                              2.2.6-3.rhel6               pgdg10
slony1-10-debuginfo.x86_64                    2.2.6-3.rhel6               pgdg10
sslutils_10.x86_64                            1.2-1.rhel6                 pgdg10
sslutils_10-debuginfo.x86_64                  1.2-1.rhel6                 pgdg10
table_version10.x86_64                        1.4.2-1.rhel6               pgdg10
tail_n_mail.noarch                            2.3.1-1.rhel6               pgdg10
tds_fdw10.x86_64                              1.0.8-1.rhel6               pgdg10
tds_fdw10-debuginfo.x86_64                    1.0.8-1.rhel6               pgdg10
temboard-agent.noarch                         1.2-1.rhel6                 pgdg10
topn_10.x86_64                                2.0.2-1.rhel6               pgdg10
topn_10-debuginfo.x86_64                      2.0.2-1.rhel6               pgdg10
usda-r18.noarch                               1.0-2.rhel6                 pgdg10
wal2json10.x86_64                             1.0-1.rhel6                 pgdg10
wal2json10-debuginfo.x86_64                   1.0-1.rhel6                 pgdg10
[root@postgresql01 PostgreSQL]# 

安装:

[root@postgresql01 PostgreSQL]# yum list | grep --color pgdg10 | grep server
postgresql10-server.x86_64                    10.4-1PGDG.rhel6            pgdg10
[root@postgresql01 PostgreSQL]# 
[root@postgresql01 PostgreSQL]# yum install -y postgresql10-server
Loaded plugins: product-id, refresh-packagekit, search-disabled-repos, security, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package postgresql10-server.x86_64 0:10.4-1PGDG.rhel6 will be installed
--> Processing Dependency: postgresql10-libs(x86-64) = 10.4-1PGDG.rhel6 for package: postgresql10-server-10.4-1PGDG.rhel6.x86_64
--> Processing Dependency: postgresql10(x86-64) = 10.4-1PGDG.rhel6 for package: postgresql10-server-10.4-1PGDG.rhel6.x86_64
--> Processing Dependency: libpq.so.5()(64bit) for package: postgresql10-server-10.4-1PGDG.rhel6.x86_64
--> Running transaction check
---> Package postgresql10.x86_64 0:10.4-1PGDG.rhel6 will be installed
---> Package postgresql10-libs.x86_64 0:10.4-1PGDG.rhel6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================================
 Package                              Arch                    Version                              Repository               Size
=================================================================================================================================
Installing:
 postgresql10-server                  x86_64                  10.4-1PGDG.rhel6                     pgdg10                  5.0 M
Installing for dependencies:
 postgresql10                         x86_64                  10.4-1PGDG.rhel6                     pgdg10                  1.6 M
 postgresql10-libs                    x86_64                  10.4-1PGDG.rhel6                     pgdg10                  325 k

Transaction Summary
=================================================================================================================================
Install       3 Package(s)

Total download size: 6.9 M
Installed size: 27 M
Downloading Packages:
(1/3): postgresql10-10.4-1PGDG.rhel6.x86_64.rpm                                                           | 1.6 MB     00:54     
(2/3): postgresql10-libs-10.4-1PGDG.rhel6.x86_64.rpm                                                      | 325 kB     00:02     
(3/3): postgresql10-server-10.4-1PGDG.rhel6.x86_64.rpm                                                    | 5.0 MB     00:05     
---------------------------------------------------------------------------------------------------------------------------------
Total                                                                                            109 kB/s | 6.9 MB     01:05     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : postgresql10-libs-10.4-1PGDG.rhel6.x86_64                                                                     1/3 
  Installing : postgresql10-10.4-1PGDG.rhel6.x86_64                                                                          2/3 
  Installing : postgresql10-server-10.4-1PGDG.rhel6.x86_64                                                                   3/3 
  Verifying  : postgresql10-10.4-1PGDG.rhel6.x86_64                                                                          1/3 
  Verifying  : postgresql10-server-10.4-1PGDG.rhel6.x86_64                                                                   2/3 
  Verifying  : postgresql10-libs-10.4-1PGDG.rhel6.x86_64                                                                     3/3 

Installed:
  postgresql10-server.x86_64 0:10.4-1PGDG.rhel6                                                                                  

Dependency Installed:
  postgresql10.x86_64 0:10.4-1PGDG.rhel6                       postgresql10-libs.x86_64 0:10.4-1PGDG.rhel6                      

Complete!
[root@postgresql01 PostgreSQL]# 

安装后,看看安装了哪些内容:

[root@postgresql01 PostgreSQL]# rpm -ql postgresql10-server
/etc/pam.d/postgresql
/etc/rc.d/init.d/postgresql-10
/etc/sysconfig/pgsql
/usr/pgsql-10/bin/initdb
/usr/pgsql-10/bin/pg_controldata
/usr/pgsql-10/bin/pg_ctl
/usr/pgsql-10/bin/pg_resetwal
/usr/pgsql-10/bin/postgres
/usr/pgsql-10/bin/postmaster
/usr/pgsql-10/lib
/usr/pgsql-10/lib/ascii_and_mic.so
/usr/pgsql-10/lib/cyrillic_and_mic.so
/usr/pgsql-10/lib/dict_int.so
/usr/pgsql-10/lib/dict_snowball.so
/usr/pgsql-10/lib/dict_xsyn.so
/usr/pgsql-10/lib/euc2004_sjis2004.so
/usr/pgsql-10/lib/euc_cn_and_mic.so
/usr/pgsql-10/lib/euc_jp_and_sjis.so
/usr/pgsql-10/lib/euc_kr_and_mic.so
/usr/pgsql-10/lib/euc_tw_and_big5.so
/usr/pgsql-10/lib/latin2_and_win1250.so
/usr/pgsql-10/lib/latin_and_mic.so
/usr/pgsql-10/lib/pgoutput.so
/usr/pgsql-10/lib/plpgsql.so
/usr/pgsql-10/lib/utf8_and_ascii.so
/usr/pgsql-10/lib/utf8_and_big5.so
/usr/pgsql-10/lib/utf8_and_cyrillic.so
/usr/pgsql-10/lib/utf8_and_euc2004.so
/usr/pgsql-10/lib/utf8_and_euc_cn.so
/usr/pgsql-10/lib/utf8_and_euc_jp.so
/usr/pgsql-10/lib/utf8_and_euc_kr.so
/usr/pgsql-10/lib/utf8_and_euc_tw.so
/usr/pgsql-10/lib/utf8_and_gb18030.so
/usr/pgsql-10/lib/utf8_and_gbk.so
/usr/pgsql-10/lib/utf8_and_iso8859.so
/usr/pgsql-10/lib/utf8_and_iso8859_1.so
/usr/pgsql-10/lib/utf8_and_johab.so
/usr/pgsql-10/lib/utf8_and_sjis.so
/usr/pgsql-10/lib/utf8_and_sjis2004.so
/usr/pgsql-10/lib/utf8_and_uhc.so
/usr/pgsql-10/lib/utf8_and_win.so
/usr/pgsql-10/share
/usr/pgsql-10/share/conversion_create.sql
/usr/pgsql-10/share/extension
/usr/pgsql-10/share/extension/plpgsql--1.0.sql
/usr/pgsql-10/share/extension/plpgsql--unpackaged--1.0.sql
/usr/pgsql-10/share/extension/plpgsql.control
/usr/pgsql-10/share/information_schema.sql
/usr/pgsql-10/share/locale/cs/LC_MESSAGES/pg_controldata-10.mo
/usr/pgsql-10/share/locale/cs/LC_MESSAGES/plpgsql-10.mo
/usr/pgsql-10/share/locale/de/LC_MESSAGES/pg_controldata-10.mo
/usr/pgsql-10/share/locale/de/LC_MESSAGES/pg_resetwal-10.mo
/usr/pgsql-10/share/locale/de/LC_MESSAGES/plpgsql-10.mo
/usr/pgsql-10/share/locale/de/LC_MESSAGES/postgres-10.mo
/usr/pgsql-10/share/locale/es/LC_MESSAGES/pg_controldata-10.mo
/usr/pgsql-10/share/locale/es/LC_MESSAGES/pg_resetwal-10.mo
/usr/pgsql-10/share/locale/es/LC_MESSAGES/plpgsql-10.mo
/usr/pgsql-10/share/locale/es/LC_MESSAGES/postgres-10.mo
/usr/pgsql-10/share/locale/fr/LC_MESSAGES/pg_controldata-10.mo
/usr/pgsql-10/share/locale/fr/LC_MESSAGES/pg_resetwal-10.mo
/usr/pgsql-10/share/locale/fr/LC_MESSAGES/plpgsql-10.mo
/usr/pgsql-10/share/locale/fr/LC_MESSAGES/postgres-10.mo
/usr/pgsql-10/share/locale/it/LC_MESSAGES/pg_controldata-10.mo
/usr/pgsql-10/share/locale/it/LC_MESSAGES/plpgsql-10.mo
/usr/pgsql-10/share/locale/it/LC_MESSAGES/postgres-10.mo
/usr/pgsql-10/share/locale/ja/LC_MESSAGES/pg_controldata-10.mo
/usr/pgsql-10/share/locale/ja/LC_MESSAGES/pg_resetwal-10.mo
/usr/pgsql-10/share/locale/ja/LC_MESSAGES/plpgsql-10.mo
/usr/pgsql-10/share/locale/ja/LC_MESSAGES/postgres-10.mo
/usr/pgsql-10/share/locale/ko/LC_MESSAGES/pg_controldata-10.mo
/usr/pgsql-10/share/locale/ko/LC_MESSAGES/pg_resetwal-10.mo
/usr/pgsql-10/share/locale/ko/LC_MESSAGES/plpgsql-10.mo
/usr/pgsql-10/share/locale/ko/LC_MESSAGES/postgres-10.mo
/usr/pgsql-10/share/locale/pl/LC_MESSAGES/pg_controldata-10.mo
/usr/pgsql-10/share/locale/pl/LC_MESSAGES/pg_resetwal-10.mo
/usr/pgsql-10/share/locale/pl/LC_MESSAGES/plpgsql-10.mo
/usr/pgsql-10/share/locale/pl/LC_MESSAGES/postgres-10.mo
/usr/pgsql-10/share/locale/pt_BR/LC_MESSAGES/pg_controldata-10.mo
/usr/pgsql-10/share/locale/pt_BR/LC_MESSAGES/pg_resetwal-10.mo
/usr/pgsql-10/share/locale/pt_BR/LC_MESSAGES/plpgsql-10.mo
/usr/pgsql-10/share/locale/ro/LC_MESSAGES/plpgsql-10.mo
/usr/pgsql-10/share/locale/ru/LC_MESSAGES/pg_controldata-10.mo
/usr/pgsql-10/share/locale/ru/LC_MESSAGES/pg_resetwal-10.mo
/usr/pgsql-10/share/locale/ru/LC_MESSAGES/plpgsql-10.mo
/usr/pgsql-10/share/locale/ru/LC_MESSAGES/postgres-10.mo
/usr/pgsql-10/share/locale/sv/LC_MESSAGES/pg_controldata-10.mo
/usr/pgsql-10/share/locale/sv/LC_MESSAGES/pg_resetwal-10.mo
/usr/pgsql-10/share/locale/sv/LC_MESSAGES/plpgsql-10.mo
/usr/pgsql-10/share/locale/sv/LC_MESSAGES/postgres-10.mo
/usr/pgsql-10/share/locale/tr/LC_MESSAGES/pg_controldata-10.mo
/usr/pgsql-10/share/locale/tr/LC_MESSAGES/pg_resetwal-10.mo
/usr/pgsql-10/share/locale/tr/LC_MESSAGES/plpgsql-10.mo
/usr/pgsql-10/share/locale/tr/LC_MESSAGES/postgres-10.mo
/usr/pgsql-10/share/locale/zh_CN/LC_MESSAGES/pg_controldata-10.mo
/usr/pgsql-10/share/locale/zh_CN/LC_MESSAGES/pg_resetwal-10.mo
/usr/pgsql-10/share/locale/zh_CN/LC_MESSAGES/plpgsql-10.mo
/usr/pgsql-10/share/locale/zh_CN/LC_MESSAGES/postgres-10.mo
/usr/pgsql-10/share/locale/zh_TW/LC_MESSAGES/plpgsql-10.mo
/usr/pgsql-10/share/man/man1/initdb.1
/usr/pgsql-10/share/man/man1/pg_controldata.1
/usr/pgsql-10/share/man/man1/pg_ctl.1
/usr/pgsql-10/share/man/man1/pg_resetwal.1
/usr/pgsql-10/share/man/man1/postgres.1
/usr/pgsql-10/share/man/man1/postmaster.1
/usr/pgsql-10/share/pg_hba.conf.sample
/usr/pgsql-10/share/pg_ident.conf.sample
/usr/pgsql-10/share/pg_service.conf.sample
/usr/pgsql-10/share/postgres.bki
/usr/pgsql-10/share/postgres.description
/usr/pgsql-10/share/postgres.shdescription
/usr/pgsql-10/share/postgresql.conf.sample
/usr/pgsql-10/share/psqlrc.sample
/usr/pgsql-10/share/recovery.conf.sample
/usr/pgsql-10/share/snowball_create.sql
/usr/pgsql-10/share/sql_features.txt
/usr/pgsql-10/share/system_views.sql
/usr/pgsql-10/share/timezonesets/Africa.txt
/usr/pgsql-10/share/timezonesets/America.txt
/usr/pgsql-10/share/timezonesets/Antarctica.txt
/usr/pgsql-10/share/timezonesets/Asia.txt
/usr/pgsql-10/share/timezonesets/Atlantic.txt
/usr/pgsql-10/share/timezonesets/Australia
/usr/pgsql-10/share/timezonesets/Australia.txt
/usr/pgsql-10/share/timezonesets/Default
/usr/pgsql-10/share/timezonesets/Etc.txt
/usr/pgsql-10/share/timezonesets/Europe.txt
/usr/pgsql-10/share/timezonesets/India
/usr/pgsql-10/share/timezonesets/Indian.txt
/usr/pgsql-10/share/timezonesets/Pacific.txt
/usr/pgsql-10/share/tsearch_data/danish.stop
/usr/pgsql-10/share/tsearch_data/dutch.stop
/usr/pgsql-10/share/tsearch_data/english.stop
/usr/pgsql-10/share/tsearch_data/finnish.stop
/usr/pgsql-10/share/tsearch_data/french.stop
/usr/pgsql-10/share/tsearch_data/german.stop
/usr/pgsql-10/share/tsearch_data/hungarian.stop
/usr/pgsql-10/share/tsearch_data/hunspell_sample.affix
/usr/pgsql-10/share/tsearch_data/hunspell_sample_long.affix
/usr/pgsql-10/share/tsearch_data/hunspell_sample_long.dict
/usr/pgsql-10/share/tsearch_data/hunspell_sample_num.affix
/usr/pgsql-10/share/tsearch_data/hunspell_sample_num.dict
/usr/pgsql-10/share/tsearch_data/ispell_sample.affix
/usr/pgsql-10/share/tsearch_data/ispell_sample.dict
/usr/pgsql-10/share/tsearch_data/italian.stop
/usr/pgsql-10/share/tsearch_data/norwegian.stop
/usr/pgsql-10/share/tsearch_data/portuguese.stop
/usr/pgsql-10/share/tsearch_data/russian.stop
/usr/pgsql-10/share/tsearch_data/spanish.stop
/usr/pgsql-10/share/tsearch_data/swedish.stop
/usr/pgsql-10/share/tsearch_data/synonym_sample.syn
/usr/pgsql-10/share/tsearch_data/thesaurus_sample.ths
/usr/pgsql-10/share/tsearch_data/turkish.stop
/usr/pgsql-10/share/tsearch_data/unaccent.rules
/usr/pgsql-10/share/tsearch_data/xsyn_sample.rules
/var/lib/pgsql
/var/lib/pgsql/10
/var/lib/pgsql/10/backups
/var/lib/pgsql/10/data
/var/run/postgresql
[root@postgresql01 PostgreSQL]# 

[root@postgresql01 PostgreSQL]# rpm -ql postgresql10-server | grep "etc"
/etc/pam.d/postgresql
/etc/rc.d/init.d/postgresql-10
/etc/sysconfig/pgsql
[root@postgresql01 PostgreSQL]# 

当前服务是停止的:

[root@postgresql01 PostgreSQL]# service postgresql-10 status
postgresql-10 is stopped
[root@postgresql01 PostgreSQL]# 

初始化PostgreSQL。

方法一:

[root@postgresql01 ~]# cd /usr/pgsql-10/
[root@postgresql01 pgsql-10]# ls -ltr
total 12
drwxr-xr-x 2 root root 4096 Jul 23 14:48 bin
drwxr-xr-x 2 root root 4096 Jul 23 14:48 lib
drwxr-xr-x 7 root root 4096 Jul 23 14:48 share
[root@postgresql01 pgsql-10]# 
[root@postgresql01 pgsql-10]# ls -ltr bin/
total 9332
-rwxr-xr-x 1 root root 6958824 May 10 03:19 postgres
-rwxr-xr-x 1 root root   61392 May 10 03:19 vacuumdb
-rwxr-xr-x 1 root root  584976 May 10 03:19 psql
-rwxr-xr-x 1 root root   21392 May 10 03:19 pg_test_timing
-rwxr-xr-x 1 root root   27824 May 10 03:19 pg_test_fsync
-rwxr-xr-x 1 root root   77424 May 10 03:19 pg_rewind
-rwxr-xr-x 1 root root   66704 May 10 03:19 pg_receivewal
-rwxr-xr-x 1 root root   49176 May 10 03:19 pg_isready
-rwxr-xr-x 1 root root   89432 May 10 03:19 pg_dumpall
-rwxr-xr-x 1 root root  379544 May 10 03:19 pg_dump
-rwxr-xr-x 1 root root   52792 May 10 03:19 pg_ctl
-rwxr-xr-x 1 root root   36216 May 10 03:19 pg_controldata
-rwxr-xr-x 1 root root   26016 May 10 03:19 pg_config
-rwxr-xr-x 1 root root  123480 May 10 03:19 pgbench
-rwxr-xr-x 1 root root  108224 May 10 03:19 pg_basebackup
-rwxr-xr-x 1 root root  119456 May 10 03:19 initdb
-rwxr-xr-x 1 root root   48720 May 10 03:19 dropdb
-rwxr-xr-x 1 root root   53008 May 10 03:19 createdb
-rwxr-xr-x 1 root root   53040 May 10 03:19 clusterdb
-rwxr-xr-x 1 root root   57104 May 10 03:19 reindexdb
-rwxr-xr-x 1 root root   74720 May 10 03:19 pg_waldump
-rwxr-xr-x 1 root root  118776 May 10 03:19 pg_upgrade
-rwxr-xr-x 1 root root  152048 May 10 03:19 pg_restore
-rwxr-xr-x 1 root root   45048 May 10 03:19 pg_resetwal
-rwxr-xr-x 1 root root   23504 May 10 03:19 pg_archivecleanup
-rwxr-xr-x 1 root root   48688 May 10 03:19 dropuser
-rwxr-xr-x 1 root root   57464 May 10 03:19 createuser
lrwxrwxrwx 1 root root       8 Jul 23 14:48 postmaster -> postgres
[root@postgresql01 pgsql-10]# 

[root@postgresql01 pgsql-10]# id postgres
uid=26(postgres) gid=26(postgres) groups=26(postgres)
[root@postgresql01 pgsql-10]# 

[root@postgresql01 pgsql-10]# mkdir /postgresql_data
[root@postgresql01 pgsql-10]# 

[root@postgresql01 pgsql-10]# chown -R postgres.postgres /postgresql_data/
[root@postgresql01 pgsql-10]# 
[root@postgresql01 pgsql-10]# su - postgres
-bash-4.1$ 
-bash-4.1$ /usr/pgsql-10/bin/initdb /postgresql_data/
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /postgresql_data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    /usr/pgsql-10/bin/pg_ctl -D /postgresql_data/ -l logfile start

-bash-4.1$ 

-bash-4.1$ ls -ltr /postgresql_data/
total 112
drwx------ 2 postgres postgres  4096 Jul 23 14:58 pg_twophase
drwx------ 2 postgres postgres  4096 Jul 23 14:58 pg_tblspc
drwx------ 2 postgres postgres  4096 Jul 23 14:58 pg_snapshots
drwx------ 2 postgres postgres  4096 Jul 23 14:58 pg_serial
drwx------ 2 postgres postgres  4096 Jul 23 14:58 pg_replslot
drwx------ 4 postgres postgres  4096 Jul 23 14:58 pg_multixact
drwx------ 2 postgres postgres  4096 Jul 23 14:58 pg_dynshmem
drwx------ 2 postgres postgres  4096 Jul 23 14:58 pg_commit_ts
drwx------ 2 postgres postgres  4096 Jul 23 14:58 pg_stat_tmp
drwx------ 2 postgres postgres  4096 Jul 23 14:58 pg_stat
-rw------- 1 postgres postgres     3 Jul 23 14:58 PG_VERSION
-rw------- 1 postgres postgres 22761 Jul 23 14:58 postgresql.conf
-rw------- 1 postgres postgres    88 Jul 23 14:58 postgresql.auto.conf
-rw------- 1 postgres postgres  1636 Jul 23 14:58 pg_ident.conf
-rw------- 1 postgres postgres  4513 Jul 23 14:58 pg_hba.conf
drwx------ 3 postgres postgres  4096 Jul 23 14:58 pg_wal
drwx------ 2 postgres postgres  4096 Jul 23 14:58 pg_xact
drwx------ 2 postgres postgres  4096 Jul 23 14:58 pg_subtrans
drwx------ 2 postgres postgres  4096 Jul 23 14:58 pg_notify
drwx------ 2 postgres postgres  4096 Jul 23 14:59 global
drwx------ 5 postgres postgres  4096 Jul 23 14:59 base
drwx------ 4 postgres postgres  4096 Jul 23 14:59 pg_logical
-bash-4.1$ 

方法二:

[root@postgresql01 pgsql-10]# service postgresql-10 status
postgresql-10 is stopped
[root@postgresql01 pgsql-10]# 
[root@postgresql01 pgsql-10]# service postgresql-10 initdb
Initializing database:                                     [  OK  ]
[root@postgresql01 pgsql-10]# 

启动服务:

[root@postgresql01 pgsql-10]# service postgresql-10 status
postgresql-10 is stopped
[root@postgresql01 pgsql-10]# 
[root@postgresql01 pgsql-10]# service postgresql-10 start
Starting postgresql-10 service:                            [  OK  ]
[root@postgresql01 pgsql-10]# 
[root@postgresql01 pgsql-10]# service postgresql-10 status
postgresql-10 (pid  28532) is running...
[root@postgresql01 pgsql-10]# 

启动后,查看系统状态:

[root@postgresql01 pgsql-10]# ps -ef | grep pgsql
postgres 28532     1  1 15:03 ?        00:00:01 /usr/pgsql-10/bin/postmaster -D /var/lib/pgsql/10/data
root     28576 27832  0 15:05 pts/1    00:00:00 grep pgsql
[root@postgresql01 pgsql-10]# 
[root@postgresql01 pgsql-10]# netstat -tupln | grep postmaster
tcp        0      0 127.0.0.1:5432              0.0.0.0:*                   LISTEN      28532/postmaster    
[root@postgresql01 pgsql-10]# 

数据目录状态:

[root@postgresql01 ~]# ls -ltr /var/lib/pgsql/10/data
total 128
drwx------ 2 postgres postgres  4096 Jul 23 15:02 pg_commit_ts
drwx------ 2 postgres postgres  4096 Jul 23 15:02 pg_twophase
drwx------ 2 postgres postgres  4096 Jul 23 15:02 pg_snapshots
drwx------ 2 postgres postgres  4096 Jul 23 15:02 pg_serial
drwx------ 4 postgres postgres  4096 Jul 23 15:02 pg_multixact
drwx------ 2 postgres postgres  4096 Jul 23 15:02 pg_dynshmem
-rw------- 1 postgres postgres     3 Jul 23 15:02 PG_VERSION
drwx------ 2 postgres postgres  4096 Jul 23 15:02 pg_tblspc
drwx------ 2 postgres postgres  4096 Jul 23 15:02 pg_stat
drwx------ 2 postgres postgres  4096 Jul 23 15:02 pg_replslot
-rw------- 1 postgres postgres 22761 Jul 23 15:02 postgresql.conf
-rw------- 1 postgres postgres    88 Jul 23 15:02 postgresql.auto.conf
-rw------- 1 postgres postgres  4269 Jul 23 15:02 pg_hba.conf
-rw------- 1 postgres postgres  1636 Jul 23 15:02 pg_ident.conf
drwx------ 3 postgres postgres  4096 Jul 23 15:02 pg_wal
drwx------ 2 postgres postgres  4096 Jul 23 15:02 pg_xact
drwx------ 2 postgres postgres  4096 Jul 23 15:02 pg_subtrans
drwx------ 5 postgres postgres  4096 Jul 23 15:02 base
drwx------ 4 postgres postgres  4096 Jul 23 15:02 pg_logical
drwx------ 2 postgres postgres  4096 Jul 23 15:03 pg_notify
drwx------ 2 postgres postgres  4096 Jul 23 15:03 log
-rw------- 1 postgres postgres    57 Jul 23 15:03 postmaster.opts
-rw------- 1 postgres postgres    30 Jul 23 15:03 current_logfiles
drwx------ 2 postgres postgres  4096 Jul 23 15:03 global
-rw------- 1 postgres postgres   104 Jul 23 15:03 postmaster.pid
drwx------ 2 postgres postgres  4096 Jul 23 15:05 pg_stat_tmp
[root@postgresql01 ~]# 
[root@postgresql01 ~]# ls -ltr /var/lib/pgsql/10/data/log/
total 4
-rw------- 1 postgres postgres 188 Jul 23 15:03 postgresql-Mon.log
[root@postgresql01 ~]# 

日志:

[root@postgresql01 ~]# cat /var/lib/pgsql/10/data/log/postgresql-Mon.log 
2018-07-23 15:03:48.282 CST [28535] LOG:  database system was shut down at 2018-07-23 15:02:46 CST
2018-07-23 15:03:48.303 CST [28532] LOG:  database system is ready to accept connections
[root@postgresql01 ~]# 

访问:PostgreSQL:

[root@postgresql01 ~]# ls /home/
[root@postgresql01 ~]# 
[root@postgresql01 ~]# mkdir /home/postgres
[root@postgresql01 ~]# cp ~/.bash_profile /home/postgres/
[root@postgresql01 ~]# 
[root@postgresql01 ~]# chown -R postgres.postgres /home/postgres/
[root@postgresql01 ~]# 
[root@postgresql01 ~]# vi /home/postgres/.bash_profile 
[root@postgresql01 ~]# cat /home/postgres/.bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=/usr/pgsql-10/bin:$PATH:$HOME/bin

export PATH
[root@postgresql01 ~]# 
[root@postgresql01 ~]# su - postgres
-bash-4.1$ 
-bash-4.1$ whereis psql
psql: /usr/bin/psql /usr/share/man/man1/psql.1
-bash-4.1$ 
-bash-4.1$ psql
psql (10.4)
Type "help" for help.

postgres=# \l
                                  List of databases
   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)

postgres=# create database adamhuan;
CREATE DATABASE
postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 adamhuan  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 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
(4 rows)

postgres=# select * from pg_stat_activity;
 datid | datname  |  pid  | usesysid | usename  | application_name | client_addr | client_hostname | client_port |         backen
d_start         |          xact_start           |          query_start          |         state_change          | wait_event_type
 |     wait_event      | state  | backend_xid | backend_xmin |              query              |    backend_type     
-------+----------+-------+----------+----------+------------------+-------------+-----------------+-------------+---------------
----------------+-------------------------------+-------------------------------+-------------------------------+----------------
-+---------------------+--------+-------------+--------------+---------------------------------+---------------------
       |          | 28539 |          |          |                  |             |                 |             | 2018-07-23 15:
03:48.305104+08 |                               |                               |                               | Activity       
 | AutoVacuumMain      |        |             |              |                                 | autovacuum launcher
       |          | 28541 |       10 | postgres |                  |             |                 |             | 2018-07-23 15:
03:48.329337+08 |                               |                               |                               | Activity       
 | LogicalLauncherMain |        |             |              |                                 | background worker
 13457 | postgres | 28709 |       10 | postgres | psql             |             |                 |          -1 | 2018-07-23 15:
13:41.215548+08 | 2018-07-23 15:16:48.500455+08 | 2018-07-23 15:16:48.500455+08 | 2018-07-23 15:16:48.500459+08 |                
 |                     | active |             |          556 | select * from pg_stat_activity; | client backend
       |          | 28537 |          |          |                  |             |                 |             | 2018-07-23 15:
03:48.331344+08 |                               |                               |                               | Activity       
 | BgWriterMain        |        |             |              |                                 | background writer
       |          | 28536 |          |          |                  |             |                 |             | 2018-07-23 15:
03:48.332912+08 |                               |                               |                               | Activity       
 | CheckpointerMain    |        |             |              |                                 | checkpointer
       |          | 28538 |          |          |                  |             |                 |             | 2018-07-23 15:
03:48.330453+08 |                               |                               |                               | Activity       
 | WalWriterMain       |        |             |              |                                 | walwriter
(6 rows)

postgres=# 
postgres=# \q
-bash-4.1$ exit
logout
[root@postgresql01 ~]# 

——————————————
Done。

说点什么

avatar

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

  Subscribe  
提醒