Thread: Problem installing PostgreSQL 9.0 via Macports on OS X Server 10.6

Problem installing PostgreSQL 9.0 via Macports on OS X Server 10.6

From
René Fournier
Date:
[…]
    --->  Installing postgresql90-server @9.0.5_0

    To create a database instance, after install do
     sudo mkdir -p /opt/local/var/db/postgresql90/defaultdb
     sudo chown postgres:postgres /opt/local/var/db/postgresql90/defaultdb
     sudo su postgres -c '/opt/local/lib/postgresql90/bin/initdb -D /opt/local/var/db/postgresql90/defaultdb'

    To tweak your DBMS, consider increasing kern.sysv.shmmax by adding an increased kern.sysv.shmmax .. to
/etc/sysctl.conf
    --->  Activating postgresql90-server @9.0.5_0
    --->  Cleaning postgresql90-server
    Sun Oct 23 12:45:49 -- server :: sudo mkdir -p /opt/local/var/db/postgresql90/defaultdb
    Sun Oct 23 12:48:41 -- server :: sudo chown postgres:postgres /opt/local/var/db/postgresql90/defaultdb
    chown: postgres: Invalid argument
    Sun Oct 23 12:48:51 -- server ::


So, according to the above instructions (and the tutorials I've read), this should simply work. What am I missing?

On a different note, I have a couple questions concerning PostgreSQL security:

1. My understanding is that making the defaultdb directory owned by the postgres user is for security. Correct?
2. Whenever starting psql, I have on my own machines had to specify "psql -U postgres", because:

    Sun Oct 23 14:27:28 -- Frodo :: psql
    psql: FATAL: role "rene" does not exist

    So, I do I need to add a role/user for my OS X user name?

Coming from MySQL, I find the devil is in the details. Just trying to figure things out… Thanks!

…Rene

On 10/23/2011 07:16 PM, René Fournier wrote:
>     […]
>     --->   Installing postgresql90-server @9.0.5_0
>
>     To create a database instance, after install do
>      sudo mkdir -p /opt/local/var/db/postgresql90/defaultdb
>      sudo chown postgres:postgres /opt/local/var/db/postgresql90/defaultdb
>      sudo su postgres -c '/opt/local/lib/postgresql90/bin/initdb -D /opt/local/var/db/postgresql90/defaultdb'
>
>     To tweak your DBMS, consider increasing kern.sysv.shmmax by adding an increased kern.sysv.shmmax .. to
/etc/sysctl.conf
>     --->   Activating postgresql90-server @9.0.5_0
>     --->   Cleaning postgresql90-server
>     Sun Oct 23 12:45:49 -- server :: sudo mkdir -p /opt/local/var/db/postgresql90/defaultdb
>     Sun Oct 23 12:48:41 -- server :: sudo chown postgres:postgres /opt/local/var/db/postgresql90/defaultdb
>     chown: postgres: Invalid argument

There could be a couple things wrong.  Does the group postgres exist?  Does the user postgres exist?  Does your chown
supportsetting both user and group?  (Some os's may been chown postgres /opt/local...; chgrp postgres /opt/local...) 

Not sure about mac ports install, but when doing it by hand, you have to create the postgres user and group by hand
first.

(grep postgres /etc/group
and grep postgres /etc/passwd will tell you)


>     Sun Oct 23 12:48:51 -- server ::
>
>
> So, according to the above instructions (and the tutorials I've read), this should simply work. What am I missing?
>
> On a different note, I have a couple questions concerning PostgreSQL security:
>
> 1. My understanding is that making the defaultdb directory owned by the postgres user is for security. Correct?

Ahh, sure.  It'll make sure nobody else can play with the files while PG is using them.  But if your user can sudo
withouta password, you got no real security. 

> 2. Whenever starting psql, I have on my own machines had to specify "psql -U postgres", because:
>
>     Sun Oct 23 14:27:28 -- Frodo :: psql
>     psql: FATAL: role "rene" does not exist
>
>     So, I do I need to add a role/user for my OS X user name?

Yeah, by default there is only a postgres user.  The very first thing I do on a new install is:
createuser --superuser andy
createdb


By default, pg_hba wont require a password when you connect via localhost.

And last, I'm not sure how the postgis list feels about cross posting but I dont think the pgsql-general list likes it
much. In general, you should find the right list for the question you have and just post it there. 

-Andy

Re: Problem installing PostgreSQL 9.0 via Macports on OS X Server 10.6

From
Brandon Phelps
Date:
By default the postgres user's group is 'daemon' on my Mac.  This is
probably true for you as well.  Change occurrences of
'postgres:postgres' in your chown commands to 'postgres:daemon'.

On 10/23/2011 8:16 PM, René Fournier wrote:
>     […]
>     --->   Installing postgresql90-server @9.0.5_0
>
>     To create a database instance, after install do
>      sudo mkdir -p /opt/local/var/db/postgresql90/defaultdb
>      sudo chown postgres:postgres /opt/local/var/db/postgresql90/defaultdb
>      sudo su postgres -c '/opt/local/lib/postgresql90/bin/initdb -D /opt/local/var/db/postgresql90/defaultdb'
>
>     To tweak your DBMS, consider increasing kern.sysv.shmmax by adding an increased kern.sysv.shmmax .. to
/etc/sysctl.conf
>     --->   Activating postgresql90-server @9.0.5_0
>     --->   Cleaning postgresql90-server
>     Sun Oct 23 12:45:49 -- server :: sudo mkdir -p /opt/local/var/db/postgresql90/defaultdb
>     Sun Oct 23 12:48:41 -- server :: sudo chown postgres:postgres /opt/local/var/db/postgresql90/defaultdb
>     chown: postgres: Invalid argument
>     Sun Oct 23 12:48:51 -- server ::
>
>
> So, according to the above instructions (and the tutorials I've read), this should simply work. What am I missing?
>
> On a different note, I have a couple questions concerning PostgreSQL security:
>
> 1. My understanding is that making the defaultdb directory owned by the postgres user is for security. Correct?
> 2. Whenever starting psql, I have on my own machines had to specify "psql -U postgres", because:
>
>     Sun Oct 23 14:27:28 -- Frodo :: psql
>     psql: FATAL: role "rene" does not exist
>
>     So, I do I need to add a role/user for my OS X user name?
>
> Coming from MySQL, I find the devil is in the details. Just trying to figure things out… Thanks!
>
> …Rene

Re: Problem installing PostgreSQL 9.0 via Macports on OS X Server 10.6

From
Basil Bourque
Date:
> By default the postgres user's group is 'daemon' on my Mac.  This is probably true for you as well.  Change
occurrencesof 'postgres:postgres' in your chown commands to 'postgres:daemon'. 

For what it's worth, here's the user groups and permissions I see on my Mac. I used the installer from EnterpriseDB.com
formy Snow Leopard MacBook. 

Typing the 'id' command-line tool:
id postgres

Renders this:
uid=502(postgres) gid=1(daemon)
groups=1(daemon),403(com.apple.sharepoint.group.2),61(localaccounts),12(everyone),402(com.apple.sharepoint.group.1)

So, "daemon" is the primary group, along with 4 other groups.

/Library/PostgreSQL
+--------------+-----------------+
|    system    |  Read & Write   |
+--------------+-----------------+
|    admin     |    Read only    |
+--------------+-----------------+
|   everyone   |    Read only    |
+--------------+-----------------+

/Library/PostgreSQL/9.0
/Library/PostgreSQL/9.1
/Library/PostgreSQL/9.1/bin
/Library/PostgreSQL/9.1/lib
/Library/PostgreSQL/9.1/pgAdmin3.app
+--------------+-----------------+
|    system    |  Read & Write   |
+--------------+-----------------+
|    daemon    |    Read only    |
+--------------+-----------------+
|   everyone   |    Read only    |
+--------------+-----------------+

/Library/PostgreSQL/9.1/data
+--------------+-----------------+
|   postgres   |  Read & Write   |
+--------------+-----------------+
|   everyone   |    No Access    |
+--------------+-----------------+

--Basil Bourque