Take the 2-minute tour ×

I am completely new to Postgresql, Postgis, and SQL and have a little bit of rails knowledge. I am trying to get an existing app going on my local and am currently receiving the following messages when running a rake task to set up my db. Any suggestions or direction on where to troubleshoot this would be greatly appreciated! thanks!

Blane-Cordess-MacBook:ajungo blanecordes$ rake postgres:create_postgis_template --trace
(in /Users/blanecordes/ajungo)
** Invoke postgres:create_postgis_template (first_time)
** Execute postgres:create_postgis_template
Enter your postgres username: blane
Password for user blane: 
psql (9.2.1, server 9.1.4)
WARNING: psql version 9.2, server version 9.1.
     Some psql features might not work.
You are now connected to database "template1" as user "blane".
psql:assets/sql/postgis_template_osx.sql:2: ERROR:  permission denied to create database
psql:assets/sql/postgis_template_osx.sql:6: ERROR:  permission denied for relation      pg_database
psql:assets/sql/postgis_template_osx.sql:7: \connect: FATAL:  database   "template_postgis" does not exist

My postgis_template_osx.sql file is the following:

\c template1
CREATE DATABASE template_postgis WITH template = template1;

-- set the 'datistemplate' record in the 'pg_database' table for
-- 'template_postgis' to TRUE indicating its a template
\c template_postgis
\i /usr/local/Cellar/postgis/2.0.1/share/postgis/postgis.sql;
\i /usr/local/Cellar/postgis/2.0.1/share/postgis/spatial_ref_sys.sql;
-- 1.5.2

-- in a production environment you may want to
-- give role based permissions, but granting all for now
GRANT ALL ON geometry_columns TO PUBLIC;
GRANT ALL ON spatial_ref_sys TO PUBLIC;

-- vacuum freeze: it will guarantee that all rows in the database are
-- "frozen" and will not be subject to transaction ID wraparound
-- problems.
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

The PostgreSQL ROLE blane does not have permission to create databases. Either ALTER blane and add the CREATEDB option or use an existing administrator role that has that capability.

postgres=# ALTER ROLE blane WITH CREATEDB;
share|improve this answer
Awesome thanks! Would you be able to provide me an example of what this looks like from the command line? –  BC00 Nov 28 '12 at 3:43
See edit. You'll need to be logged in as a superuser who can CREATEROLE, usually postgres or the user who installed PostgreSQL. –  titanofold Nov 28 '12 at 3:52
ah gotcha, this is very helpful thanks. In my database.yml file I have development database named and a username specified however since I cant create the database I am a bit stuck on where to start. Dont I need to create the database before I can go in as a superuser and add a role with? or is there a way to go into my postgres console and create this role which will be for all my apps going forward? sorry such a newb! –  BC00 Nov 28 '12 at 4:03
I got it- thanks! –  BC00 Nov 28 '12 at 4:20
add comment

Your Answer


