`pg:pull` is not a heroku command, but `db:pull` is - postgresql

I've been trying to pull a database from Heroku. For some reason when I try
heroku pg:pull HEROKU_POSTGRESQL_RAINBOW_URL newlocaldb --app myapp
it returns
! pg:pull is not a heroku command. ! Perhaps you meant
db:pull, pg:kill or pg:psql. ! See heroku help for a list
of available commands.
On the other hand, the command
heroku db:pull HEROKU_POSTGRESQL_RAINBOW_URL newlocaldb --app myapp
is recognized, despite that db:pull was replaced by pg:pull according to e.g. this.
When I try heroku help, it shows an entry for db:pull but not for pg:pull.
So, it would be nice to use the command pg:pull. But it doesn't work for me just now. (I believe it did fairly recently.) What could be the problem?

Related

Heroku Database Workflow and safety net

I'm currently deploying a rails app to heroku via codeship from the master branch. My app development is getting to a point where I want other users to be using the database and storing data.
I'm trying to determine what is the best way to manage the database when reset is no longer an option? Because the database will be full of user data.
I've done some research but I was hoping for a second opinion on these options. Is this a solid approach or is there an easier way to do this?
For General Fixes and local testing
To pull the database to my local machine:
heroku pg:pull HEROKU_POSTGRESQL_MAGENTA mylocaldb --app sushi
PUSH local to internet:
heroku pg:push mylocaldb HEROKU_POSTGRESQL_MAGENTA --app sushi
SAVE BACKUP I would use:
heroku pg:backups:capture --app sushi
SCHEDULE BACKUP I would use:
heroku pg:backups:schedule DATABASE_URL --at '02:00 America/Los_Angeles' --app sushi
In the worst case scenario I could RESTORE a backup with:
heroku pg:backups:restore b101 DATABASE_URL --app sushi
UPDATE
The pull code above didn't work so I found this. I had to pull specifically development to get it to run locally in my dev environment. It works but is it the correct way to go about it?
heroku pg:pull DATABASE_URL dbname_development --app appname

pg:pull, pg:backups no longer available in heroku cli

Just strange, I am doing back database maintenance, I tried to to a heroku pg:pull <DB_URL> local_db --app <appname> and it says:
pg:pull is not a heroku command.
I tried to create a backup with heroku pg:backups:capture <DB_URL> and i get this:
pg:backups:capture is not a heroku command.
Just trying heroku pg:backups shows:
pg:backups is not a heroku command.
Its strange because even in the --help section, looks like all the useful commands are gone:
heroku pg --help
Usage: heroku pg [DATABASE]
-a, --app APP # app to run command against
-r, --remote REMOTE # git remote of app to run command against
Commands for pg, type "heroku help pg:COMMAND" for more details:
heroku pg [DATABASE] #
heroku pg:info [DATABASE] #
heroku pg:wait [DATABASE] #
I looked around online and didn't see anything about these pg command deprications. I checked my heroku CLI version: heroku-cli/5.3.0-5329fb8 (darwin-amd64) go1.6.2
Strange becuase I've been using these commands on this same computer many times recently and suddenly they're gone.
Have these pg been depricated (I doubt)? If not does anyone know what I am doing wrong? If so, anyone know how to do push/pull/capture in the new framework?
The answer was that my CLI version was out-of-date. I followed these instructions on my Mac:
rm -rf /usr/local/heroku
rm -rf ~/.local/share/heroku ~/.config/heroku ~/.cache/heroku
And then re-installed using homebrew:
brew update
brew install heroku
Apparently the new version of the CLI is supposed to keep itself up-to-date.

Push local postgresql database to heroku: The local psql command could not be located

