零、前置条件
系统CentOS 7,并已联网,已安装gcc或者g++编译器,GNU make版本3.80或以上,系统有至少一个除root之外的普通用户user
gcc安装-参考链接 查看make命令的版本——make --version
更新make版本-参考链接 postgresql的使用一般不用root
用户,而是普通用户,这里假设普通用户名为user
。Linux创建新用户-参考链接 Xshell建立起与CentOS 7系统的会话 Xftp同样建立了与CentOS 7的链接
一、下载、转移、解压
下载
首先在本地打开以链接,下载postgresql-xx.x
,readline-7.0
,zlib-1.2.xx
https://www.postgresql.org/ftp/source/
PostgresSQL
建议下载最新版本,打开后的版本列表中,选择最新的正式版本,最好不要选带beta的
http://ftp.gnu.org/gnu/readline/readline-7.0.tar.gz
下载zlib
前,先开官网http://www.zlib.net/
看一下最新版本号,比如这里是1.2.13
,那么下面下载链接中的版本号就改成最新的版本号
http://www.zlib.net/zlib-1.x.xx.tar.gz
转移
[root@localhost ~]# mkdir pgsoft
打开xftp,将刚刚下载好的三个压缩包拖到刚刚建立目录下面/root/pgsoft
解压
[root@localhost pgsoft]# tar -xf readline-7.0.tar.gz
[root@localhost pgsoft]# tar -xf zlib-1.x.xx.tar.gz
[root@localhost pgsoft]# tar -xf postgresql-xx.x.tar.gz
二、安装
readline安装
[root@localhost pgsoft]# cd readline-7.0
[root@localhost readline-7.0]# ./configure
[root@localhost readline-7.0]# make
[root@localhost readline-7.0]# make install
安装readline开发包readline-devel
,不然后面安装postgresql
时会提示错误configure: error: readline library not found
[root@localhost readline-7.0]# yum install readline-devel
zlib安装
[ root@localhost readline-7.0]
[ root@localhost zlib-1.x.xx]
[ root@localhost zlib-1.x.xx]
[ root@localhost zlib-1.x.xx]
postgresql安装
[ root@localhost ~]
[ root@localhost ~]
[ root@localhost ~]
[ root@localhost postgresql-xx.x]
[ root@localhost postgresql-xx.x]
[ root@localhost postgresql-xx.x]
[ root@localhost postgresql-15.3]
总用量 16
drwxr-xr-x. 2 root root 4096 6 月 9 09:29 bin
drwxr-xr-x. 6 root root 4096 6 月 9 09:29 include
drwxr-xr-x. 4 root root 4096 6 月 9 09:29 lib
drwxr-xr-x. 6 root root 4096 6 月 9 09:29 share
[ root@localhost postgresql-15.3]
postgres ( PostgreSQL) 15.3
三、安装数据目录
[ root@localhost ~]
[ root@localhost ~]
[ root@localhost pgsoft]
上一次登录:五 6 月 9 09:32:48 CST 2023pts/0 上
[ user@localhost ~] $ cd /pgdata/15.3/poc
[ user@localhost poc] $ /opt/pgsql-15.3/bin/initdb -D /pgdata/15.3/poc/data/ -E UTF-8
……
……
Success. You can now start the database server using:
/opt/pgsql-15.3/bin/pg_ctl -D /pgdata/15.3/poc/data/ -l logfile start
[ userb@localhost poc] $ chmod 0700 data/
[ userb@localhost poc] $ /opt/pgsql-15.3/bin/pg_ctl -D /pgdata/15.3/poc/data/ start
waiting for server to start.. .. 2023 -06-09 09:43:50.826 CST [ 18923 ] LOG: starting PostgreSQL 15.3 on x86_64-pc-linux-gnu, compiled by gcc ( GCC) 4.8 .5 20150623 ( Red Hat 4.8 .5-44) , 64 -bit
2023 -06-09 09:43:50.828 CST [ 18923 ] LOG: listening on IPv6 address "::1" , port 5432
2023 -06-09 09:43:50.828 CST [ 18923 ] LOG: listening on IPv4 address "127.0.0.1" , port 5432
2023 -06-09 09:43:50.832 CST [ 18923 ] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2023 -06-09 09:43:50.836 CST [ 18926 ] LOG: database system was shut down at 2023 -06-09 09:42:19 CST
2023 -06-09 09:43:50.855 CST [ 18923 ] LOG: database system is ready to accept connections
done
server started
四、创建PostgreSQL第一个数据库实例
[ userb@localhost poc] $ /opt/pgsql-15.3/bin/createdb my_first_pgdb
五、将PostgreSQL的安装路径添加到Shell的搜索路径
[ root@localhost ~]
password:
[ root@localhost ~]
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[ root@localhost ~]
[ root@localhost ~]
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/opt/pgsql-15.3/bin
[ root@localhost ~]
postgres ( PostgreSQL) 15.3
[ userb@localhost poc] $ createdb my_first_pgdb