如何在Mac OSX 10.6.8上启动enterpiseDB PostgreSQL? [英] How do I start enterpiseDB PostgreSQL on Mac OSX 10.6.8?

查看:163
本文介绍了如何在Mac OSX 10.6.8上启动enterpiseDB PostgreSQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Mac OSX 10.6.8



postgres网站说postgres 9.2+与Mac OSX 10.6+兼容,因此我下载了9.2.4版本的安装程序Mac OSX在这里:



http: //www.enterprisedb.com/products-services-training/pgdownload



我接受了所有默认设置,因此postgres安装在目录中:

  /Library/PostgreSQL/9.2 

(如果要安装Postgres进行Rails开发,则要安装pg gem,您需要添加到PATH中: http://excid3.com/blog/installing-postgresql-and-pg-gem-on-mac-osx/# .UfkImuB6gy5



现在,我正在尝试弄清楚如何使用postgres。我发现一个stackoverflow线程说您可以使用以下命令启动postgres:

 〜$ /Library/PostgreSQL/9.2/bin/ pg_ctl start -D /Library/PostgreSQL/9.2/data -l postgres.log 

但这会产生此结果错误:


pg_ctl:无法打开PID文件
/Library/PostgreSQL/9.2/data/postmaster.pid:权限被拒绝


如果我使用sudo尝试相同的命令:

 〜$ sudo /Library/PostgreSQL/9.2/bin/pg_ctl start -D /Library/PostgreSQL/9.2/data -l postgres.log 

我收到此错误:


pg_ctl:无法作为root用户运行请以拥有服务器进程权限的
(非特权)用户身份登录(使用 su)。


这到底是什么意思?



另一个SO线程说,响应该错误,您应该这样做:

  $ sudo -u postgres bash 

产生以下输出:

 密码:
shell-init:检索当前目录时出错:getcwd:无法访问父目录:权限被拒绝
bash:/Users/7stud/.bashrc:权限被拒绝
bash-3.2 $

那里的错误是怎么回事?

解决方案

遇到和解决的错误列表:


  1. shell-init:检索当前目录时出错:getcwd:无法访问父目录:权限被拒绝


  2. pg_config错误


  3. 库未加载:libpq.5.dylib


  4. fe_sendauth:未提供密码


  5. pg_ctl:未指定数据库目录且未设置环境变量PGDATA


  6. pg_ctl:服务器无法关闭


  7. (PG :: Error)


A)前置档:



单击.dmg文件开始安装时,将打开一个对话框,安装程序旁边有一个README文件。阅读。我按规定更改了共享内存:

  $ sudo vi /etc/sysctl.conf 

对于具有2GB RAM的MacBook Pro,作者的sysctl.conf包含:

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

我向下滚动文件到k,并将列出的每一行更改为指定的值。然后您需要重新启动计算机。



B)安装和使用PostgreSQL:



然后再次单击.dmg文件,然后单击安装程序并安装postgres。我接受了所有默认设置。



据我所知,postgres安装程序仅将目录/Library/PostgreSQL/9.2的权限授予名为 postgres的用户。在postgres安装期间,安装程序要求数据库超级用户的密码,如果您想知道数据库超级用户的名字是 postgres,则为



sudo命令,您暂时更改为用户 root。但是,root用户无权访问目录/Library/PostgreSQL/9.2。因此,您必须使用su命令(切换用户)更改为postgres用户。但是,要发出su命令,您需要成为root用户。知道了?



因此,每当发出postgres命令时,都需要先执行以下操作:

  $ cd /Library/PostgreSQL/9.2 
$ sudo su postgres
密码:< normal sudo password>

这样的错误:

 〜$ sudo su postgres 
shell-init:检索当前目录时出错:getcwd:无法访问父目录:权限被拒绝

是由于您尝试切换到postgres用户没有权限的目录中的用户postgres而引起的,据我所知,除/Library/PostgreSQL/9.2以外的所有目录



正确切换到postgres用户后:

  $ cd /Library/PostgreSQL/9.2 
$ sudo su postgres
密码:< normal sudo password>

您会看到一个有趣的提示。就我而言,它看起来像这样:

  bash-3.2 $ 

如果发出ls命令:

  bash-3.2 $ ls 
bin安装程序脚本
数据库共享
文档pgAdmin3.app stackbuilder.app
include pg_env.sh uninstall-postgresql.app

您可以推测您位于/Library/PostgreSQL/9.2目录中。



