1、配置防火墙火配置防火墙策略;
systemctl disable firewalld.service
systemctl stop firewalld.service
2、安装需要的依赖包:
yum install -y cmake gcc gcc-c++ perl readline readline-devel openssl openssl-devel zlib zlib-devel ncurses-devel
3、创建用户:
useradd postgres
passwd postgres
mkdir /pgdata
chown postgres. /pgdata/
4、配置环境变量
vi ~/.bashrc
export PGHOME=/usr/local/pgsql
export LD_LIBRARY_PATH=${PGHOME}/lib:${LD_LIBRARY_PATH}
export PATH=S{PGHOME}/bin: S{PATH}
5、解压安装包:
tar -xzvf postgresql-12.2.tar.gz
cd postgresql-12.2
6、编译安装
./configure #可加-prefix=/usr/local/pgsql指定软件安装路径
make
make install
su - postgres
/usr/local/pgsql/bin/initdb -D /pgdata #初始化数据库
/usr/local/pgsql/bin/pg_ctl -D /pgdata -l logfile start #启动数据库服务
7、创建数据库
/usr/local/pgsql/bin/createdb test #创建数据库
/usr/local/pgsql/bin/psql #进入数据库
ALTER USER postgres WITH PASSWORD '123456'; #修改密码
8、启停PG数据库
/usr/local/pgsql/bin/pg_ctl -D /pgdata -l logfile start #会在家目录下生成logfile日志文件。
/usr/local/pgsql/bin/pg_ctl -D /pgdata -l logfile stop
/usr/local/pgsql/bin/pg_ctl -D /pgdata -l logfile restart
/usr/local/pgsql/bin/pg_ctl -D /pgdata -l logfile status