Query to back up a PostgreSQL database I made a CRUD web application that uses a small PostgreSQL database. It is a donors database with the columns name, telephone, blood type, etc.

I have some SELECT and INSERT INTO queries, but now I need a query to back up the database. Nobody has asked about it on this site before, so I think it can't be done, or else I have to make a script using pg_dump or a maintenance plan).

Is it possible to write a SQL query to perform a PostgreSQL database backup?
PostgreSQL does not generate a database backup using a query as SQL Server does (ex: backup database [db_name] to disk...)! It is a different RDBMS; you can't simply do something that other one does, just because you want!

There are 2 methods to take backups from Postgres as commented before. Using pg_dump, you can produce a full sql file including all DDL and DML statements to recreate your database in another place (or restore):

pg_dump -Fp -v -h YOUR_HOST -U YOUR_LOGIN -d DATABASE_NAME -f your_file_name.sql


PostgreSQL pg_dump documentation

Or you can take physical backups by copying the pg_data folder. 

It's up to you decide!