Thread: Total Newbie: Trouble installing postgresSQL on OS X Snow Leopard

Total Newbie: Trouble installing postgresSQL on OS X Snow Leopard

From
Kevin Goulding
Date:
Hi all, I am trying to get set up with a database in PostgresSQL and eventually postGIS, so followed the install instructions on Kyng Chaos' web site:
http://www.kyngchaos.com/software:postgres

(I installed all of the items in the list with the exception of "PostgreSQL Client-only 9.1.2-1").  Then I entered the Terminal, and went through the following, with little luck.  Can anyone help or point me in the right direction to get a new database set up?

>> My suspicion is that the problem lies in the line (below) where it says:

initdb: could not access directory "/usr/local/pgsql-9.1/data": Permission denied

Many thanks!
Kevin


>> My system:  OS X 10.6.8 Snow Leopard
>> First, I tried to create a new data base called "db1":

kevin-gouldings-imac:~ kevingoulding$ /usr/local/pgsql/bin/psql -U postgres -d db1 -f /usr/local/pgsql/share/contrib/postgis-1.5/postgis.sql
psql: FATAL:  database "db1" does not exist

>> Then I wasn't sure if postgresSQL had in fact been installed / launched correctly.  So I entered this code and my password:

kevin-gouldings-imac:~ kevingoulding$ sudo launchctl load /Library/LaunchDaemons/org.postgresql.postgres.plist

WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.

To proceed, enter your password, or type Ctrl-C to abort.

Password:
org.postgresql.postgres: Already loaded

>> It appeared that in fact it had already been loaded.  Then I read further down on Kyng Chaos' page, where he says to try the following command:

kevin-gouldings-imac:~ kevingoulding$ /usr/local/pgsql-9.1/bin/initdb -U postgres -D /usr/local/pgsql-9.1/data --encoding=UTF8 --locale=en_US
The files belonging to this database system will be owned by user "kevingoulding".
This user must also own the server process.

The database cluster will be initialized with locale en_US.
The default text search configuration will be set to "english".

initdb: could not access directory "/usr/local/pgsql-9.1/data": Permission denied

>> It appears that I do not have access to the directory, or haven't set up the permissions, roles, etc.  So I tried a bunch of commands, attempting to create a new role "kevingoulding":

kevin-gouldings-imac:~ kevingoulding$  /usr/local/pgsql/bin/createdb mydb
createdb: could not connect to database postgres: FATAL:  role "kevingoulding" does not exist
kevin-gouldings-imac:~ kevingoulding$ CREATE ROLE kevingoulding
-bash: CREATE: command not found
kevin-gouldings-imac:~ kevingoulding$ createuser kevingoulding
-bash: createuser: command not found
kevin-gouldings-imac:~ kevingoulding$ $ postmaster -D /usr/local/pgsql/data
-bash: $: command not found
kevin-gouldings-imac:~ kevingoulding$ postmaster -D /usr/local/pgsql/data
-bash: postmaster: command not found

>> Then I found this code to see if postgresSQL was running.  This might be helpful, but I do not know what it means.

kevin-gouldings-imac:~ kevingoulding$ ps auxwww | grep postgres
kevingoulding 14625   0.3  0.0  2425524    172 s000  U+   10:08PM   0:00.00 grep postgres
postgres 12360   0.0  0.0  2454996    248   ??  Ss   Tue09AM   0:02.08 postgres: stats collector process     
postgres 12359   0.0  0.0  2458912    724   ??  Ss   Tue09AM   0:02.27 postgres: autovacuum launcher process     
postgres 12358   0.0  0.0  2458780    240   ??  Ss   Tue09AM   0:08.90 postgres: wal writer process     
postgres 12357   0.0  0.0  2458780    304   ??  Ss   Tue09AM   0:12.64 postgres: writer process     
postgres 12355   0.0  0.0  2454996    216   ??  Ss   Tue09AM   0:02.72 postgres: logger process     
postgres 12352   0.0  0.0  2458256   1008   ??  Ss   Tue09AM   0:00.58 /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data








Re: Total Newbie: Trouble installing postgresSQL on OS X Snow Leopard

From
Brent Dombrowski
Date:
On Jan 26, 2012, at 10:22 AM, Kevin Goulding wrote:

> Hi all, I am trying to get set up with a database in PostgresSQL and
> eventually postGIS, so followed the install instructions on Kyng Chaos' web
> site:
> http://www.kyngchaos.com/software:postgres
>
> (I installed all of the items in the list with the exception of "PostgreSQL
> Client-only 9.1.2-1").  Then I entered the Terminal, and went through the
> following, with little luck.  Can anyone help or point me in the right
> direction to get a new database set up?
>
>>> My suspicion is that the problem lies in the line (below) where it says:
>
> *initdb: could not access directory "/usr/local/pgsql-9.1/data": Permission
> denied*
>
> Many thanks!
> Kevin
>

The data folder (/usr/local/pgsql-9.1/data) is typically owned by the user "postgres". In order to access that
directory,you need to be the postgres user. 

I've always done the database initialization as postgres:
$ sudo -u postgres /usr/local/pgsql-9.1/bin/initdb -D /usr/local/pgsql-9.1/data --encoding=UTF8 --local=en_us

>
>>> My system:  OS X 10.6.8 Snow Leopard
>>> First, I tried to create a new data base called "db1":
>
> kevin-gouldings-imac:~ kevingoulding$ /usr/local/pgsql/bin/psql -U postgres
> -d db1 -f /usr/local/pgsql/share/contrib/postgis-1.5/postgis.sql
> psql: FATAL:  database "db1" does not exist

This does not create a database. It's trying to connect to an existing database (db1) and run the postgis script. If
youhaven't installed postgis yet, that script will fail as well. 

Postgres creates a database called postgres. Try the following:
$ /usr/local/pgsql-9.1/bin/psql -P postgres -d postgres
If that gets a postgres prompt, then initdb was successful and you are up and running.

Chapter 15 of the manual has lots of details on installing postgres
http://www.postgresql.org/docs/9.1/interactive/installation.html