官网下载源代码:PostgreSQL: File Browser
mkdir /pgs
把源代码 postgresql-12.0.tar.gz 放到/pgs 目录下
cd /pgs
tar -vxzf postgresql-12.0.tar.gz
解压后,有install说明文档
1.安装相关依赖
yum install -y readline readline-devel openssl openssl-devel zlib zlib-devel python-devel
2.编译前设置,主要是设置安装目录
cd /pgs/postgresql-12.0
./configure --prefix=/pgs/usr/local/pgsql/ --with-python
3.make
---make(编译)完毕,如果成功,则提示:All of PostgreSQL successfully made. Ready to install.
make命令没有编译./contrib目录下面的各种扩展,后期如果需要使用某个扩展,那么需要重新运行上面第2步./configure(因为,我之前安装完毕,删除了./configure)
然后cd ./contrib/某扩展目录下,make && make install ——这样就可以安装了这个扩展,不需重启。
4.make install
---make install完毕,如果成功,则提示:PostgreSQL installation complete.
pgsql已经成功安装在 /pgs/usr/local/pgsql/ 目录下。
5.添加postgres用户,对数据库的所有操作都要在这个用户下
adduser postgres
#yum安装postgresql,默认会建一个名为”postgres”的系统账号,用于执行PostgreSQL;?
#同时数据库中也会生成一个名为”postgres”的数据库用户,且密码已自动生成,需要进入数据库后修改;?
#PostgreSQL在数据库用户同名的系统账号下登录免密。?
6.添加数据文件目录
mkdir /pgs/usr/local/pgsql/data
chown postgres /pgs/usr/local/pgsql/data
7.切换成postgres用户登录
su - postgres
8.初始化数据库
/pgs/usr/local/pgsql/bin/initdb -D /pgs/usr/local/pgsql/data
--初始化数据库成功:
Success. You can now start the database server using:
/pgs/usr/local/pgsql/bin/pg_ctl -D /pgs/usr/local/pgsql/data -l logfile start
9.设置全局环境变量,vi /etc/profile ----root 权限才可以编辑
export PATH=/pgs/usr/local/pgsql/bin:$PATH
export PGDATA=/pgs/usr/local/pgsql/data
export PGHOME=/pgs/usr/local/pgsql
export PGPORT=5431 ------因为gee已经有一个pgsql在运行,端口是5432,所以,这里要用端口5431
10.启动或者停止pgsql服务器
/pgs/usr/local/pgsql/bin/pg_ctl -D /pgs/usr/local/pgsql/data start [ stop ]
或者直接运行:pg_ctl start [stop] --su postgres
11.--创建一个数据库
/pgs/usr/local/pgsql/bin/createdb testdb
12.--连接到数据库
/pgs/usr/local/pgsql/bin/psql testdb
13.添加扩展
su - postgres
psql ——这个是用postgres超级用户登录
create extension hstore;
14.删除
To undo the installation use the command "make
uninstall". However, this will not remove any created directories
15.清理相关编译文件
cd /pgs/postgresql-12.0
make clean ----This
will preserve the files made by the "configure" program, so that you can
rebuild everything with "make" later on
make distclean ----To reset the source tree to the
state in which it was distributed
--查看post进程
ps -ef | grep post