You can use the pg_dump command. For example, pg_dump -U username -d dbname > backup.sql will create a SQL file containing the database's structure and data.