我需要比较2个DB方案(DDL)-Postgress 9.5
我在两个服务器上都执行以下命令:
pg_dump -U postgres --dbname=db--schema-only -f schema.sql
但是我注意到输出的前缀之一是每个对象的方案名称,例如
CREATE FUNCTION schemeName.function_name
而另一个则不,例如:
CREATE FUNCTION function_name
pg_dump中是否有任何选项可以决定是否在输出DDL中插入方案名称?(首选项至少要删除那些模式前缀...)
简而言之:你不能。但是,您可以使用sed
自动完成编辑的[[most。
#!/bin/sh
# dump only schema "tmp"
# force quoted identifiers
# use sed to strip them
# [youstillneedtoremove the "CReate SCHEMA $SCH_NAME-stuff
DB_NAME="postgres"
pg_dump -Upostgres -n tmp --schema-only --quote-all-identifiers $DB_NAME \
| sed 's/"tmp"\.//g' > tmp_schema_stripped.sql
#EOF