1. 程式人生 > >centos7上的postgresql10安裝和配置

centos7上的postgresql10安裝和配置

cli local 新建 repo down 切換 pos emctl rep

安裝數據庫

安裝參考官方文檔:https://www.postgresql.org/download/linux/redhat/

1.Install the repository RPM:
yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm
2.Install the client packages:安裝client工具
yum install postgresql10
3.Optionally install the server packages:安裝服務端
yum install postgresql10-server
4.Optionally initialize the database and enable automatic start:初始化數據庫並啟動pgsql
/usr/pgsql-10/bin/postgresql-10-setup initdb
systemctl enable postgresql-10
systemctl start postgresql-10

調整數據庫配置

數據文件目錄:

[root@fkkfapp data]# pwd
/var/lib/pgsql/10/data

修改數據庫監聽端口,開放所有ip監聽,增加所有 ipv4地址接入權限
1.修改postgresql.conf文件


[root@fkkfapp data]# vi /var/lib/pgsql/10/data/postgresql.conf 

修改以下部分:

listen_addresses = '*'       
port = 1521                          

我因為外網代理端口的原因所以修改為1521,正常不需要修改

2.修改pg_hba.conf文件

[root@fkkfapp data]# vi /var/lib/pgsql/10/data/pg_hba.conf 

新增第三行信息

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

3.修改/etc/profile文件,增加PGPORT設置

vi /etc/profile
export PGPORT=1521

4.切換到postgres用戶,測試是否可以連接

-bash-4.2$ psql
psql (10.4)
Type "help" for help.

postgres=# 

5.使用外網navicat測試,可以登錄遠程端口

新建用戶和數據庫

postgres=# create user panda with password 'panda';

postgres=# create database panda owner panda;

postgres=# grant all privileges on database panda to panda;

centos7上的postgresql10安裝和配置