转储数据库的内容,然后使用grep
怎么样?
$ pg_dump --data-only --inserts -U postgres your-db-name > a.tmp
$ grep United a.tmp
INSERT INTO countries VALUES ('US', 'United States');
INSERT INTO countries VALUES ('GB', 'United Kingdom');
同一个实用程序pg_dump可以在输出中包含列名.把--inserts
换成--column-inserts
就行了.这样你也可以搜索特定的列名.但是如果我要查找列名,我可能会转储模式而不是数据.
$ pg_dump --data-only --column-inserts -U postgres your-db-name > a.tmp
$ grep country_code a.tmp
INSERT INTO countries (iso_country_code, iso_country_name) VALUES ('US', 'United States');
INSERT INTO countries (iso_country_code, iso_country_name) VALUES ('GB', 'United Kingdom');