# Problem connecting PostgreSQL 8.2 to Rails 1.2

**URL:** <https://www.ruby-forum.com/t/problem-connecting-postgresql-8-2-to-rails-1-2/108302>\
**Category:** Rails\
**Created:** [July 2, 2007, 1:12am UTC](https://www.ruby-forum.com/t/problem-connecting-postgresql-8-2-to-rails-1-2/108302 "2007-07-02T01:12:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bornboulder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e274bd/32.png) [@bornboulder](https://www.ruby-forum.com/u/bornboulder)\
**Post date:** [July 2, 2007, 1:12am UTC](https://www.ruby-forum.com/t/problem-connecting-postgresql-8-2-to-rails-1-2/108302/1 "2007-07-02T01:12:30Z")

</div>

Hello people,

I just installed PostgreSQL on my Mac.  
I used the package available here:  
[http://www.entropy.ch/software/macosx/postgresql/](http://www.entropy.ch/software/macosx/postgresql/)

Here is a screendump of initdb…

$  
$  
$  
$  
$ /usr/local/bin/initdb -E UTF8 -D /usr/local/pgsql/data  
The files belonging to this database system will be owned by user  
“maco”.  
This user must also own the server process.

The database cluster will be initialized with locale C.

creating directory /usr/local/pgsql/data … ok  
creating subdirectories … ok  
selecting default max\_connections … 30  
selecting default shared\_buffers/max\_fsm\_pages … 2400kB/20000  
creating configuration files … ok  
creating template1 database in /usr/local/pgsql/data/base/1 … ok  
initializing pg\_authid … ok  
initializing dependencies … ok  
creating system views … ok  
loading system objects’ descriptions … ok  
creating conversions … ok  
setting privileges on built-in objects … ok  
creating information schema … ok  
vacuuming database template1 … ok  
copying template1 to template0 … ok  
copying template1 to postgres … ok

WARNING: enabling “trust” authentication for local connections  
You can change this by editing pg\_hba.conf or using the -A option the  
next time you run initdb.

Success. You can now start the database server using:

/usr/local/bin/postgres -D /usr/local/pgsql/data  
or  
/usr/local/bin/pg\_ctl -D /usr/local/pgsql/data -l logfile start  
$  
$  
$

I started the server:

$  
$  
$  
$ pg\_ctl start  
server starting  
acct1-smiths-powerbook-g4-17 maco ~ (14:44:22 ) 1 $ LOG: database system  
was shut down at 2007-07-01 14:24:19 PDT  
LOG: checkpoint record is at 0/42BEB8  
LOG: redo record is at 0/42BEB8; undo record is at 0/0; shutdown TRUE  
LOG: next transaction ID: 0/593; next OID: 10820  
LOG: next MultiXactId: 1; next MultiXactOffset: 0  
LOG: database system is ready  
$  
$

$  
$  
$ psorg post  
maco 1905 0.0 0.2 43852 1924 pa S 2:44PM 0:00.72 /usr/local/bin/postgres  
maco 1910 0.0 0.0 43772 524 ?? Ss 2:44PM 0:00.01 postgres: writer  
process  
maco 1911 0.0 0.0 39748 348 ?? Ss 2:44PM 0:00.00 postgres: stats  
collector process  
maco 1928 0.0 0.0 27376 424 pa S+ 2:44PM 0:00.01 grep -i post  
$  
$  
$

I created a database:  
$  
$  
$  
$ createdb e10d  
CREATE DATABASE  
$  
$  
$

I created a table:

$  
$  
$  
$ psql --help

This is psql 8.2.3, the PostgreSQL interactive terminal.

Usage:  
psql [OPTIONS]… [DBNAME [USERNAME]]

General options:  
-d DBNAME specify database name to connect to (default: “maco”)  
-c COMMAND run only single command (SQL or internal) and exit  
-f FILENAME execute commands from file, then exit  
-1 (“one”) execute command file as a single transaction  
-l list available databases, then exit  
-v NAME=VALUE set psql variable NAME to VALUE  
-X do not read startup file (~/.psqlrc)  
–help show this help, then exit  
–version output version information, then exit

Input and output options:  
-a echo all input from script  
-e echo commands sent to server  
-E display queries that internal commands generate  
-q run quietly (no messages, only query output)  
-o FILENAME send query results to file (or |pipe)  
-n disable enhanced command line editing (readline)  
-s single-step mode (confirm each query)  
-S single-line mode (end of line terminates SQL command)  
-L FILENAME send session log to file

Output format options:  
-A unaligned table output mode (-P format=unaligned)  
-H HTML table output mode (-P format=html)  
-t print rows only (-P tuples\_only)  
-T TEXT set HTML table tag attributes (width, border) (-P tableattr=)  
-x turn on expanded table output (-P expanded)  
-P VAR[=ARG] set printing option VAR to ARG (see \pset command)  
-F STRING set field separator (default: “|”) (-P fieldsep=)  
-R STRING set record separator (default: newline) (-P recordsep=)

Connection options:  
-h HOSTNAME database server host or socket directory (default: “local  
socket”)  
-p PORT database server port (default: “5432”)  
-U NAME database user name (default: “maco”)  
-W prompt for password (should happen automatically)

For more information, type “?” (for internal commands) or “\help”  
(for SQL commands) from within psql, or consult the psql section in  
the PostgreSQL documentation.

Report bugs to [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid).

$  
$  
$

$  
$  
$ psql -d e10d  
Welcome to psql 8.2.3, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms  
\h for help with SQL commands  
? for help with psql commands  
\g or terminate with semicolon to execute query  
\q to quit

e10d=# create table dropme(n integer);  
CREATE TABLE  
e10d=#  
e10d=#  
e10d=# drop table dropme;  
DROP TABLE  
e10d=#  
e10d=#  
e10d=#

Next, I checked my gems to make sure I have the PostgreSQL adaptor:

$  
$  
$  
$ gem list | grep -i postg  
postgres-pr (0.4.0)  
A pure Ruby interface to the PostgreSQL (\>= 7.4) database  
$  
$  
$  
$

Next I created my database.yml

$  
$  
$  
$ ll  
total 24  
drwxr-xr-x 17 maco admin 578 Jul 1 12:57 ./  
drwxr-xr-x 7 maco admin 238 Jul 1 15:25 …/  
drwxr-xr-x 11 maco admin 374 Jul 1 13:14 .svn/  
-rw-r–r-- 1 maco admin 8001 Jul 1 12:57 README  
-rw-r–r-- 1 maco admin 307 Jul 1 12:57 Rakefile  
drwxr-xr-x 7 maco admin 238 Jul 1 12:57 app/  
drwxr-xr-x 3 maco admin 102 Jul 1 12:57 components/  
drwxr-xr-x 8 maco admin 272 Jul 1 15:27 config/  
drwxr-xr-x 5 maco admin 170 Jul 1 13:12 db/  
drwxr-xr-x 4 maco admin 136 Jul 1 12:57 doc/  
drwxr-xr-x 4 maco admin 136 Jul 1 12:57 lib/  
drwxr-xr-x 7 maco admin 238 Jul 1 12:57 log/  
drwxr-xr-x 16 maco admin 544 Jul 1 13:11 public/  
drwxr-xr-x 13 maco admin 442 Jul 1 12:57 script/  
drwxr-xr-x 9 maco admin 306 Jul 1 12:57 test/  
drwxr-xr-x 7 maco admin 238 Jul 1 12:57 tmp/  
drwxr-xr-x 5 maco admin 170 Jul 1 12:58 vendor/  
$  
$

$  
$  
$ cat config/database.yml

development:  
encoding: unicode  
adapter: postgresql  
database: e10d

production:  
encoding: unicode  
adapter: postgresql  
database: e10p

$  
$  
$

I tried rake…

$  
$  
$  
$ rake db:migrate  
(in /pt/webprops/edgar411/e10)  
FATAL: no PostgreSQL user name specified in startup packet  
rake aborted!  
FATAL C28000 Mno PostgreSQL user name specified in startup packet  
Fpostmaster.c L1525 RProcessStartupPacket

(See full trace by running task with --trace)  
$  
$  
$

I checked my  
/usr/local/pgsql/data/pg\_hba.conf  
file…

$  
$  
$  
$ grep -v ‘#’ /usr/local/pgsql/data/pg\_hba.conf|sort -u

host all all 127.0.0.1/32 trust  
host all all ::1/128 trust  
local all all trust  
$  
$  
$

It looks fine to me.

So,  
Here is the error:  
FATAL: no PostgreSQL user name specified in startup packet

Here is some info about my rails setup:

$  
$  
$  
$ script/about  
FATAL: no PostgreSQL user name specified in startup packet  
About your application’s environment  
Ruby version 1.8.5 (powerpc-darwin7.9.0)  
RubyGems version 0.9.2  
Rails version 1.2.3  
Active Record version 1.15.3  
Action Pack version 1.13.3  
Action Web Service version 1.2.3  
Action Mailer version 1.3.3  
Active Support version 1.4.2  
Edge Rails revision 3  
Application root /pt/webprops/edgar411/e10  
Environment development  
Database adapter postgresql  
$  
$  
$

Do any of you Rails-PostgreSQL people have any clues about the problem?

Anyone out there running Rails 1.2.3 with PostgreSQL 8.2 ??

What does your database.yml look like?  
How about your  
/usr/local/pgsql/data/pg\_hba.conf  
file?

-b

---

<div class="post-metadata">

**Author:** ![bornboulder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e274bd/32.png) [@bornboulder](https://www.ruby-forum.com/u/bornboulder)\
**Post date:** [July 2, 2007, 1:36am UTC](https://www.ruby-forum.com/t/problem-connecting-postgresql-8-2-to-rails-1-2/108302/2 "2007-07-02T01:36:05Z")

</div>

People,

I found the answer here:

[http://wiki.rubyonrails.org/rails/pages/PostgreSQL](http://wiki.rubyonrails.org/rails/pages/PostgreSQL)

I fixed it with 1 (one!) command line:

gem install postgres –  
–with-pgsql-include-dir=/usr/local/pgsql/include  
–with-pgsql-lib-dir=/usr/local/pgsql/lib

More info:

$  
$  
$  
gem install postgres –  
–with-pgsql-include-dir=/usr/local/pgsql/include  
–with-pgsql-lib-dir=/usr/local/pgsql/lib  
Bulk updating Gem source index for: [http://gems.rubyforge.org](http://gems.rubyforge.org)  
Building native extensions. This could take a while…  
Successfully installed postgres-0.7.1  
$  
$  
$

$  
$  
$ gem list|grp post  
gem list|grp post  
postgres (0.7.1)  
The extension library to access a PostgreSQL database from Ruby.  
postgres-pr (0.4.0)  
A pure Ruby interface to the PostgreSQL (\>= 7.4) database

# $ rake db:migrate (in /pt/webprops/edgar411/e10) ERROR: relation “schema\_info” already exists STATEMENT: CREATE TABLE schema\_info (version integer) == AddSessions: migrating

# – create\_table(:sessions) NOTICE: CREATE TABLE will create implicit sequence “sessions\_id\_seq” for serial column “sessions.id” NOTICE: CREATE TABLE will create implicit sequence “sessions\_id\_seq” for serial column “sessions.id” NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index “sessions\_pkey” for table “sessions” NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index “sessions\_pkey” for table “sessions” → 0.2986s – add\_index(:sessions, :session\_id) → 0.0086s – add\_index(:sessions, :updated\_at) → 0.0091s == AddSessions: migrated (0.3176s)

$  
$  
$
