I connected to Heroku postgresql DB (Hobby env):
heroku pg:psql --app
The prompt shows :
appname::DATABASE=>
Error :
appname::DATABASE=> CREATE DATABASE hello ENCODING 'UTF-8';
ERROR: permission denied to create database
Any help regarding this will be appreciated.
Creating a database is disallowed because it's unnecessary. When you provision a Heroku Postgres add-on, the database and user are created on your behalf. You can see the information by running heroku config and checking the database configuration string.
Related
I launched my Rails application on Heroku.
And I want to connect it to the database of an existing project of my friend, which is also deployed on Heroku. A friend gave me credentials and url to the database. However, I do not understand how to connect my project to my friend's database. I tried to change DABASE _URL but all is useless. Also, credential data was placed in database.yml and when I run the heroku run db:setup in the heroku terminal i get
FATAL: permission denied for database "postgres"
DETAIL: User does not have CONNECT privilege.
Couldn't create '*************' database. Please check your configuration.
rake aborted!
PG::ConnectionBad: FATAL: permission denied for database "postgres"
DETAIL: User does not have CONNECT privilege
Use following steps:
1) Add DATABASE_URL (complete url username, password, host) under settings / Config Vars.
2) For Rails apps you should look to use db:schema:load, db:structure:load or db:migrate instead of db:setup.
here is more info about issue https://help.heroku.com/63D7ALXT/why-am-i-seeing-user-does-not-have-connect-privilege-error-with-heroku-postgres-on-review-apps
You can share a single Heroku Postgres database between multiple apps with the heroku addons:attach command
heroku addons:attach my-originating-app::DATABASE --app new_app
for more info check here https://devcenter.heroku.com/articles/heroku-postgresql#sharing-heroku-postgres-between-applications
hope this helps
The reason you cannot update DATABASE_URL is because it's currently pointing at another database without any auxiliary attachments. This is a safety mechanism to prevent users from accidentally shooting themselves in the foot. This should allow for your changes.
heroku addons:attach <addon name, eg postgresql-cloudy-12345> --as ORIGINAL_DB --app <app name>
This will create an additional attachment name so you don't lose reference to the original database
heroku addons:detach DATABASE_URL --app <app name>
This will remove the Heroku-managed DATABASE_URL config var.
heroku config:set DATABASE_URL=<the connection string for the other database> --app <app name>
This sets DATABASE_URL to point at the other database which should put things into an operable state.*
* This caveat here is that this is a brittle configuration because hostnames can change for databases. If the db undergoes maintenance you will need to manually change the config var (ie repeat step 3).
I solved this situation by going to heroku.com to my app then setting then Config Vars
The DATABASE_URL was different than the ORIGINAL_DB_URL so I changed the DATABASE_URL to be similar to ORIGINAL_DB_URL
In my case: postgres://quxhxkemlsfzzv:964c7..........
I've provisioned and switched to a new database in my heroku app. And it seemed to work fine, but now I attempted to run the console and it had the data from my old database. I ran heroku addons:destroy <DATABASE_URL> --remote live and now the hobby-dev db has been destroyed and now when I try to run a query from the console I get PG::ConnectionBad: FATAL: role "fgedboaquoao" is not permitted to log in
Anybody know how I can stop my app from referencing the old database?
I had it hard coded in my production.rb to share the databases. that was the problem
I am pretty new to heroku & postgresql. I am trying to dump my production database into my local development database in my local machine.
I dumped like this (my actual info redacted):
pg_dump --host=<myhost> --port=<port> --username=<username> --password --dbname=app_production > output.sql
Then I imported to my local app_development database like this:
psql -d app_development -f output.sql
but now, when I start my server I get this:
PG::InsufficientPrivilege: ERROR: permission denied for relation schema_migrations : SELECT "schema_migrations".* FROM "schema_migrations"
I also use Navicat to see the local database, and now I can't open any of my tables. Each time I try I get
ERROR: permission denied for relation <nameofwhatevertable>
How can I reset permissions for my app_development database when I've dumped my app_production database.
It seems like your db permissions have been mangled. Do you have PgAdmin III installed? http://www.pgadmin.org/download/
PgAdmin III will let you reset all db and user parameters. It will also allow you to see what is going on in your database(s) and tables so you can debug them.
It's a PostGreSQL development tool that is very much like MySQL Workbench. Free download from PostGreSQL. Runs on multiple platforms. Easy to set up.
It is most handy in cases like this, when you're trying to track down an intractable error. Highly recommended tool. Takes the guessing out of pg work.
I have an app on Heroku and I'm trying to replace the database on Heroku with the database on my local machine.
I was under the impression that
heroku pg:reset DATABASE
would clear the remote database and allow me to push. However, after running pg:reset, I run
heroku pg:push
and I stil get this error:
Usage: heroku pg:push <LOCAL_SOURCE_DATABASE> <REMOTE_TARGET_DATABASE>
push from LOCAL_SOURCE_DATABASE to REMOTE_TARGET_DATABASE
REMOTE_TARGET_DATABASE must be empty.
Couple of questions:
1. do I have to specify local db and remote db? [I am in the root directory of my application on my local machine]
2. if so, how do I find what my local database name is? I know that heroku can divine the remote database via DATABASE_URL?
You have to specify BOTH the local database(where the data is coming from) and the remote database(where the data is going). The part about REMOTE_TARGET_DATABASE must be empty. is just a reminder to make sure you clear the Heroku database before you push.
You should be able to find your database from your database.yml file.
You can also find the heroku database by heroku pg:info
Reminder: Heroku runs PostgreSQL so you should be using PostgreSQL locally as well.
I've been given access to Heroku application with rather strange setup. It has one database but when I run heroku config, I get different DATABASE_URL and HEROKU_POSTGRESQL_BRONZE_URL.
When I run heroku pg:info I get the following result:
=== HEROKU_POSTGRESQL_BRONZE_URL
Plan: Dev
Status: available
Connections: 1
PG Version: 9.2.4
Created: 2013-09-05 11:02 UTC
Data Size: 6.5 MB
Tables: 0
Rows: 0/10000 (In compliance)
Fork/Follow: Unsupported
I realised that my database is at DATABASE_URL, but I can't access that database, only through heroku run console. All heroku pg commands fail with this message:
! Unknown database: DATABASE_URL. Valid options are: HEROKU_POSTGRESQL_BRONZE_URL
If I run heroku pg HEROKU_POSTGRESQL_BRONZE_URL, I get access to empty database from above.
Since I have some issues with running migrations, I think my database might be full, and I'd like to check it. Any ideas how I can do that?
Here's the error after I run heroku run rake db:migrate:
PG::Error: ERROR: permission denied for relation schema_migrations
: INSERT INTO "schema_migrations" ("version") VALUES ('20130918114202')
More information about the setup:
rails 3.2.12
RAILS_ENV: staging (I don't have access to production, but I know this is "dev" server and there's also real "staging" from which this app was forked).
I have same problem and i fixed it:
Just Keep a Backup from your database and restore it back again, here is the steps:
heroku pg:info <-- to get the Database Name
heroku addons:add pgbackups <-- make sure you have the addons for backup
heroku pgbackups:capture <-- Capture the backup
heroku pgbackups <-- check your backups and make sure its there
heroku pg:reset DATABASE_NAME <-- Reset your database don't worry we have a backup, replace DATABASE_NAME with database name
heroku pgbackups:restore DATABASE_NAME b001 <-- Restore the backup again, replace DATABASE_NAME with database name and b001 with your Database version you can see this version number in heroku pgbackups step
heroku run rake db:migrate <-- Now you can run your migration and Operate in normal mode.
This seems like something screwy on the Heroku side. Have you tried submitting a ticket with them? I've always had good luck with their support.
I just got an update from my client. Before, I couldn't drop the database, because of the data in it. At the end, we decided to drop the database since the data can be added back (it's dev server, doesn't matter if we loose some dummy data).
I didn't find a solution for the problem above, but promoting HEROKU_POSTGRESQL_BRONZE_URL and restoring from backup solved the issue about not being able to access the database.