Remote database not empty - database

I'm trying to push my local database to Heroku using the following command:
heroku pg:push <local db name> DATABASE --app <heroku appname>
and I get:
env: psql: No such file or directory ! Remote database is not
empty. ! Please create a new database, or use heroku pg:reset
So I run heroku pg:reset which resets it but I then get the following when trying to push again therefore going around in circles:
env: psql: No such file or directory ! Remote database is not
empty. ! Please create a new database, or use heroku pg:reset
Any ideas on how to solve this?

Related

'[ERROR] Connection failed: could not find driver' when using OctoberCMS with Laradoc & MSSQL

I am trying to use OctoberCMS with Laradoc and MSSQL as the database
I have
Cloned laradoc into my project
Set up the laradoc .env to use php v8.1
Run docker-compose up -d nginx mssql
Entered the container and run php artisan october:install
Followed the steps
When it gets to the point of creating the database, I get [ERROR] Connection failed: could not find driver
I am not sure how to proceed
These are the settings in my octoberCMS .env file:
DB_CONNECTION=sqlsrv
DB_HOST=mssql
DB_PORT=3306
DB_DATABASE=mssql
DB_USERNAME=root
DB_PASSWORD=

Cannot boot Chainlink: opening db: failed to open db:

When I "chainlink node start",
I get the error:
"Cannot boot Chainlink: opening db: failed to open db: failed to connect to host=/private/tmp user=myname database=: server error (FATAL: unrecognized configuration parameter "?application_name" (SQLSTATE 42704))"
I follow this youtube video: https://youtu.be/ZB3GLtQvgME?t=2017
I have a .env
but it is not reading from there.
No matter what I change on DATABASE_URL,
I get the same error.
ETH_URL=wss://kovan.infura.io/ws/v3/
FEATURE_EXTERNAL_INITIATORS=true
LOG_LEVEL=debug
ETH_CHAIN_ID=42
MIN_OUTGOING_CONFIRMATIONS=2
LINK_CONTRACT_ADDRESS=
CHAINLINK_TLS_PORT=0
SECURE_COOKIES=false
ALLOW_ORIGINS=*
DATABASE_URL=postgresql://localhost:5432/kovan_demo?sslmode=disable
DATABASE_TIMEOUT=0
FEATURE_FLUX_MONITOR=true
MINIMUM_CONTRACT_PAYMENT=0
CHAINLINK_DEV=true
The database parameters are set via environment variable
As Richard said, you need to set DATABASE_URL as an environment variable. For some reason, the chainlink client cannot read file .env and set the environment variable as expected.
The way how I solve the problem is to set DATABASE_URL as an environment variable explicitly by command:
export DATABASE_URL=postgresql://<usrname>:<passswd>#localhost:5432/chainlink_node?sslmode=disable
You can find all configurations of Chainlink node here.
Hope it helps.
The format to connect to the database is the following:
DATABASE_URL=postgresql://$USERNAME:$PASSWORD#$SERVER:$PORT/$DATABASE
I always follow this steps to create the database:
sudo -u postgres psql
create database $DATABASE;
create user $USERNAME with encrypted password '$PASSWORD';
grant all privileges on database $DATABASE to $USERNAME;
Just change the variables
sudo -u postgres psql
create database chainlink;
create user username with encrypted password 'pass';
grant all privileges on database chainlink to username;
And then:
DATABASE_URL=postgresql://username:pass#localhost:5432/chainlink?sslmode=disable
I don't recommend at all this credentials for production.

DB reset after deploy to meteor servers

