I'm using postgresql 9.6,it's ok to execute in psql command:
select pg_cancel_backend(a.pid) from pg_locks a join pg_class b on a.relation = b.oid join pg_stat_activity c on a.pid = c.pid where c.datname = 'mydb' and a.mode like '%AccessShareLock%';
However, it prompts an error : "ERROR: canceling statement due to user request" when I execute the following scripts:
/app/postgres/pgsql/bin/psql -h "127.0.0.1" -p 6661 -U "postgres" -d "mydb" -tc "select pg_cancel_backend(a.pid) from pg_locks a
> join pg_class b on a.relation = b.oid
> join pg_stat_activity c on a.pid = c.pid
> where c.datname = 'mydb' and a.mode like '%AccessShareLock%';"
what is the difference between this two methods?