如何从postgresql打印表结构?

发布于 2024-12-23 05:48:58 字数 70 浏览 3 评论 0原文

我在浏览器中使用 phpPgAdmin,在 Windows 中使用 PgAdmin III。有没有办法打印整个数据库的表结构?

I am using phpPgAdmin in the browser and PgAdmin III for Windows. Is there anyway to take the printout of the table structure for the entire database?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

¢蛋碎的人ぎ生 2024-12-30 05:48:58

导出数据库模式的标准方法是 pg_dump

#!/bin/sh
pg_dump --schema-only MYDBNAME > output-file.sql

稍微好一点的方法将 pg_dump 与 pg_restore 列表过滤相结合:

#!/bin/sh
dump=`mktemp`
list=`mktemp`
pg_dump --schema-only MYDBNAME -Fc -f $dump
pg_restore -l $dump | grep ' TABLE ' > $list
pg_restore -L $list $dump > output-file.sql
rm $list $dump

如果您更喜欢 GUI 向导, pg_dump 命令可以在 PgAdmin III 中生成:

  • 右键单击对象浏览器中的数据库,选择“备份”
  • 选择目标文件名(常见扩展名是.sql 或.txt)
  • 选择“Plain”格式。 (即文本格式)
  • 在“转储选项#1”选项卡上,勾选“仅架构”
  • 单击“备份”

注意:生成的文件不仅包含表,还包含所有其他对象(视图、函数等)。如果您只需要最少的打印输出,您可以在文本编辑器中编辑此文件并删除不需要的内容。仅保留“类型:表;”项目。

The standard way of exporting database schema is pg_dump:

#!/bin/sh
pg_dump --schema-only MYDBNAME > output-file.sql

Sligtly better way combines pg_dump with pg_restore list filtering:

#!/bin/sh
dump=`mktemp`
list=`mktemp`
pg_dump --schema-only MYDBNAME -Fc -f $dump
pg_restore -l $dump | grep ' TABLE ' > $list
pg_restore -L $list $dump > output-file.sql
rm $list $dump

If you prefer GUI wizards, pg_dump command can be generated in PgAdmin III:

  • right click the database in object browser, select "Backup"
  • select destination filename (common extension is .sql or .txt)
  • Choose "Plain" format. (that is, text format)
  • on "Dump Options #1" tab, tick "Only Schema"
  • click "Backup"

Note: the resulting file will have not only tables, but also all other objects (views, functions, etc.). If you need only the minimal printout, you can edit this file in text editor and remove unneeded stuff. Leave only "Type: TABLE;" items.

∞琼窗梦回ˉ 2024-12-30 05:48:58

如果您使用的是 Windows 和 pgAdmin,则 psql 应该位于 C:\Program files\postgresql\\bin\psql 中。

运行 psql,然后您将看到 \d 打印所有表和索引,以及 \d 为您提供有关一个表的详细信息。

If you are on Windows and pgAdmin, you should have psql somewhere in C:\Program files\postgresql\<version>\bin\psql.

Run psql and then you have \d which prints all tables and indexes and \d <table_name> which gives you details about one table.

无可置疑 2024-12-30 05:48:58

您可以根据需要一次执行一项。右键单击 pgAdminIII 中的表,转到“报告”并选择“数据字典报告”。

对于输出格式,选择“XHTML 1.0 Transitional”,选择“嵌入默认样式表”选项,为其指定文件名,然后单击“确定”。

在浏览器中打开 XML 文件并打印。

You can do them one at a time as you need them. Right click on a table in pgAdminIII, go to Reports and select "Data Dictionary Report".

For the output format, select "XHTML 1.0 Transitional", choose "Embed the default stylesheet" option, give it a file name and click OK.

Open the XML file in your browser and print.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文