Error creating a connection to Postgresql while preparing konga database - postgresql

After installing Konga, we are trying to prepare Konga database on the already running Postgresql database. by using suggested command i.e.
node ./bin/konga.js prepare --adapter postgres --uri postgresql://localhost:5432/konga
But we are facing the error as below:
Error creating a connection to Postgresql using the following settings:
postgresql://localhost:5432/konga?host=localhost&port=5432&schema=true&ssl=false&adapter=sails-postgresql&user=postgres&password=XXXX&database=konga_database&identity=postgres
* * *
Complete error details:
error: password authentication failed for user "root"
error: A hook (`orm`) failed to load!
error: Failed to prepare database: error: password authentication failed for user "root"
We even created the schema konga_database manually and have tried several variations for prepare command but no fate
node ./bin/konga.js prepare --adapter postgres --uri postgresql://kong:XXXX#localhost:5432/konga_database
node ./bin/konga.js prepare --adapter postgres --uri postgresql://kong#localhost:5432/konga
node ./bin/konga.js prepare --adapter postgres --uri postgresql://kong#localhost:5432/konga_database
Below is config/connections.js
postgres: {
adapter: 'sails-postgresql',
url: process.env.DB_URI,
host: process.env.DB_HOST || 'localhost',
user: process.env.DB_USER || 'postgres',
password: process.env.DB_PASSWORD || 'XXXX',
port: process.env.DB_PORT || 5432,
database: process.env.DB_DATABASE ||'konga_database',
// schema: process.env.DB_PG_SCHEMA ||'public',
// poolSize: process.env.DB_POOLSIZE || 10,
ssl: process.env.DB_SSL ? true : false // If set, assume it's true
},
Below is .env file configuration
PORT=1337
NODE_ENV=production
KONGA_HOOK_TIMEOUT=120000
DB_ADAPTER=postgres
DB_URI=postgresql://localhost:5432/konga
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=XXXX
KONGA_LOG_LEVEL=info
TOKEN_SECRET=
kong and postgresql are already running on the AWS linux AMI 2 server on there respective ports i.e. 8443 & 5432
Please help us to prepare DB and start konga service. Also. let us know in case you need more info.
Node v: v12.19.0
NPM v: 6.14.8
Regards
Nitin G

Maybe I overlooked it, but what version of PostreSQL are you using?
Konga is not able to support postgresql 12:
https://github.com/pantsel/konga/issues/487

Have you tried like this?
.env
DB_URI=postgresql://userdb:passworddb#localhost:5432/kongadb
I tried on Postgresql 9.6
https://www.rosehosting.com/blog/how-to-install-postgresql-9-6-on-ubuntu-20-04/

Related

GAE Connection to SQL: password authentication failed for user 'postgres'

nodejs app on GAE flex deploys correctly, but won't connect to postgres, even though initial knex migration worked and the tables were created. Ive read through the documentation and cant understand how all of the below can be true.
running psql -h [ipaddress] -p 5432 -U postgres mydb and entering the password from my local machine works!
package.json..
"prestart": "npx knex migrate:latest && npx knex seed:run
"start": "NODE_ENV=production npm-run-all build server"
worked! tables were created and seed was run
knexfile
production: {
client: 'postgresql',
connection: {
database: DB_PASS,
user: DB_USER,
password: DB_PASS,
host: DB_HOST
},
pool: {
min: 2,
max: 10
},
migrations: {
directory: './db/migrations',
tableName: 'knex_migrations'
},
seeds: {
directory: './db/seeds/dev'
}
}
yaml
runtime: nodejs
env: flex
instance_class: F2
beta_settings:
cloud_sql_instances: xxxx-00000:us-west1:myinst
env_variables:
DB_USER: 'postgres'
DB_PASS: 'mypass'
DB_NAME: 'myddb'
DB_HOST: '/cloudsql/xxxx-00000:us-west1:myinst'
handlers:...
IAM
oddly, it was a log only issue. the logs still say user authentication failed, but actually the app was connected.

