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

 

 
原文地址:https://www.cnblogs.com/maybo/p/5250588.html