41 lines
1.1 KiB
Plaintext
41 lines
1.1 KiB
Plaintext
问题:sudo service postgresql start 启动后 发现连不上数据库,psql 和msfconsole都提示:
|
||
|
||
could not connect to database template1: could not connect to server: No such file or directory.
|
||
|
||
Is the server running locally and accepting
|
||
|
||
connections on Unix domain socket "var/run/postgresql/.s.PGSQL.5432"?
|
||
|
||
发现并没有监听默认5432端口。
|
||
|
||
多次尝试后发现,并没有初始化数据库,现记录下初始化并启动过程(postgresql安装完毕):
|
||
|
||
1.给数据库的postgres用户设置密码:
|
||
|
||
$ sudo passwd postgres
|
||
|
||
|
||
2.创建postgresql的data文件夹
|
||
|
||
$ sudo mkdir /data
|
||
$ sudo chmod o+w /data
|
||
$ su - postgres
|
||
$ mkdir /data/postgresql
|
||
$ mkdir /data/postgresql/data
|
||
3.postgres用户初始化数据库
|
||
|
||
$ /usr/lib/postgresql/12/bin/initdb -D /data/postgresql/data
|
||
初始化看到几个OK之后,最后Success,然后提示启动数据库命令:pg_ctl ...
|
||
|
||
|
||
|
||
4.postgres用户启动数据库
|
||
|
||
/usr/lib/postgresql/12/bin/pg_ctl -D /data/postgresql/data -l logfile start
|
||
waiting for server to start .... done
|
||
|
||
server started
|
||
|
||
5.检查是否监听端口
|
||
|
||
$ ss -ant |