Postgres无法看到我的PGDATA环境变量 [英] Postgres cannot see my PGDATA environment variable

查看:1408
本文介绍了Postgres无法看到我的PGDATA环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释一下吗

~$ echo $PGDATA
/Library/PostgreSQL/9.2/data

~$ cd /Library/PostgreSQL/9.2/

/Library/PostgreSQL/9.2$ sudo su postgres

bash-3.2$ echo $PGDATA
<blank line>   

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

bash-3.2$ export PGDATA="/Library/PostgreSQL/9.2/data"

bash-3.2$ pg_ctl start
server starting

bash-3.2$ 

以下是我的〜/ .bashrc文件:

The following is in my ~/.bashrc file:

export PGDATA="/Library/PostgreSQL/9.2/data"

我没有在PGDATA中拼写错误的路径:

I'm not mis-spelling the path in PGDATA:

                ~$ echo $PGDATA
                /Library/PostgreSQL/9.2/data
 export PGDATA="/Library/PostgreSQL/9.2/data"


推荐答案


sudo不能假定保留了调用方的环境变量。
有关特定操作系统的详细信息,请参见其手册页。

sudo can't be assumed to keep the environment variables of its caller. See its manpage for the details with your specific OS.

据我所知,环境变量附加在

As far as I know, environment variables are attached to a shell, and as far as I can tell I'm in the same shell.

这对我有用:

~$ cd /Library/PostgreSQL/9.2/
/Library/PostgreSQL/9.2$ sudo -E su postgres  

...

   -E          The -E (preserve environment) option will override the
               env_reset option in sudoers(5)).  It is only available when
               either the matching command has the SETENV tag or the
               setenv option is set in sudoers(5).

我仅了解以下内容:

The -E (preserve environment) option

下一条评论:


当我su到postgres时,我做su-postgres。注意连字符。

When I su to postgres I do su - postgres. Notice the hyphen.

这是我的手册页关于连字符的内容:

Here is what my man pages say about the hyphen:

 -l      Simulate a full login.  The environment is discarded except for
         HOME, SHELL, PATH, TERM, and USER.  HOME and SHELL are modified
         as above.  USER is set to the target login.  PATH is set to
         ``/bin:/usr/bin''.  TERM is imported from your current environ-
         ment.  The invoked shell is the target login's, and su will
         change directory to the target login's home directory.

 -       (no letter) The same as -l.

我看不到它将如何保存PGDATA环境变量,这就是我发生的情况尝试连字符:

I don't see how that will preserve the PGDATA environment variable, and this is what happened when I tried the hyphen:

/Library/PostgreSQL/9.2$ sudo su - postgres
Password:
7studs-computer:~ postgres$ ls
bin             pgAdmin3.app
data                pg_env.sh
doc             scripts
include             share
installer           stackbuilder.app
lib             uninstall-postgresql.app
7studs-computer:~ postgres$ pg_ctl start
-bash: pg_ctl: command not found
7studs-computer:~ postgres$ ls 
bin             pgAdmin3.app
data                pg_env.sh
doc             scripts
include             share
installer           stackbuilder.app
lib             uninstall-postgresql.app
7studs-computer:~ postgres$ cd bin
7studs-computer:bin postgres$ ls
clusterdb       pg_config       pgbench
createdb        pg_controldata      pltcl_delmod
createlang      pg_ctl          pltcl_listmod
createuser      pg_dump         pltcl_loadmod
dropdb          pg_dumpall      postgres
droplang        pg_receivexlog      postmaster
dropuser        pg_resetxlog        psql
ecpg            pg_restore      reindexdb
initdb          pg_standby      vacuumdb
oid2name        pg_test_fsync       vacuumlo
pg_archivecleanup   pg_test_timing
pg_basebackup       pg_upgrade
7studs-computer:bin postgres$ ./pg_ctl start
pg_ctl: no database directory specified and environment variable PGDATA unset
Try "pg_ctl --help" for more information.
7studs-computer:bin postgres$ 

所以连字符对我不起作用( OSX 10.6.8)。

So the hyphen doesn't work for me (OSX 10.6.8).

这篇关于Postgres无法看到我的PGDATA环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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