UnhandledPromiseRejectionWarning: SequelizeConnectionError: database "dbname" does not exist - postgresql

While trying to connect to a DB instance running the PostgreSQL database engine on Amazon RDS.
I have checked the environment variables and the values are set correctly.
However, when I run npm run dev I encounter the error below
(node:32031) UnhandledPromiseRejectionWarning: SequelizeConnectionError: database "database-1" does not exist
My DB is publicly accessible and security groups have been checked to be correct(allows inbound and outbound connection).

Was able to solve this by using the default database name postgres for the env --dbname option.

Related

Amazon RDS postgres Data wiped and can't connect to database?

I created an RDS Postgres instance. I'm new to RDS.
db host:
demodb.xxxuxxvxxxxx.us-east-2.rds.amazonaws.com
db identifier:
demodb
Every tutorial says to connect with this URL:
jdbc:postgresql://demodb.xxxuxxvxxxxx.us-east-2.rds.amazonaws.com:5432/demodb
but every time I do I get this error-
FATAl: database "demodb" does not exist.
I am able to connect using this:
jdbc:postgresql://demodb.xxxuxxvxxxxx.us-east-2.rds.amazonaws.com:5432/postgres
Now, while I was excited to connect after I used SQL workbench to create tables and insert data into those tables, a few hours later all my tables and data were deleted/wiped/dropped. Why would this happen? and How can I prevent it from happening in the future?
FATAl: database "demodb" does not exist.
demodb is db instance identifier. It is NOT the name of your database inside of PostgreSQL.
By default RDS PostgreSQL does not create a database for you. It seems to me that you haven't created an actual database when you setup your RDS PostgreSQL.
To create a database at RDS creation there is an option called Initial database name where you should specify the name of the database you want. Otherwise, no database is created, which is a default behavior:

Cannot drop db in postgres [duplicate]

I can't seem to reset my database while using docker compose. I've tried killing the server, killing just the database, and restarting the machine.
Anyone know the best way to clear out the development database?
Here's what I tried:
docker-compose run web rake db:reset
I am getting this error:
PG::ObjectInUse: ERROR: cannot drop the currently open database
: DROP DATABASE IF EXISTS "postgres"
Couldn't drop database 'postgres'
rake aborted!
I'm using the setup exactly as described by the docker-compose quickstart: https://docs.docker.com/compose/rails/
I have a rails container and a postgres container
You are using the wrong database.
The database postgres is normally not used for user data, but for administrative purposes. For example, if you want to drop a database, you have to be connected to a different database in the PostgreSQL database cluster to issue the SQL statement DROP DATABASE. Normally, the database postgres is used for that purpose, and I have no doubt that Docker does exactly that when it tries to drop a database.
If you really want to drop the database postgres, you'd have to connect to some other database in the cluster. The correct solution, however, is to keep your data in a different database. Then the problem should go away by itself.

Fusionauth-app docker without mysql superuser credentials

I would like to connect to a hosted remote mySQL DB (mariadb 10.1.39). I use the available fusionauth docker images (app and search) from docker hub and the published docker compose file. The db hosting provider does not grant superuser credentials. The assigned user rights should be sufficient to maintain the tables of the schema. Unfortunately, using the docker container mysql superuser credentials seems to be mandatory.
I imported the DB dump of a local (dockerized) mariadb (10.1.40) to the remote db. Username and schema name are the same local and remote. I tried not to provide DATABASE_ROOT_USER with the docker-compose yaml, but this approach ends in maintenance mode.
Is there an approach to connect to a remote mysql db without superuser credentials?
We will be enhancing our automated setup to better support external db service providers. See https://github.com/FusionAuth/fusionauth-issues/issues/95
Your current option is to create the schema manually. https://fusionauth.io/docs/v1/tech/installation-guide/fusionauth-app#advanced-installation
You may also try to use your user credentials in the superuser fields, it may work.

Specifying the DB to connect with gcloud sql

When connecting to a Google Cloud SQL instance, is there a way to specify the database I want to connect to?
This is the command I execute and the error I get:
$ gcloud beta sql connect MY_INSTANCE --user=MY_USER
Whitelisting your IP for incoming connection for 5 minutes...done.
Connecting to database with SQL user [MY_USER].Password for user MY_USER:
psql: FATAL: database "MY_USER" does not exist
It seems to try to connect to a database that has the same name than the user, but what when that's not the case? (I don't want to create a dummy DB called MY_USER just to be able to jump to the DB I want).
Here are the docs for the command gcloud beta sql, but I don't see anything useful for this there: https://cloud.google.com/sdk/gcloud/reference/beta/sql/connect
gcloud sql connect does not currently allow you to specify the database name. There is a open issue to add it: https://issuetracker.google.com/issues/69314375
In the meantime, you can work around this by utilizing the PGDATABASE environment variable:
e.g.
PGDATABASE=mydb gcloud sql connect myinstance
You could create a shell alias to do this for you.
In the meanwhile the beta version of the gcloud sql connect command has added support for a --database=<dbname> flag
Entire command:
gcloud beta sql connect INSTANCE [--database=DATABASE, -d DATABASE] [--user=USER, -u USER] [GCLOUD_WIDE_FLAG …]
https://cloud.google.com/sdk/gcloud/reference/beta/sql/connect

Importing data into two postgres servers works on one, not on other

I dumped my production db from an Amazon RDS postgresql instance and on occasion, I restore production to our staging and development databases.
Currently the staging and development databases reside on an RDS instance and the import works great. I am currently attempting to restore the database to a postgres installation that isn't an RDS instance and I continuously get the error invalid command \N before that I get ERROR: relation "locations" does not exist. I have been trying everything to get this to work. I have recreated the database several times ensuring all of the settings match what I can see of the RDS instance, and am having no luck.
I am attempting to use psql -h {host} -U {user} -d {db} < production.sql