database "public" does not exist - postgres/sequelize - node.js

I'm trying to connect postgres database from sequelize (node.js).But sequelize throws error like ERROR: database "public" does not exist.
The database url is given below:
postgres://postgres:root#localhost:5432/public
The show db result is given below:
I have modified the database url as follows:
postgres://postgres:root#localhost:5432/postgres, where postgres is valid database.Please find the attached image below:

database and schema in postgresql are not the same object .. you should provide the database name not the schema name
you could get the list of the database using
psql -U pgadmin -l

The postgres database is a default database meant for use by users, utilities and third party applications.
If you don't specify a database while connecting to postgres (using, day, psql), it will connect to postgres DB.
It is possible that you connected to postgres without specifying the DB and created the tables. Hence they were created in postgres DB.
References:
https://www.postgresql.org/docs/15/app-initdb.html
https://stackoverflow.com/a/2411860/12242023

Related

How to create the connection string for a database generated with pgAdmin4

I developed my app with SQLAlchemy testing it on an SQLite database.
Now I would like to testing more using PostgreSQL but in a localhost once again.
For this reason, I tried to create a local Postgre database with pdAdmin4 (my laptop has Windows 7 so I installed the v4 version of the database manager).
Now I am trying to generate the connection string for this Postgre database but I cannot understand how to do it.
This is what I created in pgAdmin4:
while the details of the server are these:
The connection string I am trying to use is this:
selected_engine = create_engine('postgresql+psycopg2://postgres:123#localhost/test_server/test_database')
The password 123 is the password I set at the first access to pgdAmin4.
However, I got this error:
OperationalError: (psycopg2.OperationalError) connection to server at "localhost" (::1), port 5432 failed: FATAL: database "test_server/test_database" does not exist
I am sure I am wrong and I cannot figure out what is the correct URL for my database.

Unable to connect with Mongodb Atlas using Mongoose [duplicate]

When I try to connect to Mongo instance using this connection string
mongodb://root:password#localhost:27017/
everything works, however, when I try to specify the database name in the connection string
i.e
mongodb://root:password#localhost:27017/storefont
I get the following error MongoDB Connection Error: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoError: Authentication failed.
Specify the authentication database like this:
mongodb://root:password#localhost:27017/storefont?authSource=admin
If you specify a database then this database is also taken for authentication by default. The MongoDB documentation is not 100% clear in that topic.
See also Authentication failure while trying to save to mongodb
The answer provided by Wernfield is correct. I am providing a small tweak along with an example to connect to a replica set:
When using the authSource query param, please ensure that the connection string is wrapped in single quotes OR just use --authenticationDatabase argument instead,
mongo mongodb://ip1:27017,ip2:27017,ip3:27017/my-db --authenticationDatabase admin -u myUsername -p myPassword

Connecting to Aurora Postgres (Babelfish, 1433)

I'm attempting to connect to a new Aurora PostgreSQL instance with Babelfish enabled.
NOTE: I am able to connect to the instance using the pg library through the normal port 5432 (the Postgres TDAS endpoint).
However, for this test, I am attempting to connect through the Babelfish TDS endpoint (1433) using the standard mssql package.
If I specify a database name (it is correct), I receive the error 'database "postgres" does not exist':
var config = {
server: 'xxx.us-east-1.rds.amazonaws.com',
database: 'postgres',
user: 'xxx',
password: 'xxx'
};
and the connection closes since the connection fails.
if I omit the database property in the config, like:
var config = {
server: 'xxx.us-east-1.rds.amazonaws.com',
user: 'xxx',
password: 'xxx'
};
It will connect. Also, I can use that connection to query basic things like SELECT CURRENT_TIMESTAMP and it works!
However, I can't access any tables.
If I run:
SELECT COUNT(1) FROM PERSON
I receive an error 'relation "person" does not exist'.
If I dot-notate it:
SELECT COUNT(1) FROM postgres.dbo."PERSON"
I receive an error "Cross DB query is not supported".
So, I can't connect to the specific database directly and if I connect without specifying a database, I can't cross-query to the table.
Any one done this yet?
Or, if not, any ideas on helping me figure out what to try next? I'm out of ideas.
Babelfish databases (that you connect to on port 1433) have nothing to do with PostgreSQL databases (port 5432). Essentially, all of Babelfish lives within a single PostgreSQL database (parameter babelfishpg_tsql.database_name).
You seem to have a single-db setup, because Cross DB query is not supported. With such a setup, you can only have a single database via port 1433 (apart from master and tempdb). You have to use CREATE DATABASE to create that single database (if it isn't already created; ask sys.databases).
I can't tell if it is supported to create a table in PostgreSQL (port 5432) and use it on port 1433 (the other way around is fine), but if so, you have to create it in a schema that you created with CREATE SCHEMA while connected on port 1433.
The answer was that I should be connecting to database "master".
Even though there is no database titled master in the instance, you still do connect to it.
Once connected, running the following:
select current_database();
This will indicate you are connected to database "babelfish_db".
I don't know how that works or why a database would have an undocumented alias.
The bigger answer here is that cross-DB object references are not currently supported in Babelfish, outside your current SQL Server database.
This is currently being worked on. Stay tuned.

Writing to localhost Postgres returning infamous"42P01 parse_relation.c" error

Use-case: I am trying to write data from a nodejs process running locally (on a docker container) to my locally running postgres server (no docker container). The nodejs process is able to connect to the server (setting the address to host.docker.internal solved that problem) however, when I attempt a simple "SELECT * FROM contact LIMIT 1" query, this error is returned:
{"type":"postgres error","request":"SELECT * FROM contact",
"error":{
"name":"error","length":106,
"severity":"ERROR",
"code":"42P01",
"position":"15",
"file":"parse_relation.c",
"line":"1376",
"routine":"parserOpenTable"}}
The relation error suggests the table is not found-- I created this table using a postgres client (postico) and have been able to successfully query the table's contents with other pg clients as well
I see multiple posts are suggesting running the sequelize db:migrate command, but would this be the right solution here?
I did not create a model nor a migration, and created the table directly in the table. Is there something else I may be overlooking that is producing this error?

Mongoose connection error when using db name in connection string

When I try to connect to Mongo instance using this connection string
mongodb://root:password#localhost:27017/
everything works, however, when I try to specify the database name in the connection string
i.e
mongodb://root:password#localhost:27017/storefont
I get the following error MongoDB Connection Error: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoError: Authentication failed.
Specify the authentication database like this:
mongodb://root:password#localhost:27017/storefont?authSource=admin
If you specify a database then this database is also taken for authentication by default. The MongoDB documentation is not 100% clear in that topic.
See also Authentication failure while trying to save to mongodb
The answer provided by Wernfield is correct. I am providing a small tweak along with an example to connect to a replica set:
When using the authSource query param, please ensure that the connection string is wrapped in single quotes OR just use --authenticationDatabase argument instead,
mongo mongodb://ip1:27017,ip2:27017,ip3:27017/my-db --authenticationDatabase admin -u myUsername -p myPassword

Resources