Automticaly setup add-on Heroku-Postgresql with one command - postgresql

I want use PostgreSQL 9 in my app and to host on Heroku. By default heroku use Postgres 8.3.
To use Postgres 9, I need to install add-on heroku-postgres(https://addons.heroku.com/heroku-postgresql). In the documentation I found several steps to use Postgresql 9. It is simple, but I need to automatize and simplify all deploy steps.
Questions, I need at least one answer from these questions:
Is it possible by default use Postgresql 9 in Heroku without any add-on?
Is it possible to setup custom database urls names when I add the add-on like heroku addons:add heroku-postgresql:dev CUSTOME_HEROKU_DATABASE_URL_NAME?
Is it possible to use last database url in promote, e.g. heroku pg:promote HEROKU_POSTGRESQL_LAST?
Is it possible to promote database on adding add-on e.g.:heroku addons:add heroku-postgresql:dev --promote?
I don't want to use tools like grep or sed. This solution I built already.

PostgreSQL 9 is the default on Heroku now.
When you create a new Heroku database, it will always auto-generate a name for you (a color), you cannot change this.
There is no way to promote a new database to default without using grep / sed / customizations.

Is it possible by default use Postgresql 9 in Heroku without any add-on?
The dev plan will be the default on heroku. If you want it to be the default for you now, you can by adding this feature flag:
heroku labs:enable default-heroku-postgresql-dev
Is it possible to setup custom database urls names when I add the add-on like heroku addons:add heroku-postgresql:dev CUSTOME_HEROKU_DATABASE_URL_NAME?
No, not yet.
Is it possible to use last database url in promote, e.g. heroku pg:promote HEROKU_POSTGRESQL_LAST?
No, but if you have that flag set up, when you push code for the first time it will provision a dev database for you and it will have been promoted.
Is it possible to promote database on adding add-on e.g.:heroku addons:add heroku-postgresql:dev --promote?
No, but interesting idea.

Related

Run local database with Heroku

What I need to know if I use service to create PostgreSQL in Heroku, can I set up this database locally in development mode?
I couldn't find in their documentation on how to do this.

pgbackups on Heroku not found

I have been using pgbackups to capture databases and load them locally but since yesterday, I am getting this message when provisioning the add on for new apps.
! Add-on plan not found.
Has pgbackups been disabled for new instances? It still works on apps it was previously integrated with. If it has been deprecated, what is the recommended replacement?
Heroku have recently made changes. "PG Backups as an add-on has been deprecated." For new commands, see here:
https://devcenter.heroku.com/articles/mapping-pgbackups-commands
Old command:
heroku pgbackups:capture --app sushi
New Command
heroku pg:backups capture --app sushi
So I missed this little disclaimer here: https://devcenter.heroku.com/articles/pgbackups
PG Backups as an add-on has been deprecated. The commands exist as part of the Heroku Postgres namespace in the CLI. The new functionality is live and available for use. We also have a mapping guide to show you how the old commands transfer to the new ones.
To add to response from jcuenod above the same would apply for heroku pg:backups:restore. The new command will be heroku pg:backups restore. Heroku documentation is inconsistent and should be updated.

Whitelist allowed hosts for Heroku postgres?

I have a heroku app running with the postgres addon. I was wondering if it's possible to whitelist the allowed hosts. Normally this is done by editing the pg_hba.conf file, but that's not possible on heroku.
It's not possible - Heroku don't provide access to that. They use highly complex and randomly generated username/passwords as you can see in your heroku config output but permit access from any host.

Postgres databases linked to separate Heroku environments

Using this article: Heroku dev environments
I successfully made two separate Heroku apps, one test, and one prod. This each have their own remotes on my local development box. But now I don't know how to separate the postgres tables of my now distinct development and prod applications.
This is the command I use to create a postgres table with my Heroku app:
heroku addons:add heroku-postgresql
But then I lost access to my original postgres DB. I would like this setup so I don't inadvertently hose my prod DB from my development branch.
TL;DR: How do i keep distinct postgres databases with a single Heroku application that has multiple environments?
EDIT #1: I found that I can call:
heroku addons:add heroku-postgresql:dev
multiple times to create several dev databases. What is the best practice for pointing my dev vs. prod apps to each database without having to hard code my database links like this:
//this function connects to the Heroku postgres db
function pg_connection_string(){
return "dbname=dcs1k5588jbfad host=ec2-54-243-224-162.compute-1.amazonaws.com port=5432 user=###user_name### password=######### sslmode=require";
}
Is there a Heroku-fung-shui of swapping database pointers?
You can set the environment variable or heroku config variable DATABASE_URL to anything you wish. This is what Heroku applications expect to be the default database for that application.
If you're using a production Database you can Fork from your production app to a test app to get a copy of the data as well: https://devcenter.heroku.com/articles/heroku-postgres-fork

How do I connect to my heroku shared database for postgresql?

I have pulled the SHARED_DATABASE_URL from heroku config
SHARED_DATABASE_URL => postgres://username:xxxx#host.com/db_name
I am using pgAdmin to try to connect to it but it keeps on timing out. Do I need to specify a port? What am i missing?
You can use this command to connect to psql.
heroku pg:psql
If you are happy to change to postgres 9.1 you can use the newly launched development database, which permits connections via normal postgres tools. Read more at https://postgres.heroku.com/blog/past/2012/4/26/heroku_postgres_development_plan/
You cannot access the shared database using psql, pgadmin, etc.
Heroku offers you the choice of running on a shared or dedicated database package. The shared plan is suitable for development and staging applications. It runs Postgres 8.3. The dedicated plans are suitable for production scale applications. In addition, the dedicated databases offer a number of advantages, including direct access (via psql or any native postgres library), stored procedures, and Postgres 9 support.[source]