pgsql复制DB
-- 确保没有连接到源数据库
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'DBname' AND pid <> pg_backend_pid();
-- 复制数据库
CREATE DATABASE DBname_2 WITH TEMPLATE DBname OWNER postgres;
-- 查看后台进程状态
SELECT pid, query, state, age(clock_timestamp(), query_start)
FROM pg_stat_activity
WHERE query LIKE '%CREATE DATABASE%';

浙公网安备 33010602011771号