はじめに
少しはまったので記事にします。
問題
「フロントエンド開発のためのテスト入門」 10章での開発環境構築エラー解消 ( User root
was denied access on the database app-db.public
)
https://qiita.com/osa-osa/items/b1e4466b19d7bde896d5
// 実際にDockerでたてているpostgresにpostgresユーザでログインする
$ psql -h localhost -p 5432 -U postgres
記事を書かれた方と同じように、Dockerでたてているpostgresにpostgresユーザでログインしようとしました。
Mac Book AirのM1のせいか、postgres のroleがないというエラーでした。
% psql -h localhost -p 5432 -U postgres
psql (14.13 (Homebrew), server 14.2)
Type "help" for help.
# 現在のデータベースに存在するすべてのロール(ユーザー)とその属性を一覧表示
postgres=> \du
List of roles
Role name | Attributes | Member of
----------------+------------------------------------------------------------+-----------
postgres | | {}
username | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
解決方法
「-U username -d postgres」と、コマンドを少し変える必要がありました。
usernameはご自身のものを入力してください。
% psql -h localhost -p 5432 -U username -d postgres
psql (14.13 (Homebrew), server 14.2)
Type "help" for help.
# 既存のpostgresロールにスーパーユーザー権限を付与
postgres=# ALTER ROLE postgres WITH SUPERUSER;
ALTER ROLE
# 現在のデータベースに存在するすべてのロール(ユーザー)とその属性を一覧表示
postgres=# \du
List of roles
Role name | Attributes | Member of
----------------+------------------------------------------------------------+-----------
postgres | Superuser | {}
username | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
# rootという名前の新しいロールを作成し、スーパーユーザー権限を付与
postgres=# create role root with superuser login password 'password';
CREATE ROLE
# 現在のデータベースに存在するすべてのロール(ユーザー)とその属性を一覧表示
postgres=# \du
List of roles
Role name | Attributes | Member of
----------------+------------------------------------------------------------+-----------
postgres | Superuser | {}
root | Superuser | {}
username | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
postgres=# exit
おわりに
どなたかの参考になれば幸いです。
参考
「フロントエンド開発のためのテスト入門」 10章での開発環境構築エラー解消 ( User root
was denied access on the database app-db.public
)
https://qiita.com/osa-osa/items/b1e4466b19d7bde896d5
Postgresqlでスーパーユーザー権限をもったユーザーを作成する
https://qiita.com/IzumiSy/items/6879ae9eb181b5e43087