• IDEA连接linux下的Postgresql时报错


    错误提示:

    Connection to 192.168.10.106:5432 refused.  Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

    这语句翻译下,用户名密码是正确的,但是tcp/ip的连接失败了。这个解决方法其实就是去建立tcp/ip连接过程。

    原因是宿主机并没有监听其他的主机接口,因此没有建立连接。

    默认postgresql 监听在127.0.0.1 的5432端口

    1. 我们要修改配置文件,让它监听到所有外部ip请求,

    修改配置文件/etc/postgresql/13/main/postgresql.conf

    在listen_addresses注释这一行下面,加一行配置

    listen_addresses='*'

    表示监听所有ip过来的请求。

    如果你只想对内网提供访问,可以改成一个内网ip地址,比如 192.168.10.106 。

    2. 然后修改密码加密方式为:

    password_encryption = scram-sha-256 # md5 or scram-sha-256

    3. 接下来修改 允许访问配置pg_hba.conf

    打开配置文件 /etc/postgresql/13/main/pg_hba.conf

    加一行

    host        all                all                 0.0.0.0/0                 md5

    说明:在配置文件最后有IPV4和IPV6的配置,新增一行(这里我用的IPV4,开放所有IP)

    host all all 0.0.0.0/0 md5

    该配置为允许所有IP访问

    另外:

    32 -> 192.168.1.1/32 表示必须是来自这个IP地址的访问才合法;

    24 -> 192.168.1.0/24 表示只要来自192.168.1.0 ~ 192.168.1.255的都合法;

    16 -> 192.168.0.0/16 表示只要来自192.168.0.0 ~ 192.168.255.255的都合法;

    8 -> 192.0.0.0/16 表示只要来自192.0.0.0 ~ 192.255.255.255的都合法;

    0 -> 0.0.0.0/0 表示全部IP地址都合法。

    4. 重启生效

    数据库配置,访问授权都搞好了,接下来就重启服务吧

    systemctl restart postgresql

    查看端口启动

    netstat -lantp #查看端口是否启动

    ps aux | grep postgres #查看数据库服务是否启动

    REF

    https://www.jianshu.com/p/f5a807250ab3
    https://blog.csdn.net/a654540233/article/details/115458860
    https://blog.csdn.net/qq_40907977/article/details/101347148

  • 相关阅读:
    Linux 安装 jdk 后 jps 出现问题/usr/jdk1.8.0_151/bin/jps: /lib/ld-linux.so.2: bad ELF interpreter: No such
    Jackson 注解
    Git 右键添加Git Bash
    No validator could be found for constraint
    rror querying database. Cause: java.sql.SQLException: null, message from server: "Host '192.168.30.1' is not allowed to connect to this MySQL server"
    Linux 安装 Mysql-5.7.23-linux-glibc2
    Promise
    PAT(B) 1094 谷歌的招聘(Java)
    PAT(B) 1074 宇宙无敌加法器(Java)
    PAT(B) 1078 字符串压缩与解压(Java)
  • 原文地址:https://www.cnblogs.com/arxive/p/16753934.html
Copyright © 2020-2023  润新知