由于想添加个gis功能模块,看django推荐gis用PostgreSQL数据库,拿来试用下,安装的时候有几个注意的小问题。 html
1.To use the yum repository, you must first install the repository RPM. To do this, download the correct RPM from the repository RPM listing, and install it with commands like:
yum install http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-redhat93-9.3-1.noarch.rpm
2.Once this is done, you can proceed to install and update packages the same way as the ones included in the distribution.
yum install postgresql93-server postgresql93-contrib
service postgresql-9.3 initdb
chkconfig postgresql-9.3 on python
centos须要手动初始化下而后设置默认自启动。 mysql
另外用psycopg2时也碰到几个问题 web
下载问题不大,直接去http://initd.org/psycopg/download/下载tar包就行了,安装的时候报了几回错。 sql
首先一个pg_cong问题,而后一个libpq问题。去看他文档说了这么几点: shell
Psycopg is a C wrapper to the libpq PostgreSQL client library. To install it from sources you will need: 数据库
A C compiler. django
The Python header files. They are usually installed in a package such as python-dev. A message such as error: Python.h: No such file or directory is an indication that the Python headers are missing. ubuntu
The libpq header files. They are usually installed in a package such as libpq-dev. If you get an error: libpq-fe.h: No such file or directory you are missing them. centos
The pg_config program: it is usually installed by the libpq-dev package but sometimes it is not in a PATHdirectory. Having it in the PATHgreatly streamlines the installation, so try runningpg_config --version: if it returns an error or an unexpected version number then locate the directory containing the pg_config shipped with the right libpq version (usually/usr/lib/postgresql/X.Y/bin/) and add it to the PATH:
$ export PATH=/usr/lib/postgresql/X.Y/bin/:$PATH
You only need it to compile and installpsycopg2, not for its regular usage.
Note
The libpq header files used to compilepsycopg2should match the version of the library linked at runtime. If you get errors about missing or mismatching libraries when importingpsycopg2check (e.g. using ldd) if the modulepsycopg2/_psycopg.sois linked to the rightlibpq.so.
2.第二个,折腾了很久,centos里面python-dev 是python-devel,另外libpq-dev叫libpqxx-deve!
我屮艸芔茻!尼玛!
文档介绍忒不清楚!坑爹了!
这样就行了,yum install下,后面就一路顺利了。
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
libpqxx i686 1:4.0.1-1.rhel6 pgdg93 189 k
libpqxx-debuginfo i686 1:4.0.1-1.rhel6 pgdg93 772 k
libpqxx-devel i686 1:4.0.1-1.rhel6 pgdg93 91 k
Installing for dependencies:
postgresql93-devel i686 9.3.3-1PGDG.rhel6 pgdg93 1.4 M
Transaction Summary
================================================================================
Install 4 Package(s)
安装完成以后, 系统中会多出一个名为 postgres 的用户, 这个用户用于登陆数据库. 但没法直接用该用户在 shell 或 xdm 中登陆, 须先用其它用户登陆 shell, 而后su到该用户. 先为该用户设置一下密码
这样会以 postgres 用户身份登陆, 若是要输入密码就输入刚才为 postgres 用户设置的密码.
PostgreSQL默认的超级管理员密码是postgres
链接方法:psql -U postgres(注意,是大写的-U)
默认密码为空
修改密码的方法是,用psql登入管理:psql -U postgres
而后用这样的命令来修改密码:alter user postgres with password 'new password
|
1>新建了database,及user后,且受权后
postgres =# CREATE USER quanpower WITH PASSWORD 'XXXXXX';
CREATE ROLE
postgres =# CREATE DATABASE SmartLinkCloud;
CREATE DATABASE
postgres =# GRANT ALL PRIVILEGES ON DATABASE SmartLinkCloud TO quanpower;
GRANT
用psql -U quanpower -d SmartLinkCloud -h localhost登陆,报错:
postgres Peer authentication failed for user “quanpower”:
在配置以前需将postgresql的端口号5432在iptables下开放。
开放方法参考:http://blog.csdn.net/ivan820819/archive/2009/02/03/3860163.aspx
yum安装postgresql后的安装路径为:/var/lib/pgsql下,主要配置文件在其data文件夹下,进入data文件夹
一、修改postgresql.conf文件
若是想让PostgreSQL监听整个网络的话,将listen_addresses前的#去掉,并将listen_addresses = 'localhost'改为listen_addresses = '*'
二、修改pg_hba.conf
sudo vi /var/lib/pgsql/9.3/data/pg_hba.conf
这个文件最后有一个列表,它决定了分派了每个用户的权限,以及认证方式。格式是“Type Database User Address Method”,要注意的是method最好写md5。
在列表后追加一行:host all all 192.168.1.0/24 password
三、修改postgres用户密码:passwd postgres
四、暂时将pg_hba.conf中,本机的认证方式改成trust,切换当前用户为postgres:su postgres
五、用psql登陆PostgreSQL系统,“SELECT * FROM pg_shadow;”,发现这个表里的postgres这个用户根本尚未存储密码;因而,再“ALTER USER postgres PASSWORD '它的密码';
六、重启服务/etc/init.d/postgresql-9.3 restart,链接成功。
PS:
Q. I've installed Postgresql under Red Hat Enterprise Linux 5.x server. I've created username / password and database. But when I try to connect it via PHP or psql using following syntax:
psql -d myDb -U username -W
It gives me an error that read as follows:
psql: FATAL: Ident authentication failed for user "username"
How do I fix this error?
A. To fix this error open PostgreSQL client authentication configuration file /var/lib/pgsql/data/pg_hba.conf :
# vi /var/lib/pgsql/data/pg_hba.conf
This file controls:
By default Postgresql uses IDENT-based authentication. All you have to do is allow username and password based authentication for your network or webserver. IDENT will never allow you to login via -U and -W options. Append following to allow login via localhost only:
local all all trust host all 127.0.0.1/32 trust
Save and close the file. Restart Postgresql server: # service postgresql restart Now, you should able to login using following command: $ psql -d myDb -U username -W