EnterpriseDB安装程序在安装完成后会自动为您启动postgres服务器。如果您需要启动服务器,例如您已关闭计算机,请参阅下面的第5步中的可以从命令行停止或启动服务器。



C)使用pgAdmin3:

我花了数小时试图弄清楚如何启动服务器,并且通常只使用postgres而没有运气。然后我偶然在目录/Library/PostgreSQL/9.2中看到名为pgAdmin3的东西。我单击了它,然后打开了一个包含多个窗格的窗口。



在pgAdmin3窗口的左窗格中,它显示:

 服务器组
-服务器(1)
---- PostgresSQL 9.2(localhost:5432)

我单击 PostgreSQL 9.2(localhost:5432)以突出显示它,然后右键单击以显示一个菜单,选择连接。出现提示时,我输入了数据库超级用户密码。



D)设置Rails以使用PostgreSQL:

然后我按照本教程中的说明进行Rails设置:



https://pragtob.wordpress.com/2012/09/12/setting-up-postgresql-for -ruby-on-rails-on-linux /#comment-1142



如下:



1)第一步是创建一个新用户。

如果您使用与Mac用户名相同的名称,则不必添加用户名(或密码)添加到您的Rails应用程序中的database.yml文件中:

  $ cd /Library/PostgreSQL/9.2 
$ sudo su postgres
密码:<普通sudo密码>
bash-3.2 $ createuser --interactive 7stud
新角色是超级用户吗? (y / n)n
是否应允许新角色创建数据库? (y / n)是
是否应允许新角色创建更多新角色? (y / n)n
密码:<数据库超级用户密码>
bash-3.2 $

这将创建一个没有密码的新用户。



然后,在pgAdmin3中,如果您单击:

 - -登录角色(1)

以突出显示它,然后单击刷新所选对象图标在窗口顶部,您将看到显示的新用户。



createuser的postgres文档在此处:



http://www.postgresql.org/docs/ 9.2 / interactive / app-createuser.html



还有一个dropuser命令:

  bash-3.2 $ dropuser 7stud 

2)然后



3)然后尝试使用Bundler安装pg宝石。 :

  rails_projects / sample_app / $捆绑安装-不生产

当我尝试这样做时,我得到了一个'pg_config'错误。要解决该错误,我遵循了以下建议:



http://excid3.com/blog/installing-postgresql-and-pg-gem-on-mac-osx/#.UftQUOB6gy6



,并将/Library/PostgreSQL/9.2添加到我的PATH中(我在.bashrc中执行所有PATH操作。)。别忘了'source'.bashrc或退出Terminal并重新启动Terminal以使新的PATH生效。



然后,我能够无错误地安装pg gem。 :

  rails_projects / sample_app / $捆绑安装-无生产
rails_projects / sample_app / $捆绑更新
rails_projects / sample_app / $捆绑安装

(我不太明白为什么你必须做全部

4)接下来,更改您的config / database.yml文件。

对于每个部分:测试,开发和生产,更改适配器和数据库行,并添加编码行,例如:

 开发:
适配器:postgresql
数据库:ArbitaryDatabaseName(例如sampleapp_dev)
编码:utf8

池:5
超时:5000

确保所有三个数据库行均已指定



5)然后尝试创建数据库:

  rails_projects / sample_app / $ bundle exec rake db:create:all 

尝试时,出现错误:

  dlopen(/Users/7stud/.rvm/gems/ruby-2.0 .0-p247 @ railstutorial_rails_4_0 / gems / pg-0.15.1 / lib / pg_ext.bundle,9):未加载库:libpq.5.dylib 
未加载库:libpq.5.dylib
引用自:/Users/7stud/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/pg-0.15.1/lib/pg_ext.bundle

库libpq.5.dylib位于

  /库/PostgreSQL/9.2/lib 

在此处使用建议:



https://github.com/PostgresApp/PostgresApp/issues/109



我通过将以下内容添加到m中解决了该错误y .bashrc文件(或您可以将其放在.bash_profile中):

  export DYLD_FALLBACK_LIBRARY_PATH = / Library / PostgreSQL / 9.2 / lib:$ DYLD_LIBRARY_PATH 

