Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>List of errors encountered and solved:</p> <ol> <li><p>shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied</p></li> <li><p>pg_config error</p></li> <li><p>Library not loaded: libpq.5.dylib</p></li> <li><p>fe_sendauth: no password supplied </p></li> <li><p>pg_ctl: no database directory specified and environment variable PGDATA unset</p></li> <li><p>pg_ctl: server does not shut down</p></li> <li><p>(PG::Error)</p></li> </ol> <p><strong>A) Pre-installation:</strong></p> <p>When you click on the .dmg file to begin installation, a dialog window opens, and there is a README file alongside the installer. Read that. I changed the shared memory as prescribed:</p> <pre><code>$ sudo vi /etc/sysctl.conf On a MacBook Pro with 2GB of RAM, the author's sysctl.conf contains: kern.sysv.shmmax=1610612736 kern.sysv.shmall=393216 kern.sysv.shmmin=1 kern.sysv.shmmni=32 kern.sysv.shmseg=8 kern.maxprocperuid=512 kern.maxproc=2048 </code></pre> <p>I scrolled down the file to the k's and changed each of the listed lines to the specified values. Then you need to reboot your computer.</p> <p><strong>B) Installing and using PostgreSQL:</strong></p> <p>Then click on the .dmg file again, then click on the installer and install postgres. I accepted all the defaults.</p> <p>As far as I can tell, the postgres installer only gives permissions for the directory /Library/PostgreSQL/9.2 to a user named 'postgres'. During the postgres installation, the installer asked for a password for the database superuser, and if you wondered what the database superuser's name was, it's 'postgres'.</p> <p>When you issue the sudo command, you are temporarily changing to the user 'root'. However, the root user does not have access to the dir /Library/PostgreSQL/9.2. So you have to use the su command (switch user) to change to the postgres user. But in order to issue the su command, you need to be the root user. Got that? </p> <p>As a result, whenever you issue postgres commands you need to do this first:</p> <pre><code>$ cd /Library/PostgreSQL/9.2 $ sudo su postgres Password: &lt;normal sudo password&gt; </code></pre> <p>Errors like this:</p> <pre><code>~$ sudo su postgres shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied </code></pre> <p>are caused by the fact that you are trying to switch to the user postgres in a directory where the postgres user does not have permissions, which is, as far as I can tell, every directory except /Library/PostgreSQL/9.2</p> <p>After you correctly switch to the postgres user:</p> <pre><code>$ cd /Library/PostgreSQL/9.2 $ sudo su postgres Password: &lt;normal sudo password&gt; </code></pre> <p>you get a funny looking prompt. In my case, it looks like this:</p> <pre><code>bash-3.2$ </code></pre> <p>If you issue the ls command:</p> <pre><code>bash-3.2$ ls bin installer scripts data lib share doc pgAdmin3.app stackbuilder.app include pg_env.sh uninstall-postgresql.app </code></pre> <p>you can surmise that you are in the /Library/PostgreSQL/9.2 directory.</p> <p><strong>The enterpriseDB installer automatically starts the postgres server for you when it is done with the installation.</strong> If you need to start the server, e.g. you turned your computer off, see "you can stop or start the server from the command line" in step 5 below.</p> <p><strong>C) Connecting to the server using pgAdmin3:</strong><br> I spent hours trying to figure out how to start the server and just generally use postgres with no luck. Then I happened to see something called pgAdmin3 in the dir /Library/PostgreSQL/9.2. I clicked on that, and a window with several panes opened up.</p> <p>In the left pane of the pgAdmin3 window, it says:</p> <pre><code>Server Groups --Servers(1) ----PostgresSQL 9.2 (localhost:5432) </code></pre> <p>I clicked on 'PostgreSQL 9.2 (localhost:5432)' to highlight it, and then I right clicked to bring up a menu, and I chose Connect. When prompted, I entered the database superuser password.</p> <p><strong>D) Setting up rails to use PostgreSQL:</strong><br> Then I followed the directions in this tutorial for getting rails setup:</p> <p><a href="https://pragtob.wordpress.com/2012/09/12/setting-up-postgresql-for-ruby-on-rails-on-linux/#comment-1142" rel="nofollow noreferrer">https://pragtob.wordpress.com/2012/09/12/setting-up-postgresql-for-ruby-on-rails-on-linux/#comment-1142</a></p> <p>as follows:</p> <p><strong>1) The first step is creating a new user.</strong><br> If you use the same name as your mac user name, then you don't have to add a username (or a password) to the database.yml file in your rails app:</p> <pre><code>$ cd /Library/PostgreSQL/9.2 $ sudo su postgres Password: &lt;normal sudo password&gt; bash-3.2$ createuser --interactive 7stud Shall the new role be a superuser? (y/n) n Shall the new role be allowed to create databases? (y/n) y Shall the new role be allowed to create more new roles? (y/n) n Password:&lt;database superuser password&gt; bash-3.2$ </code></pre> <p>That creates a new user with no password. </p> <p>Next, in pgAdmin3 if you click on:</p> <pre><code>---Login Roles(1) </code></pre> <p>to highlight it, and then click on the icon "Refresh the selected object" at the top of the window, you will see the new user displayed.</p> <p>The postgres docs for createuser are here:</p> <p><a href="http://www.postgresql.org/docs/9.2/interactive/app-createuser.html" rel="nofollow noreferrer">http://www.postgresql.org/docs/9.2/interactive/app-createuser.html</a></p> <p>There is also a dropuser command: </p> <pre><code>bash-3.2$ dropuser 7stud </code></pre> <p><strong>2) Then add the 'pg' gem to your Gemfile</strong>, and comment out the sqlite gems.</p> <p><strong>3) Then try to install the pg gem with Bundler:</strong></p> <pre><code>rails_projects/sample_app/$ bundle install --without production </code></pre> <p>When I tried that, I got a 'pg_config' error. To fix that error, I followed the advice here:</p> <p><a href="http://excid3.com/blog/installing-postgresql-and-pg-gem-on-mac-osx/#.UftQUOB6gy6" rel="nofollow noreferrer">http://excid3.com/blog/installing-postgresql-and-pg-gem-on-mac-osx/#.UftQUOB6gy6</a></p> <p>and added /Library/PostgreSQL/9.2 to my PATH (I do all PATH manipulations in .bashrc.). Don't forget to 'source' .bashrc or quit Terminal and restart Terminal for the new PATH to take effect.</p> <p>Then I was able to install the pg gem without error:</p> <pre><code>rails_projects/sample_app/$ bundle install --without production rails_projects/sample_app/$ bundle update rails_projects/sample_app/$ bundle install </code></pre> <p>(I don't really understand why you have to do all three of those commands, but that is what railstutorial does.)</p> <p><strong>4) Next change your config/database.yml file.</strong><br> For each of the sections: test, development, and production change the 'adapter' and 'database' lines, and add an 'encoding' line, e.g.:</p> <pre><code>development: adapter: postgresql database: ArbitaryDatabaseName (e.g. sampleapp_dev) encoding: utf8 pool: 5 timeout: 5000 </code></pre> <p>Make sure all three database lines specify a different name.</p> <p><strong>5) Then try to create the databases:</strong></p> <pre><code>rails_projects/sample_app/$ bundle exec rake db:create:all </code></pre> <p>When I tried that, I got the error:</p> <pre><code>dlopen(/Users/7stud/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/pg-0.15.1/lib/pg_ext.bundle, 9): Library not loaded: libpq.5.dylib Library not loaded: libpq.5.dylib Referenced from: /Users/7stud/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/pg-0.15.1/lib/pg_ext.bundle </code></pre> <p>The library libpq.5.dylib is located in </p> <pre><code>/Library/PostgreSQL/9.2/lib </code></pre> <p>Using the suggestions here:</p> <p><a href="https://github.com/PostgresApp/PostgresApp/issues/109" rel="nofollow noreferrer">https://github.com/PostgresApp/PostgresApp/issues/109</a></p> <p>I solved that error by adding the following to my .bashrc file(or you can put it in .bash_profile):</p> <pre><code>export DYLD_FALLBACK_LIBRARY_PATH="/Library/PostgreSQL/9.2/lib:$DYLD_LIBRARY_PATH" </code></pre> <p>(Remember to 'source' .bashrc or exit Terminal and start a new Terminal window.)</p> <p>Then I tried to create the databases again:</p> <pre><code>rails_projects/sample_app/$ bundle exec rake db:create:all fe_sendauth: no password supplied … </code></pre> <p>To solve that blasted error, you need to change the pg_hba.conf file, which is in the directory </p> <pre><code>/Library/PostgreSQL/9.2/data </code></pre> <p>You can't go into that directory using Finder--you have to use the postgres user to go into that directory:</p> <pre><code>$ cd /Library/PostgreSQL/9.2 $ sudo su postgres Password: &lt;normal sudo password&gt; bash-3.2$ cd data bash-3.2$ ls PG_VERSION pg_hba.conf pg_notify pg_subtrans postgresql.conf base pg_ident.conf pg_serial pg_tblspc postmaster.opts global pg_log pg_snapshots pg_twophase postmaster.pid pg_clog pg_multixact pg_stat_tmp pg_xlog bash-3.2$ mvim pg_hba.conf (or instead of mvim open with another text editor, e.g. vim) </code></pre> <p>In the .conf file you need to change 'md5' to 'trust':</p> <pre><code># TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only local all all trust #md5 # IPv4 local connections: host all all 127.0.0.1/32 trust #md5 # IPv6 local connections: host all all ::1/128 trust #md5 # Allow replication connections from localhost, by a user with the # replication privilege. #local replication postgres md5 #host replication postgres 127.0.0.1/32 md5 #host replication postgres ::1/128 md5 </code></pre> <p>The access METHOD 'md5' means the database is expecting an encrypted password for the specified database users. But when you created the new user, you created it without a password. The access METHOD 'trust' means the database does not expect a password.</p> <p>Then I tried to create the databases again:</p> <pre><code>rails_projects/sample_app/$ bundle exec rake db:create:all fe_sendauth: no password supplied … </code></pre> <p>In an attempt to get the server to read the changes I made in the .conf file, I disconnected from the server in pgAdmin3:</p> <pre><code>Server Groups --Servers(1) ----PostgresSQL 9.2 (localhost:5432) Click on PostgresSQL 9.2 (localhost:5432) to highlight it, right click, then select Disconnect, then right click and select Connect. </code></pre> <p>But apparently that wasn't working. Disconnecting and reconnecting to the server does not cause the server to reload the .conf file. To get the server to reload the .conf file, in pgAdmin3 you can right click on <code>PostgresSQL 9.2 (localhost:5432)</code> and select:</p> <pre><code>Reload configuration </code></pre> <p><strong>Or you can stop and then start the server from the command line:</strong><br> (Note the following commands assume you have already switched to the postgres user, see "Installing and using PostgreSQL" above.)</p> <pre><code>bash-3.2$ cd /Library/PostgreSQL/9.2/ bash-3.2$ pg_ctl stop (First disconnect from the server in pgAdmin3) </code></pre> <p>However, that produced the error:</p> <pre><code>pg_ctl: no database directory specified and environment variable PGDATA unset Try "pg_ctl --help" for more information. </code></pre> <p>I solved that error like this:</p> <pre><code>bash-3.2$ export PGDATA=/Library/PostgreSQL/9.2/data bash-3.2$ echo $PGDATA /Library/PostgreSQL/9.2/data bash-3.2$ pg_ctl stop waiting for server to shut down.... done server stopped bash-3.2$ pg_ctl start server starting </code></pre> <p>If you don't disconnect from the server first in pgAdmin3, you get the output:</p> <pre><code>bash-3.2$ pg_ctl stop waiting for server to shut down............................................................... failed pg_ctl: server does not shut down HINT: The "-m fast" option immediately disconnects sessions rather than waiting for session-initiated disconnection. bash-3.2$ </code></pre> <p>Later, I was unable to shut down the server when I had the rails console open. I added a User to the database using <code>User.create(....)</code>, and I forgot to start postgres beforehand, so I wondered what was going to happen to that record. For some reason, the postgress server was already running on my system(it seems that postgress starts every time I boot my computer--solved below). Next, I tried to stop the server, and I was unable to. After closing the rails console, the server stopped.</p> <p>Finally, no errors:</p> <pre><code>~/rails_projects/sample_app4_0$ bundle exec rake db:create:all ~/rails_projects/sample_app4_0$ bundle exec rake db:migrate ~/rails_projects/sample_app4_0 </code></pre> <p>I guess that means the db's were created. If you look in pgAdmin3, you should be able to see three new databases (although they have red x's on them). If you can't see them, right click on the Databases directory(in pgAdmin3) and select Refresh.</p> <p>Edit: I ran into some problems later. To fully test if things are working, see here:</p> <p><a href="https://stackoverflow.com/questions/18094845/how-do-i-get-my-rails-app-to-use-my-postgresql-db">How do I get my rails app to use my postgresql db?</a></p> <p><strong>6) Guard/Spork</strong><br> When I started up my Guard/Spork combination:</p> <pre><code>~/rails_projects/sample_app4_0$ bundle exec guard </code></pre> <p>I got this error:</p> <pre><code>... ... Preloading Rails environment Loading Spork.prefork block... FATAL: the database system is shutting down (PG::Error) </code></pre> <p>I fixed that by starting the postgres server, and using pgAdmin3 to connect to the server.</p> <p>Eventually, I figured out how to keep the postgres server from starting every time I boot my computer. I had to make two changes:</p> <p>1) <code>$ sudo vim /Library/LaunchDaemons/com.edb.launchd.postgresql-9.2.plist</code><br> Substitute your version of postgres in place of 9.2.</p> <p>2) Locate the line RunAtLoad</p> <p>3) Change the next line from <code>&lt;true/&gt;</code> to <code>&lt;false/&gt;</code></p> <p><a href="https://superuser.com/questions/244589/prevent-postgresql-from-running-at-startup">https://superuser.com/questions/244589/prevent-postgresql-from-running-at-startup</a></p> <p>Those steps alone did not work for me. Then I found this advice:</p> <p>4) <code>$ sudo launchctl unload -w /Library/LaunchDaemons/com.edb.launchd.postgresql-9.2.plist</code> </p> <p>Substitute your version of postgres in place of 9.2.</p> <p><a href="http://www.postgresql.org/message-id/flat/4B41FD48.7030009@enterprisedb.com#4B41FD48.7030009@enterprisedb.com" rel="nofollow noreferrer">http://www.postgresql.org/message-id/flat/4B41FD48.7030009@enterprisedb.com#4B41FD48.7030009@enterprisedb.com</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload