Skip to content

Commit 7b3b022

Browse files
committed
update postgres config
1 parent cf7d02d commit 7b3b022

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,12 @@ docker-compose up -d
6666
```bash
6767
git stash push -- docker-compose.yml
6868
```
69+
70+
### postgres 修改密码
71+
72+
```bash
73+
docker-compose exec postgres sh
74+
psql -U postgres
75+
ALTER USER postgres WITH PASSWORD 'postgres';
76+
# 注:密码postgres要用引号引起来; 命令最后有分号
77+
```

docker-compose.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ services:
2929
restart: always
3030
image: postgres:latest
3131
container_name: postgres
32+
command: postgres -c config_file=/var/lib/postgresql/postgresql.conf
3233
volumes:
3334
- pgdata:/var/lib/postgresql
34-
ports:
35-
- '5432:5432'
35+
- ./postgres/postgresql.conf:/var/lib/postgresql/postgresql.conf:ro
36+
- ./postgres/pg_hba.conf:/var/lib/postgresql/pg_hba.conf:ro
37+
# ports:
38+
# - '5432:5432'
3639
environment:
3740
- POSTGRES_USER=${DATABASE_USER}
3841
- POSTGRES_PASSWORD=${DATABASE_PASSWORD}

postgres/pg_hba.conf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# TYPE DATABASE USER ADDRESS METHOD
2+
3+
# "local" is for Unix domain socket connections only
4+
# 容器内
5+
local all all trust
6+
# local all all scram-sha-256
7+
8+
# Docker 内网
9+
host all all 172.16.0.0/12 scram-sha-256
10+
11+
# 本机
12+
# IPv4 local connections:
13+
host all all 127.0.0.1/32 scram-sha-256
14+
# IPv6 local connections:
15+
host all all ::1/128 scram-sha-256
16+
17+
# Allow replication connections from localhost, by a user with the
18+
# replication privilege.
19+
local replication all scram-sha-256
20+
host replication all 127.0.0.1/32 scram-sha-256
21+
host replication all ::1/128 scram-sha-256
22+
23+
host all all all scram-sha-256

postgres/postgresql.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
listen_addresses='*'
2+
hba_file='/var/lib/postgresql/pg_hba.conf'
3+
password_encryption='scram-sha-256'

0 commit comments

Comments
 (0)