Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 在PostgreSQL 12上使用单个CLI命令终止所有打开的连接_Bash_Postgresql_Postgresql 12 - Fatal编程技术网

Bash 在PostgreSQL 12上使用单个CLI命令终止所有打开的连接

Bash 在PostgreSQL 12上使用单个CLI命令终止所有打开的连接,bash,postgresql,postgresql-12,Bash,Postgresql,Postgresql 12,我有如下CLI命令: $psql-U postgres

我有如下CLI命令:


$psql-U postgres<您的单引号不需要受shell保护,因为它们已经在双引号中了。为了保护它们不受psql的影响,您需要将它们加倍,而不是反向打击它们。所以

psql -U postgres < <(psql -U postgres -Atc "select 'SELECT pg_terminate_backend(pid) 
    FROM pg_stat_activity WHERE datname = '''||datname||'''; /* I WILL ADD MORE QUERIES HERE LATER. */
    'from pg_database where 
    datistemplate=false AND datname != 'postgres';")

psql-U postgres<您始终可以执行
$sudo systemctl restart postgresql
否。在我的CI系统中,我无法执行
systemctl restart
。在删除这些数据库之后,我还将执行一些其他任务。我成功地完成了其他部分。我只是无法终止连接。在PG13中,这是作为
DROP DATABASE my_db WITH(FORCE)
引入的,但是我的一些应用程序仍然依赖于PG12。工作顺利!谢谢你@jjanes
psql -U postgres < <(psql -U postgres -Atc "select 'SELECT pg_terminate_backend(pid) 
    FROM pg_stat_activity WHERE datname = '''||datname||'''; /* I WILL ADD MORE QUERIES HERE LATER. */
    'from pg_database where 
    datistemplate=false AND datname != 'postgres';")