(记住要'source'.bashrc或退出Terminal并启动一个新Terminal



然后我尝试再次创建数据库:

  rails_projects / sample_app / $捆绑执行rake db:create:all 
fe_sendauth:未提供密码…

要解决该错误,您需要更改pg_hba.conf文件,该文件位于目录

  / Library /PostgreSQL/9.2/data 

您不能使用Finder进入该目录-您必须使用postgres用户进入该目录:

  $ cd /Library/PostgreSQL/9.2 
$ sudo su postgres
密码:<普通sudo密码>
bash-3.2 $ cd数据
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
全局pg_log pg_snapshots pg_twophase postmaster.pid
pg_clog pg_multixact pg_stat_tmp pg_xlog

bash-3.2 $ mvim pg_hba.conf
(或代替mvim用另一个文本编辑器,例如vim打开)

在.conf文件中,您需要将'md5'更改为'trust':

 #类型数据库用户地址方法

# local仅用于Unix域套接字连接
local all trust#md5
#IPv4本地连接:
托管所有127.0.0.1/32信任#md5
#IPv6本地连接:
托管所有::: 1/128 trust# md5
#允许复制连接具有
#复制特权的用户从localhost执行的操作。
#本地复制postgres md5
#主机复制postgres 127.0.0.1/32 md5
#主机复制postgres :: 1/128 md5

访问方法'md5'表示数据库需要指定数据库用户的加密密码。但是,当您创建新用户时,创建时没有密码。访问方法信任表示数据库不需要密码。



然后我尝试再次创建数据库:

  rails_projects / sample_app / $ bundle exec rake db:create:all 
fe_sendauth:未提供密码…

为了使服务器读取我在.conf文件中所做的更改,我在pgAdmin3中与服务器断开连接:

 服务器组
-服务器(1)
---- PostgresSQL 9.2(localhost:5432)

单击PostgresSQL 9.2(localhost:5432)使其突出显示,右键单击
,然后选择断开连接,然后单击
,然后右键单击并选择连接。

但显然这没有用。断开连接并重新连接到服务器不会导致服务器重新加载.conf文件。要使服务器重新加载.conf文件,请在pgAdmin3中右键单击 PostgresSQL 9.2(localhost:5432)并选择:

 重新加载配置

您可以从命令行停止然后启动服务器:

(请注意,以下命令假设您已经切换到postgres用户,请参见上面的安装和使用PostgreSQL。)

  bash-3.2 $ cd /Library/PostgreSQL/9.2/ 
bash-3.2 $ pg_ctl stop(首先断开pgAdmin3中的服务器)

但是,这会产生错误:

  pg_ctl:未指定数据库目录,并且未设置环境变量PGDATA 
尝试 pg_ctl --help以获取更多信息。

我解决了这样的错误:

  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停止
等待服务器关闭....完成
服务器已停止
bash-3.2 $ pg_ctl开始
服务器开始

如果不首先在pgAdmin3中断开与服务器的连接,则输出:

  bash-3.2 $ pg_ctl stop 
等待服务器关闭.................. ...................................................失败
pg_ctl:服务器没有关闭
提示: -m fast选项立即断开会话的连接,而不是
等待会话启动的断开连接。
bash-3.2 $

后来,我无法关闭服务器导轨控制台打开。我使用 User.create(....)将一个User添加到数据库中,但是我忘记了事先启动postgres,所以我想知道该记录会发生什么。由于某种原因,postgress服务器已经在我的系统上运行(似乎每次启动计算机时都会启动postgress -在下面解决)。接下来,我试图停止服务器,但无法停止。关闭rails控制台后,服务器停止了。



最后,没有错误:

 〜/ 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

我想这意味着数据库已创建。如果您查看pgAdmin3,则应该可以看到三个新数据库(尽管它们上有红色的x)。如果看不到它们,请右键单击数据库目录(在pgAdmin3中),然后选择刷新。



编辑:以后我遇到了一些问题。要全面测试一切是否正常,请参见此处:



如何让我的Rails应用使用我的postgresql数据库?



6)Guard / Spork

当我启动我的Guard / Spork组合时:

 〜/ rails_projects / sample_app4_0 $ bundle execguard 

我收到此错误:

  ... 
...
预加载Rails环境
正在加载Spork.prefork块...
致命:数据库系统正在关闭
(PG :: Error)

我通过启动postgres服务器并使用pgAdmin3连接到服务器来解决该问题。



最终,我弄清楚了如何防止每次引导时都启动postgres服务器。我的电脑。我必须进行两个更改:



1) $ sudo vim /Library/LaunchDaemons/com.edb.launchd.postgresql-9.2.plist

