更新时间:2023-12-01 10:06:04
如何转储数据库内容,然后使用 grep
?
How about dumping the contents of the database, then using 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可以在输出中包含列名。只需更改 - 插入
到 - 列插入
。这样您也可以搜索特定的列名称。但如果我在寻找列名,我可能会转储模式而不是数据。
The same utility, pg_dump, can include column names in the output. Just change --inserts
to --column-inserts
. That way you can search for specific column names, too. But if I were looking for column names, I'd probably dump the schema instead of the data.
$ 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');