postgresql 11.6 源码安装
1.下载源码介质
下载地址:
源码下载地址: https://www.postgresql.org/ftp/source/
二进制下载地址:https://www.enterprisedb.com/download-postgresql-binaries
我这里下载的介质是:
postgresql-11.6.tar.gz
2.安装依赖包
yum install readline
yum install gcc
yum -y install -y readline-devel
yum install zlib-devel
3.源码安装
[root@host135 soft]# tar -xvf postgresql-11.6.tar.gz
[root@host135 soft]# cd postgresql-11.6
[root@localhost soft]#mkdir -p /opt/postgresql-11.6
[root@localhost soft]#./configure --prefix=/opt/postgresql-11.6
[root@localhost soft]#make
[root@localhost soft]#make install
4.创建相应的用户
[root@localhost opt]# groupadd postgres
[root@localhost opt]# useradd -g postgres postgres
5.创建数据及日志目录,并做相应授权
[root@localhost soft]#mkdir -p /opt/postgresql-11.6/{data,log}
[root@localhost soft]#chown -R postgres:postgres /opt/postgresql-11.6
6.初始化数据库
#su - postgres
[postgres@localhost bin]$ cd /opt/postgresql-11.6/bin
[postgres@localhost bin]$ ./initdb -D /opt/postgresql-11.6/data/
7.启动数据库
[postgres@localhost bin]$ cd /opt/postgresql-11.6/bin
[postgres@localhost bin]$./pg_ctl -D /opt/postgresql-11.6/data -l /opt/postgresql-11.6/log/postgres.log start
8.登陆使用
[postgres@localhost bin]$cd /opt/postgresql-11.6/bin
[postgres@localhost bin]$ ./psql
psql (11.6)
Type "help" for help.
postgres=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
9.设置环境变量
[postgres@localhost ~]$ vi .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/opt/postgresql-11.6/bin
export PATH
10.修改postgres用户的访问密码并测试建库建表
PostgreSQL 数据库默认会创建一个postgres的数据库用户作为数据库的管理员,默认密码为空,我们需要修改为指定的密码,这里设定为postgres.
su - postgres
psql
# ALTER USER postgres WITH PASSWORD 'postgres';
# select * from pg_shadow ;
创建用户
create user hxl with password 'postgres';
创建数据库
create database db_test owner hxl; -- 创建数据库指定所属者
将数据库得权限,全部赋给某个用户
grant all on database db_test to hxl;
11.配置postgresql允许远程访问
只需要修改data目录下的pg_hba.conf和postgresql.conf这两个文件:
pg_hba.conf:配置对数据库的访问权限;
postgresql.conf:配置PostgreSQL数据库服务器的相应的参数
vim /opt/postgresql-11.6/data/pg_hba.conf
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 md5
重新加载配置文件
su - postgres
pg_ctl -D /opt/postgresql-11.6/data reload
修改postgresql.conf
vim /opt/postgresql-11.6/data/postgresql.conf
listen_addresses = '*' # what IP address(es) to listen on;
修改该改参数需要重启动
pg_ctl -D /opt/postgresql-11.6/data -l /opt/postgresql-11.6/log/postgres.log stop
pg_ctl -D /opt/postgresql-11.6/data -l /opt/postgresql-11.6/log/postgres.log start
12.修改postgres用户的密码
[postgres@localhost log]$ psql
postgres=# alter user postgres with password 'postgres';
然后通过navicate for postgresql即可进行连接
----------------------------------------------------------------------------------------------------各版本安装--------------------------------------------------------------------------------
源码安装12
[root@host135 soft]# tar -xvf postgresql-12.11.tar.gz
[root@host135 soft]# cd postgresql-12.11
[root@localhost soft]#mkdir -p /opt/postgresql-12.11
[root@localhost soft]#./configure --prefix=/opt/postgresql-12.11
[root@localhost soft]#make
[root@localhost soft]#make install
[root@localhost soft]#mkdir -p /opt/postgresql-12.11/{data,log}
[root@localhost soft]#chown -R postgres:postgres /opt/postgresql-12.11
#su - postgres
[postgres@localhost bin]$ cd /opt/postgresql-12.11/bin
[postgres@localhost bin]$ ./initdb -D /opt/postgresql-12.11/data/
./pg_ctl -D /opt/postgresql-12.11/data -l /opt/postgresql-12.11/log/postgres.log start
./pg_ctl -D /opt/postgresql-12.11/data -l /opt/postgresql-12.11/log/postgres.log stop
./pg_ctl -D /opt/postgresql-12.11/data -l /opt/postgresql-12.11/log/postgres.log start
源码安装13
[root@host135 soft]# tar -xvf postgresql-13.7.tar.gz
[root@host135 soft]# cd postgresql-13.7
[root@localhost soft]#mkdir -p /opt/postgresql-13.7
[root@localhost soft]#./configure --prefix=/opt/postgresql-13.7
[root@localhost soft]#make
[root@localhost soft]#make install
[root@localhost soft]#mkdir -p /opt/postgresql-13.7/{data,log}
[root@localhost soft]#chown -R postgres:postgres /opt/postgresql-13.7
#su - postgres
[postgres@localhost bin]$ cd /opt/postgresql-13.7/bin
[postgres@localhost bin]$ ./initdb -D /opt/postgresql-13.7/data/
./pg_ctl -D /opt/postgresql-13.7/data -l /opt/postgresql-13.7/log/postgres.log start
./pg_ctl -D /opt/postgresql-13.7/data -l /opt/postgresql-13.7/log/postgres.log stop
./pg_ctl -D /opt/postgresql-13.7/data -l /opt/postgresql-13.7/log/postgres.log start
源码安装14
[root@host135 /]# cd soft
[root@host135 soft]# tar -xvf postgresql-14.4.tar.gz
[root@host135 soft]# cd postgresql-14.4
[root@localhost soft]#mkdir -p /opt/postgresql-14.4
[root@localhost soft]#./configure --prefix=/opt/postgresql-14.4
[root@localhost soft]#make
[root@localhost soft]#make install
[root@localhost soft]#mkdir -p /opt/postgresql-14.4/{data,log}
[root@localhost soft]#chown -R postgres:postgres /opt/postgresql-14.4
#su - postgres
[postgres@localhost bin]$ cd /opt/postgresql-14.4/bin
[postgres@localhost bin]$ ./initdb -D /opt/postgresql-14.4/data/
./pg_ctl -D /opt/postgresql-14.4/data -l /opt/postgresql-14.4/log/postgres.log start
./pg_ctl -D /opt/postgresql-14.4/data -l /opt/postgresql-14.4/log/postgres.log stop
./pg_ctl -D /opt/postgresql-14.4/data -l /opt/postgresql-14.4/log/postgres.log start
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?