postgresql部署(编译安装)

- 一、下载地址

https://www.postgresql.org/download/

    二、安装部署 1、解压
tar -zxvf postgresql-12.3.tar.gz

2、安装依赖包

yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel  python-devel gcc-c++ openssl-devel cmake gcc* readline-devel
mkdir /home/postgres
chown -R postgres:postgres /home/postgres

4、添加环境变量

vi /etc/profile
#在配置文件的最后添加环境变量
export PATH=/home/postgres/bin:$PATH
export PGHOME=/home/postgres
export PGDATA=/home/postgres/data
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PGHOME/lib
export PATH=$PGHOME/bin:$PATH:$HOME/bin
#是配置文件生效
source  /etc/profile

5、安装编译

./configure --prefix=/home/postgres/ --with-python --with-libxml --with-libxslt
make && make install

6、初始化数据库

#切换用户
su - postgres
#修改数据库相关配置
vim /home/postgres/data/postgresql.conf
#找到listen_addresses和port参数,根据自己需求修改
listen_addresses = *
port = 5432
#设置放行的ip规则
# IPv4 local connections:
host    all             all             192.168.0.0/16            md5

host配置写法如下

#初始化数据库
/home/postgres/bin/initdb -D $PGDATA -E UTF8
#可以将“$PGDATA”写成“/home/postgres/data”

7、数据库启动

/home/postgres/bin/pg_ctl -l /home/postgres/server.log start

8、数据库连接

./bin/psql
#如果使用的不是默认端口,./bin/psql -p 5432

8、创建数据库,创建用户并设置密码

CREATE DATABASE bcia_fire;
CREATE USER test WITH PASSWORD 123456;

此时就可以用可视化软件(Navicat Premium 15)连接 建议使用高版本Navicat,用12版本的Navicat 是看不到数据库中表

经验分享 程序员 微信小程序 职场和发展