Linux 非root用户安装postgres

首先得有root权限。Centos 7上已经安装了postgres,后面需要把它停掉。

1)下载文件
先安装依赖:
https://www.postgresql.org/download/linux/redhat/

我先下载下来再安装
wget https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum install pgdg-redhat-repo-latest.noarch.rpm

然后在官网下载source code:https://www.runoob.com/postgresql/linux-install-postgresql.html

安装方法:https://blog.csdn.net/hanzheng260561728/article/details/91357229
注意,这里不要指定root了,用自己local的路径

2)停掉系统上的postgres
先su,然后systemctl list-units|grep postgresql查看名称,然后service postgresql.service stop。
具体参考这里:https://unix.stackexchange.com/questions/267329/how-do-you-stop-posgresql-on-centos-7

3)打开自己安装的local postgres服务
cd到安装目录的postgresql/bin
./initdb -D ../data/
./pg_ctl -D ../data/ -l logfile start
./postgres -D ../data/

以szymon的用户名进入"postgres"默认数据库:
./psql -U szymon postgres

具体参考:https://www.endpointdev.com/blog/2013/06/installing-postgresql-without-root/#:~:text=%20Installing%20PostgreSQL%20without%20Root%20%201%20Download,installed.%20The%20–with-python...%204%20Run.%20%20More%20

  1. 创建用户,设置密码:
    https://blog.csdn.net/hanzheng260561728/article/details/91357229

psql -U szymon postgres
CREATE DATABASE abc;
\q
psql -U szymon abc

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容