centos 7.5 安装postgresql 软件

https://mp.csdn.net/postedit/83785475

postpresql+postgis交流QQ群:642773979

1、安装pgsql软件(在线装postgresql 10.5)

安装前:

安装环境:CentOS-7-x86_64-Minimal-1804

其他设置:

禁用防火墙:systemctl disable firewalld

禁用selinux:

修改/etc/selinux/config 文件将SELINUX=enforcing改为SELINUX=disabled重启机器即可

 

安装可能需要的依赖库 

yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm

yum install -y readline readline-devel gcc.x86_64 glibc.x86_64 glibc-devel.x86_64 vim-enhanced.x86_64 gcc-java apr apr-devel openssl openssl-devel libgcc.x86_64 perl-Module-Install.noarch

安装PostgreSQL
yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm
yum install -y postgresql10-contrib.x86_64 postgresql10-server.x86_64

2、配置环境变量
vi /etc/profile
在/etc/profile的末尾添加如下配置:
export PATH=$PATH:/usr/pgsql-10/bin
export PGHOME=/usr/pgsql-10
export PGDATA=/data/pgsql
export PATH=$PGHOME/bin:$PATH:$HOME/bin
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH

保存退出后刷新环境变量
source /etc/profile
postgres --version
postgres (PostgreSQL) 10.5

3、初始化数据库
创建数据存储目录
mkdir -p /data/pgsql
修改目录权限 
chown  postgres:postgres /data/pgsql
初始化数据库
su postgres
initdb  -U postgres -E utf8 -D /data/pgsql  

4、修改配置文件
1)、配置数据库访问
将前两个host中的127.0.0.1/32改为0.0.0.0/0,以下为修改后的
vi /data/pgsql/pg_hba.conf
IPv4 local connections:
host    all             all             0.0.0.0/0               trust
replication privilege.
local   replication     all                                     trust
host    replication     all             0.0.0.0/0               trust

0.0.0.0/0表示允许连接的主机信息,可以使用主机IP地址, 也可以使用网段来表示,如192.168.5.0/24表示192.168.5.0网段可以连接

2)、修改pg_hba.conf
找到listen_addresses和port修改即可。
vi /data/pgsql/postgresql.conf
listen_addresses='*'
port=5432 

主要配置参数详解:
listen_addresses='localhost'        Postgresql监听的网卡ip,默认仅仅本地,可以配置多个,使用“,”分割。“*” 代表所有的网卡ip
port=5432                          Postgres服务端口
max_connections=100               最大服务器连接数
superuser_reserved_connections=3   为管理员保留的专用连接数,普通用户无法使用这些连接,不能大于max_connections
authentication_timeout=60s  登录验证超时时间设置
ssl=false                    是否使用SSL进行连接
password_encryption=true   当使用create user、alter user管理用户时,如果没有显示进行加密与否的限定,postgresql服务器是否自动进行密码加密
shared_buffers=32m          共享缓存,非常重要的性能参数,其最小值为(128k,16k*max_connections)
max_prepared_transactions=5  最大并行prepared 事务,如果为0,则禁止使用prepared事务,最大值与max_connections相同
temp_buffers=8m              每个会话可以使用的临时(表)缓存大小
work_mem=1m                  指定内部排序、连接、group等等时,postgresql可以使用的内存大小,超过该值,将使用磁盘临时文件; 实际使用的内存和该类操作同时执行的数目相乘
maintenance_work_men=16m    维护语句vacuum、create index等等可以使用的内存大小; 实际使用的内存和该类操作同时执行的数目相乘
fsync=on                  (物理数据)日志必须同步写入磁盘可能导致严重的性能损失,却能确保最高的日志数据安全。
synchronous_commit=on       (逻辑事务数据)日志必须同步写入磁盘,如果设为on,会立即调用fsync,相当于设置了fsync=on
full_page_writes=on          写整页
wal_buffers=64K                 WAL日志缓存大小
wal_writer_delay=200ms      将wal日志从wal_buffer中写入磁盘的时间周期
commit_delay=0ms           事务日志commit后,写入磁盘的延时。这个设置只有在commit_sibings(并行的多个排队事务)在延时内存在是才有效
commit_siblings=5             并行事务数

5、启动数据库
pg_ctl start -D /data/pgsql

登录postgresql并设置密码,postgresql在安装时默认添加用户postgres
su - postgres && cd ~
连接数据库
psql -h localhost -U postgres
修改postgres用户密码为postgres
alter user postgres with password 'postgres'

至此,pgsql安装完成,可以使用客户端工具进行远程连接。
参考:
启动数据库:    pg_ctl start -D /data/pgsql
重启数据库:    pg_ctl restart -D /data/pgsql
停止数据库:    pg_ctl stop -D /data/pgsql
强制重启:      pg_ctl restart -D /data/pgsql -m f
强制停止:      pg_ctl stop -D /data/pgsql -m f
加载配置:      pg_ctl reload -D /data/pgsql
显示服务状态:  pg_ctl status -D /data/pgsql

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值