PostgreSQL安装
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
1
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
1
权限配置
mkdir /opt/software/postgres
chown -R postgres:postgres /opt/software/postgres/
1
2
配置环境变量
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
1
2
3
4
5
6
7
8
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
1
2
3
4
5
6
7
8
9
10
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
到此postgres服务就安装完毕了。
4、使用数据库
进入数据库
su postgres
#进入数据库
[postgres@localhost postgres]$ psql
psql ()
Type "help" for help.
postgres=#
1
2
3
4
5
6
7
8
9
修改数据库配置,允许其他服务器连接
#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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
配置好以后就可以使用postgres数据库了。
————————————————
版权声明:本文为CSDN博主「xiaoxaoyu」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/xiaoxaoyu/article/details/116074446