postgresql安装与使用

今天在使用Miniflux时需要用到postgresql数据库,折腾了好长时间才搞明白这个东西怎么用。 开篇之前我要先吐槽postgresql好难用啊,太他妈难用了啊啊啊。 3.10 更正:刚看到python社区发的报告,这数据库使用率第一??这样看来大概是我坑爹emmm……不敢吐槽了,赶紧好好看看咋用。 ### 环境 Ubuntu 18.4LTS postgresql 最新版

问题:

1、安装: 首先安装使用sudo apt install postgresql 安装之后会出现

1
2
3
4
5
6
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
此处注意postgresql只能使用非特权用户运行,管理之类的也只能使用postgres用户操作,所以接下来su - postgres

切换以后上面提示里面的命令运行后会报错说配置文件不存在

接下来可以手动指定/etc/postgresql目录下面的配置文件,也可以重新初始化数据库使用/usr/lib/postgresql/10/bin/pg_ctl initdb -D /var/lib/postgresql/11重新初始化一个数据库这样子配置文件就在这个文件夹

可以直接使用/usr/lib/postgresql/10/bin/pg_ctl -D /var/lib/postgresql/11 -l logfile start启动

到此安装完毕。

2、卸载: 我们正常思路可能是用sudo apt remove postgresql然而事实上并不行

重新安装后会发现配置文件还在没法重新初始化

这里搬运一下完全卸载方法:

1
2
3
4
5
6
1.apt-get --purge remove postgresql\* //删除软件本体
2.rm -r /etc/postgresql/ //删除配置文件
3.rm -r /etc/postgresql-common/ //同上
4.rm -r /var/lib/postgresql/ //同上
5.userdel -r postgres //删除软件自动创建的用户
6.groupdel postgres //删除其用户组

参考资料: http://www.u3coding.com/2017/08/27/%E5%BC%80%E6%BA%90%E6%95%B0%E6%8D%AE%E5%BA%93postgresql%E5%AE%89%E8%A3%85%E5%8D%B8%E8%BD%BD%E6%80%BB%E7%BB%93/ https://github.com/yandex-qatools/postgresql-embedded/issues/74 https://blog.csdn.net/dyx1024/article/details/6594851 https://juejin.im/post/5b2cb169e51d4558cc35bd7c


postgresql安装与使用
https://blog.yrpang.com/posts/48821/
作者
yrPang
发布于
2019年3月3日
许可协议