homebrew的data_directory在哪里?或者对于postgresql或者如何解决错误,""global/pg_filenode.map":没有这样的文件或目录"?

 思紅顏0114 发布于 2022-12-20 14:09

通过homebrew安装后我遇到了postgresql的困难.我在Mac OS X 10.9.5上(今天刚刚更新并重启).

注意我没有故意通过自制软件从默认的postgresql安装中更改任何内容

问题

我无法卸载postgresql

我无法登录查看表格/启动postgres的"命令行"

createdb返回有关pg_filenode.map的错误"没有这样的文件或目录"

initdb返回错误想知道data_directory在哪里(我不知道)

任何这些都是成功的

登录到psql(所以我可以像在mysql中一样创建数据库或表,浏览现有表)

完全卸载postgres(所以我可以用postgresql.app重新尝试)

我花了近10个小时对此进行故障排除,并且做得很短.

我已经看了很多答案(包括SO问题24132418和14510237)虽然由于没有声望点我不能包含所有链接

任何指针都会非常感激!

下面似乎很长,因为我已经粘贴了所有日志,如果我错过了一些重要信息,请告诉我

谢谢,-Mark

细节

我一直在研究Heroku的介绍,他们说安装postgresql是一个要求,所以我用自制程序做了

brew install postgresql

我没有检查它,我继续构建我的应用程序,但第二天我在本地运行webapp并得到错误,

Request URL:    http://localhost:5000/admin/
Django Version: 1.6.5
Exception Type: OperationalError
Exception Value:    
FATAL:  could not open relation mapping file "global/pg_filenode.map": No such file or directory
Exception Location: /Users/macuser/Dropbox/code/heroku/awe01/lib/python2.7/site-packages/psycopg2/__init__.py in connect, line 164

所以我想调查一下.现在我以前从未使用过postgresql,所以我想为postgresql"到达命令行"

请注意,我是一个完整的新手,之前从未使用过postgresql.

在mysql中,我知道这将是

mysql -u root -p

(然后输入密码)

我无法在postgresql中做相同的操作

  moriartymacbookair13:~ macuser$ postgres
  postgres does not know where to find the server configuration file.
  You must specify the --config-file or -D invocation option or set the PGDATA environment variable.
  moriartymacbookair13:~ macuser$ postgres -V
  postgres (PostgreSQL) 9.3.5

更详细的heroku文档建议使用postgres.app安装postgresql我没有这样做,我用的是自制软件,所以我尝试卸载postgresql

moriartymacbookair13:~ macuser$ brew uninstall postgres
Uninstalling /usr/local/Cellar/postgresql/9.3.5_1...
Error: Permission denied - /usr/local/bin/clusterdb

这没用,所以回到原来的位置.为了弄清楚要指定的路径,我跑了

brew info postgresql

如果向下滚动到底部,您可以看到它告诉我路径

moriartymacbookair13:~ macuser$ brew info postgres
postgresql: stable 9.3.5 (bottled), devel 9.4beta2
http://www.postgresql.org/
Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.3.5_1 (2927 files, 38M) *
  Poured from bottle
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/postgresql.rb
==> Dependencies
Required: openssl ?, readline ?
Recommended: ossp-uuid ?
==> Options
--32-bit
    Build 32-bit only
--enable-dtrace
    Build with DTrace support
--no-perl
    Build without Perl support
--no-tcl
    Build without Tcl support
--with-python
    Build with python support
--without-ossp-uuid
    Build without ossp-uuid support
--devel
    install development version 9.4beta2
==> Caveats
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
  https://github.com/Homebrew/homebrew/issues/issue/2510

To migrate existing data from a previous major version (pre-9.3) of PostgreSQL, see:
  http://www.postgresql.org/docs/9.3/static/upgrading.html

When installing the postgres gem, including ARCHFLAGS is recommended:
  ARCHFLAGS="-arch x86_64" gem install pg

To install gems without sudo, see the Homebrew wiki.

To reload postgresql after an upgrade:
    launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or, if you don't want/need launchctl, you can just run:
    postgres -D /usr/local/var/postgres

注意:我忽略了顶部的评论:

Conflicts with: postgres-xc
    /usr/local/Cellar/postgresql/9.3.5_1 (2927 files, 38M) *

无论如何我们有它,在那个大输出结束时它确认我的路径是/ usr/local/var/postgres,所以我试过-D