I re-deployed my app to meteor by using 'meteor deploy '
and my Database was reset.
Any clue why this happened or how I can avoid it in the future ?
When a meteor app is deployed, your data saved in local mongo would not deployed to the server. So you could use mongodump and mongorestore to solve it:(docs)
Now first dump your database somewhere
mongodump --host localhost:3001
Get your mongodb`s credentials by running (in your app dir):
meteor mongo myapp.meteor.com --url
This will give you database url in the form:
mongodb://username:password#host:port/databasename
With these info you could fill them into mongorestore (docs) and restore your local database over
mongorestore -u username -p password -h host:port -d databasename ~/desktop/location_of_your_mongodb_dump
All of your data would get transferred in this way. I wish it could help.

How can I import a .sql file into my Heroku postgres database?

I have a backup sql file from another database that I want to import into Heroku's postgres database. How do you do that?
This is how you do it:
heroku pg:psql --app YOUR_APP_NAME_HERE < updates.sql
And if you want to restore your production into staging (assuming both are heroku postgres DBs):
heroku pgbackups:restore YOUR_STAGING_DATABASE_NAME `heroku pgbackups:url --app YOUR_PRODUCTION_APP_NAME` --app YOUR_STAGING_APP_NAME --confirm YOUR_STAGING_APP_NAME
Make sure to preserve the special single quotes around heroku pgbackups:url --app YOUR_PRODUCTION_APP_NAME.
HEROKU TOOLBELT UPDATE
Heroku has recently updated their toolbelt so the old commands are no longer valid (see this link for more info). Below is the new version of the restore command.
heroku pg:backups restore \
`heroku pg:backups public-url -a YOUR_PRODUCTION_APP_NAME` \
YOUR_STAGING_DATABASE_NAME \
--app YOUR_STAGING_APP_NAME \
--confirm YOUR_STAGING_APP_NAME
Making backup file:
pg_dump -U USERNAME DATABASE --no-owner --no-acl -f backup.sql
Restoring from sql file to heroku :
heroku pg:psql --app APPNAME < backup.sql
(Bonus) Deleting all tables from heroku app database (example):
heroku pg:reset --app APPNAME HEROKU_POSTGRESQL_ROSE
get DATABASE_URL from posgresql heroku panel (psql line)
Load the SQL into a local Postgres instance and make sure it's correct. Then dump the data using the directions here: https://devcenter.heroku.com/articles/heroku-postgres-import-export
Finally, upload the dump to a public web server (like S3) and restore to Heroku like this:
heroku pgbackups:restore DATABASE 'https://s3.amazonaws.com/me/items/3H0q/mydb.dump'
Django local db import on Heroku on windows
create backup
pg_dump -U postgres -d hawkishfinance > C:\Users\Fauzan\Projects\hawkishfinance.sql
dump on server
heroku pg:psql --app hawkishfinance < hawkishfinance.sql
You must add run in this command. It will work successfully!
heroku pg:psql run --app YOUR_APP_NAME_HERE < updates.sql

How can I attach a database to an app in Heroku?

I'm using Heroku's Postgres addon, and I created a new production database from the Heroku Postgres addon page.
I Didn't add it directly to my App using the Resources page of my App.
Now I want to attach this database to my App so it'll be recognized by the heroku pg command.
I'm able to use the database btw after setting the DATABASE_URL config var of my app to point to it, but heroku pg command doesn't recognize it yet.
Additional info: The previous database was Shared, and the new one is a Production.
Heroku add-ons may now be attached across applications and multiple times on a single app.
heroku addons:attach ADDON_NAME -a APP_NAME
Source: https://devcenter.heroku.com/changelog-items/646
To know the name of your addon, do:
heroku addons
Source: https://devcenter.heroku.com/articles/managing-add-ons
Did you add the database using the app-independent https://postgres.heroku.com/ site? Or did you just create a postgresql database in your Heroku control panel?
If you created your database on https://postgres.heroku.com/, you will not see the database via your heroku pg:info command. What you can do to add your database to your application, however, would be to:
Log into https://postgres.heroku.com/.
Click on the database you want to attach to your application.
Under 'Connection Settings', click the configuration button at the top right.
Then click the 'URL' option.
Copy your database URL, this should be something like "postgres://blah:blah#ec2-23-23-122-88.compute-1.amazonaws.com:5432/omg".
In your application, on the command line, run heroku config:set DATABASE_URL=postgres://blah:blah#ec2-23-23-122-88.compute-1.amazonaws.com:5432/omg
What we did there was assign your database to the DATABASE_URL environment variable in your application. This is the variable that's used by default when you provision databases locally to your application, so theoretically, assigning this value should work just fine for you.
To get your database that you created at https://postgres.heroku.com/ attached to your actual heroku app that you are working on you can't use any of the pg backup commands and as far as I can tell there is no supported Heroku way of attaching a database to a heroku app.
You can however create a backup of your database using pg_dump and then use pg_restore to populate your new database that is attached to your app:
pg_dump -i -h hostname -p 5432 -U username -F c -b -v -f "backup-filename" database_name
Once that is complete you can populate your new database with:
pg_restore -i -h new_hostname -p 5432 -U new_username -d new_database_name -v "same_backup_filename"
Even if you are upgrading from the "basic plan" to a the "crane plan" you still have to do a backup and restore, but since the db's are already attached to your app you have the advantage of using the heroku backup commands.

Resources