用您的postgres版本代替9.2。



2)找到RunAtLoad

$ b行
$ b

3)将下一行从< true /> 更改为< false />



https://superuser.com/questions/244589/prevent-postgresql-from-running-at-startup



仅这些步骤对我不起作用。然后我找到了这个建议:



4) $ sudo launchctl unload -w /Library/LaunchDaemons/com.edb.launchd.postgresql-9.2。 plist



用您的postgres版本代替9.2。



http://www.postgresql。 org / message-id / flat / 4B41FD48.7030009 @ enterprisedb.com#4B41FD48.7030009 @ enterprisedb.com


Mac OSX 10.6.8

The postgres website says postgres 9.2+ is compatible with Mac OSX 10.6+, so I downloaded the 9.2.4 version of the installer for Mac OSX here:

http://www.enterprisedb.com/products-services-training/pgdownload

I accepted all the defaults, so postgres was installed in the directory:

/Library/PostgreSQL/9.2

(If you are installing postgres for rails development, in order to install the pg gem you need to add to your PATH: http://excid3.com/blog/installing-postgresql-and-pg-gem-on-mac-osx/#.UfkImuB6gy5)

Now, I am trying to figure out how to use postgres. I found a stackoverflow thread that said you can start postgres with this command:

~$ /Library/PostgreSQL/9.2/bin/pg_ctl start -D /Library/PostgreSQL/9.2/data -l postgres.log

But that produces this error:

pg_ctl: could not open PID file "/Library/PostgreSQL/9.2/data/postmaster.pid": Permission denied

If I try the same command with sudo:

~$ sudo /Library/PostgreSQL/9.2/bin/pg_ctl start -D /Library/PostgreSQL/9.2/data -l postgres.log

I get this error:

pg_ctl: cannot be run as root Please log in (using, e.g., "su") as the (unprivileged) user that will own the server process.

What the heck does that mean??

Another SO thread says that in response to that error, you should do this:

$ sudo -u postgres bash

which produces this output:

Password:
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
bash: /Users/7stud/.bashrc: Permission denied
bash-3.2$ 

What's going on with the error there?

解决方案

List of errors encountered and solved:

  1. shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied

  2. pg_config error

  3. Library not loaded: libpq.5.dylib

  4. fe_sendauth: no password supplied

  5. pg_ctl: no database directory specified and environment variable PGDATA unset

  6. pg_ctl: server does not shut down

  7. (PG::Error)

A) Pre-installation:

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:

$ 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

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.

B) Installing and using PostgreSQL:

Then click on the .dmg file again, then click on the installer and install postgres. I accepted all the defaults.

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'.

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?

As a result, whenever you issue postgres commands you need to do this first:

$ cd /Library/PostgreSQL/9.2
$ sudo su postgres
Password: <normal sudo password>

Errors like this:

~$ sudo su postgres
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied

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

After you correctly switch to the postgres user:

$ cd /Library/PostgreSQL/9.2
$ sudo su postgres
Password: <normal sudo password>

you get a funny looking prompt. In my case, it looks like this:

bash-3.2$ 

If you issue the ls command:

bash-3.2$ ls
bin             installer           scripts
data                lib             share
doc             pgAdmin3.app            stackbuilder.app
include             pg_env.sh           uninstall-postgresql.app

you can surmise that you are in the /Library/PostgreSQL/9.2 directory.

The enterpriseDB installer automatically starts the postgres server for you when it is done with the installation. 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.

C) Connecting to the server using pgAdmin3:
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.

In the left pane of the pgAdmin3 window, it says:

Server Groups
--Servers(1)
----PostgresSQL 9.2 (localhost:5432)

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.

D) Setting up rails to use PostgreSQL:
Then I followed the directions in this tutorial for getting rails setup:

https://pragtob.wordpress.com/2012/09/12/setting-up-postgresql-for-ruby-on-rails-on-linux/#comment-1142

as follows:

1) The first step is creating a new user.
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:

$ cd /Library/PostgreSQL/9.2
$ sudo su postgres
Password: <normal sudo password>
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:<database superuser password>
bash-3.2$

That creates a new user with no password.

Next, in pgAdmin3 if you click on:

---Login Roles(1)

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.

The postgres docs for createuser are here:

http://www.postgresql.org/docs/9.2/interactive/app-createuser.html

There is also a dropuser command:

bash-3.2$ dropuser 7stud