I'm trying to push a local postgresql database to my heroku project. Unfortunately, it doesn't work.
Postgresql works perfectly on my computer and the psql command works as well (Path is set correctly to the bin folder)!
But when I try to push my databse with
heroku pg:push mylocaldb HEROKU_POSTGRESQL_MAGENTA --app sushi
(with my db name as mylocaldb and my real app name), it doesn't work at all.
Problem: The local psql command could not be located
Why? As said before, psql works fine. Even a reinstall of postgresql doesn't help.
The pull statement (see: doesn't work either because postgres always wants to authenticate as my windows user (I don't know how to change the user name when using the heroku pg:pull command, this didn't help: https://devcenter.heroku.com/articles/heroku-postgresql#pg-push-and-pg-pull)
Thanks for your help!
Have you tried calling the psql command with its full path?
For example: /opt/PostgreSQL/9.1/bin/psql
Or if that doesn't help, you can try this

Heroku postgresql db sharing between 2 apps error

I can't manage to share two PostgreSQL heroku dbases between two heroku apps.
Doesn't work
What I've tried so far (I'm using the Heroku CLI):
$ heroku config:set DATABASE_URL=`heroku config:get DATABASE_URL -a my-heroku-app-original`
Setting config vars and restarting my-heroku-app... done, v20
DATABASE_URL: postgres://...correct url...
$ heroku config
=== msite-poniai Config Vars
DATABASE_URL: postgres://...correct url...
When I try to access psql, depending on whether I've added a new db or not, I get these two answer (I both cases heroku doesn't see the DATABASE_URL I've just provided.
$ heroku pg:psql
! Your app has no databases.
$ heroku pg:psql
! Unknown database. Valid options are: HEROKU_POSTGRESQL_NEWLYADDED_URL
Works
If I provide psql with the exact location of the db (in this case the original app that has the db as an add-on) it does manage to connect.
$ heroku pg:psql HEROKU_POSTGRESQL_ORIGINAL_URL --app my-heroku-app-original
psql (9.1.9)
I've read
I've closely followed advice given in Share database between 2 apps in Heroku and heroku-postgresql#create-new-db.
Simply copying a config var from one app to another does not attach the referenced database to the app. Were the host or password to change on the first, your second app would be broken. There is a highly alpha plugin you can try https://github.com/heroku/heroku-attachable-resources but it does some weird things like no longer give default names to databases, and overwrites DATABASE_URL if you don't pass in --config and sometimes doesn't let you remove databases.

Heroku postgresql database name

This is the command I have to find the name of a heroku database:
$ heroku config | grep POSTGRESQL
I get a result similar to:
HEROKU_POSTGRESQL_NAVY_URL: postgres://wxjwilh:tKDSwUlfZ8Da#fr6-84-24-28-19.compute-1.amazonaws.com:52/d14grmkt
which part of this output is the database name I can use with the command:
$ heroku pg:reset <DATABASE>
I tried using the whole url but got an invalid argument error.
hope everyone confuses with placeholder and constant.
Assume having a db with name d6u5qhrlnbdfmp. then it is NOT necessary to type
heroku pg:reset d6u5qhrlnbdfmp
Instead we can plainly type
heroku pg:reset DATABASE_URL
the sample output
E:\git\stutzen>heroku pg:reset d6u5qhrlnbdfmp --app stutzen
! Unknown database: d6u5qhrlnbdfmp. Valid options are: DATABASE_URL, HEROKU_
POSTGRESQL_CYAN_URL
E:\git\stutzen>heroku pg:reset DATABASE_URL --app stutzen
! WARNING: Destructive Action
! This command will affect the app: stutzen
! To proceed, type "stutzen" or re-run this command with --confirm stutzen
> stutzen
Resetting HEROKU_POSTGRESQL_CYAN_URL (DATABASE_URL)... done
URL consists of the following parts:
scheme://username:password#host:port/database
So, in your case DB name is d14grmkt.
I had a hard time to reset my database on Heroku. I post this, because I think it's the most straightforward solution. To find out the database name cd to your application folder and type:
heroku pg:info
Output will be something like
=== HEROKU_POSTGRESQL_BRONZE_URL
#other stuff
To reset the database type:
heroku pg:reset HEROKU_POSTGRESQL_BRONZE_URL
you have to confirm with your application name.
While using the command:
$ heroku pg:reset DATABASE
It will tell you the available database name like this:
! Unknown database: DATABASE_URL. Valid options are: HEROKU_POSTGRESQL_COPPER_URL, SHARED_DATABASE
so try the options it gave like this
$ heroku pg:reset HEROKU_POSTGRESQL_COPPER_URL
Late to the party, but if you need the db name, for example to add it as an addon to another instance, you run
heroku addons
In the list you will see your postgres addon, in the 'Add-on' column is the name of the db app that is attached
NOT MENTIONED IN THE HEROKU WEBSITE DOCUMENTATION:
heroku addons:create heroku-postgresql:hobby-dev --version=12 --app "APPNAME" --name "APPNAME-database"
--app : Specify the heroku app you want to add the database too. Really good if you have more than one heroku app.
--name : The name you would like to give your database. I like to take my application name and postfix it with "database" as a nice convention. Better than whatever randomly generated name you'll get.
APPNAME: A placeholder for whatever your application name is.