PostgreSQL安装

PostgreSQL Linux环境安装

  • 安装环境:Centos7
  • postgresql版本:13.0
  • 安装方式:编译安装

1、下载

  • 官网下载:https://ftp.postgresql.org/pub/source/v13.0/postgresql-13.0.tar.gz
  • wget下载:wget https://ftp.postgresql.org/pub/source/v13.0/postgresql-13.0.tar.gz

2、安装前准备

  • 配置用户和组
groupadd postgres
useradd postgres -g postgres
  • 环境准备
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 /opt/software/postgres
chown -R postgres:postgres /opt/software/postgres/
  • 配置环境变量
vi /etc/profile

#在文件末尾将以下环境变量添加进去
export PATH=/opt/software/postgres/bin:$PATH
export PG_HOME=/opt/software/postgres
export PGDATA=/opt/software/postgres/data/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PG_HOME/lib/
export PATH=$PG_HOME/bin:$PATH

3、安装过程

3.1、安装数据库

cd 下载好的压缩包存放路径

#解压文件
tar -zxvf postgresql-13.0.tar.gz

cd  postgresql-13.0
#参数根据自己需求配置
./configure --prefix=/opt/software/postgres/ --with-python --with-libxml --with-libxslt
make
make install

3.2、初始化数据库

# 切换用户,不能用root用初始化
su postgres

#初始化数据库的参数也是根据自己需要添加 ,可以通过--help查看
/opt/software/postgres/bin/initdb -D $PGDATA  -E  UTF8  

#如果出现以下message就说明初始化成功了
*********************************************************************

    creating directory /opt/software/postgres/data ... ok
    creating subdirectories ... ok
    selecting default max_connections ... 100
    selecting default shared_buffers ... 128MB
    selecting dynamic shared memory implementation ... posix
    creating configuration files ... ok
    running bootstrap script ... ok
    performing post-bootstrap initialization ... ok
    syncing data to disk ... ok
    
    WARNING: enabling "trust" authentication for local connections
    You can change this by editing pg_hba.conf or using the option -A, or
    --auth-local and --auth-host, the next time you run initdb.
    
    Success. You can now start the database server using:
    
        /opt/software/postgres/bin/pg_ctl -D /opt/software/postgres/data -l logfile start
    
********************************************************************
#启动数据库服务

#数据文件和日志文件的路径根据自己需求指定。
/opt/software/postgres/bin/pg_ctl -D $PGDATA -l /opt/software/postgres/server.log start

到此postgres服务就安装完毕了。

4、使用数据库

  • 进入数据库
su postgres

#进入数据库

[postgres@localhost postgres]$ psql
psql ()
Type "help" for help.

postgres=#
  • 修改数据库配置,允许其他服务器连接
#postgres安装好以后需要修改2个配置文件才能允许别的服务器访问。
cd /opt/software/postgres/data

vi postgresql.conf
#找到listen_addresses和port参数,修改如下,也可根据自己需求修改
listen_addresses = '*'
port = 5432

#根据自己的网段设置下放行的ip规则
vi pg_hba.conf

# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
host    all             all             0.0.0.0/0               trust

配置好以后就可以使用postgres数据库了。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值