Query to back up a PostgreSQL database
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!