moriartymacbookair13:~ macuser$ postgres -D /usr/local/postgres
postgres cannot access the server configuration file "/usr/local/postgres/postgresql.conf": No such file or directory

所以这次我指定了配置文件:

moriartymacbookair13:~ macuser$ postgres --config-file=/usr/local/var/postgres/postgresql.conf 
postgres does not know where to find the database system data.
This can be specified as "data_directory" in "/usr/local/var/postgres/postgresql.conf", or by the -D invocation option, or by the PGDATA environment variable.

(出于绝望,我甚至尝试删除它并再次去)

                moriartymacbookair13:~ macuser$ initdb /usr/local/var/postgres
        The files belonging to this database system will be owned by user "macuser".
        This user must also own the server process.
The database cluster will be initialized with locale "en_GB.UTF-8".
        The default database encoding has accordingly been set to "UTF8".
        The default text search configuration will be set to "english".

        Data page checksums are disabled.

        initdb: directory "/usr/local/var/postgres" exists but is not empty
        If you want to create a new database system, either remove or empty
        the directory "/usr/local/var/postgres" or run initdb
        with an argument other than "/usr/local/var/postgres".
        moriartymacbookair13:~ macuser$ rm -rf /usr/local/var/postgres
        moriartymacbookair13:~ macuser$ initdb /usr/local/var/postgres -E utf8
        The files belonging to this database system will be owned by user "macuser".
        This user must also own the server process.

        The database cluster will be initialized with locale "en_GB.UTF-8".
        The default text search configuration will be set to "english".

        Data page checksums are disabled.

        creating directory /usr/local/var/postgres ... ok
        creating subdirectories ... ok
        selecting default max_connections ... 100
        selecting default shared_buffers ... 128MB
        creating configuration files ... ok
        creating template1 database in /usr/local/var/postgres/base/1 ... ok
        initializing pg_authid ... ok
        initializing dependencies ... ok
        creating system views ... ok
        loading system objects' descriptions ... ok
        creating collations ... ok
        creating conversions ... ok
        creating dictionaries ... ok
        setting privileges on built-in objects ... ok
        creating information schema ... ok
        loading PL/pgSQL server-side language ... ok
        vacuuming database template1 ... ok
        copying template1 to template0 ... ok
        copying template1 to postgres ... ok
        syncing data to disk ... ok

        WARNING: enabling "trust" authentication for local connections
        You can change this by editing pg_hba.conf or using the option -A, or
        --auth-local and --auth-host, the next time you run initdb.

        Success. You can now start the database server using:

            postgres -D /usr/local/var/postgres
        or
            pg_ctl -D /usr/local/var/postgres -l logfile start


    moriartymacbookair13:~ macuser$ postgres -D /usr/local/postgres
    postgres cannot access the server configuration file "/usr/local/postgres/postgresql.conf": No such file or directory
    moriartymacbookair13:~ macuser$ postgres --config-file=/usr/local/var/postgres/postgresql.conf 
    postgres does not know where to find the database system data.
    This can be specified as "data_directory" in "/usr/local/var/postgres/postgresql.conf", or by the -D invocation option, or by the PGDATA environment variable.

所以我看了看那个文件:

在conf文件本身中,未定义数据变量

  moriartymacbookair13:~ macuser$ ls /usr/local/var/postgres/
  PG_VERSION       pg_ident.conf    pg_stat/         pg_xlog/
  base/            pg_multixact/    pg_stat_tmp/     postgresql.conf
  global/          pg_notify/       pg_subtrans/
  pg_clog/         pg_serial/       pg_tblspc/
  pg_hba.conf      pg_snapshots/    pg_twophase/
  moriartymacbookair13:~ macuser$ vim /usr/local/var/postgres/postgresql.conf 

显示该值被注释掉(参见第41行...几乎整个文件被注释掉)

 35 # FILE LOCATIONS
 36 #-----------------------------------------------------------------------------    -
 37 
 38 # The default values of these variables are driven from the -D command-line
 39 # option or PGDATA environment variable, represented here as ConfigDir.
 40 
 41 #data_directory = 'ConfigDir'           # use data in another directory
 42                                         # (change requires restart)
 43 #hba_file = 'ConfigDir/pg_hba.conf'     # host-based authentication file
 44                                         # (change requires restart)
 45 #ident_file = 'ConfigDir/pg_ident.conf' # ident configuration file
 46                                         # (change requires restart)
 47 
 48 # If external_pid_file is not explicitly set, no extra PID file is written.
 49 #external_pid_file = ''                 # write an extra PID file
 50                                         # (change requires restart)

