26

In a similar vein to this question, how would I do a schema-only dump in PostgreSQL?

49

pg_dump --schema-only

  • easier than I realized it would be :) – warren Aug 31 '09 at 4:22
  • 3
    Frankly, I haven't much clue about postgres administration, but I've been watching videos from pgcon 09 and someone mentioned pg_dump. – jldugger Aug 31 '09 at 4:27
  • either way - it's what I needed :) – warren Sep 7 '09 at 13:41
  • 7
    @warren: it's even easier: pg_dump -s. – hans0l0 Nov 20 '13 at 14:58
4

If you only want the CREATE TABLE statements, then you can do pg_dump -s databasename | awk 'RS="";/CREATE TABLE[^;]*;/'

  • 1
    Not sure why the downvotes as this command works perfectly. So +1 from me. – Dave Mar 4 '17 at 19:17
  • I agree that sometimes you only need the CREATE TABLE statements... though to be fair, the question asked for 'schema'... – arod Mar 4 '17 at 22:42
  • 1
    That was the rigth answer to me, because i couldn't create file with functions, views and etc. – Natan Medeiros Jun 18 '18 at 12:27
  • @Dave because adding an additional option not at all linked to the initial question 6 years later is not that useful. – Arne Nov 21 '18 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.