PostgreSQL安装

安装PostgreSQL源

CentOS 6.x 32bit

sudo rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-6-i386/pgdg-centos94-9.4-1.noarch.rpm

CentOS 6.x 64bit

sudo rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-1.noarch.rpm

CentOS 7 64bit

sudo rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.4-1.noarch.rpm

      在添加源的步骤中并没有太多的区别,主要是源的地址有一定的变化。

三、执行安装命令

sudo yum update
sudo yum install postgresql94-server postgresql94-contrib

四、验证是否安装成功

sudo rpm -aq| grep postgres

执行结果如下:

postgresql94-libs-9.4.1-1PGDG.rhel7.x86_64
postgresql94-server-9.4.1-1PGDG.rhel7.x86_64
postgresql94-9.4.1-1PGDG.rhel7.x86_64
postgresql94-contrib-9.4.1-1PGDG.rhel7.x86_64

五、初始化数据库

CentOS 6.x 系统

sudo service postgresql-9.4 initdb

CentOS 7 系统

sudo /usr/pgsql-9.4/bin/postgresql94-setup initdb

在初始化数据库时可以指定参数 --PGDATA=“/data”,该参数是用于指明数据库的数据文件的存放路径,默认是在/var/lib/pgsql/9.4/data路径下。

如果我在CentOS 7下执行 service postgresql-9.4 initdb 将会报如下问题

The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.

六、启动服务并设置为开机启动

CentOS 6.x 系统

sudo service postgresql-9.4 start
sudo chkconfig postgresql-9.4 on

CentOS 7 系统

sudo systemctl enable postgresql-9.4
sudo systemctl start postgresql-9.4

七、开放防火墙端口

CentOS 6.x 系统

vi /etc/sysconfig/iptables

按下I进入输入模式,在文件中加入一下语句

-A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

输入完成后按ESC退出编辑模式,输入:wq退出VI编辑界面。

重启防火墙服务

sudo service iptables restart

CentOS 7 系统

sudo firewall-cmd --permanent --add-port=5432/tcp
sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --reload

八、访问PostgreSQL

su - postgres

输出结果如下:

上一次登录:一 5月 18 15:17:29 CST 2015pts/0 上
-bash-4.2$

输入命令psql将看到PostgrSQL的版本信息。

psql (9.4.1)
输入 "help" 来获取帮助信息.

九、设置postgres用户密码

postgres=# \password postgres

以上操作基本完成整个PostgreSQL的安装。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值