You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to connect to embedded POSTGRESQL on Mac OSX Lion Server

Hi all,


I've upgraded my Mac OSX 10.6 server to 10.7 server 2 days ago.


My web sites databases are still under MySQL server cause it's still running after the upgrade.


I manage to migrate the databases to PostgreSQL, so i've enabled the wiki from the server.app to launch the PostgreSQL server.


I can see that it's now running through a ps -ef | grep sql and that it's listening on the unix domain socket 5432 with netstat -an | grep SQL in a terminal shell.


The problem is that I'am unable to connect to it.


I tried psql -U postgres, and installed the Navcat for postgreSQL Lite, but they failed to connec to the database server twith the same error :

psql: could not connect to server : Permission Denied

Is the server running locally and accepting connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?


It seems that there is a permission problem on the Unix Domain Socket /var/pgsql_socket/.s.PGSQL.5432.

It has a 0770 permission on it, but i don't know if it's relly the problem.


I've compared with MySQL server, which I am able to manage through Navcat for MySQL Lite without any problem, and the socket permission are 0777 on /var/mysql/mysql.sock.


Does somebody able to connect to the embedded PostgreSQL server ?


Or am I doing something wrong ?


Thanks.

Posted on Jul 22, 2011 5:59 AM

Reply
42 replies

Aug 3, 2011 3:09 PM in response to Tim Bloom1

Hi Tim,


To answer your question about creating a role in postgresql. This can be accomplished in psql (you don't need pgAdmin). To do so:


Start psql with the _postgres user which already has a role assigned:

sudo -u _postgres psql template1

(daefromlos angeles has graciously included a screen-shot above)


Then once in, create a new role:

create role <MYUSERNAME> with login createdb


The <MYUSERNAME> would be whatever you log-in as.


You can see all of the options by typing in:

\h create role


You can now log out using \q and re-log in using psql or Navicat.

When logging-in, if no parameters for the database are specified then it will assume that your username is the default database. As a convenience use the createdb command to create a brand new database (instead of psql).

Aug 5, 2011 6:12 AM in response to Yansolo

Hi guys! Just figured out how to enable TCP access to PostgreSQL! 🙂


by executing the following in Terminal:

ps ax | grep postgres


revealed that there are some mysterious command line parameters given to PostgreSQL at start. The most concerning is the "-c listen_addresses=" which effectively turns off all TCP listening!


By trying to kill the postgres process both nicely and forcefully didn't help - the ******* respawns! I tried:

sudo -u _postgres pg_ctl stop -D /var/pgsql

and

sudo kill {enter postgres pid here}


So... I Googled a bit to find out about what happens at OSX's bootup. Found out that there's a system called "launchd" since Tiger (10.4), which handles all the extensions loading, etc.: http://en.wikipedia.org/wiki/Launchd


After initial system boot, the launchd goes over all files found in /System/Library/LaunchDaemons. There's a file called org.postgresql.postgres.plist which includes all the command line parameters. By modifying the parameters, and restarting system, TCP connection to PostgreSQL works! 😎


Also remember to add all IP addresses allowed to access PostgreSQL to /var/pgsql/pg_hba.conf.


Btw. it's a good idea to add e.g. a user named postgres to access the db, because user _postgres uses the same password as system admin...



Cheers,

/Sami

Aug 6, 2011 5:12 AM in response to Androidi

to connect to another computer, I did


1. edit file /system/library/LaunchDaemons/org.postgresql.postgres.plist


deteteв lines

<string>-c</string>

<string>listen_addresses=</string>

2. edit file /var/pgsql/pg_hba.conf


add lines

host all all 192.168.0.0/24 trust

3. edit file /var/pgsql/postgresql.conf

edit lines

#listen_addresses = 'localhost'

listen_addresses = '*'

#port = 5432

port = 5432

4. restart mac os x server


connect ok

Aug 6, 2011 9:49 AM in response to Yansolo

I managed to open an TCP/IP port with the embedded PostgreSQL server so that I can connect to it with PGAdmin using localhost:5432. You need to open file "/System/Library/LaunchDaemons/org.postgresql.postgres.plist" and change the "listen_addresses" property. Then restart (serveradmin stop postgres, serveradmin start postgres) and you have the port open. Try using: telnet localhost 5432.


You can find more info here:

http://blogs.madplanet.com/2011/08/06/using-embedded-lion-server-postgresql-data base/


- Andy

How to connect to embedded POSTGRESQL on Mac OSX Lion Server

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.