在linux上安装postgresql
前提条件(前三个一定要有)
- gmake或make要求至少3.8以上
可使用下列命令查看make版本
make --version
- 需要一个C 编译器(至少是 C99兼容的)。我们推荐使用最近版本的GCC
- tar软件包
- GNU readline library
- zlib compression library
源码安装
创建postgres用户
1.创建postgres用户组
groupadd postgres
2.在postgres用户组下创建postgres用户
useradd -g postgres postgres
3.修改用户口令
passwd postgres
修改数据库安装路径
创建一个文件夹,将这个文件夹的所有者改为postgres用户
chown -R postgres:postgres /home/xzh/postgres
下载源码
https://ftp.postgresql.org/pub/source/v12.6/postgresql-12.6.tar.gz
wget 'https://ftp.postgresql.org/pub/source/v12.6/postgresql-12.6.tar.gz'
解压
tar -zxvf postgresql-12.6.tar.gz
进入到解压后的文件中,执行
./configure --prefix=/home/xzh/postgres/12.6
编译
make world
安装
make install-world
初始化数据库,在之前prefix的路径中找到bin目录
/home/xzh/postgres/12.6/bin/initdb -D /home/xzh/postgres/12.6/data
完成后会提示下面内容
根据提示将数据库开启
/home/xzh/postgres/12.6/bin/pg_ctl -D /home/xzh/postgres/12.6/data -l logfile start

使用 ps -ef | grep postgres确认下进程是否开启,可以看到postgres已经开启
配置环境变量, 因为此处使用的是ubuntu,所以在/etc/profile文件中配置
export PATH=/home/xzh/postgres/12.6/bin:$PATH
export PGDATA=/home/xzh/postgres/12.6/data
source /etc/profile
此时可以输入psql,回车
退出时,遇到
去创建这个目录和文件,解决
修改配置文件
修改/home/xzh/postgres/12.6/data/pg_hba.conf文件
添加下面一行
host all all 0.0.0.0/0 md5
意为使用IPV4的客户端可以访问所有数据库,可以通过所有用户来访问,需要通过md5认证, 第一个all是数据库,第二个all是用户
修改/home/xzh/postgres/12.6/data/postgresql.conf文件
修改 #listen_addresses
listen_addresses = '*'
这样就可以让非本机的客户端访问到数据库
改完后要重启服务
pg_ctl restart -m fast
手工启停数据库
关闭数据库
pg_ctl stop -m fast
开启数据库
pg_ctl start -D /home/xzh/postgres/12.6/data -l /home/xzh/postgres/12.6/startup.log
这里-D就是指定数据库集群路径 -l 就是日志文件
版权声明:本文为weixin_44331517原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。