1. 复制一个表
SELECT vale1, value2 into Table2 from Table1 SELECT * into act_flowcategory_1011_init from act_flowcategory;
2. 复制一个库
pg_dump --dbname="postgresql://127.0.0.1:5432/tenant_1011080?user=postgres&password=po##@#es" -F c -b -v -f "$back/tenant_1011333-"$send".backup"
3. 改一个表名
1.更改表名 alter table 表名 rename to 新表名 2.更改字段名 alter table 表名 rename 字段名 to 新字段名 https://blog.csdn.net/sq8706/article/details/7077148
4. 改一个库名
SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE datname='db_name' AND pid<>pg_backend_pid(); ALTER DATABASE db_name RENAME TO db_name_bak;
ALTER DATABASE account RENAME TO account_bak0831;
5. 导入sql文件
psql -h127.0.0.1 -U postgres -d xw_metadata -f /tmp/1109/MetaModel-2021-11-08.sql