你好,游客 登录 注册 搜索
背景:
阅读新闻

Ubuntu 12.04下PostgreSQL-9.1 在线安装及配置详解

[日期:2016-07-06] 来源:Linux社区  作者:Linux [字体: ]

说明:

      我是用root用户在终端登陆的,如果是非root用户,那在命令前需要加上"sudo",你懂的...

第一步:Ubuntu下安装Postgresql

        1.使用 apt-get install 安装
        root@server2-virtual-machine:~# apt-get install -y postgresql-9.1 postgresql-client-9.1 postgresql-contrib-9.1 postgresql-server-dev-9.1 
       [代码说明] 
       安装服务端和命令行客户端psql。等待一段时间,系统会自动从网上下载下安装文件并完成安装

第二步:修改PostgreSQL数据库的默认用户postgres的密码(注意不是linux系统帐号)
         2.PostgreSQL登录(使用psql客户端登录)
        root@server2-virtual-machine:~# sudo -u postgres psql        
        //其中,sudo -u postgres 是使用postgres 用户登录的意思
        //PostgreSQL数据默认会创建一个postgres的数据库用户作为数据库的管理员,密码是随机的,所以这里
        //设定为
'postgres'
        3.修改PostgreSQL登录密码:
          postgres=# ALTER USER postgres WITH PASSWORD 'postgres';
         //postgres=#为PostgreSQL下的命令提示符
        4.退出PostgreSQL psql客户端
        postgres=# \q
        [代码说明]
       ‘#’和’#'之前的字符是系统提示符,’postgres=#’是psql客户端的提示符,红色字符为输入命令(本文其它部分亦如此);
        [功能说明]
       PostgreSQL数据默认会创建一个postgres的数据库用户作为数据库的管理员,密码是随机的,我人需要修改为指定的密码,这里设定为’postgres’
第三步:修改linux系统的postgres用户的密码(密码与数据库用户postgres的密码相同)
        1.删除PostgreSQL用户密码
        root@server2-virtual-machine:~# sudo passwd -d postgres
        passwd: password expiry information changed.
        //passwd -d 是清空指定用户密码的意思
        2.设置PostgreSQL用户密码
        PostgreSQL数据默认会创建一个linux用户postgres,通过上面的代码修改密码为'postgres’(这取决于 
        第二步中的密码,只要与其相同即可)。
        现在,我们就可以在数据库服务器上用 postgres帐号通过psql或者pgAdmin等等客户端操作数据库了。
        root@server2-virtual-machine:~#sudo -u postgres passwd
        输入新的 UNIX 密码:
        重新输入新的 UNIX 密码:
        passwd:已成功更新密码

第四步:修改PostgresSQL数据库配置实现远程访问
        root@server2-virtual-machine:~# vi /etc/postgresql/9.1/main/postgresql.conf
          1.监听任何地址访,修改连接权限
          #listen_addresses = ‘localhost’改为 listen_addresses = ‘*’        
          2.启用密码验证

          #password_encryption = on改为password_encryption = on
          3.可访问的用户ip段
          root@server2-virtual-machine:~# vi /etc/postgresql/9.1/main/pg_hba.conf,并在文档末尾加上以下内容
       
# to allow your client visiting postgresql server
          host all all 0.0.0.0 0.0.0.0 md5
          4.重启
PostgreSQL数据库
          root@server2-virtual-machine:~# /etc/init.d/postgresql restart
       
         
第五步:管理PostgreSQL用户和数据库
            1.登录postgre SQL数据库
          root@server2-virtual-machine:~# psql -U postgres -h 127.0.0.1
            2.创建新用户zhaofeng,但不给建数据库的权限
            postgres=# create user “zhaofeng” with password ‘123456’ nocreatedb;
          //注意用户名要用双引号,以区分大小写,密码不用
            3.建立数据库,并指定所有者
           
postgres=# create database “testdb” with owner=”zhaofeng”;
            4.在外部命令行的管理命令
            root@server2-virtual-machine:~# -u postgres createuser -D -P test1
            //
-D该用户没有创建数据库的权利,-P提示输入密码,选择管理类型y/n
            root@server2-virtual-machine:~# -u postgres createdb -O test1 db1
            //
-O设定所有者为test1

第六步:安装postgresql数据库pgAdmin3客户端管理程序
          root@server2-virtual-machine:~# apt-get install -y pgadmin3
       
 
PS:如果要在Ubuntu的图形界面启动pgadmin,只需要按下键盘的windows键,在搜索中输入pgadmin,就可以查找到它,点击就可以启动。如果要方便以后使用,可以把它拖到启动器上锁定就行了。

------------------------------------华丽丽的分割线------------------------------------

CentOS 6.5上编译安装PostgreSQL 9.3数据库 http://www.linuxidc.com/Linux/2016-06/132272.htm

CentOS 6.3环境下yum安装PostgreSQL 9.3 http://www.linuxidc.com/Linux/2014-05/101787.htm

PostgreSQL缓存详述 http://www.linuxidc.com/Linux/2013-07/87778.htm

Windows平台编译 PostgreSQL http://www.linuxidc.com/Linux/2013-05/85114.htm

Ubuntu下LAPP(Linux+Apache+PostgreSQL+PHP)环境的配置与安装 http://www.linuxidc.com/Linux/2013-04/83564.htm

Ubuntu上的phppgAdmin安装及配置 http://www.linuxidc.com/Linux/2011-08/40520.htm

CentOS平台下安装PostgreSQL9.3 http://www.linuxidc.com/Linux/2014-05/101723.htm

PostgreSQL配置Streaming Replication集群 http://www.linuxidc.com/Linux/2014-05/101724.htm

------------------------------------华丽丽的分割线------------------------------------

PostgreSQL 的详细介绍请点这里
PostgreSQL 的下载地址请点这里

本文永久更新链接地址http://www.linuxidc.com/Linux/2016-07/132952.htm

linux
相关资讯       Ubuntu 12.04下安装PostgreSQL