Skip to content

Instantly share code, notes, and snippets.

@cloverink
Created August 11, 2022 05:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cloverink/f524bb4f4bf478cb785587dbead29e4d to your computer and use it in GitHub Desktop.
Save cloverink/f524bb4f4bf478cb785587dbead29e4d to your computer and use it in GitHub Desktop.
Postgres Duplicate Database
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'db-name-1'
AND pid <> pg_backend_pid();
CREATE DATABASE "db-name-2"
WITH TEMPLATE "db-name-1"
OWNER produsr;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment