Postgres allows the use of any existing database on the server as a template when creating a new database.
(创建新数据库时,Postgres允许使用服务器上的任何现有数据库作为模板。)
I'm not sure whether pgAdmin gives you the option on the create database dialog but you should be able to execute the following in a query window if it doesn't: (我不确定pgAdmin是否在创建数据库对话框中为您提供了该选项,但是如果没有,您应该能够在查询窗口中执行以下操作:)
CREATE DATABASE newdb WITH TEMPLATE originaldb OWNER dbuser;
Still, you may get:
(不过,您可能会得到:)
ERROR: source database "originaldb" is being accessed by other users
To disconnect all other users from the database, you can use this query:
(要将所有其他用户与数据库断开连接,可以使用以下查询:)
SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'originaldb' AND pid <> pg_backend_pid();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…