zl程序教程

您现在的位置是:首页 >  其他

当前栏目

postgresql 11.6 源码安装

2023-09-27 14:20:53 时间

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