centos6.5+postgresql10环境搭建

1、首先打开官网,打开download页签,选择linux下面的RedHat,选择想要安装的版本,我这里是10,系统选用的是centOs6.5,架构是x86或者64;

centos6.5+postgresql10环境搭建

centos6.5+postgresql10环境搭建

centos6.5+postgresql10环境搭建


2、按照给出的命令,执行安装步骤,首先是安装rpm仓库:

yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-6-x86_64/pgdg-centos10-10-1.noarch.rpm

centos6.5+postgresql10环境搭建


3、安装客户端安装包:

yum install postgresql10

centos6.5+postgresql10环境搭建


4、安装服务器端安装包:

yum install postgresql10-server

centos6.5+postgresql10环境搭建


5、初始化数据库:

service postgresql-10 initdb

centos6.5+postgresql10环境搭建


6、设置数据库开机启动:

chkconfig postgresql-10 on


7、开启数据库服务

service postgresql-10 start


8、进入postgresql命令行模式,需要注意的是,最好以root用户切换到postgres用户,不然需要密码;

centos6.5+postgresql10环境搭建


9、\l命令查看所有数据库:

centos6.5+postgresql10环境搭建


10、执行sql创建数据库:

centos6.5+postgresql10环境搭建



11、切换到数据库:

centos6.5+postgresql10环境搭建


12、查看所有表:

centos6.5+postgresql10环境搭建


13、创建表,在输入sql语句的时候,可以输入回车符,末尾输入分号才会执行sql语句:

centos6.5+postgresql10环境搭建


14、插入数据并显示:

centos6.5+postgresql10环境搭建


接下来是新建用户,并设置可以远程访问:

15、查看当前postgresql的用户,当前只有postgres一个用户:

centos6.5+postgresql10环境搭建


16、新建用户,在赋值命令的时候注意单引号的中英文输入:

create user ambzer superuser password ‘password123’;

centos6.5+postgresql10环境搭建


17、postgresql默认安装位置在/var/lib/pgsql下:

centos6.5+postgresql10环境搭建


18、编辑postgresql.conf文件,设置监听所有ip的请求:

vim /var/lib/pgsql/10/data/postgresql.conf,

在文件中快速定位到listen_addresses这一行,将开头的#去除,将localhost改为*,然后保存退出,快速定位的方法:摁esc退出编辑模式,输入“:/listen_addr”回车就可以快速定位到匹配的行。

centos6.5+postgresql10环境搭建


19、编辑pg_hba.conf文件:

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

在该位置添加如下内容:

centos6.5+postgresql10环境搭建

,如果想要特定网段ip的主机连接,请将0.0.0.0/0设置为对应的ip加子网掩码

重启postgresql服务:

centos6.5+postgresql10环境搭建


20、查看数据库服务器ip地址:

centos6.5+postgresql10环境搭建


21、设置防火墙开放5432端口,编辑防火墙的配置文件:

vim /etc/sysconfig/iptables;

在图中位置添加一下命令:

centos6.5+postgresql10环境搭建

重启防火墙服务即可:

service iptables restart

使用Navicat远程连接数据库:

centos6.5+postgresql10环境搭建

使用idea连接数据库:

centos6.5+postgresql10环境搭建