# Postgres db setup

**URL:** <https://www.ruby-forum.com/t/postgres-db-setup/52907>\
**Category:** Rails\
**Created:** [January 20, 2006, 5:16am UTC](https://www.ruby-forum.com/t/postgres-db-setup/52907 "2006-01-20T05:16:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [January 20, 2006, 5:16am UTC](https://www.ruby-forum.com/t/postgres-db-setup/52907/1 "2006-01-20T05:16:24Z")

</div>

All of the tutorials and the Agile book use MySQL and I’ve got that  
working. I am now trying to use PostgreSQL and can’t seem to get going.

Is my problem the db setup in postgresql?

I have installed postgres-pr

The error message when I try to access [http://localhost:3000/clients](http://localhost:3000/clients)  
when using PostgreSQL (MySQL works fine)

ActiveRecord::StatementInvalid (RuntimeError:  
ERROR C42501 Mpermission denied for relation  
clients Faclchk.c L987 Raclcheck\_error: SELECT COUNT(\*) FROM  
clients ):  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active\_record/connection\_adapters/abstract\_adapter.rb:88:in  
`log' /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/postgresql_adapter.rb:137:in `execute’

\*\*\* there’s more but I didn’t think I needed to \*\*\*

Postgres setup…  
CREATE TABLE clients (  
id serial primary key NOT NULL,  
first\_name character varying(25) NOT NULL,  
middle\_initial character varying(1) NOT NULL,  
last\_name character varying(25) NOT NULL,  
gov\_id character varying(18) NOT NULL,  
dob date  
);

MySQL setup  
CREATE TABLE `clients` (  
`id` int(8) NOT NULL auto\_increment,  
`first_name` varchar(25) NOT NULL default ‘’,  
`middle_initial` char(1) NOT NULL default ‘’,  
`last_name` varchar(25) NOT NULL default ‘’,  
`gov_id` varchar(18) default NULL,  
`dob` date default NULL,  
PRIMARY KEY (`id`)  
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [January 20, 2006, 5:37am UTC](https://www.ruby-forum.com/t/postgres-db-setup/52907/2 "2006-01-20T05:37:30Z")

</div>

On Jan 19, 2006, at 10:39 PM, Craig W. wrote:

> Is my problem the db setup in postgresql?

I think so…

> ActiveRecord::StatementInvalid (RuntimeError:  
> ERROR C42501 Mpermission denied for relation

Well, that’s pretty clear…

What user did you login as to create the tables? The  
same user you configured into Rails?

Did you give a GRANT command of any sort?

> CREATE TABLE clients (  
> id serial primary key NOT NULL,  
> first\_name character varying(25) NOT NULL,  
> middle\_initial character varying(1) NOT NULL,  
> last\_name character varying(25) NOT NULL,  
> gov\_id character varying(18) NOT NULL,  
> dob date  
> );

I don’t think it’s related to the error, but gov\_id  
should be an INT4, if you’re planning on using Rails’  
conventions.

And, if you’re not planning on using Rails’  
conventions at the beginning of a project, you’re  
making a mistake.

P.S. Check out the migrations video on the RoR  
website. I held out for a while (avoiding  
learning yet another brand new concept) but  
I just finished converting my schema to an  
initial migration and it’s very, very cool.

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [January 20, 2006, 5:40am UTC](https://www.ruby-forum.com/t/postgres-db-setup/52907/3 "2006-01-20T05:40:31Z")

</div>

On Jan 19, 2006, at 10:39 PM, Craig W. wrote:

> Is my problem the db setup in postgresql?

I think so…

> ActiveRecord::StatementInvalid (RuntimeError:  
> ERROR C42501 Mpermission denied for relation

Well, that’s pretty clear…

What user did you login as to create the tables? The  
same user you configured into Rails?

Did you give a GRANT command of any sort?

> CREATE TABLE clients (  
> id serial primary key NOT NULL,  
> first\_name character varying(25) NOT NULL,  
> middle\_initial character varying(1) NOT NULL,  
> last\_name character varying(25) NOT NULL,  
> gov\_id character varying(18) NOT NULL,  
> dob date  
> );

I don’t think it’s related to the error, but gov\_id  
should be an INT4, if you’re planning on using Rails’  
conventions.

And, if you’re not planning on using Rails’  
conventions at the beginning of a project, you’re  
making a mistake.

P.S. Check out the migrations video on the RoR  
website. I held out for a while (avoiding  
learning yet another brand new concept) but  
I just finished converting my schema to an  
initial migration and it’s very, very cool.

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [January 20, 2006, 6:01am UTC](https://www.ruby-forum.com/t/postgres-db-setup/52907/4 "2006-01-20T06:01:36Z")

</div>

On Thu, 2006-01-19 at 23:00 -0500, Tom M. wrote:

> What user did you login as to create the tables? The  
> same user you configured into Rails?

* * *

## duh - I would swear that I checked this out many times but it turns out that this must be the issue as it worked when I set the user to postgres

> Did you give a GRANT command of any sort?

* * *

## probably during many of the create/drop cycles and didn’t this last time. Obviously this will be the solution to my problem. Thanks

> I don’t think it’s related to the error, but gov\_id  
> should be an INT4, if you’re planning on using Rails’  
> conventions.

* * *

## I lacked the right term for it when I was creating it - it’s not a social security number and not really a number at all, but sometimes letters and numbers which I see as a text string.

> And, if you’re not planning on using Rails’  
> conventions at the beginning of a project, you’re  
> making a mistake.
> 
> P.S. Check out the migrations video on the RoR  
> website. I held out for a while (avoiding  
> learning yet another brand new concept) but  
> I just finished converting my schema to an  
> initial migration and it’s very, very cool.

* * *

I’m starting from scratch and in the meantime plowing through the Agile  
book and haven’t gotten to migrations yet but I did see the video and  
thought it cool. Obviously I am going to have a lot of iterations before  
I get any real work done but I wanted to start playing with it since  
that is the only way I will learn and all of the demonstrations use  
MySQL and I want to get to PostgreSQL and away from MySQL and you have  
enabled me to do that…thanks

Craig
