由於想添加個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