数据库

 首页 > 数据库 > postgresql > Ubuntu系统中安装Postgresql和pgAdmin3的步骤

Ubuntu系统中安装Postgresql和pgAdmin3的步骤

分享到:
【字体:
导读:
         摘要:sudoapt-getinstallpostgresql-8.4postgresql-client-8.4postgresql-contrib-8.4sudoapt-getinstallpgadmin3以上指令安装客户端和服务端,一些额外的工具、pgAdmin3都可以工作在数据库下工作。配置Postgresql现在我们...

Ubuntu系统中安装Postgresql和pgAdmin3的步骤

sudo apt-get install postgresql-8.4 postgresql-client-8.4 postgresql-contrib-8.4

sudo apt-get install pgadmin3

以上指令安装客户端和服务端,一些额外的工具、pgAdmin3都可以工作在数据库下工作。

配置Postgresql

现在我们需要重置“postgres”用户的密码。

sudo su postgres -c psql template1
template1=# ALTER USER postgres WITH PASSWORD ‘xxxx’
template1=# q

这样就修改了数据库中的密码,现在我们也需要在unix用户“postgres”这么作。

sudo passwd -d postgres
sudo su postgres -c passwd

然后输入跟之前一样的密码。

现在,我们就可以在数据库服务器上使用psql或者pgAdmin操作数据库了。

但是若想在pgAdmin中能够更好的记录日志和监视的华,在启动pgAdmin前需要建立PostgreSQL admin pack。打开命令行。

首先,我们需要编辑postgresql.conf:

sudo gedit /etc/postgresql/8.4/main/postgresql.conf

现在,我们需要修改“连接和权限”两行。

改变行:
#listen_addresses = ‘localhost’
修改为:
listen_addresses = ‘*’
和行:
#password_encryption = on
修改为:
password_encryption = on

保存并关闭gedit。

最后一步,我们必须设置谁才可以操作数据服务器,这一切都是在pg_hba.conf中完成的。

sudo gedit /etc/postgresql/8.4/main/pg_hba.conf

把以下内容复制到pg_hba.conf底部:

# DO NOT DISABLE!
# If you change this first entry you will need to make sure that the
# database
# super user can access the database using some other method.
# Noninteractive
# access to all databases is required during automatic maintenance
# (autovacuum, daily cronjob, replication, and similar tasks).
#
# Database administrative login by UNIX sockets
local all postgres ident sameuser
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# “local” is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Connections for all PCs on the subnet
#
# TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD
host all all [ip address] [subnet mask] md5

在最后一行中,添加你的子网掩码(如255.255.255.0)和机器IP地址(如138.250.192.115). 如果要使用一个IP地址范围,只需要把最后一个数字用0替换,那么所有这个网段的IP都可以使用了。

例子
# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

# "local" is for Unix domain socket connections only
local   all         all                               trust
# IPv4 local connections:
host    all         all         127.0.0.1/32          trust
host    all         all         192.0.0.1/8          trust
host    all         all         143.0.0.1/8          trust
host    all         all         172.0.0.1/8          trust
# IPv6 local connections:
host    all         all         ::1/128               trust

重启服务器即可。

sudo /etc/init.d/postgresql-8.4 restart

现在可以在Ubuntu下使用PostgreSQL了。

使用命令行创建数据库

sudo -u postgres createuser -D -A -P mynewuser
sudo -u postgres createdb -O mynewuser mydatabase

Ubuntu系统中安装Postgresql和pgAdmin3的步骤
分享到:
MySQL与PostgreSQL如何选择
MySQL与PostgreSQL如何选择 Naresh Kumar是一位软件工程师与热情的博主,对编程与新事物充满了激情和兴趣。近日,Naresh撰写了一篇博文,对开源世界最常见的两种数据库MySQL与PostgreSQL的特点进行了详尽的分析和比对。 如果打算为项目选择一款免费、开源的数据库,那么你可能会在MySQL与PostgreSQL之间犹豫不定。MySQL...
libpq-PostgreSQL客户端编程接口使用基础...
libpq-PostgreSQL客户端编程接口使用基础教程 PostgreSQL作为目前最优秀的跨平台的开源数据库,其介绍及优点这里不再赘述,它能让我以最快的速度忘记my*,ms*。libpq是PostgreSQL的C应用程序接口,它允许客户程序向PostgreSQL服务器进程发送查询并获得查询结果。 我的实验环境是: 操作系统:Linux wheezy 3.2.0-4-amd6...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……