How can I do a dump of only the table structure in PostgreSQL?
60,268
Solution 1
pg_dump --schema-only
Solution 2
If you only want the CREATE TABLE
statements, then you can do pg_dump -s databasename | awk 'RS="";/CREATE TABLE[^;]*;/'
Related videos on Youtube
Author by
warren
I'm a hobbyist programmer, part-time sysadmin, and full-time analytics, big data, data center management, automation, and cloud computing architect and delivery engineer.
Updated on September 17, 2022Comments
-
warren over 1 year
In a similar vein to this question, how would I do a schema-only dump in PostgreSQL?
-
warren over 14 yearseasier than I realized it would be :)
-
jldugger over 14 yearsFrankly, I haven't much clue about postgres administration, but I've been watching videos from pgcon 09 and someone mentioned pg_dump.
-
warren over 14 yearseither way - it's what I needed :)
-
hans0l0 over 10 years@warren: it's even easier:
pg_dump -s
. -
Dave about 7 yearsNot sure why the downvotes as this command works perfectly. So +1 from me.
-
Arne over 5 years@Dave because adding an additional option not at all linked to the initial question 6 years later is not that useful.
-
elrobis almost 5 years@Arne. Disagree. The question title, which specifies dumping "only the table structure", gives this page a high search rank. And plenty of people, like Natan who remarked prior to you, want to avoid moving functions and/or views from old extensions in the event that they are starting with a fresh db with updated extensions. So it absolutely is "useful", as opposed to "not useful", which are the voting criteria. Absolutely getting my +1.
-
Emilio Platzer over 4 years@Dave. I think that this answer is right. I opened because the title. I'm searching table-only struct dump. This is better than the other or the title is not acurated.