Script-Collected/sh/db/init_postgresql_bug.sh

26 lines
1007 B
Bash

#!/bin/bash
# 修复 PostgreSQL 密码认证问题
# 1. 为 postgres 用户设置密码
POSTGRES_PASSWORD="YourStrongPassword@123"
sudo -u postgres psql <<EOF
ALTER USER postgres WITH PASSWORD '${POSTGRES_PASSWORD}';
ALTER USER "1825713423" WITH PASSWORD 'hsc1825713423';
EOF
# 2. 确保 pg_hba.conf 配置正确
sudo -u postgres cat > /data/postgresql/pg_hba.conf <<EOF
# TYPE DATABASE USER ADDRESS METHOD
local all postgres scram-sha-256
local all all scram-sha-256
host all all 127.0.0.1/32 scram-sha-256
host all all ::1/128 scram-sha-256
host all all 0.0.0.0/0 scram-sha-256
EOF
# 3. 重启服务
sudo systemctl restart postgresql-14
# 4. 验证连接
echo "验证 postgres 用户连接..."
psql -U postgres -h 127.0.0.1 -c "SELECT version();" -W