帮助:是否有人知道我应该在data_directory指定的地方指定'ConfigDir'AS?

如果这里有用,是Cellar文件夹的内容

moriartymacbookair13:~ macuser$ ls /usr/local/Cellar/postgresql/9.3.5_1/
COPYRIGHT                       homebrew.mxcl.postgresql.plist
HISTORY                         include/
INSTALL_RECEIPT.json            lib/
README                          share/
bin/

(我不明白为什么我在Cellar有一些postgres文件,有些在usr/local/var中)

我也尝试过其他一些东西:

    moriartymacbookair13:~ macuser$ sudo -u postgres pg_ctl -D /usr/local/var/postgres -w start
    sudo: unknown user: postgres

这是基于其他SO问题

    moriartymacbookair13:~ macuser$ ls -ld /usr/local/var/postgres/
    drwx------  19 macuser  admin   646B 20 Sep 19:46 /usr/local/var/postgres//
    moriartymacbookair13:~ macuser$ chown -R postgres /usr/local/var/postgres
    chown: postgres: illegal user name
    moriartymacbookair13:~ macuser$ brew uninstall postgresql
    Uninstalling /usr/local/Cellar/postgresql/9.3.5_1...
    Error: Permission denied - /usr/local/bin/clusterdb
    moriartymacbookair13:~ macuser$ brew uninstall postgres
    Uninstalling /usr/local/Cellar/postgresql/9.3.5_1...
    Error: Permission denied - /usr/local/bin/clusterdb
    moriartymacbookair13:~ macuser$ 

