天天看点

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

1、环境准备

检查PostgreSQL 是否已经安装

rpm -qa | grep postgres

检查PostgreSQL 安装位置

rpm -qal | grep postgres

卸载已安装PostgreSQL

rpm –e PostgreSQL版本

查看卸载是否已完成

rpm -qa | grep postgres

新增postgres用户组

groupadd postgres

新增postgres用户并且设置这个用户属于上面创建的postgres用户组

useradd -g postgres postgres

修改postgres用户密码

passwd postgres

2、yum安装

(不需要事先创建用户和用户组)

2.1、安装

使用yum安装postgresql

yum –y install postgresql-server.x86_64

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章
PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

初始化postgresql数据库

service postgresql initdb

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

启动postgresql服务

service postgresql start

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

查看postgresql的服务状态

service postgresql status

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

查postgres的进程信息

ps -ef | grep postgres

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

查postgres的端口号5432是否已经打开

netstat -tpnl |grep 5432

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

设置开机启动postgresql

chkconfig postgresql on

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

2.2、连接测试

切换用户

su postgres

连接数据库

psql -U postgres

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

查看数据库表

select * from pg_shadow;

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

列出所有的数据库

\l

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

退出

\q

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

2.3、修改配置

默认安装时,PostgreSQL的数据库目录在/var/lib/pgsql/data目录

(1)修改postgresql的配置文件

vi /var/lib/pgsql/data/postgresql.conf

修改监听IP:

listen_addresses = '*'

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

日志采集器打开

logging_collector = on

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

设置日志目录

log_directory = 'pg_log'

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

只保留一天的日志,进行循环覆盖

log_truncate_on_rotation = on
log_rotation_age = 1d           
PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

共享内存大小

shared_buffers = 32MB

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

(2)修改postgresql服务连接文件

vi /var/lib/pgsql/data/pg_hba.conf

第80行【local all all peer】peer改为md5

第82行【host all all 127.0.0.1/32 iden】下增加一条,【0.0.0.0/24】允许所有IP连接

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

关闭防火墙

service iptables stop

开放5432端口

iptables -I INPUT -p tcp --dport 5432 -j ACCEPT

重启数据库

service postgresql restart

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

2.4、远程连接

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章
PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

3、离线安装

3.1、安装包准备

访问官网生成下载链接

访问官网

https://www.postgresql.org/

→点击Download→选择需要的操作系统版本

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

在线服务器上下载yum 源

yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

查找安装包

yum search postgres

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

下载 Postgresql

mkdir psql10
yum install --downloadonly --downloaddir=psql10 postgresql10 postgresql10-server           
PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

打包并上传到离线服务器

tar -zcvf pgsql10.tar.gz *

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

3.2、安装

解压并安装

tar -xzvf pgsql10.tar.gz
cd /pgsql10
rpm -ivh postgre*           
PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

设置自启动

systemctl enable postgresql-10
systemctl start postgresql-10           

启动服务

service postgresql-10 initdb
chkconfig postgresql-10 on           

3.3、连接测试

进入创建的用户

su postgres

psql -U postgres

select * from pg_shadow;

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

3.4、修改配置

(1)修改postgresql的配置文件

`

vi /var/lib/pgsql/10/data/postgresql.conf

listen_addresses = '*'

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章
PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

vi /var/lib/pgsql/10/data/pg_hba.conf

第26行【local all all peer】peer改为md5

第28行【host all all 127.0.0.1/32 iden】下增加一条, 【0.0.0.0/24】允许所有IP连接

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

service iptables stop

iptables -I INPUT -p tcp --dport 5432 -j ACCEPT

service postgresql restart

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

3.5、远程连接

PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章
PostGresql数据库Linux服务器安装1、环境准备2、yum安装3、离线安装附:参考文章

附:参考文章

https://www.cnblogs.com/qiyebao/p/4562557.html https://blog.51cto.com/11298469/2414026?source=dra https://www.cnblogs.com/mchina/archive/2012/06/06/2539003.html https://blog.csdn.net/u010177412/article/details/82150207 https://www.postgresql.org/download/linux/redhat/ https://blog.51cto.com/hsbxxl/2117398 https://blog.csdn.net/qq_36395686/article/details/100133098