In a similar vein to this question, how would I do a schema-only dump in PostgreSQL?
2 Answers
pg_dump --schema-only
- easier than I realized it would be :)warren– warren2009-08-31 04:22:41 +00:00Commented Aug 31, 2009 at 4:22
- 3Frankly, I haven't much clue about postgres administration, but I've been watching videos from pgcon 09 and someone mentioned pg_dump.jldugger– jldugger2009-08-31 04:27:19 +00:00Commented Aug 31, 2009 at 4:27
- either way - it's what I needed :)warren– warren2009-09-07 13:41:51 +00:00Commented Sep 7, 2009 at 13:41
- 7@warren: it's even easier:
pg_dump -s.hans0l0– hans0l02013-11-20 14:58:37 +00:00Commented Nov 20, 2013 at 14:58 -
If you only want the CREATE TABLE statements, then you can do pg_dump -s databasename | awk 'RS="";/CREATE TABLE[^;]*;/'
- 6Not sure why the downvotes as this command works perfectly. So +1 from me.Dave– Dave2017-03-04 19:17:43 +00:00Commented Mar 4, 2017 at 19:17
- 5That was the rigth answer to me, because i couldn't create file with functions, views and etc.Natan Medeiros– Natan Medeiros2018-06-18 12:27:25 +00:00Commented Jun 18, 2018 at 12:27
- 1@Dave because adding an additional option not at all linked to the initial question 6 years later is not that useful.Arne– Arne2018-11-21 13:28:19 +00:00Commented Nov 21, 2018 at 13:28
- 1@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.elrobis– elrobis2019-08-09 19:23:20 +00:00Commented Aug 9, 2019 at 19:23
- 1@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.Emilio Platzer– Emilio Platzer2019-10-09 14:20:56 +00:00Commented Oct 9, 2019 at 14:20