1

I want to export the database structure from a PostgreSQL database. I want to include all tables, functions, etc., created by me but exclude everything created by database extensions like PostGIS. What is the easiest way how to do that?

The problem is that there are hundreds of functions and procedures in the same (public) schema as my own functions.

6
  • Would not creating your objects in the public schema be an option?
    – mustaccio
    Commented May 8, 2023 at 17:58
  • Well, they are already there :)
    – Fido
    Commented May 8, 2023 at 18:03
  • Did you try it? This is automatically the way it works. Extensions are dumped by their "CREATE EXTENSION..." statements, not by listing their individual objects. (There are some exceptions to this, but for postgis that exception is a single config table, not hundreds of things)
    – jjanes
    Commented May 9, 2023 at 0:47
  • @jjanes Of course. You are right that there are only a few extension tables. BUT there are about a thousand functions and procedures...
    – Fido
    Commented May 15, 2023 at 17:08
  • But those functions should not get dumped. What version of postgresql and postgis are you using?
    – jjanes
    Commented May 16, 2023 at 1:51

1 Answer 1

-1

You can use the pg_dump utility to export the structure of your PostgreSQL database.

To exclude objects created by database extensions like PostGIS, you can use the --exclude-extension option followed by the name of the extension. For example, to exclude all objects created by the PostGIS extension, you can use the following command:

pg_dump --exclude-extension=postgis -U <username> -s <databasename> > <outputfile>

This command will create a SQL script that includes the structure of all tables, functions, etc., created by you, but excludes everything created by the PostGIS extension. The -s option specifies that only the database schema should be exported, without the data.

You can customize the command further by specifying additional options such as the --schema option to include only specific schemas, or the --table option to include only specific tables. You can also pipe the output of pg_dump to a compression utility such as gzip to create a compressed backup file.

2
  • There does not seem to be any such parameter of pg_dump. Where do you have this information from?
    – Fido
    Commented May 15, 2023 at 17:17
  • This option doesn't exists
    – jordsti
    Commented Jan 19 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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