How to install PostgreSQL on OSX Yosemite using MacPorts

I want to install PostgreSQL for a node project that I am developing in OSX Yosemite . I use MacPorts and therefore tried the method described here: https://github.com/codeforamerica/ohana-api/wiki/Installing-PostgreSQL-with-MacPorts-on-OS-X

... but in step 2 I get an error message:

 $ sudo gem install pg -- --with-pg-config=/opt/local/lib/postgresql93/bin/pg_config > ruby_error ERROR: Error installing pg: ERROR: Failed to build gem native extension. /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb --with-pg-config=/opt/local/lib/postgresql93/bin/pg_config Using config values from /opt/local/lib/postgresql93/bin/pg_config checking for libpq-fe.h... yes checking for libpq/libpq-fs.h... yes checking for pg_config_manual.h... yes checking for PQconnectdb() in -lpq... no checking for PQconnectdb() in -llibpq... no checking for PQconnectdb() in -lms/libpq... no Can't find the PostgreSQL client library (libpq) *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. 

... thinking that I do not need to install pg gem, since I want to work with node, not Ruby, I went on to the next steps. But there I encountered an error during step 3.3:

 $ sudo su postgres -c '/opt/local/lib/postgresql93/bin/initdb -D /opt/local/var/db/postgresql93/defaultdb' shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied could not identify current directory: Permission denied could not identify current directory: Permission denied could not identify current directory: Permission denied The program "postgres" is needed by initdb but was not found in the same directory as "initdb". Check your installation. 

... checking the directory my / opt / local / lib / postgresql93 / bin /, I see both initdb and postgres . I see the lines that say Permission denied , and I wonder what that means.

I don’t know how to progress. Thinking about using Postgres.app, if it is really simpler but not sure, it would be better to install using MacPorts, as I install most other things using MacPorts. Tips for any of my problems appreciated!

+6
source share
2 answers

Permissions / ownership of directories between / and defaultdb can be fixed. I think PostgreSQL may be sensitive to owning them, although it seems that in your case, PostgreSQL simply does not have access to them. This is what I have for each directory.

 $ ls -hlt /opt/local/var/db/ total 0 drwxr-xr-x 7 root admin 238B Jan 23 16:54 texmf drwxr-xr-x 3 root admin 102B Dec 25 07:37 postgresql94 

You can fix permissions by running sudo chmod a+rx /opt/local/var/db/ as needed.

For the defaultdb directory defaultdb you should follow the instructions you link to, which seem to have the same as mine:

 sudo chown postgres:postgres /opt/local/var/db/postgresql93/defaultdb 

Below are instructions adapted from my blog (although I recommend using PostgreSQL 9.4, which I am currently doing). I am running PostgreSQL using MacPorts with 9.1 without major problems.

1. Install PostgreSQL using MacPorts.

Of course, I assume that you have MacPorts on your system.

 sudo port install postgresql93 +perl +python27 sudo port install postgresql93-server 

2. PostgreSQL setup

First I need to initialize the database cluster and then start the server. The following screen instructions are provided with the MacPorts postgresql93-server port.

 sudo mkdir -p /opt/local/var/db/postgresql93/defaultdb sudo chown postgres:postgres /opt/local/var/db/postgresql93/defaultdb sudo su postgres -c '/opt/local/lib/postgresql93/bin/initdb -D /opt/local/var/db/postgresql93/defaultdb' 

Note that MacPorts creates a startup daemon. To download it now and make sure that it starts at system startup, follow these steps:

 sudo defaults write /Library/LaunchDaemons/org.macports.postgresql93-server.plist Disabled -bool false sudo launchctl load /Library/LaunchDaemons/org.macports.postgresql93-server.plist 

Then I use psql for some tuning to get my database.

 sudo su - postgres /opt/local/lib/postgresql93/bin/psql -U postgres -d template1 

If you get here, then PostgreSQL will work on your system.

+12
source

I had the same problem when trying to run initdb even when you follow the Ian Gow description:

 $ sudo su postgres -c '/opt/local/lib/postgresql94/bin/initdb -D /opt/local/var/db/postgresql94/defaultdb' shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied could not identify current directory: Permission denied could not identify current directory: Permission denied could not identify current directory: Permission denied The program "postgres" is needed by initdb but was not found in the same directory as "initdb". Check your installation. 

It turns out that the postgres user can do nothing if you try to get him to run the command from his own home directory, because there postgres not allowed to read his own location and therefore cannot determine any other way. Therefore, a simple solution is to run cd / before any command that should run as postgres ( initdb , pg_ctl , etc.). After that, you can quickly return to the previous working directory with cd - .

+5
source

Source: https://habr.com/ru/post/982195/


All Articles