postgresql centos6.5安装以及常用命令

Posted 沁园下的一缕残云

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了postgresql centos6.5安装以及常用命令相关的知识,希望对你有一定的参考价值。

   今天在centos6.5下安装postgresql数据库,现在整理自己操作步骤。

一. Centos6.5 下安装postgresql9.4

 1.1. 显示所有的有关postgresql安装包

    yum list postgres*

技术分享

1.2. 安装数据库

    yum install postgresql94-server
1.2. 初始化数据库(初始化数据库默认路径在/var/lib/pgsql/9.4/data)
service install postgresql-9.4 initdb
1.3. 启动服务
service postgresql9.4 start

二. postgresql数据库密码设置

  2.1. 切换用户到postgres

      su - postgres

  2.2. 连接数据库

    psql -U postgres

  3.3. 为用户名设置密码

    \password postgres(设置密码)

    alter user postgres with password ‘123456‘(修改)

  3.4. 修改默认的验证方式(重要)

    

    在/var/lib/pgsql/data/pg_hba.conf中,将默认验证方法

        host all all 127.0.0.1/32 ident

         改为密码验证

         host all all 127.0.0.1/32 md5

  3.5. 重启数据库

                systemctl restart postgresql

  3.6. 新用户登陆

    psql -U postgres -h 127.0.0.1 

四. 数据库导入导出命令

       4.1. 备份

      备份数据库:
      -bash-3.2$ pg_dump music >/tmp/music.dmp

      查看备份:

        -bash-3.2$ cd /tmp/
        -bash-3.2$ ls

   4.2. 导入 

psql -U postgres(用户名)  数据库名(缺省时同用户名) < /data/dum.sql

 

 

 

以上是关于postgresql centos6.5安装以及常用命令的主要内容,如果未能解决你的问题,请参考以下文章

centos6.5 编译安装pgsql9.4.4 和主从流复制

CentOS6.5 64??????????????????PostgreSQL9.5.1

Postgresql源码安装

vmware安装centos6.5以及初始化

Centos6.5下的vsftp安装配置

RMBP使用Parallels Desktop安装centos6.5以及搭建redis集群