$ sudo pkg install postgresql15-server postgresql15-client
# 安装完之后会自动注册到服务列表
root@freebsd14-11-199:~ # service -l|grep post
postgresql
# 将postgresl添加到开机自启动
root@freebsd14-11-199:~ # service -e|grep post
root@freebsd14-11-199:~ # sysrc 'postgresql_enable=YES'
postgresql_enable: ?-> YES
root@freebsd14-11-199:~ # service -e|grep post
/usr/local/etc/rc.d/postgresql
root@freebsd14-11-199:~ # /usr/local/etc/rc.d/postgresql initdb
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
……
Success. You can now start the database server using:
? ? /usr/local/bin/pg_ctl -D /var/db/postgres/data15 -l logfile start
修改将5432端口绑定到*上而不是默认的localhost
root@freebsd14-11-199:/var/db/postgres/data15 # vi postgresql.conf?
#listen_addresses = 'localhost' ? ? ? ? # what IP address(es) to listen on;
listen_addresses = '*' ? ?
新增一条允许远程登录策略
root@freebsd14-11-199:/var/db/postgres/data15 # vi pg_hba.conf?
# IPv4 local connections:
……
host ? ?all ? ? ? ? ? ? all ? ? ? ? ? ? 0.0.0.0/0 ? ? ? ? ? ? ? md5?
root@freebsd14-11-199:~ # ?service postgresql start
2002-02-04 19:05:52.238 CST [10417] LOG: ?ending log output to stderr
2002-02-04 19:05:52.238 CST [10417] HINT: ?Future log output will go to log destination "syslog".
root@freebsd14-11-199:~ # service postgresql status
pg_ctl: server is running (PID: 10417)
/usr/local/bin/postgres "-D" "/var/db/postgres/data15"