title: can't grant user privileges to postgresql database (for a rails app)
body: <p>I combed through: <a href="http://www.postgresql.org/docs/current/interactive/app-psql.html#APP-PSQL-META-COMMANDSf" rel="noreferrer">http://www.postgresql.org/docs/current/interactive/app-psql.html#APP-PSQL-META-COMMANDSf</a> and <a href="https://www.digitalocean.com/community/articles/how-to-use-roles-and-manage-grant-permissions-in-postgresql-on-a-vps--2" rel="noreferrer">https://www.digitalocean.com/community/articles/how-to-use-roles-and-manage-grant-permissions-in-postgresql-on-a-vps--2</a> but still couldn't get this to work.</p>
  
  <p>I did this to get postgres to work locally: <a href="https://askubuntu.com/questions/42013/problem-installing-and-configuring-postgresql">https://askubuntu.com/questions/42013/problem-installing-and-configuring-postgresql</a>. </p>
  
  <pre><code>pavan@myUbuntuLaptop% which psql
  /usr/bin/psql
  </code></pre>
  
  <p>this got me in:</p>
  
  <pre><code>pavan@myUbuntuLaptop% sudo su - postgres
  [sudo] password for pavan: 
  postgres@myUbuntuLaptop% 
  </code></pre>
  
  <p>So...</p>
  
  <pre><code>postgres@myUbuntuLaptop% createuser pavankat
  Shall the new role be a superuser? (y/n) y
  postgres@myUbuntuLaptop% 
  </code></pre>
  
  <p>this gets all the roles</p>
  
  <pre><code>\du
  </code></pre>
  
  <p>that shows pavankat, so the role was made</p>
  
  <p>This works:</p>
  
  <pre><code>postgres=# CREATE database lateraldev;
  CREATE DATABASE
  postgres=# \l
  </code></pre>
  
  <p>Now I try to grant privileges to lateraldev to the user, pavankat: </p>
  
  <p>this doesn't work:</p>
  
  <pre><code>GRANT RULE ON lateraldev to pavankat
  </code></pre>
  
  <p>doesn't work: </p>
  
  <pre><code>GRANT ALL ON lateraldev TO pavankat;
  </code></pre>
  
  <p>doesn't work:</p>
  
  <pre><code>postgres=# GRANT ALL ON lateraldev TO pavankat;
  ERROR:  relation "lateraldev" does not exist
  </code></pre>
  
  <p>this looked like it worked but, \du didn't show anything:</p>
  
  <pre><code>postgres=# GRANT ALL ON DATABASE lateraldev TO pavankat;
  GRANT
  </code></pre>
  
  <p>same with this, doesn't do it: </p>
  
  <pre><code>postgres=# GRANT ALL ON ALL TABLES IN SCHEMA public TO pavankat;
  GRANT
  postgres=# GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO pavankat;
  GRANT
  postgres=# GRANT ALL ON ALL FUNCTIONS IN SCHEMA public TO pavankat;
  GRANT
  postgres=# \du
  </code></pre>
  
  <p>I used this post: <a href="http://imaginaryrobots.wordpress.com/2010/03/10/grant-all-in-postgres/" rel="noreferrer">http://imaginaryrobots.wordpress.com/2010/03/10/grant-all-in-postgres/</a> and copied the shell script into the rails app.</p>
  
  <p>then ran (to make the file executable):</p>
  
  <pre><code>pavan@myUbuntuLaptop% chmod 755 give_permissions_script.sh
  </code></pre>
  
  <p>and it doesn't work:</p>
  
  <pre><code>postgres@myUbuntuLaptop$ ./give_permissions_script.sh
  GRANT ALL ON DATABASE lateraldev TO pavankat;
  could not change directory to "/home/pavan/Dropbox/venturelateral"
  could not change directory to "/home/pavan/Dropbox/venturelateral"
  </code></pre>
  
  <p>tried this out: <a href="http://smokeandumami.com/2009/11/11/grant-permissions-on-all-tables-and-sequences-in-postgresql/" rel="noreferrer">http://smokeandumami.com/2009/11/11/grant-permissions-on-all-tables-and-sequences-in-postgresql/</a>
  and it seems to have done something, but doesn't work:</p>
  
  <pre><code>pavan@myUbuntuLaptop% chmod 755 give_permissions_script2.sh
  pavan@myUbuntuLaptop% ./give_permissions_script2.sh
  GRANT SELECT,UPDATE,DELETE,INSERT ON TABLE public.relname to pavankat;
  </code></pre>
  
  <p>see:</p>
  
  <pre><code>postgres=# grant all privileges on database lateraldev to pavan;
  GRANT
  postgres=# \du
  </code></pre>
  
  <p>This doesn't work either:
  connect to the database first:</p>
  
  <pre><code>postgres=# psql lateraldev
  
  lateraldev=# GRANT ALL ON DATABASE lateraldev TO pavankat;
  GRANT
  lateraldev=# \du
                               List of roles
   Role name |                   Attributes                   | Member of 
  -----------+------------------------------------------------+-----------
   pavan     | Superuser, Create role, Create DB, Replication | {}
   pavankat  | Superuser, Create role, Create DB, Replication | {}
   postgres  | Superuser, Create role, Create DB, Replication | {}
  </code></pre>
  
  <p>I'm out of ideas. Help me please?</p>
  
  <p>Merry Christmas and Happy Holidays!</p>