加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql – Postgres看不到我的PGDATA环境变量

发布时间:2020-12-13 15:54:51 所属栏目:百科 来源:网络整理
导读:谁能解释一下: ~$echo $PGDATA/Library/PostgreSQL/9.2/data~$cd /Library/PostgreSQL/9.2//Library/PostgreSQL/9.2$sudo su postgresbash-3.2$echo $PGDATAblank line bash-3.2$pg_ctl startpg_ctl: no database directory specified and environment vari
谁能解释一下:

~$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文件:

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

我不是在拼错PGDATA中的路径:

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

解决方法

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

据我所知,环境变量附加到shell,据我所知,我在同一个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

下一条评论:

When I su to postgres I do su – postgres. Notice 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环境变量,这就是我尝试连字符时发生的事情:

/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).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读