centos7中,默认的pgsql版本为9.2.241
2
3
4
5
6
7
8================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
postgresql-server x86_64 9.2.24-1.el7_5 updates 3.8 M
Installing for dependencies:
postgresql x86_64 9.2.24-1.el7_5 updates 3.0 M
postgresql-libs x86_64 9.2.24-1.el7_5 updates 234 k
如果要安装10版本呢?
访问pgsql官方下载页面,https://www.postgresql.org/download/linux/redhat/
选择版本:10
平台:CentOS 7
架构:x86_64
便可以得到安装步骤,我综合了参考[1]中的一些设置,安装步骤具体如下:
这次我同样也是在proxmox开了个kvm的虚拟机,专门用作服务的数据库使用,想着安全稳定,所以安装了CentOS-7.
安装镜像:CentOS-7-x86_64-Minimal-1804.iso 最小化镜像即可
- pre-setup
关闭selinux
vim /etc/selinux/config1
SELINUX=disabled
停止firewall并关闭开机启动1
2systemctl stop firewalld.service
systemctl disable firewalld.service
- 安装pgsql的RPM仓库:
1
yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm
安装完了后,就可以使用yum搜索到pgsql10的相关包了1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21# yum search postgresql10
...
========================== N/S matched: postgresql10 ===========================
postgresql10-debuginfo.x86_64 : Debug information for package postgresql10
postgresql10-tcl-debuginfo.x86_64 : Debug information for package
: postgresql10-tcl
postgresql10.x86_64 : PostgreSQL client programs and libraries
postgresql10-contrib.x86_64 : Contributed source and binaries distributed with
: PostgreSQL
postgresql10-devel.x86_64 : PostgreSQL development header files and libraries
postgresql10-docs.x86_64 : Extra documentation for PostgreSQL
postgresql10-libs.x86_64 : The shared libraries required for any PostgreSQL
: clients
postgresql10-odbc.x86_64 : PostgreSQL ODBC driver
postgresql10-plperl.x86_64 : The Perl procedural language for PostgreSQL
postgresql10-plpython.x86_64 : The Python procedural language for PostgreSQL
postgresql10-pltcl.x86_64 : The Tcl procedural language for PostgreSQL
postgresql10-server.x86_64 : The programs needed to create and run a PostgreSQL
: server
postgresql10-tcl.x86_64 : A Tcl client library for PostgreSQL
postgresql10-test.x86_64 : The test suite distributed with PostgreSQL
安装pgsql包和第三方社区贡献(Contributed source)包
1
yum install -y postgresql10-server postgresql10-contrib
初始化
1
/usr/pgsql-10/bin/postgresql-10-setup initdb
修改设置
vim /var/lib/pgsql/10/data/pg_hba.conf
在IPv4 local connections位置添加1
host all all 0.0.0.0/0 md5
或者其他指定ip段,ip地址使用CIDR格式
客户端再用ssh中转即可
修改监听网卡地址,外网可访问
vim /var/lib/pgsql/data/postgresql.conf1
listen_addresses = '*'
启动pgsql
1
2systemctl enable postgresql-10
systemctl start postgresql-10postgres的默认密码为空,上面弄好以后记得改密码。
1
2
3sudo su - postgres
psql
ALTER USER postgres PASSWORD 'passwordhere';
ps:
python操作pgsql的模块psycopg2:1
pip install psycopg2
参考: