Redhat Linux Server 7.4 安装postgresql 10

安装Postgresql

  1. 安装对当于前版本的 repository RPM:

    yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-redhat10-10-2.noarch.rpm

  2. 安装postgresql 10 服务器包 和客户端包

    yum install postgresql10-server

    yum install postgresql10

  3. 初始化数据库

    /usr/pgsql-10/bin/postgresql-10-setup initdb

  4. 启动postgresql 服务

    systemctl start postgresql-10

  5. 将postgresql服务开机自启动项服务(可选)

    systemctl enable postgresql-10

Postgresql远程连接配置

  1. 修改用户密码

    su – postgres 

    切换用户,执行后提示符会变为 ‘-bash-4.2$’

    psql -U postgres

    登录数据库,执行后提示符变为 ‘postgres=#’

    ALTER USER postgres WITH PASSWORD 123456;   

    设置postgres用户密码为123456

    \q 

    退出数据库

  2. 开启远程访问

    vi /var/lib/pgsql/10/data/postgresql.conf

    修改#listen_addresses = ‘localhost’

    为 listen_addresses=’*’

    当然,此处’*’也可以改为任何你想开放的服务器IP

  3. 设置信认连接

    vi /var/lib/pgsql/10/data/pg_hba.conf

        修改如下内容,信任指定服务器连接

        # IPv4 local connections:

        host    all            all      127.0.0.1/32      ident

        host all all
    0.0.0.0/0 (也可设定为只需要连接的服务器IP) md5

  4. 重启服务

    systemctl restart postgresql-10

测试连接:

安装过程中遇面的问题及解决方法:

安装中无法找到package, 这是因为repository 中对应的$releasever 不能正确的解晰成对应的系统版本而造成的。解决办法是直接 $releasever改为系统版本。

[root@lux01 download]# yum install postgresql10

Loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

Loading mirror speeds from cached hostfile

* epel: mirrors.yun-idc.com

* remi-php73: mirrors.tuna.tsinghua.edu.cn

* remi-safe: mirrors.tuna.tsinghua.edu.cn

* webtatic: us-east.repo.webtatic.com

https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-%24releasever-x86_64/repodata/repomd.xml: [Errno 14] HTTPS Error 404 – Not Found

Trying other mirror.

To address this issue please refer to the below wiki article

https://wiki.centos.org/yum-errors

If above article doesn’t help to resolve this issue please use https://bugs.centos.org/.

https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-%24releasever-x86_64/repodata/repomd.xml: [Errno 14] HTTPS Error 404 – Not Found

Trying other mirror.

One of the configured repositories failed (PostgreSQL 11 for RHEL/CentOS $releasever – x86_64),

and yum doesn’t have enough cached data to continue. At this point the only

safe thing yum can do is fail. There are a few ways to work “fix” this:

1. Contact the upstream for the repository and get them to fix the problem.

2. Reconfigure the baseurl/etc. for the repository, to point to a working

upstream. This is most often useful if you are using a newer

distribution release than is supported by the repository (and the

packages for the previous distribution release still work).

3. Run the command with the repository temporarily disabled

yum –disablerepo=pgdg11 …

4. Disable the repository permanently, so yum won’t use it by default. Yum

will then just ignore the repository until you permanently enable it

again or use –enablerepo for temporary usage:

yum-config-manager –disable pgdg11

or

subscription-manager repos –disable=pgdg11

5. Configure the failing repository to be skipped, if it is unavailable.

Note that yum will try to contact the repo. when it runs most commands,

so will have to try and fail each time (and thus. yum will be be much

slower). If it is a very temporary problem though, this is often a nice

compromise:

yum-config-manager –save –setopt=pgdg11.skip_if_unavailable=true

failure: repodata/repomd.xml from pgdg11: [Errno 256] No more mirrors to try.

https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-$releasever-x86_64/repodata/repomd.xml: [Errno 14] HTTPS Error 404 – Not Found

解决方法:

  1. 执行完 yum install postgresql10
  2. 查找对应的repo 文件,将文件中的releasever 改为系统版本, 如7


需要将repo 文件中的releasever都改正过来


保存后,重新执行 yum install postgresql10 ,问题应该 可以解决。

Leave a Comment