postgresql 如何在 psql 控制台中打印当前工作目录?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45091269/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 02:36:23  来源:igfitidea点击:

How to print current working directory in psql console?

postgresqlpsql

提问by Don P

I am trying to restore a schema on a remote server using the psql console in pgAdmin and an sql dump file. I receive the following error:

我正在尝试使用 pgAdmin 中的 psql 控制台和 sql 转储文件在远程服务器上恢复模式。我收到以下错误:

user=> \i file.sql
file.sql: No such file or directory

I can't seem to print the directory listings due to lacking superuser privileges.

由于缺乏超级用户权限,我似乎无法打印目录列表。

Is there a way to identify or print the current working directory in psql console? What is the default directory?

有没有办法在 psql 控制台中识别或打印当前工作目录?默认目录是什么?

采纳答案by vipulsinghthakur

Typing in the command \! pwdwill print the current working directory in psql. To change working directory use command \cd <path>; replace <path>with desired path. Eg. Running command \cd /run/mountwill change the current working directory to /run/mount. Try changing the your working directory to that containing the file which you want to run and then use \imeta command as you did earlier. It will definitely work.

输入命令\! pwd将打印 psql 中的当前工作目录。要更改工作目录,请使用命令\cd <path>;替换<path>为所需的路径。例如。运行命令\cd /run/mount会将当前工作目录更改为/run/mount. 尝试将您的工作目录更改为包含您要运行的文件的目录,然后\i像之前一样使用meta 命令。它肯定会起作用。

回答by Rich Lysakowski PhD

I am shocked that no one answered the question directly in over 2 years. Everyone assumes that because you are using postgres that you must be running Linux. Well, postgres is now becoming a very popular DBMS on Windows 10.

我很震惊,两年多来没有人直接回答这个问题。每个人都假设因为您使用的是 postgres,所以您必须运行 Linux。好吧,postgres 现在正在成为 Windows 10 上非常流行的 DBMS。

In Windows 10, in a psql command prompt type "! dir" to print the current working directory.

在 Windows 10 中,在 psql 命令提示符下键入“!dir”以打印当前工作目录。

To change directories in the Windows 10 psql client, "\cd /users/yourlogin".

要更改 Windows 10 psql 客户端中的目录,请使用“\cd /users/yourlogin”。

The psql client is a unix shell running on Windows, so it is a mix of unix and dos syntax commands.

psql 客户端是在 Windows 上运行的 unix shell,因此它是 unix 和 dos 语法命令的混合。

回答by Karthick Selvakumar

Just you use this command it will display your current working directory

只要你使用这个命令,它就会显示你当前的工作目录

pwd

密码