MikroORM failed to connect to database despite correct username and password

I'm following Ben Awad's youtube tutorial on writing a full stack application. I'm using MikroORM with postgres.
I created a database called tut, a user called tut, then gave that user access to the database. I can verify that the user has access to the db like so:
$ su - tut
Password:
user:/home/tut$ psql
tut=>
Here's what my mikro-orm.config.ts looks like:
import {Post} from "../entities/Post";
import {MikroORM} from "#mikro-orm/core";
import path from "path"
export default {
migrations: {
path: path.join(__dirname, "./migrations"),
pattern: /^[\w-]+\d+.*\.[tj]s$/
},
entities: [Post],
dbName: 'tut',
user: 'tut',
password: 'tut',
type: 'postgresql',
debug: process.env.NODE_ENV !== 'production',
} as Parameters<typeof MikroORM.init>[0]
When I attempt to connect to the db in index.ts I get a "MikroORM failed to connect to database tut on postgresql://tut:*****#127.0.0.1:5432" (error code 28P01).
Am I supposed to be running a psql server on localhost? The tutorial doesn't have you do that as far as I can tell.
I fixed this by running \password in psql as tut, thanks #AdrianKlaver

Elixir-Phoenix: mix ecto.create and mix phx.server provoke same error but contain different postgres db parameters

