I am working to run PostgreSQL is running locally but I cannot connect. I installed postgress using brew, then I downloaded http://postgresapp.com
When I try to create a database
createdb: could not connect to database postgres: 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"?
I tried to troubleshot this by using :
sudo sysctl -w kern.sysv.shmall=65536
sudo sysctl -w kern.sysv.shmmax=16777216
But nothing work out.
Any ideas how to solve this
-
Don't know about mac but postgres is not running. You have to start the postgres service before doing anythingFabrizio Mazzoni– Fabrizio Mazzoni2014年01月17日 14:10:28 +00:00Commented Jan 17, 2014 at 14:10
2 Answers 2
If you have installed postgresql with brew there's one createdb
that comes with it and that will connect to brew's postgresql.
Then if you have also installed Postgres.app there's another createdb
at a different location that will connect to Postgres.app's postgresql.
Since OS X also ships with its own createdb
in /usr/bin
, that's a third createdb
that expects to connect to Apple's postgresql, which is not running unless it's OS X Server Edition. According to the error message, this is the one that you're trying to use and which fails.
The solution is to use the createdb
command that comes with the PostgreSQL you're actually running. Locate its directory and type the full path of createdb
, as in /Applications/Postgres.app/Contents/MacOS/bin/createdb
, and/or change your $PATH
as suggested in postgresapp's doc.
This is a common problem for PostgreSQL on Mac OS X due the existence of many concurrent packages and of client-side programs pre-installed by Apple.
-
Do you mean by changing the path in .profile, adding this line PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"user3001937– user30019372014年01月17日 22:35:53 +00:00Commented Jan 17, 2014 at 22:35
Manually:
create the directory where you want the database files to be:
mkdir /postgres_data
chown postgres /postgres_data
then initialize the directory:
initdb /postgres_data --encoding=UTF8
start the database engine:
pg_ctl -D /postgres_data start
Now you can create your database:
createdb test
-
I got this error message when I try to initdb : Data page checksums are disabled. fixing permissions on existing directory /postgres_data ... initdb: could not change permissions of directory "/postgres_data": Operation not permitteduser3001937– user30019372014年01月17日 22:31:01 +00:00Commented Jan 17, 2014 at 22:31
-
Try executing the command as the postgres user
su postgres
Fabrizio Mazzoni– Fabrizio Mazzoni2014年01月18日 11:19:14 +00:00Commented Jan 18, 2014 at 11:19 -
It says that "-bash: initdb: command not found"user3001937– user30019372014年01月19日 06:33:17 +00:00Commented Jan 19, 2014 at 6:33