The standard way to export a database schema is pg_dump :
Too better a way to combine pg_dump with 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
If you prefer GUI wizards, the pg_dump command can be generated in PgAdmin III :
- right-click the database in the object browser, select "Backup"
- select destination file name (common extension -.sql or .txt)
- Select the "Normal" format. (i.e. text format)
- on the "Parameters of dump No. 1" tab, check "Schema only"
- Click "Backup"
Note. In the resulting file, not only tables will be displayed, but also all other objects (views, functions, etc.). If you need only a minimal printout, you can edit this file in a text editor and delete unnecessary things. Leave only "Type: TABLE;" elements.
source share