0
0

More than 1 year has passed since last update.

設定ファイル(postgresql.conf)の内容が消えてしまった(全行"~"になった)→ディレクトリに注意!

Last updated at Posted at 2021-08-31

環境

バージョン
Host OS Windows 10 Home 21H1(OSビルド:19043.1165)
Virtual Machine WSL2 -
Remote OS Ubuntu 20.04.2 LTS (GNU/Linux 5.4.72-microsoft-standard-WSL2 x86_64)
Database PostgreSQL 12.7 (Ubuntu 12.7-0ubuntu0.20.04.1)
Database GUI 無し -
Docker 無し -

何があった?

WSL2・DBeaverでPostgreSQLを使えるようにすべくPostgreSQLの設定ファイル(postgresql.conf)の書き換えを試みたところ、下スクショのような状態に書き換わってしまった。
1.png

本来であれば「listen_address='local host'」を含むコード(?)が何行も表示されるはずが、全て「~」に書き換わってしまった。

何をしたらこうなった?

設定ファイル「/etc/postgresql/12/main/postgresql.conf」をテキストエディタviで開き
「listen_addresses = 'localhost'」を「listen_addresses = '*'」に変更しようと試みた。

【やったこと】
WSL2のターミナルで
下記を実行
umesan@MyComputer:~$ cd /etc/postgresql/12/main

下記を実行
umesan@MyComputer:/etc/postgresql/12/main$ vi postgresql.conf
(viでpostgresql.confファイルを開く、の意)

(WSL2ターミナルにpostgresql.confテキストファイルが展開される)
「/listen」+Enerで listen_addressを検索

iキーを押下し、コマンドモードから編集モードに変更。

「localhost」を「*」に書き換えようとするも違う箇所の文字を変えてしまい
取り急ぎ こちら を参考に「ファイルの変更を保存しないでviを終了」を実行しようと、「:q!」を実行した。

再び「vi postgresql.conf」で設定ファイルを開くと、上記画面のように「~」が羅列されている状態になっていた。

原因

再度「vi postgresql.conf」で開いた際のディレクトリが「umesan@MyComputer:~$」になっていた。
「umesan@MyComputer:/etc/postgresql/12/main$ 」に移動しないといけない!

対処方法

WSL2ターミナルで「umesan@MyComputer:~$ cd /etc/postgresql/12/main」を実行してから
「umesan@MyComputer:/etc/postgresql/12/main$ vi postgresql.conf」を実行したら
目的のファイルを正しく開くことができた。

おわりに

今どのディレクトリにいるのかという位置を、きちんと確認・意識しよう。

未解決事項

ディレクトリ「umesan@MyComputer:~$」で「vi postgresql.conf」を実行したことで
このディレクトリ内に上記スクショのファイル(画面左下にNew Fileとある)を「postgresql.conf」として新規作成してしまった状態、になっている??
であれば、そのファイルを削除する必要がある??

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