Oddly, it should be simple, but I can't connect to a local PostGIS database. My installation is with Mac OS X (10.8), Postgres.app (in doc it's said to have PostGIS included) and Quantum GIS 1.8.
When I want to add a connection to Postgres, I'm specifying name, host (localhost), port (5432), database name, user name and password (service field left empty).
I can connect to a database with Navicat, so database server seems to run correctly. With the exact information in QGIS used in Navicat, it can't connect… why?
Thank you!
Best Answer
You should verify that you can connect using
psql
. Trypsql -U username -h localhost dbname
. It should prompt for a password then connect. RunSELECT postgis_version();
to verify that PostGIS is active in the database.If you can connect but
SELECT postgis_version()
reports an error, PostGIS isn't installed in the database:Other solution:
If you want also to see the version of PostGIS and the version number of the libraries GEOS and Proj4 just change
lib
toFull
.If you get the above error, then presuming you're running PostGIS 2.0 on PostgreSQL 9.1 or above, connect as user
postgres
and runCREATE EXTENSION postgis;
. Eg:You might also need to install some of the extras, like the PostGIS topology support:
or the legacy support script, which isn't packaged as an extension and must be sourced:
See the PostGIS documentation.
If you can't connect to the DB, it's probably a
pg_hba.conf
issue, failure to create the DB or user, etc. Hard to say without error messages and log contents.