0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

.pgpass を設定しても postgresql に接続できなかった

0
Last updated at Posted at 2019-01-22

概要

Postgresql からスキーマ情報を、シェルスクリプトにてダンプしようとしたところ、パスワードによる認証が必要でした。.pgpass でシェルスクリプトから Postgresql に接続できるとあったので、設定してみましたが、正常終了しませんでした。

環境

Postgresql : 10.4 on x86_64-pc-linux-gn
クライアント : psql (PostgreSQL) 11.1

実行したシェル

.pgpass をホームディレクトリに配置して、chmode で 600 を付与しました。

sqlFileName=./result.sql
\cp -f ./.pgpass $HOME/
chmod 0600 $HOME/.pgpass
pg_dump --schema-only --username=user -t 'schema.tb*' -n dbname --no-password --host=host.domain.name > $sqlFileName

pg_dump: [archiver (db)] connection to database "dbname" failed: fe_sendauth: no password supplied

回避策

 非推奨の方法として、PGPASSWORD環境変数 を使用して回避。幸い本番で稼働しているようなものではなかったのでこれで回避しました。
chmode 600 をしないと、下記の警告が出るので、認識はしているらしいのですが、、、謎です。

WARNING: password file "/Users/username/.pgpass" has group or world access; permissions should be u=rw (0600) or less

なぜ .pgpass で入れないのだろう?
クライアントとサーバーのバージョン差異が影響しているのかな?

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?