ubuntu安装postgreSQL 9.3

  1. Install dependency
    Open Terminal and execute the following commands:
    1
    2
    sudo apt-get update
    sudo apt-get -yinstallpython-software-properties
  2. Add PostgreSQL 9.3 repository
    Before installing PostgreSQL 9.3, we have to add the PostgreSQL repository where the packages are located.
    Setup key:
    1
    wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc |sudoapt-key add -

    Setup repository:
    Run the following command and note down the output. It is the codename of your Ubuntu release.

    1
    lsb_release -c

    Replace the codename in the below command with the one you got from above command and run:

    1
    sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ codename-pgdg main" >> /etc/apt/sources.list.d/postgresql.list'
  3. Install PostgreSQL 9.3 using aptitude
    1
    2
    sudo apt-get update
    sudo apt-get install postgresql-9.3 pgadmin3
  4. Accessing Database from Terminal
    Installation of PostgreSQL will automatically create a Unix/Ubuntu user, namedpostgres. We will have to login with this user in order to perform various database activities such as accessing database, taking and restoring backups, starting/stopping server etc.
    We may need to reset the password for postgres user before we are able to login to that account.

     The UNIX user, postgres is locked by default. Changing the password for this user will unlock the account. It is not preferred and even considered as a serious security threat.

    To start with PostgreSQL, you can connect to the default database using the following command:

    1
    sudo -u postgres psql

    For other activities like taking data base dump, you have to login as postgres UNIX user as shown below(assuming you have root user privileges):

    1
    sudo su postgres
  5. Accessing Database from pgAdmin
    Just like the Unix user, PostgreSQL will also create a database user named postgres, which we should use for login to database for the first time.
    To be able to access database from pgAgent3, we should follow either one of the following two options:
    1. Change the password for the postgres DB user
    2. Change the database access rights  in the pg_hba.conf file

    We will proceed with the second method, since setting password for postgres DB user is not preferred.

    1. After loging into postgres DB in terminal, run the following command to get the path to your pg_hba.conf file
      1
      show hba_file;

      In my case it returned: /etc/postgresql/9.3/main/pg_hba.conf

    2. Open the file using any text editors
      1
      sudo gedit/etc/postgresql/9.3/main/pg_hba.conf

      And replace the two lines mentioned below:

      1
      local  all             all                                    md5

      to

      1
      local  all             all                                    trust

      And

      1
      host    all             all             127.0.0.1/32           md5

      to

      1
      host    all             all             127.0.0.1/32           trust

      If you are not able to find any lines similar to above two lines, adding the substitute lines at the top of the file will also do the job.

    3. Restart PostgreSQL server once.
      sudo /etc/init.d/postgresql stop
      sudo /etc/init.d/postgresql start

    If you want more information about the pg_hba.conf file and its contents, you can read it here or here.

  6. That’s it!  You’ve installed PostgreSQL 9.3 on Ubuntu and now you can use pgAdmin3 to login to your database with any password.

转自:http://technobytz.com/install-postgresql-9-3-ubuntu.html

cyper的笔记:
sudo -u postgres psql的意思是做为一个sudoer,我(当前为cyper)切换到用户postgres下执行psql命令(PostgreSQL的命令行程序),
执行的结果如下:
cyper@cyper-pc:~$ sudo -u postgres psql
psql (9.3.5)
Type "help" for help.


postgres=# \q

输入\q退出postgresql命令行提示符并切回当前用户(cyper)

2.我没有找到这行
local  all             all                                    md5
我找到了两行以host开始以md5结尾的,我把那两个md5替换成了trust如下:


暂时没有发现任何问题

3.文中提到了不要修改postgres的密码
(这个用户默认是被锁定的,不修改密码就不会激活这个用户,但是本地的sudoers可以执行postgres+任意密码来使用该数据库)

继续阅读这里:http://blog.sina.com.cn/s/blog_6af33caa0100ypck.html




转载于:https://my.oschina.net/uniquejava/blog/347003

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值