0

I want to create a procedure which when I call creates a backup by creating an .sql file and saves it in my computer.

The procedure's name is trial_gen(). When I execute call trial_gen(), it should create a plain .sql file of the schema.

All solutions I found were only using the SQL shell

  • Do you want to create the procedure by creating a *.sql* file, or do you want to create the backup *as* a *.sql* file (i.e. a database dump)? Your question is ambiguous, please [edit] it to clarify. – Bergi Jan 02 '23 at 12:53
  • How do you want to call the procedure? By "*saves it in my computer*", do you refer to the same computer that the database is running on? – Bergi Jan 02 '23 at 12:54
  • Why not just [`pg_dump`](https://www.postgresql.org/docs/current/app-pgdump.html), why do you want this to work as a query in pgAdmin? It's possible to get DDL statements for everything from system tables and spit it out through `COPY` into an .sql file on your drive (assuming it's a local database), but you'll either have to settle for a subset of your relations, or re-invent a slower, pure-SQL `pg_dump`. pgAdmin already offers a [backup and restore dialog](https://www.pgadmin.org/docs/pgadmin4/latest/backup_and_restore.html), that's basically a GUI for `pg_dump`. – Zegarek Jan 02 '23 at 12:58

1 Answers1

0

SQL code is a script, so I think it makes sense to run one from SQL shell. It would be a stored script (text) in a file anyway.

  • I don't think that's what the OP meant, but let's wait for them to clarify – Bergi Jan 02 '23 at 12:55
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 02 '23 at 14:36