When running mix ecto.create I get the following error:
17:47:14.118 [error] GenServer #PID<0.299.0> terminating
** (Postgrex.Error) FATAL 28000 (invalid_authorization_specification) no pg_hba.conf entry for host "10.110.0.3", user "staging", database "postgres", SSL off
(db_connection 2.4.0) lib/db_connection/connection.ex:100: DBConnection.Connection.connect/2
(connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
(stdlib 3.15.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
Then, if I try to run mix phx.server I get the following error:
[error] Postgrex.Protocol (#PID<0.358.0>) failed to connect: ** (Postgrex.Error) FATAL 28000 (invalid_authorization_specification) no pg_hba.conf entry for host "10.110.0.3", user "staging", database "contact", SSL off
My database config in dev.exs is:
config :contact_api, ContactApi.Repo,
username: System.get_env("DB_USER") || "postgres",
password: System.get_env("DB_PWD") || "postgres",
database: System.get_env("DB_NAME") || "contact",
hostname: System.get_env("DB_HOST") || "localhost",
port: System.get_env("DB_PORT") || "5432",
show_sensitive_data_on_connection_error: true,
pool_size: 10
I have already checked that env variables are properly setter.
I have also tried to test different env values but mix ecto.create still shows postgres for the database name at the error trace.
I can connect to the database using psql from the same server as the app.
When running a local DB with docker; mix ecto.create, mix ecto.migrate, mix test, and mix phx.server run as expected.
Any help will be much appreciated!
I have solved my problem. I am working with a cloud managed postgres database that is hosted by Digital Ocean. The only connections allowed are encrypted ones using ssl certificates. Error trace just informs about no user entry in pg_hba.conf but no reference to the ssl issue. Hence I had to modify config/dev.exs:
config :contact_api, ContactApi.Repo,
username: System.get_env("DB_USER") || "postgres",
password: System.get_env("DB_PWD") || "postgres",
database: System.get_env("DB_NAME") || "contact",
hostname: System.get_env("DB_HOST") || "localhost",
port: System.get_env("DB_PORT") || "5432",
show_sensitive_data_on_connection_error: true,
pool_size: 10
ssl: true,
ssl_opts: [
cacertfile: "cert/ca-certificate.crt"
]

Heroku can't connect with Postgres DB/Knex/Express

I have an Express API deployed to Heroku, but when I attempt to run the migrations, it throws the following error:
heroku run knex migrate:latest Running knex migrate:latest on ⬢
bookmarks-node-api... up, run.9925 (Free) Using environment:
production Error: connect ECONNREFUSED 127.0.0.1:5432
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1117:14)
In my knexfile.js, I have:
production: {
client: 'postgresql',
connection: {
database: process.env.DATABASE_URL
},
pool: {
min: 2,
max: 10
},
migrations: {
directory: './database/migrations'
}
}
I also tried assigning the migrations directory to tableName: 'knex_migrations' which throws the error:
heroku run knex migrate:latest Running knex migrate:latest on ⬢
bookmarks-node-api... up, run.7739 (Free) Using environment:
production Error: ENOENT: no such file or directory, scandir
'/app/migrations'
Here is the config as set in Heroku:
-node-api git:(master) heroku pg:info
=== DATABASE_URL
Plan: Hobby-dev
Status: Available
Connections: 0/20
PG Version: 10.7
Created: 2019-02-21 12:58 UTC
Data Size: 7.6 MB
Tables: 0
Rows: 0/10000 (In compliance)
Fork/Follow: Unsupported
Rollback: Unsupported
I think the issue is that for some reason, it is looking at localhost for the database, as if the environment is being read as development though the trace shows Using environment: production.
When you provide an object as your connection you're providing individual parts of the connection information. Here, you're saying that the name your database is everything contained in process.env.DATABASE_URL:
connection: {
database: process.env.DATABASE_URL
},
Any keys you don't provide values for fall back to defaults. An example is the host key, which defaults to the local machine.
But the DATABASE_URL environment variable contains all of the information that you need to connect (host, port, user, password, and database name) in a single string. That whole value should be your connection setting:
connection: process.env.DATABASE_URL,
You should check to see if the Postgres add-on is setup as described in these docs since the DATABASE_URL is automatically set for you as stated here.

what is client property of knexfile.js

In knex documentation of configuration of knexfile.js for PostgreSQL, they have a property called client, which looks this way:
...
client: 'pg'
...
However, going through some other projects that utilize PostgreSQL I noticed that they have a different value there, which looks this way:
...
client: 'postgresql'
...
Does this string correspond to the name of some sort of command line tool that is being used with the project or I misunderstand something?
Postgresql is based on a server-client model as described in 'Architectural Fundamentals'
psql is the standard cli client of postgres as mentioned here in the docs.
A client may as well be a GUI such as pg-admin, or a node-package such as 'pg' - here's a list.
The client parameter is required and determines which client adapter will be used with the library.
You should also read the docs of 'Server Setup and Operation'
To initialize the library you can do the following (in this case on localhost):
var knex = require('knex')({
client: 'mysql',
connection: {
host : '127.0.0.1',
user : 'your_database_user',
password : 'your_database_password',
database : 'myapp_test'
}
})
The standard user of the client deamon ist 'postgres' - which you can use of course, but its highly advisable to create a new user as stated in the docs and/or apply a password to the standard user 'postgres'.
On Debian stretch i.E.:
# su - postgres
$ psql -d template1 -c "ALTER USER postgres WITH PASSWORD 'SecretPasswordHere';"
Make sure you delete the command line history so nobody can read out your pwd:
rm ~/.psql_history
Now you can add a new user (i.E. foobar) on the system and for postgres
# adduser foobar
and
# su - postgres
$ createuser --pwprompt --interactive foobar
Lets look at the following setup:
module.exports = {
development: {
client: 'xyz',
connection: { user: 'foobar', database: 'my_app' }
},
production: { client: 'abc', connection: process.env.DATABASE_URL }
};
This basically tells us the following:
In dev - use the client xyz to connect to postgresqls database my_app with the user foobar (in this case without pwd)
In prod - retrieve the globalenv the url of the db-server is set to and connect via the client abc
Here's an example how node's pg-client package opens a connection pool:
const pool = new Pool({
user: 'foobar',
host: 'someUrl',
database: 'someDataBaseName',
password: 'somePWD',
port: 5432,
})
If you could clarify or elaborate your setup or what you like to achieve a little more i could give you some more detailed info - but i hope that helped anyways..