正如我所说,我安装了Postgresql只是为了试用heroku,所以这是我在foreman start本地运行时从代码中给出的错误.(注意"django app"只是一个演示应用程序https://devcenter.heroku.com/articles/getting-started-with-python#prepare-the-app)它适用于localhost:5000家庭,但是当我添加/admin(与数据库交互的页面)时,我收到以下错误:

OperationalError at /admin/
FATAL:  could not open relation mapping file "global/pg_filenode.map": No such file or directory
Request Method: GET
Request URL:    http://localhost:5000/admin/
Django Version: 1.6.5
Exception Location: /Users/macuser/Dropbox/code/heroku/awe01/lib/python2.7/site-packages/psycopg2/__init__.py in connect, line 164
Python Executable:  /Users/macuser/Dropbox/code/heroku/awe01/bin/python

完整错误回溯日志: http://dpaste.com/3CREGVQ

注意这个答案/sf/ask/17360801/ 建议不仅仅是initdb

以上错误与我运行createdb时的错误相同:

moriartymacbookair13:~ macuser$ createdb /usr/local/var/postgres/
createdb: could not connect to database template1: FATAL:  could not open relation mapping file "global/pg_filenode.map": No such file or directory

这里建议的步骤 Postgres失败了'无法打开关系映射文件'global/pg_filenode.map"' 是

Remove and re-add the launch agent
Kill the processes for 
Initialize the db initdb /usr/local/var/postgres
Restart my computer

如果这是相关的,请告诉我如何"删除并重新添加启动代理"?是这个吗?(基于之前brew信息postgresql的输出)

moriartymacbookair13:~ macuser$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
moriartymacbookair13:~ macuser$ killall postgresql
No matching processes belonging to you were found
moriartymacbookair13:~ macuser$ killall postgres
No matching processes belonging to you were found
moriartymacbookair13:~ macuser$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

最后,如果它激励任何人,

moriartymacbookair13:~ macuser$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry and just ignore them. Thanks!

Warning: The /usr/local directory is not writable.
Even if this directory was writable when you installed Homebrew, other
software may change permissions on this directory. Some versions of the
"InstantOn" component of Airfoil are known to do this.

You should probably change the ownership and permissions of /usr/local
back to your user account.

Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected dylibs:
    /usr/local/lib/libguide.dylib
    /usr/local/lib/libKLF_OGL.dylib

Warning: Some directories in your path end in a slash.
Directories in your path should not end in a slash. This can break other
doctor checks. The following directories should be edited:
    $/Users/macuser/Dropbox/code/aws/ElasticBeanstalkCommandLineTools/AWS-ElasticBeanstalk-CLI-2.6.3/AWSDevTools.sh/macosx/python2.7/    /Users/macuser/Dropbox/code/aws/ElasticBeanstalkCommandLineTools/AWS-ElasticBeanstalk-CLI-2.6.3/AWSDevTools/eb/macosx/python2.7/

Warning: /usr/bin occurs before /usr/local/bin
This means that system-provided programs will be used instead of those
provided by Homebrew. The following tools exist at both paths:

    git
    git-cvsserver
    git-receive-pack
    git-shell
    git-upload-archive
    git-upload-pack

Consider setting your PATH so that /usr/local/bin
occurs before /usr/bin. Here is a one-liner:
    echo export PATH='/usr/local/bin:$PATH' >> ~/.bash_profile
moriartymacbookair13:~ macuser$ 

今天早些时候我创建了这个错误:无法连接到数据库postgres:无法连接到服务器:没有这样的文件或目录服务器是否在本地运行并接受Unix域套接字"/tmp/.s.PGSQL.5432"上的连接?

http://www.postgresql.org/docs/9.3/interactive/tutorial-createdb.html 但错误现在似乎已经消失

关于取消或重新安装postgresql,解决unknown user: postgres错误,设置位置#data_directory = 'ConfigDir'或任何其他提示的任何建议......我真的很感激.现在已经失去了一整天,所以我会很感激.

1 个回答
  • FATAL: could not open relation mapping file "global/pg_filenode.map": No such file or directory

    您有一个PostgreSQL安装,但在服务器运行时删除或移动了数据目录.或者您将其安装在可移动磁盘上,然后将其删除.或者您系统上的某些应用程序正在弄乱其他应用程序如何更改文件.

      moriartymacbookair13:~ macuser$ postgres
      postgres does not know where to find the server configuration file.
    

    postgres是服务器应用程序.客户是psql.但是,如果global/pg_filenode.map遗失了,你就不会再有运气了psql.

      moriartymacbookair13:~ macuser$ brew uninstall postgres
    

    sudo brew uninstall postgres

    无论如何,我们有它,在那个大输出结束时它确认了我的路径/usr/local/var/postgres,所以我尝试了-D

    moriartymacbookair13:~ macuser$ postgres -D /usr/local/postgres
    postgres cannot access the server configuration file "/usr/local/postgres/postgresql.conf": No such file or directory
    

    你错了路.注意什么"酿造信息"说:

        Or, if you don't want/need launchctl, you can just run:
        postgres -D /usr/local/var/postgres
    

    至于postgres用户:

    moriartymacbookair13:~ macuser$ sudo -u postgres pg_ctl -D /usr/local/var/postgres -w start
    sudo: unknown user: postgres
    

    我认为某些Mac OS X安装使用_postgrespostgres_.我没有mac,所以我无法检查.但无论如何,在你的情况下并不重要,因为datadir由你的用户拥有,而不是postgres:

    moriartymacbookair13:~ macuser$ ls -ld /usr/local/var/postgres/
    drwx------  19 macuser  admin   646B 20 Sep 19:46 /usr/local/var/postgres//
    

    它看起来像你或你的系统上的一些工具已经破坏你的PostgreSQL数据目录,破坏它.这不应该发生,所以我会努力找出删除的内容pg_filenode.map以及如何/何时删除.

    如果数据目录中没有您关心的数据,则应删除它并重新初始化.

    我没有Mac,我无法看到Homebrew如何配置你的PostgreSQL安装的启动,但听起来它可能postgres以用户身份运行macuser.在这种情况下,只需:

    launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
    rm -rf /usr/local/var/postgres
    initdb -D /usr/local/var/postgres -U postgres --auth-local peer --auth-host md5 -E utf-8l
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
    

    最后,重新:

    注意,当我尝试使用postgres.app安装程序时,它告诉我"无法在端口5432上启动"并在安装过程中冻结

    猜测,当你尝试使用postgresHomebrew 的服务器已经在5432上运行,但由于数据目录损坏而无法运行.

    所以你真的有两件事:

    重新初始化datadir以使PostgreSQL再次运行; 和

    弄清楚它是如何被破坏的

    2022-12-20 14:11 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有