PostgreSQL配置127.0.0.1登录

PostgreSQL配置127.0.0.1登录

𝓓𝓸𝓷 Lv6

配置PG localhost本机TCP/IP登录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
[postgres@server ~]$ psql -h 127.0.0.1 -U admin -p 5432 -d mydb
psql: could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?

(1)确认postgre服务正常运行
[postgres@server ~]$ ps -ef|grep -v grep|grep postgres:
postgres 5195 5193 0 11:20 ? 00:00:00 postgres: checkpointer process
postgres 5196 5193 0 11:20 ? 00:00:00 postgres: writer process
postgres 5197 5193 0 11:20 ? 00:00:00 postgres: wal writer process
postgres 5198 5193 0 11:20 ? 00:00:00 postgres: autovacuum launcher process
postgres 5199 5193 0 11:20 ? 00:00:00 postgres: archiver process
postgres 5200 5193 0 11:20 ? 00:00:00 postgres: stats collector process
postgres 5201 5193 0 11:20 ? 00:00:00 postgres: bgworker: logical replication launcher

(2)修改postgresql.conf配置文件
[postgres@server ~]$ vi $PGDATA/postgresql.conf
listen_addresses = '192.168.1.136, 127.0.0.1'

(4)修改防火墙配置文件,添加以下内容
[postgres@server ~]$ vi $PGDATA/pg_hba.conf
host all all 127.0.0.1/32 trust

(5)重启PG
[postgres@server ~]$ vi $PGDATA/pg_hba.conf

(6)登录验证
[postgres@server ~]$ psql -h 127.0.0.1 -U admin -p 5432 -d mydb
psql (10.12)
Type "help" for help.

mydb=>
  • Title: PostgreSQL配置127.0.0.1登录
  • Author: 𝓓𝓸𝓷
  • Created at : 2024-06-18 21:16:30
  • Updated at : 2024-07-26 11:34:48
  • Link: https://www.zhangdong.me/postgresql-localhost-login.html
  • License: This work is licensed under CC BY-NC-SA 4.0.
评论