您的位置:首页 > Web前端

Fedora下postgresql的安装与配置

2011-07-11 21:11 555 查看
1、安装
yum install postgresql-server
附带安装:postgresql, postgresql-libs

2、数据库初始化
# su - postgres
$ initdb /var/lib/pgsql/data/
$ pg_ctl -D /var/lib/pgsql/data -l logfile start

3、简单测试
//创建数据库test
$ createdb test
//显示数据库
$ psql -l
//创建用户
$ createuser -sADEP testuser
//测试用户登录
$ psql -d test -U testuser

4、修改配置,提供外部连接
修改文件/var/lib/pgsql/data/pg_hba.conf
添加内容(此处为本地IP,根据IP修改):
hostssl all all 127.0.0.1/32 md5

修改文件/var/lib/pgsql/data/postgresql.conf
放开listen_addresses和port的注释,修改为:
listen_addresses = '*'
port = 5432

重新加载配置:
$ pg_ctl -D /var/lib/pgsql/data reload

5、用pgadmin3连接
安装pgadmin3,打开连接。

6、django连接
安装python-psycopg2
配置Django配置文件settings.py
DATABASE_ENGINE = 'postgresql_psycopg2'
DATABASE_NAME = 'test'
DATABASE_USER = 'testuser'
DATABASE_PASSWORD = '123456'

测试连接:
python manage.py shell
>>> from django.db import connection
>>> cursor = connection.cursor()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: