我已使用命令连接数据库
sudo -i -u postgres
Run Code Online (Sandbox Code Playgroud)
\l 在我也尝试\d查看所有可用数据库的列表之后,它不起作用。相反,我得到以下输出:
d:command not found and
l:command not found error is showing
Run Code Online (Sandbox Code Playgroud)
怎么办,如何获取 postgresql 数据库列表?
如果你想从 shell 执行命令,可以使用-cpsql 中的选项:
psql -c '\l'
Run Code Online (Sandbox Code Playgroud)
例子:
peter@blackrain:~$ sudo su postgres
postgres@blackrain:/home/peter$ psql -c '\l'
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
------------+----------+----------+-------------+-------------+-----------------------
blackrain | peter | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 |
postgres | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 |
redpepper | peter | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 |
template0 | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
x | peter | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 |
(6 rows)
postgres@blackrain:/home/peter$
Run Code Online (Sandbox Code Playgroud)