很多工具不太支持PG17,看了下要
WINDOS测试链接

查看端口
[shark@sharkdb=>~]$pg_isready/tmp:5432- accepting connections
查看PG日志
2024-11-22 05:23:27.361 CST [113921] LOG: invalid authentication method"192.168.2.0/24"2024-11-22 05:23:27.361 CST [113921] CONTEXT: line 117 of configurationfile "/Program/pg17/pg_data/pg_hba.conf"2024-11-22 05:23:27.361 CST [113921] FATAL: could notload/Program/pg17/pg_data/pg_hba.conf2024-11-2205:23:27.363CST [113921]LOG:databasesystemisshut down
修改PG_HDB.CONF
# TYPE DATABASE USER ADDRESS METHOD# "local" is for Unix domain socket connections onlylocalallalltrust# IPv4 local connections:hostallall127.0.0.1/32 trusthostallall192.168.2.0/24 trust# IPv6 local connections:hostallall::1/128 trust# Allow replication connections from localhost, by a user with the# replication privilege.localreplicationalltrusthostreplicationall127.0.0.1/32 trusthostreplicationall::1/128 trust
在IPV4添加:
host all all 192.168.2.0/24 trust
pg_hba.conf中的规则格式解读
-
TYPE:指定规则的类型,常见的有
local(本地连接)、host(TCP/IP连接)和hostssl(仅限SSL加密的TCP/IP连接)。 -
DATABASE:指定规则适用的数据库名称,可以使用
all表示所有数据库。 -
USER:指定规则适用的用户名,可以使用
all表示所有用户。 -
ADDRESS:指定客户端的IP地址或子网,可以使用CIDR表示法(如
192.168.1.0/24)。 -
METHOD:指定认证方法,常见的有
trust(无密码认证)、md5(MD5密码认证)、password(明文密码认证)等。
认证方法的类型与选择
选择合适的认证方法对于确保数据库的安全性至关重要。以下是一些常用的认证方法及其特点:
-
trust:允许任何用户无需密码即可连接。适用于测试环境,但在生产环境中应谨慎使用。
-
md5:使用MD5哈希值进行密码验证,安全性较高,适用于大多数生产环境。
-
password:使用明文密码进行验证,安全性较低,不推荐在生产环境中使用。
-
scram-sha-256:使用SCRAM-SHA-256协议进行密码验证,安全性更高,适用于对安全性要求较高的场景。
-
cert:使用SSL证书进行身份验证,适用于需要高度安全性的环境。
配置pg_hba.conf文件以允许特定IP地址和用户连接,可以通过以下步骤实现:
-
确定连接类型:根据连接方式选择
local、host或hostssl。 -
指定数据库和用户:明确规则适用的数据库和用户。
-
设置IP地址:使用CIDR表示法指定允许连接的IP地址或子网。
-
选择认证方法:根据安全需求选择合适的认证方法。
# 允许本地用户无密码连接localallalltrust# 允许来自192.168.1.0/24子网的用户通过TCP/IP连接,并使用MD5密码认证hostallall192.168.1.0/24 md5# 允许来自10.0.0.0/8子网的用户通过SSL连接,并使用SCRAM-SHA-256认证hostsslallall10.0.0.0/8 scram-sha-256
重启后本地无法登陆
Connection options:-h,--host=HOSTNAME database server host or socket directory-p,--port=PORT database server port-U,--username=USERNAME database user name-w,--no-password never prompt for password-W,--password force password prompt (should happen automatically)
[shark@sharkdb=>pg_data]$pgsql -h192.168.2.178-p5432-U shark -W123456Password:pgsql: error: connection to server at"192.168.2.178", port5432failed: 拒绝连接Is the server running on that hostandaccepting TCP/IP connections?
修改核心配置POSTGRESQL.CONF
# - Connection Settings -listen_addresses = '192.168.2.0/24' # what IP address(es) to listen on;# comma-separated list of addresses;# defaults to 'localhost'; use '*' for all# (change requires restart)port = 5432 # (change requires restart)max_connections = 100 # (change requires restart)
居然不支持网段:
2024-11-22 06:17:12.626 CST [116588] WARNING: could not create listen socket for "192.168.2.0/24"2024-11-22 06:17:12.626 CST [116588] FATAL: could not create any TCP/IP sockets2024-11-22 06:17:12.630 CST [116588] LOG: database system is shut down
哦搞错了 listen_addresses 应该是服务器要监控哪个IP,这个IP是服务器对外服务的IP.
listen_addresses = '192.168.2.178' # what IP address(es) to listen on;
换成真实IP就OK
[shark@sharkdb=>pg_data]$pgsql -h 192.168.2.178 -p 5432 -U shark -W "123456" -d testdbpgsql: warning: extra command-line argument "123456" ignoredPassword:pgsql (17.1)Type "help" for help.SHARKSQL> quit[shark@sharkdb=>pg_data]$pgsql -h 192.168.2.178 -p 5432 -U shark -w 123456 -d testdbpgsql: warning: extra command-line argument "123456" ignoredpgsql (17.1)Type "help" for help.SHARKSQL>
TMD PGADMIN4


NAVICAT PREMIUM


给业务用户授权
SHARKSQL> grant all on database postgres to shark;GRANTTime: 54.094 ms
查看表结构:
SHARKSQL> \d pg_database;Table "pg_catalog.pg_database"Column | Type | Collation | Nullable | Default----------------+-----------+-----------+----------+---------oid | oid | | not null |datname | name | | not null |datdba | oid | | not null |encoding | integer | | not null |datlocprovider | "char" | | not null |datistemplate | boolean | | not null |datallowconn | boolean | | not null |dathasloginevt | boolean | | not null |datconnlimit | integer | | not null |datfrozenxid | xid | | not null |datminmxid | xid | | not null |dattablespace | oid | | not null |datcollate | text | C | not null |datctype | text | C | not null |datlocale | text | C | |daticurules | text | C | |datcollversion | text | C | |datacl | aclitem[] | | |
没有列:datlastsysoid
下载最新的NAVICAT17
navicat17_pgsql_cs_x64

PGADMIN版本:

去官网下载最新的:
https://www.pgadmin.org/download/pgadmin-4-windows/
![]()

NND不支持WIN7
么要WIN10,要么PG17修改了元数据的字段
PG17配置与认证方法解析

被折叠的 条评论
为什么被折叠?



