分享

Ubuntu下安装Postgresql

 云中凌 2014-10-24

一、在Ubuntu下安装Postgresql

1.使用 apt-get install 安装

$ sudo apt-get install -y postgresql-9.1 postgresql-client-9.1 postgresql-contrib-9.1 postgresql-server-dev-9.1

二、修改PostgreSQL数据库的默认用户postgres的密码

1.使用postgres用户登录psql客户端

$ sudo -u postgres psql

2.修改PostgreSQL默认用户postgres的密码(postgres=#为psql中的命令行)

postgres=# ALTER USER postgres WITH PASSWORD 'postgres';

3.退出PostgreSQL的psql客户端

postgres=# \q

三、修改Linux系统的postgres用户的密码

1.设置PostgreSQL用户密码

PostgreSQL数据库默认会创建一个Linux用户postgres,通过下面的代码修改密码为'postgres’。

$ sudo -u postgres passwd
    输入新的 UNIX 密码:
    重新输入新的 UNIX 密码:

现在就可以在数据库服务器上,用postgres账号通过psql或者pgAdmin等等客户端操作数据库了。

四、修改PostgresSQL数据库配置实现远程访问

1.监听任何地址访问,修改连接权限

将/etc/postgresql/9.1/main/postgresql.conf文档中如下注释去掉:

#listen_addresses = ‘localhost’ 改为 listen_addresses = ‘*’
    #password_encryption = on 改为 password_encryption = on

在/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

2.重启PostgreSQL数据库

$ /etc/init.d/postgresql restart

五、管理PostgreSQL用户和数据库

1.登录postgre SQL数据库

$ psql -U postgres -h 127.0.0.1

2.创建新用户test,密码123456,无建数据库的权限

$ postgres=# create user “test” with password ‘123456’ nocreatedb;

3.建立数据库,并指定所有者

$ postgres=# create database “testdb” with owner=”test”;

六、安装postgresql数据库pgAdmin3客户端管理程序

$ apt-get install -y pgadmin3

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多