postgresql9.5 安装使用
1 下载&安装postgresql9.5
1.1 官网下载
https://www.postgresql.org/download/linux/redhat/
1.2 下载postgresql9.5的repo
# yum install https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-7-x86_64/pgdg-redhat95-9.5-3.noarch.rpm
# ll /etc/yum.repos.d/
-rw-r--r-- 1 root root 482 Jan 5 2016 pgdg-95-redhat.repo1.3 安装postgresql9.5的客户端
# yum install postgresql95
1.4安装postgresql9.5的服务端
# yum install postgresql95-server
1.5 设置数据库开机自起
# systemctl enable postgresql-9.5
# systemctl start postgresql-9.5
1.6 查看数据运行的状态
# systemctl status postgresql-9.5.service
● postgresql-9.5.service - Postgresql 9.5 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-9.5.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2018-04-18 07:40:03 EDT; 52s ago
*****************
1.7 初始化postgresql9.5数据库
# /usr/pgsql-9.5/bin/postgresql95-setup initdb
Initializing database ... OK
2 配置 & 使用postgresql9.5数据库
参考:https://help.ubuntu.com/stable/serverguide/postgresql.html
2.1 修改postgres用户的密码
# su - postgres
-bash-4.2$ psql -U postgres
postgres=# \? -- 查看帮助
postgres=# ALTER USER postgres WITH PASSWORD '1234' --修改postgres用户的密码
2.2开启远程访问数据库
# vi /var/lib/pgsql/9.5/data/postgresql.conf
******
listen_addresses = '*' # what IP address(es) to listen on;
2.3信任远程连接
修改成以下配置
# vi /var/lib/pgsql/9.5/data/pg_hba.conf
***********
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all ::/32 md5
local replication postgres md5
2.4 关闭linux服务器的防火墙
#systemctlstopfirewalld
#systemctldisablefirewalld
2.5 重启postgresql服务
# systemctl restart postgresql-9.5.service