PostgreSQL是一个功能非常强大的、源代码开放的客户/服务器关系型数据库管理系统,且因为许可证的灵活,任何人都可以以任何目的免费使用、修改和分发PostgreSQL。现在国产数据库大力发展阶段,学习和熟悉postgresql的功能是非常有必要的,今天我们就了解下postgresql15的启动和关闭方法。
一、启动
1.1,postgres命令
postgres启动需要指定数据库数据簇目录,才能启动

如果通过-D指定,通过设置PGDATA环境变量也可以启动,不指定则报错:
不指定启动,报错:

指定启动:

1.2,postgres后台启动
当然,我们一般都是通过后台去启动命令,这样即使我们连接中断,命令还是可以正常完成:
postgres -D /opt/postgresql15/data > /var/log/postgresql15.log 2>&1 &

1.3,pg_ctl命令
postgresql内置了启动数据库的命令工具pg_ctl,我们可以使用它进行启动:
pg_ctl start -l /var/log/postgresql15.log

1.4,自启动脚本
当我们数据库服务器重启时候,我们想让postgresql随机器启动而启动,我们可以通过自启动脚本:
我们通过在/etc/systemd/system目录里面新增一个postgresql15.service文件,并加入如下内容:
[Unit]
 Description=postgresql15
 Documentation=man:postgres(1)
 [Service]
 Type=notify
 User=postgres
 ExecStart=/opt/postgresql15/bin/postgres -D /opt/postgresql15/data
 ExecReload=/bin/kill -HUP $MAINPID
 KillMode=mixed
 KillSignal=SIGINT
 TimeoutSec=0
 [Install]
 WantedBy=multi-user.target
















![[Day 15]54.螺旋矩阵(简单易懂 有画图)](https://i-blog.csdnimg.cn/direct/4bea2ec0becf4b4dbf584542708cdf10.png)


