3
2

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 3 years have passed since last update.

【PostgreSQL】ルートユーザーとしてログインする方法。デフォルトで勝手にユーザー名が指定されてしまう時の対処法

Posted at

PostgresSQLで初期設定をした時に、ルートのパスワードのみ設定した。

その後、psalで対話モードに入ろうとすると、ユーザーが勝手に自分のPCになってしまい指定したパスワードで入れない、、

対処法

先に結論から。ユーザー名をpostgresがルートユーザー名になっているため、コマンドpsql -U postgresで入れる。

$ psql -U postgres
Password for user postgres:
psql (13.2)
Type "help" for help.

postgres=#

Passwordには初期に設定したものを使用。無事対話モードに入れた。


## 発生した原因 なぜ`psql`と設定したパスワードで入れないかというと、デフォルトでユーザーにPCにユーザー名が設定されてしまうから。
$ psql
Password for user <ユーザー名>:
psql: error: FATAL:  password authentication failed for user "<ユーザー名>"

勝手に<ユーザー名>が指定される。設定したパスワードを入力すると認証エラーになる。(<ユーザー名>を登録してないので当前)


ヘルプを確認すると勝手にデフォルトのユーザーが指定されている。`default: "<ユーザー名>"`
$ psql --help
psql is the PostgreSQL interactive terminal.

General options:
  -d, --dbname=DBNAME      database name to connect to (default: "<ユーザー名>")

省略...

以上。
3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?