[英]Local authentication on postgres failing
我正在嘗試配置一個由 cron 定期運行的腳本。 我更新了 Postgres 配置以信任本地連接,但我收到了對等身份驗證錯誤。
ubuntu@ubuntu:~$ sudo /data/postgresql-backup.sh
pg_dump: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: Peer authentication failed for user "rails_admin"
# If you want to allow non-local connections, you need to add more
# "host" records. In that case you will also need to make PostgreSQL
# listen on a non-local interface via the listen_addresses
# configuration parameter, or via the -i or -h command line switches.
host all all 0.0.0.0/0 md5
host all all ::/0 md5
host all all 127.0.0.1/32 trust
# DO NOT DISABLE!
# If you change this first entry you will need to make sure that the
# database superuser can access the database using some other method.
# Noninteractive access to all databases is required during automatic
# maintenance (custom daily cronjobs, replication, and similar tasks).
#
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
#host all all 127.0.0.1/32 scram-sha-256
# IPv6 local connections:
host all all ::1/128 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 scram-sha-256
host replication all ::1/128 scram-sha-256
#!/bin/bash
BACKUP_DIR="/data/psql-db-backup/"
FILE_NAME=$BACKUP_DIR`date +%d-%m-%Y-%I-%M-%S-%p`.sql
pg_dump -U rails_admin rails_production_db > $FILE_NAME
您只能以操作系統用戶rails_admin
的身份運行該腳本,因為只允許該用戶使用peer
身份驗證進行連接。
您可以放寬peer
trust
(如果您信任數據庫服務器計算機上的所有操作系統用戶),或者您可以將用戶名 map添加到pg_ident.conf
以允許操作系統用戶作為數據庫用戶rails_admin
連接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.