You should verify that you can connect using psql
. Try psql -U username -h localhost dbname
. It should prompt for a password then connect. Run SELECT 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:
ERROR: function postgis_version() does not exist
LINE 1: SELECT postgis_version();
Other solution:
SELECT * FROM Postgis_lib_version();
If you want also to see the version of PostGIS and the version number of the libraries GEOS and Proj4 just change lib
to Full
.
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 run CREATE EXTENSION postgis;
. Eg:
psql -U postgres -h localhost dbname -c 'CREATE EXTENSION postgis;'
You might also need to install some of the extras, like the PostGIS topology support:
CREATE EXTENSION postgis_topology;
or the legacy support script, which isn't packaged as an extension and must be sourced:
psql -U postgres -h localhost dbname -f /path/to/postgis-2.0/legacy.sql
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.
It looks like you have confused the username and the database name.
If you created a database called shashi, you should have Database: shashi in the QGIS PostGIS Connection window. Your username is likely postgres.
If that doesn't work, look in the message log. My logs are in /usr/local/pgsql/var/, but they may be somewhere else on your machine.
Best Answer
Looking at the QGIS help for another type of "New Database Connection" showed these
Name = A name to identify the connection settings.
Provider/DSN = The database server IP address or DNS name (not sure about this I got this from http://tinyurl.com/kjpqm6k)
Host = Name or IP address of the computer hosting the database server (leave blank for local connections)
Database = Name of the database (leave blank for default database on server).
Username = Database user name.
Password = Database password.
EDIT: In this question Mapperz says "Provider/DSN parameters not needed if you have a host."