2) Then add the 'pg' gem to your Gemfile, and comment out the sqlite gems.

3) Then try to install the pg gem with Bundler:

rails_projects/sample_app/$ bundle install --without production

When I tried that, I got a 'pg_config' error. To fix that error, I followed the advice here:

http://excid3.com/blog/installing-postgresql-and-pg-gem-on-mac-osx/#.UftQUOB6gy6

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.

Then I was able to install the pg gem without error:

rails_projects/sample_app/$ bundle install --without production
rails_projects/sample_app/$ bundle update
rails_projects/sample_app/$ bundle install

(I don't really understand why you have to do all three of those commands, but that is what railstutorial does.)

4) Next change your config/database.yml file.
For each of the sections: test, development, and production change the 'adapter' and 'database' lines, and add an 'encoding' line, e.g.:

development:
  adapter: postgresql
  database: ArbitaryDatabaseName (e.g. sampleapp_dev)
  encoding: utf8

  pool: 5
  timeout: 5000

Make sure all three database lines specify a different name.

5) Then try to create the databases:

rails_projects/sample_app/$ bundle exec rake db:create:all

When I tried that, I got the error:

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

The library libpq.5.dylib is located in

/Library/PostgreSQL/9.2/lib

Using the suggestions here:

https://github.com/PostgresApp/PostgresApp/issues/109

I solved that error by adding the following to my .bashrc file(or you can put it in .bash_profile):

export DYLD_FALLBACK_LIBRARY_PATH="/Library/PostgreSQL/9.2/lib:$DYLD_LIBRARY_PATH"

(Remember to 'source' .bashrc or exit Terminal and start a new Terminal window.)

Then I tried to create the databases again:

rails_projects/sample_app/$ bundle exec rake db:create:all
fe_sendauth: no password supplied …

To solve that blasted error, you need to change the pg_hba.conf file, which is in the directory

/Library/PostgreSQL/9.2/data 

You can't go into that directory using Finder--you have to use the postgres user to go into that directory:

$ cd /Library/PostgreSQL/9.2
$ sudo su postgres
Password: <normal sudo password>
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)

In the .conf file you need to change 'md5' to 'trust':

# 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

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.

Then I tried to create the databases again:

rails_projects/sample_app/$ bundle exec rake db:create:all
fe_sendauth: no password supplied …

In an attempt to get the server to read the changes I made in the .conf file, I disconnected from the server in pgAdmin3:

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.

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 PostgresSQL 9.2 (localhost:5432) and select:

Reload configuration

Or you can stop and then start the server from the command line:
(Note the following commands assume you have already switched to the postgres user, see "Installing and using PostgreSQL" above.)

bash-3.2$ cd /Library/PostgreSQL/9.2/
bash-3.2$ pg_ctl stop  (First disconnect from the server in pgAdmin3)

However, that produced the error:

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

I solved that error like this:

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

If you don't disconnect from the server first in pgAdmin3, you get the output:

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$

Later, I was unable to shut down the server when I had the rails console open. I added a User to the database using User.create(....), 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.

Finally, no errors:

~/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

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.

Edit: I ran into some problems later. To fully test if things are working, see here:

How do I get my rails app to use my postgresql db?

6) Guard/Spork
When I started up my Guard/Spork combination:

~/rails_projects/sample_app4_0$ bundle exec guard

I got this error:

...
...
Preloading Rails environment
Loading Spork.prefork block...
FATAL:  the database system is shutting down
 (PG::Error)

I fixed that by starting the postgres server, and using pgAdmin3 to connect to the server.

Eventually, I figured out how to keep the postgres server from starting every time I boot my computer. I had to make two changes:

1) $ sudo vim /Library/LaunchDaemons/com.edb.launchd.postgresql-9.2.plist
Substitute your version of postgres in place of 9.2.

2) Locate the line RunAtLoad

3) Change the next line from <true/> to <false/>

https://superuser.com/questions/244589/prevent-postgresql-from-running-at-startup

Those steps alone did not work for me. Then I found this advice:

4) $ sudo launchctl unload -w /Library/LaunchDaemons/com.edb.launchd.postgresql-9.2.plist

Substitute your version of postgres in place of 9.2.

http://www.postgresql.org/message-id/flat/4B41FD48.7030009@enterprisedb.com#4B41FD48.7030009@enterprisedb.com

这篇关于如何在Mac OSX 10.6.8上启动enterpiseDB PostgreSQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