欢迎投稿

今日深度:

centos73 postgresql9.6.2rpm 安装,

centos73 postgresql9.6.2rpm 安装,


postgresql9.6.2 rpm 安装

1、安装rpm包

rpm -ivf postgresql96-libs-9.6.2-2PGDG.rhel7.x86_64.rpm 

rpm -ivf postgresql96-9.6.2-2PGDG.rhel7.x86_64.rpm 

rpm -ivf postgresql96-server-9.6.2-2PGDG.rhel7.x86_64.rpm 

rpm -ivf postgresql96-contrib-9.6.2-2PGDG.rhel7.x86_64.rpm

rpm -ivf postgresql96-devel-9.6.2-2PGDG.rhel7.x86_64.rpm


2、初始化PostgreSQL 数据库

/usr/pgsql-9.6/bin/postgresql96-setup initdb

3、启动服务

systemctl start postgresql-9.6.service

4、把PostgreSQL 服务加入到启动列表

systemctl enable postgresql-9.6.service

5、修改PostgreSQL 数据库用户postgres的密码(注意不是linux系统帐号)

PostgreSQL 数据库默认会创建一个postgres的数据库用户作为数据库的管理员,默认密码为空,我们需要修改为指定的密码,这里设定为’postgres’。

# su - postgres 切换用户,执行后提示符会变为 '-bash-4.2$'

  

$  psql 登录数据库,执行后提示符变为 'postgres=#'

  

postgres=# alter user postgres with password 'postgres';

ALTER ROLE

postgres=# select * from pg_shadow;

6、测试数据库

6.1 创建测试数据库

postgres=# create database test;

6.2、切换到david 数据库

# \c test

6.3、创建测试表

test=# create table t1 (id integer, name text);

6.4、插入测试数据

test=# insert into t1 values (1,'t1');

INSERT 0 1

test=# 

6.5、选择数据

test=# select * from t1 ;

 id | name  

----+-------

  1 | t1

(1 row)

test=#

测试完成,RPM包安装成功。

7、修改linux 系统用户postgres 的密码

PostgreSQL 数据库默认会创建一个linux 系统用户postgres,通过passwd 命令设置系统用户的密码为postgres。

# passwd postgres

8、修改PostgresSQL 数据库配置实现远程访问

8.1 修改postgresql.conf 文件

# vim /var/lib/pgsql/9.6/data/postgresql.conf

如果想让PostgreSQL 监听整个网络的话,将listen_addresses 前的#去掉,并将 listen_addresses = 'localhost' 改成 listen_addresses = '*'

8.2 修改客户端认证配置文件pg_hba.conf

将需要远程访问数据库的IP地址或地址段加入该文件。

# vim /var/lib/pgsql/9.6/data/pg_hba.conf

在“# IPv4 local connections”添加

host    all             all             127.0.0.1/32            ident

host    all             all             192.168.1.199/24        md5

9. 重启服务以使设置生效

# systemctl restart postgresql-9.6.service

10、远程测试可以使用客户端工具或者装有postgresql的机器,通过cmd访问

psql -U postgres -h 192.168.1.199

问题:

1)、配置支持远程连接

$ vim /var/lib/pgsql/9.6/data/pg_hba.conf

#### 直接配置为不限制IP,即0.0.0.0,注意:/后面也必须为0!!! ####

将 127.0.0.1/32 改为 0.0.0.0/0

顺便将该行method属性的ident修改为trust,不然用客户端工具远程连接的时候会报用户postgres ident认证失败的错误。


2)、去除版本号启动服务

cd /usr/lib/systemd/system

ln -s postgresql-9.6.service postgresql.service

以后就可以使用

systemctl start postgresql



本文转自 corasql 51CTO博客,原文链接:http://blog.51cto.com/corasql/1909783,如需转载请自行联系原作者

www.htsjk.Com true http://www.htsjk.com/postgresSQL/10926.html NewsArticle centos73 postgresql9.6.2rpm 安装, postgresql9.6.2 rpm 安装 1、安装rpm包 rpm -ivf postgresql96-libs-9.6.2-2PGDG.rhel7.x86_64.rpm  rpm -ivf postgresql96-9.6.2-2PGDG.rhel7.x86_64.rpm  rpm -ivf postgresql96-server-9.6.2-2PGDG.rhel7....
评论暂时关闭