【问题标题】:Error in run sql file in postgres | No such file or directory在 postgres 中运行 sql 文件时出错 |没有相应的文件和目录
【发布时间】:2021-08-18 12:39:06
【问题描述】:

问题

尝试在 psql shell 中运行 sql 文件时...

给出“没有这样的文件或目录”错误!

$ ls
config.sql  config.yaml

$ sudo -i -u postgres psql

postgres=# \i config.sql

config.sql: No such file or directory

感谢您的回复!

快速解决方案:

-i => 进入用户的主目录!

结果./config.sql地址不正确!

随便用

$ psql -U <user_name>

postgres=# \i config.sql

【问题讨论】:

  • 你在运行sudo -i时切换了当前目录
  • @a_horse_with_no_name 问题解决了!谢谢

标签: postgresql psql


【解决方案1】:

man sudo告诉你:

-i, --login

将目标用户的密码数据库条目指定的 shell 作为登录 shell 运行。这意味着特定于登录 资源文件如.profile.bash_profile.login 将被shell 读取。如果指定了命令,则通过 通过 shell 的 -c 选项到 shell 执行。

特别是,这会将您当前的工作目录设置为用户 postgres 的主目录。

如果您想避免这种情况,请不要使用“-i”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-09
    • 2011-02-04
    • 2015-02-20
    • 2012-08-28
    • 2016-08-15
    相关资源
    最近更新 更多