2

I hava PostgreSQL 9.3 installed by homebrew in Mac OS X 10.9.3. When I first installed it, it worked well. After reboot it happened to be not launched and I don’t know how to launch by pg_ctl it because I can't find out what its data directory is:

$ pg_ctl start
pg_ctl: no database directory specified and environment variable PGDATA unset
Try "pg_ctl --help" for more information.

$ pwd
/usr/local/var/postgres

$ ls -al
total 96
drwx------  21 alex  admin    714 Jun  2 21:23 .
drwx------   3 alex  admin    102 Jun  1 15:08 ..
-rw-------   1 alex  admin      4 Jun  1 15:08 PG_VERSION
drwx------   6 alex  admin    204 Jun  2 11:40 base
drwx------  42 alex  admin   1428 Jun  2 14:18 global
drwx------   3 alex  admin    102 Jun  1 15:08 pg_clog
-rw-------   1 alex  admin   4465 Jun  2 10:58 pg_hba.conf
-rw-------   1 alex  admin   1636 Jun  1 15:08 pg_ident.conf
drwx------   4 alex  admin    136 Jun  1 15:08 pg_multixact
drwx------   3 alex  admin    102 Jun  1 18:24 pg_notify
drwx------   2 alex  admin     68 Jun  1 15:08 pg_serial
drwx------   2 alex  admin     68 Jun  1 15:08 pg_snapshots
drwx------   7 alex  admin    238 Jun  2 21:23 pg_stat
drwx------   2 alex  admin     68 Jun  2 21:23 pg_stat_tmp
drwx------   3 alex  admin    102 Jun  1 15:08 pg_subtrans
drwx------   2 alex  admin     68 Jun  1 15:08 pg_tblspc
drwx------   2 alex  admin     68 Jun  1 15:08 pg_twophase
drwx------   4 alex  admin    136 Jun  1 15:08 pg_xlog
-rw-------   1 alex  admin  20571 Jun  1 15:08 postgresql.conf
-rw-------   1 alex  admin     79 Jun  1 18:24 postmaster.opts
-rw-------   1 alex  admin   1482 Jun  2 21:23 server.log

In /Library there is nothing titled PostgreSQL or something.

How do I find it out?

UPDATE:

$ sudo chown -R _postgres /usr/local/var/postgres
$ ls -ld /usr/local/var/postgres
drwx------  21 _postgres  admin  714 Jun  2 21:23 /usr/local/var/postgres

#################

$ sudo -u _postgres pg_ctl -D /usr/local/var/postgres -w start
could not identify current directory: Permission denied
pg_ctl: could not open PID file "/usr/local/var/postgres/postmaster.pid": Permission denied

$ ls -al /usr/local/var/postgres/postmaster.pid
ls: /usr/local/var/postgres/postmaster.pid: Permission denied

$ sudo ls -al /usr/local/var/postgres/postmaster.pid
ls: /usr/local/var/postgres/postmaster.pid: No such file or directory
6
  • PostgreSQL version? Installed from where, and how? (Links). Mac OS X version? Commented Jun 10, 2014 at 4:12
  • @AlexanderSupertramp SHOW data_directory; did you try ?? Commented Jun 10, 2014 at 5:21
  • @hector, no I didn't try. How can I try it if it's not launched! Commented Jun 10, 2014 at 5:37
  • @AlexanderSupertramp its the query that you can use via pgAdmin Commented Jun 10, 2014 at 6:08
  • or you can get your data directory path with the same query using psql Commented Jun 10, 2014 at 6:12

1 Answer 1

4

pg_ctl doesn't look in the current directory for the datadir. You have to specify it with the PGDATA env var or the -D command line argument.

To launch:

sudo -u postgres pg_ctl -D /usr/local/var/postgres -w start

however, you should really set it up to start using launchd. AFAIK it's covered in the Homebrew documentation.

Sign up to request clarification or add additional context in comments.

8 Comments

the error - sudo -u _postgres pg_ctl -D /usr/local/var/postgres -w start Password: could not identify current directory: Permission denied
pg_ctl: could not open PID file "/usr/local/var/postgres/postmaster.pid": Permission denied
ls -ld /usr/local/var/postgres
drwx------ 21 alex admin 714 Jun 2 21:23 /usr/local/var/postgres
Looks like you initdb'd the datadir as your own user not the postgres user, so the postgres user doesn't have the right to access it and run. That's probably why it's failing to autostart if you added it to launchd too. chown -R postgres /usr/local/var/postgres should do the job.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.