大网数据广告活动
服务器运维问答

Backing up PostgreSQL - being prompted for password

· 52CE 我爱测

OS: Ubuntu Xenial 16.04 LTS PostgreSQL Version: 9.5.4 I am trying to set up automatic database backups on my server, and every time I run pg_dump , it tells me that no password was supplied. Here's the command I'm using to test: …

问题原文

原帖链接 · Alexander · CC BY-SA 3.0

OS: Ubuntu Xenial 16.04 LTS

PostgreSQL Version: 9.5.4

I am trying to set up automatic database backups on my server, and every time I run pg_dump, it tells me that no password was supplied. Here's the command I'm using to test:

pg_dump --host $DB_HOST --port 5432 --username $DB_USER --no-password  --format custom --blobs --verbose --file ~/backups/postgresql/test.backup $DB_NAME

All of my environment variables are working just fine. To supply PostgreSQL with the password, I've created a .pgpass file in ~/.pgpass. Here's what it looks like:

# hostname:port:database:username:password $DB_HOST:5432:$DB_NAME:$DB_USER:$DB_PASS

The file has 0600 permissions, as specified in the guide. Yet, for some reason, it's not using the password whenever I run pg_dump. I've looked at other answers and multiple guides online but still can't figure out what the problem is.

Any help would be greatly appreciated.

已采纳解答

原帖链接 · Tometzky · CC BY-SA 3.0

You need to have literal values in ~/.pgpass, not shell variables like $DB_HOST.

If you need environment variables then you can use these supported by libpq (PostgreSQL client library) like $PGDATABASE or $PGPASSWORD. There are many others. You won't need ~/.pgpass at all is you use them.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-10-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。