我正在使用 kubernetes,并且只想过滤postgreSQL 上的sampledb 。
我尝试使用这个命令:
kubectl exec podname-89tq4763k23-klp83 -- bash -c "psql -U postgres --tuples-only -P format=unaligned -c "SELECT datname FROM pg_database WHERE NOT datistemplate AND datname <> 'postgres'";"
但它没有显示我的终端的任何输出,我的期望是它应该显示sampledb作为输出
尝试使用此命令列出所有数据库名称并且它正在工作。
kubectl exec -it podname-89tq4763k23-klp83 -- psql -U postgres -c "\l"
我的问题是如何从数据库列表中仅过滤sampledb名称?
List of databases
Name | Owner | Encoding | Collate | Ctype | ICU Locale | Locale Provider | Access privileges
-------------+----------+----------+------------+------------+------------+-----------------+-----------------------
sampledb | postgres | UTF8 | en_US.utf8 | en_US.utf8 | | libc |
postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 | | libc |
template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | | libc | =c/postgres +
| | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | | libc | =c/postgres +
| | | | | | | postgres=CTc/postgres
(4 rows)
注意:如果这个 kubectl 命令可以作为我的 bash 脚本的变量,我还计划使用它。