PostgresSQL数据库在centos7的安装和部署

官网下载源代码:https://www.postgresql.org/ftp/source/v12.0/

 

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

2.编译前设置,主要是设置安装目录
cd /pgs/postgresql-12.0
./configure --prefix=/pgs/usr/local/pgsql/

3.make
---make(编译)完毕,如果成功,则提示:All of PostgreSQL successfully made. Ready to install.

4.make install
---make install完毕,如果成功,则提示:PostgreSQL installation complete.

pgsql已经成功安装在  /pgs/usr/local/pgsql/  目录下。

5.添加postgres用户,对数据库的所有操作都要在这个用户下
    adduser postgres

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]


11.--创建一个数据库
/pgs/usr/local/pgsql/bin/createdb testdb

12.--连接到数据库
/pgs/usr/local/pgsql/bin/psql testdb


13.删除
To undo the installation use the command "make
uninstall". However, this will not remove any created directories


14.清理相关编译文件
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

 

 

 

你可能感兴趣的:(PostgresSQL)