4
4

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.

PostgreSQLにpsqlでログインする方法を忘れた時の対処法

Posted at

何度も何度も何度も何度も psql で対話的ログインする方法と必要なパスワードを忘れてしまうので大体の場合なら無理やり解決できる方法をメモ。

解決策

$ sudo su - postgres
postgres: $ createuser ironsand
postgres: $ Shall the new role be a superuser? (y/n) y
postgres: $ exit
$ psql -U ironsand -d postgres

やってること

インストールするときに自動的に作成されるユーザーに sudo su - でなってしまって自分のユーザー名で管理者権限を持つユーザーを作ってしまう。

psql で対話的に処理するにはとりあえず何かDBに接続しないとダメなのでデフォルトで存在してるpostgresに接続する。

あとはSQL文を好きに発行できるので ALTER ROLE ironsand WITH PASSWORD 'pass';とかでパスワードをつけるなりなんなりテキトーに。

4
4
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
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?