设置文件(postgresql.conf)的内容消失了(全行变为”~”)→注意目录!
环境
バージョンHost OSWindows 10 Home21H1(OSビルド:19043.1165)Virtual MachineWSL2-Remote OSUbuntu20.04.2 LTS (GNU/Linux 5.4.72-microsoft-standard-WSL2 x86_64)DatabasePostgreSQL12.7 (Ubuntu 12.7-0ubuntu0.20.04.1)Database GUI無し-Docker無し-
发生了什么事?

本来应该显示多行包含“listen_address=’local host’”的代码(?),但现在全部被替换成了“~”。
做了什么导致发生这种情况? (What did you do that led to this situation?)
我试图用文本编辑器vi打开设置文件“/etc/postgresql/12/main/postgresql.conf”,并将“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”+Enter来搜索listen_address
↓
按下i键,从命令模式切换到编辑模式
↓
试图将“localhost”替换为“*”,但不小心更改了其他地方的字符
匆忙参考此处,尝试执行“不保存文件修改而退出vi”的操作,输入“:q!”
↓
再次使用“vi postgresql.conf”打开配置文件,发现屏幕上出现了上述情况的波浪线“~”列表。
There are a few possible ways to paraphrase the word “原因” (cause/reason) in Chinese. Here’s one option:
引发这一情况的因素是什么? (What are the factors that triggered this situation?)
当再次打开“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”,那么在该目录下会创建一个名为“postgresql.conf”的新文件,并且在该文件中会存在上述截图中的文件(屏幕左下方显示为New File)。如果是这种情况,是否需要删除该文件?