If you want to use the PostgreSQL database for Python applications on PythonAnywhere, you need to purchase the custom plan.
After purchasing the custom plan, you can set up the PostgreSQL database.
In your PythonAnywhere account, go to the "Database" tab.
First, assign the PostgreSQL Superuser Password.
Also, note the following information in this menu:
This information is very important for running the psql and pg_dump commands (for importing and exporting PostgreSQL databases) and for using the correct Django version that supports the current PythonAnywhere PostgreSQL server version.
Step 1: First place the SQL file in your Pythonanywhere user directory (export your SQL file in plain text format).
Step 2: Then use the following command to upload the SQL file to your Pythonanywhere PostgreSQL database
psql -U your_username -h username-111.postgres.pythonanywhere-services.com -p port_no -d your_database -f /home/yourusername/your_file.sql
Open the bash console and type the following command.
pg_dump -h <hostname> -U <username> -d <database_name> -p <port_no> -f <output_file.sql>
Replace the placeholders with your actual values:
Download the Backup File:
Note: If you want to create a compressed backup, you can use: (use with port no)
pg_dump -h username-111.postgres.pythonanywhere-services.com -U your_username -d your_database -p 14111 -Fc -f mydatabase_backup.dump
The -Fc option creates a custom-format dump, which can be restored with pg_restore.
psql is the interactive terminal for PostgreSQL. It allows you to execute SQL commands directly against the database.
Common uses:
Basic usage:
psql -h hostname -U username -d database_name
pg_dump is a utility for backing up a PostgreSQL database. It creates a logical backup, meaning it dumps the SQL commands necessary to recreate the database.
Common uses:
Basic usage:
pg_dump -h hostname -U username -d database_name -f output_file.sql
pg_restore is designed to restore a PostgreSQL database from a backup file. This file can be in various formats, including the custom format, directory format, or tar format created by pg_dump.
Common uses:
Basic usage:
pg_restore [OPTIONS]... [DUMPFILE]
Common Options
© 2024 Webapptiv. All rights reserved.