安装
apt install postgresql
就可以了, 如果没有权限, 在前面加上sudo
. Ubuntu 18.04 默认安装的是10版本.
配置
安装完成后, 有提示
Success. You can now start the database server using:
/usr/lib/postgresql/10/bin/pg_ctl -D /var/lib/postgresql/10/main -l logfile start
Ver Cluster Port Status Owner Data directory Log file
10 main 5432 down postgres /var/lib/postgresql/10/main /var/log/postgresql/postgresql-10-main.log
这是启动数据库服务的命令, 但是利用命令service --status-all
发现, postgresql
服务已经处于运行状态, 所以不用再执行上面提示的这个命令.
安装中自动创建了postgres用户, 该用户处于锁定状态(没有密码). 经过搜索, 不建议修改它的密码, 对于需要执行postgresql命令的时候, 在命令前面, 加上: sudo -u postgres
就行了.
更改监听网卡并允许非localhost连接
如果不需要在非localhost上连接数据库, 这一步可以忽略.
这一步需要改两个配置文件, 分别为pg_hba.conf
和postgresql.conf
. 首先找到这两个文件, 在我的服务器上, 其所在目录为/etc/postgresql/10/main