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?

【SadServers学習メモ #7】使ったコマンドまとめ(find, systemctl, psql)

Posted at

初めに

Linuxの学習目的でSadServersを始めました。
備忘のために使用したコマンドをアウトプットします。

SadServersとは

Linuxの学習サイト。
架空のサーバを題材とし、その管理者となって与えられた依頼をこなしていく。
実際にコマンドを使って作業をすることで、実践的なスキルが身につくことが期待できる。

今回のお題

タイトル

"Bucharest": Connecting to Postgres

詳細

ローカルホストに立てられたPostgreSQLサーバに接続ができないので、問題を解決する。

$ PGPASSWORD=app1user psql -h 127.0.0.1 -d app1 -U app1user -c '\q'
psql: error: FATAL:  pg_hba.conf rejects connection for host "127.0.0.1", user "app1user", database "app1", SSL on
FATAL:  pg_hba.conf rejects connection for host "127.0.0.1", user "app1user", database "app1", SSL off

作業の流れ

  • 接続できない原因を特定
    • エラーの内容を見ると、pg_hba.confファイルが関係してそうなので、修正する
  • postgresのサービスを再起動
  • 再度接続確認する

使ったコマンド

find

対象のファイルを見つけるコマンド。
検索したい場所を指定し、検索対象のファイル名を-nameオプションで指定。

$ sudo find / -name pg_hba.conf
/etc/postgresql/13/main/pg_hba.conf

systemctl

systemdを操作するコマンド。
システムの起動、停止、再起動を行う。

$ sudo systemctl restart postgresql

systemctlについては以前こちらの記事でまとめたので良ければご覧ください。

その他修正内容

pg_hba.confの修正

pg_hba.confはpostgresqlのアクセス制御を設定するファイル。
左から順に、「接続タイプ」「DB」「ユーザ」「接続元IP」「認証方法」となっている。

このファイルを見ると、以下のように「全てDBへの接続をrejectする」という指定がはいっていたことが、原因だったよう。コメントアウトした。

pg_hba.conf
host    all             all             all                     reject
host    all             all             all                     reject

終わりに

postgresqlは普段業務でも使用するものであり、今回のようなトラブルシューティングは仕事でも役に立ちそうです。その他にも設定ファイルがあったので、時間があるときにどんな設定なのか調べてみようと思います。

ここまでご覧いただきありがとうございました!

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?