Migrate PostgreSQL database back to local machine - ruby-on-rails

I've recently re-installed Mac OS X on my Macbook, and am just getting my development environment and projects back up and running again. For one of my Ruby on Rails apps (which is running on Heroku) I need to grab the (PostgreSQL) database from Heroku and migrate it back to my development environment. How would I go about doing this?

I fixed this by first creating my database (psql in Terminal) and then using the CREATE DATABASE db_name command. Then I used heroku pg:backups capture to capture a backup/shot of the database. I downloaded this using heroku pg:backups public-url b001 and then pg_restore --dbname=db_name --verbose /path/to/download.
Hope that hopes anyone!

Related

Steps for postgres update from 10 to 11 on heroku

PostgreSQL 10.22 reaches End of Life on 2022-Nov-10. Due to security and operational concerns, Heroku cannot run unsupported software as a service. Therefore, the following database will need to be updated before 2022-Nov-10
So, this is not really an issue but I wanted to have a clearer picture.
My current heroku postgres version is 10 which will deprecate and i would like to move to 11. The rails version is 5.2 and ruby is 2.6.7
I was suggested to use the pg_upgrade tool because my checksums are enabled as per the heroku documentation. It says to provision a follower, turn maintenance mode on and then hit pg upgrade. I am not sure how it will automatically select the next version or where to specify it?
The second option is from from this Stackoverflow verified article
This works locally for me, but am not sure if I can use this on live server. I want to make sure there is no loss of data.
Can some please provide me the steps or the right article to get my postgres upgraded from 10 to 11 on Heroku.
Turns out I was trying to add the version while creating an add on, where this should be done while using the pg_upgrade tool.
Shared below are the steps i had to follow:
heroku addons:create heroku-postgresql:standard-0 --follow HEROKU_POSTGRESQL_PUCE_URL --app -app_name-production
heroku maintenance:on --app app_name-production
heroku pg:upgrade HEROKU_POSTGRESQL_CYAN --version 11 --app app_name-production
heroku pg:wait --app app_name-production
heroku pg:promote HEROKU_POSTGRESQL_CYAN --app app_name-production
heroku maintenance:off --app app_name-production

how can I access my postgresql database on heroku and offline?

I am learning ruby on rails and heroku.
I have some questions.
Could somebody help me?
After running heroku create, the terminal is somehow connected to the repository/project in heroku. After that the developer can see logs, access database, ect. But, how can I access via terminal my completed project,which is online already, in heroku without creating the same apps and upload it again to heroku?
How can access my pg database in heroku or offline?
I saw this and try to run heroku pg:psql. it gives me hidden-atoll-4790::DATABASE=> help I try \? to see pg command but I cannot use it.
I saw this link to see pg db offline. But why cannot I access /var/lib/postgresql/9.3/main directory ? it is said that I don't have permission eventhough my account is administrator account.
1.Run heroku run rails console
Run
$ heroku apps # to see all apps created by your account
$ heroku open # to open you current project in browser (run it form root of your project)
$ heroku pg:psql DATABASE_URL # to gain access to heroku postgresql terminal, here you can run SQL queries
Refer to
CLI and Heroku PG for more info

Push an SQLite database to Heroku with taps?

So I am trying to push a SQLite3 database to Heroku which I thought used to be possible, but reading here and here imply that it may not be (the below doesn't work).
heroku pg:push sqlite://db/development.sqlite3 HEROKU_POSTGRESQL_OLIVE_URL
! LOCAL_SOURCE_DATABASE is not a valid database name
Was this changed when Heroku switched the syntax to pg:push from db:push or was it never possible?
Given that it's not possible is the solution to migrate any data from SQLite3 to local postgres and then push to Heroku?
Heroku uses a read-only filesystem, which means that local file system based databases like SQLite3 aren't compatible with their infrastructure. And to my knowledge it has never been possible to push from a SQLite3 db directly to Postgres on Heroku.
You should migrate your data to a local Postgres database and push from there.
For what it's worth, it was possible to db:push from a local sqlite3 database to Heroku postgres, but there was a timestamp bug in any version of Ruby after 1.9.3.
Switching to postgres on local will end up being easier than messing with RVM and Gemfiles whenever you want to send data up to the server.

Heroku: Dump Postgres database into local SQLite3 database for Rails project

Is there way to dump heroku postgres database and import the data into my local SQLite database?
I tried using https://github.com/ludicast/yaml_db and heroku db:pull with no success. I am developing on Windows 7.
Please read through
https://devcenter.heroku.com/articles/heroku-postgres-import-export
and follow those to export.
Though the above link can be used to export alone, it does not have solution for the entire process. So you can look on the similar question and its solution
Copy a heroku postgres db to a local sqlite db

migrate mongodb database to heroku

I have now my rails 3.2.1 app running on Heroku.
I've tried to upload the database to mongohq via the heroku mongo:push command, after installing the heroku mongo plugin.
https://github.com/pedro/heroku-mongo-sync
I get the message asking me to confirm if I want to push, but once the push is done, there is nothing my db.
I'm not sure if it is a problem with heroku or if i'm missing a step.
Could it be that i need to put my app in production mode and migrate the database to production?
I'm not sure how to do that either.
Cheers
does your local heroku connection conform to the plugins assumptions [in the readme's config section]? if not you'll have to set it via:
export MONGO_URL = mongodb://user:pass#localhost:1234/db
i'll also note, that even after doing this i had to uninstall the heroku plugin and reinstall it from this fork: http://github.com/fjg/heroku-mongo-sync.git
heroku plugins:install http://github.com/fjg/heroku-mongo-sync.git
Check out the MongoSync Ruby Gem
It's a gem I wrote for that very purpose when I had to constantly copy my Local MongoDB database to and from my Production DB for a Project (I know it's stupid). It's extremely easy to use. Once you've entered your DB details in the mongo_sync.yml file, you can push and pull DBs using these rake tasks:
$ rake mongo_sync:push # Push DB to Remote
$ rake mongo_sync:pull # Pull DB to Local
Note: It's also available as shell script for non-ruby apps: mongo-sync

Resources