麻烦安装Postgis(PostgreSQL)(Django)(Mac OS x 10.7)

时间:2012-09-22 21:33:04

标签: python django macos postgresql postgis

编辑:

好的,我根据下面列出的说明卸载了我的版本并重新安装:

我跑了:

POSTGIS_SQL_PATH=/usr/local/Cellar/postgis15/1.5.3/share/postgis
# Creating the template spatial database.
createdb -E UTF8 template_postgis
createlang -d template_postgis plpgsql # Adding PLPGSQL language support.
# Allows non-superusers the ability to create from this template
psql -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE datname='template_postgis';"
# Loading the PostGIS SQL routines
psql -d template_postgis -f $POSTGIS_SQL_PATH/postgis.sql
psql -d template_postgis -f $POSTGIS_SQL_PATH/spatial_ref_sys.sql
# Enabling users to alter spatial tables.
psql -d template_postgis -c "GRANT ALL ON geometry_columns TO PUBLIC;"
psql -d template_postgis -c "GRANT ALL ON geography_columns TO PUBLIC;"
psql -d template_postgis -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;" 

然后跑了:

$ createdb -T template_postgis newdb
$ createuser --createdb poop
Shall the new role be a superuser? (y/n) y

现在,这是我的数据库列表:

$ psql -l
                                  List of databases
       Name       | Owner | Encoding |  Collation  |    Ctype    | Access privileges 
------------------+-------+----------+-------------+-------------+-------------------
 newdb            | User  | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 postgres         | User  | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0        | User  | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/User          +
                  |       |          |             |             | User=CTc/User
 template1        | User  | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/User          +
                  |       |          |             |             | User=CTc/User
 template_postgis | User  | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
(5 rows)

确保我的版本正确无误:

$ psql newdb
psql (9.0.8)
Type "help" for help.

newdb=# SELECT PostGIS_full_version();
                                       postgis_full_version                                       
--------------------------------------------------------------------------------------------------
 POSTGIS="1.5.3" GEOS="3.3.5-CAPI-1.7.5" PROJ="Rel. 4.8.0, 6 March 2012" LIBXML="2.7.3" USE_STATS
(1 row)

newdb=# \dt
         List of relations
 Schema |       Name       | Type  | Owner 
--------+------------------+-------+-------
 public | geometry_columns | table | User
 public | spatial_ref_sys  | table | User
(2 rows)

看起来所有的依赖关系都得到了解决,数据库看起来很开心,一切看起来都很干净! (但是,我将geograph_colums授予所有用户访问上述内容的位置?)

现在,settings.py:

DATABASES = {
    'default': {
         'ENGINE': 'django.contrib.gis.db.backends.postgis',
         'NAME': 'newdb',
         'USER': 'poop', # yes, I named my user poop
     }
}

现在我跑的时候:

$ python manage.py syncdb

我得到了以:

结尾的各种文件的链接
psycopg2.OperationalError: could not connect to server: Permission denied
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

显然我的数据库正在运行,因为我可以将psql插入其中。但是权限设置不正确?

的pg_hba.conf:

# 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
# IPv6 local connections:
host    all             all             ::1/128                 trust

解答: Postgresql socket error on OSX 10.7.3 when running Django's syncdb

1 个答案:

答案 0 :(得分:1)

我不确定当前的Django版本是否与PostGIS 2.0兼容。您可能想尝试安装PostGIS 1.5。这也可能意味着安装PostgreSQL 9.0。这两个软件包都是自制软件包,但您需要“点击”版本公式:

brew update
brew tap homebrew/versions
brew install postgresql9

然后,您需要将默认postgis15包更改为指向postgresql9postgresql包的最新更新使其与postgis15不兼容,并且该公式尚未更新):

brew edit postgis15

postgresql的两个实例更改为postgresql9,例如:

第12行:

depends_on 'postgresql9'

第30行:

postgresql = Formula.factory 'postgresql9'

然后安装postgis15:

brew install postgis15

并像以前一样创建相关数据库。

请注意psql和Python psycopg2包连接到正确的数据库(postgres 9.0)。另外需要针对正确的库编译psycopg2。确保这一点的最简单方法是首先从自制软件包中卸载postgresql软件包(如果你没有使用它),并在安装postgis15之前将/usr/local/var/postgres数据目录移开:

brew uninstall postgresql
mv /usr/local/var/postgres /usr/local/var/postgres9.1
initdb /usr/local/var/postgres -E utf8
brew install postgresql9

...并针对新库重新编译psycopg2(进入你的virtualenv):

pip uninstall psycopg2
pip install psycopg2

这可能没有帮助,但除非您愿意尝试,调试和提交补丁,否则使用已知可用的版本总是好的: - )