I have deployed my SpringBoot app to Heroku. Now I would like to copy my local PostgreSQL to Heroku.
I have found some information on devcenter.heroku.com.
However I don't understand enough about the using of file db.changelog-master.yaml.
Could anyone give me details about the simplest solutions to copy the database?
Create a valid dump of your local postgres database and host it somewhere publicly available. Now you will be able to restore this entire dataset (schema and records) with pg:backups:restore as shown here. The sole caveat here is that the target database must be completely empty for this to work. You can empty a Heroku postgres database with heroku pg:reset.
If you cannot take the approach listed above then you can run pg_restore directly from your local instance, provided your local version of Postgres is >= the target version of Postgres. This also applies to creating the dumpfile and is a requirement because pg utilities are not guaranteed to be forward compatible. Documentation for pg_restore is here.
Related
I’m taking John Elder’s Udemy course titled: “How To Push Django Python Apps To Heroku for Web Hosting”. I've pushed to Heroku successfully already. Now I am experimenting with other aspects of deploying my Django project, specifically managing PostgreSQL.
When I initially set everything up 2 weeks ago, it appears I created three PostgreSQL database instances. See here for a screenshot on imgur.
My question: In that screenshot of my Heroku dashboard, what are the second and third configuration entries for?
I’ve already got some non-critical data in production on my live demo site. I’d like to delete the two of the three duplicate PostreSQL instances that I am not using but I’m curious and would first like to establish which one is the active one and which two are not.
What is a potential use case for even having multiple duplicate databases? Rolling back a database to a given state (like by using PostreSQL’s Continuous Archiving and Point-in-Time Recovery (PITR) feature) and importing/exporting instances are ways of backing up and restoring data which have been corrupted. But how are those features different or similar from configuring more than one db URL in the Heroku dashboard, as depicted in my imgur screenshot above?
I’ve Googled around using search terms such as ‘config vars heroku django postgresql colors’ (and variations) which loop me around to Heroku’s Configuration and Config Vars doc without addressing multiple PostgreSQL instances, like in my situation. Turning to Heroku’s Databases & Data Management doc explains how to handle PostgreSQL but doesn’t refer to configuration variables.
I have this small project that specifies sqlite as the database choice.
For this particular project, the framework is Django, and the server is hosted by Heroku. In order for the database to work, it must be set up with migration commands and credentials whenever the project is deployed to continuous integration tools or development site.
The question is, that many of these environments do not actually use the my_project.sqlite3 file that comes with the source repository, which we version control with git. How do I incorporate changes to the deployed database? Is a script that set up the database suitable for this scenario? Meanwhile, it is worth notice that there are security credentials that should not appear in a script in unencrypted ways, which makes the situation tricky.
that many of these environments do not actually use the my_project.sqlite3 file that comes with the source repository
If your deployment platform does not support your chosen database, then your development environment should probably be moved to using one of the databases they do support. It is possible to run different databases in development and production, but just seems like the source of headaches.
I have found a number of articles that state that Heroku just doesn't support SQLite in production and instead recommends Postgres.
How do I incorporate changes to the deployed database? Is a script that set up the database suitable for this scenario?
I assume that you are just extracting data from one database to give to another, so yes,as long as that script is a one time batch operation each time the code is updated, then it should be fine. You will want something else if you are adding/manipulating data in production and then exporting it to your git.
Meanwhile, it is worth notice that there are security credentials that should not appear in a script in unencrypted ways
An environment variable should solve that. You set your host machine to have environment variables with your credentials and then just retrieve them within the script. You are looking to have something like this:
# Set environment vars
os.environ['USER'] = 'username'
os.environ['PASSWORD'] = 'password'
# Get environment vars
USER = os.getenv('USER')
PASSWORD = os.environ.get('PASSWORD')
My Django application (a PoC, not a final product) with a backend library uses a SQLite database - read only. The SQLite database is part of the repo and deployed to Heroku. This is working fine.
I have the requirement to allow updates to this database via the Django admin interface. This is not a Django managed database, so from Django's point of view just a binary file.
I could allow for a FileField to handle this, overwriting the database; I guess this would work in a self-managed server, but I am on Heroku and have the constraints imposed by Disk Backed Storage. My SQLite is not my webapp database, but limitations apply the same: I can not write to the webapp's filesystem and get any guarantee the new data will be visible by the running webapp.
I can think of alternatives, all with drawbacks:
Put the SQLite database in another server (a "media" server), and access it remotely: this will severely impact performance. Besides, accessing SQLite databases over the network does not seem easy.
Create a deploy script for the customer to upload the database via the usual deploy mechanisms. Since the customer is not technically fit, and I can not provide direct support, this is unfeasible.
Move out of Heroku to a self-managed server, so I can implement this quick-and-dirty upload without complications.
Do you have another suggestion?
PythonAnywhere.com
deploy your app and you can easily access all of your files and update them and your Sqlite3 database is going to be updated in real time without losing data.
herokuapp.com erase your Sqlite3 database every 24 hours that's why it's not preferred for Sqlite3 having web apps
I'm trying to develop a Django website with Heroku. Having no previous experience with databases (except the sqlite3 one from the tutorial), it seems to me a good idea to have the following file structure:
Projects
'-MySite
|-MySite
'-MyDB
I'm finding it hard to figure out how to do it, with psql commands preferring to put the databases in some obscure directory instead. Perhaps it's not such a good idea?
Eventually I want to be able to test and develop my site (it'll be just a blog for a while, I'm still learning) locally (ie. add a post, play with the CSS) and sync with the Heroku repository, but I also want to be able to add posts via the website itself occasionally.
The underlying data files (MyDb) has nothing to do with your project files and should not be under your project.
EDIT
added two ways to sync your local database with the database ON the Heroku server
1) export-import
This is the most simple way, do the following steps every now and then:
make an export on the Heroku server by using the pg_dump utility
download the dump file
import the dump into your local database by using the psql utility
2) replication
A more sophisticated way for keeping your local db in sync all the time is Replication. It is used in professional environments and it is probably an overkill for you at the moment. You can read more about it here: http://www.postgresql.org/docs/9.1/static/high-availability.html
I am trying to host my php application over heroku cloud services. This is my first ever try with any GIT client; following the procedure as defined in heroku documentation, I am done with pushing my files to the repo.
But now one place where I am totally lost is where is the heoku database, how can I configure it?
I went through myapp>resources where it tells the 5mb of database can be used for free, the only clickable link there is the 5mb label but even that is not taking me anywhere.
But where is the control panel of that database, where I can edit and use sql to configure my database? Finds its name, username etc. (may be an interface like phpmyadmin)?
Kindly guide me through this.
Thank you.
There is no "control panel" for the Heroku database. As for "where is it", there is a SHARED_DATABASE_URL environment variable of the form:
$ heroku config | grep DATABASE
SHARED_DATABASE_URL => postgres://username:password#host:port/database_name
In your PHP code, you can get this like so:
$database_url = getenv('SHARED_DATABASE_URL');
You may need to do some parsing of that URL to get it into a format that your PHP database API needs (it's been a while since I wrote any PHP).
As for "how do I configure my database", either from the command line, e.g.
$ heroku run php
or, assuming your code has some ORM-y features, invoking that to set up the database schema, or using heroku's db:push command, e.g.:
$ heroku db:push [URL_TO_MY_LOCAL_SOURCE_DATABASE]
I was looking for something like phpmyadmin for heroku databases, and I found the Adminium add-on, which works in a similar way.
Much easier than console.
Heroku will automatically setup your access to the database.
You may use taps to push and pull data betweeen your development machine and heroku. See http://devcenter.heroku.com/articles/taps
Alternateively, you may use pgbackup - http://devcenter.heroku.com/articles/pgbackups
Heroku recommends pgbackup as the most complete way of handling your database data (as described on the taps page).
Usually when you push something to Heroku it is the production side of the application, so it has a separate database that uses the same schema that you have designed once it has been migrated over.
So all your data will need re-entering through the Heroku App which can be found at:
'app name'.herokuapp.com