Cannot connect to Postgres Database from Strapi on Google App Engine - postgresql

Need help connecting to my Google SQL Postgres Database from Google App Engine. I've followed https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/deployment/hosting-guides/google-app-engine.html but keep running into the following error:
2022-09-27 16:11:32 default[20220928t020816] [2022-09-27 16:11:32.307] debug: ⛔️ Server wasn't able to start properly.
2022-09-27 16:11:32 default[20220928t020816] [2022-09-27 16:11:32.309] error: connect ECONNREFUSED /cloudsql/project-id:us-central1:database-id/.s.PGSQL.5432
database.ts
export default ({ env }) => ({
connection: {
client: 'postgres',
connection: {
host: env('DATABASE_HOST', '127.0.0.1'),
port: env.int('DATABASE_PORT', 5432),
database: env('DATABASE_NAME', 'database-id'),
user: env('DATABASE_USERNAME', 'strapi'),
password: env('DATABASE_PASSWORD', 'strapi'),
ssl: env.bool('DATABASE_SSL', false),
},
},
});
app.yaml
runtime: nodejs16
instance_class: F1
env_variables:
ADMIN_JWT_SECRET: 'XXXXXXXXXXXXX'
API_TOKEN_SALT: 'XXXXXXXXXXXXX'
APP_KEYS: 'XXXXXXXXXXXXX'
DATABASE_HOST: '/cloudsql/project-id:us-central1:database-id'
DATABASE_PORT: '5432'
DATABASE_NAME: 'database-id'
DATABASE_USERNAME: 'postgres'
DATABASE_PASSWORD: 'XXXXXXXXXXXXX'
DATABASE_SSL: 'false'
HOST: '0.0.0.0'
JWT_SECRET: 'XXXXXXXXXXXXX'
NODE_ENV: 'production'
PORT: '1337'
beta_settings:
cloud_sql_instances: 'project-id:us-central1:database-id'

One of the causes of error: connect ECONNREFUSED and the most common one when connecting to Cloud SQL using Unix Sockets (as is the case here) is that your GCP project does not have the Cloud SQL Admin API enabled.
Enable the Cloud SQL Admin API and that should help resolve the connectivity issue.

Related

Mongodb Compass: Connection timed out

I installed Mongodb on my remote server using this documentation. I have Ubuntu 16.04 on my remote server. Mongodb got installed successfully. I added the user like this:
use admin
db.createUser(
{
user: 'myuser',
pwd: 'password',
roles: [ { role: 'readWrite', db: 'mydb' } ]
}
);
I also made changes in the mongod.conf like this:
net:
port: 27017
bindIp: 127.0.0.1,<server_ip>
security:
authorization: 'enabled'
Now when I try to connect to mongodb using conneciton string like this:
mongodb://myuser:password#server_ip:27017/mydb
It gives me the following error:
connection timed out
What am I doing wrong here? I am using Laravel Forge to manage sever.
As it turned out the port was not open and that was the only issue. Opened the port and now its working fine.

MongoDb user permission denied

First I created mongoDB database and made it live AWS. Then I'm creating mongoDB database to MongoDb BI connector locally.
And I created Configuration file which is mentioned below:
security:
enabled: true
defaultMechanism: default
defaultSource: admin
mongodb:
net:
uri: MongoUrl
auth:
username: MongoUser
password: MongoPass
net:
bindIp: localhost
port: 3307
ssl:
mode: "allowSSL"
PEMKeyFile: "/mongo.pem"
MongoDB BI connector
And my cubeJS env file is this:
CUBEJS_DEV_MODE=true
CUBEJS_DB_TYPE=mongobi
CUBEJS_API_SECRET=9c7a834d9be0cd2fb4e7b86a88a2bd1368ffbc614dcf8fa8f836933b00d00c6916fa83b074c66a2b26579266edc93e0e1990b1271f6214ee799dc08b05b6a097
CUBEJS_EXTERNAL_DEFAULT=true
CUBEJS_SCHEDULED_REFRESH_DEFAULT=true
CUBEJS_WEB_SOCKETS=true
CUBEJS_DB_HOST=localhost
CUBEJS_DB_NAME=MongoDbName
CUBEJS_DB_USER=mongoUserName
CUBEJS_DB_PASSWORD=MongoPassword
CUBEJS_DB_PORT=3307
CUBEJS_DEV_MODE=true
CUBEJS_REFRESH_WORKER=true
port=4242
CUBEJS_DB_SSL=true
#CUBEJS_DB_SSL_CA=<SSL_CA>
#CUBEJS_DB_SSL_CERT=<SSL_CERT>
#CUBEJS_DB_SSL_CIPHERS=<SSL_CIPHERS>
#CUBEJS_DB_SSL_PASSPHRASE=<SSL_PASSPHRASE>
CUBEJS_DB_SSL_REJECT_UNAUTHORIZED=false
and Error is showing this:
Access denied for user
C:\Users\dell 7470>"C:\Users\dell 7470\Desktop\sql\mysql-8.0.31-winx64\bin\mysql.exe" --enable-cleartext-plugin --protocol tcp --port 3307 --user=hikarsmarttag --ssl-key=C:\mongo.pem --ssl-cert=C:\certificate.pem -p
Enter password: *****************
ERROR 1045 (28000): Access denied for user 'hikarsmarttag'
Whenever I try to connect to BI tools MySQL-Client, The same Error is being thrown.
Access denied in mySQL-Client

Why does puppet module postgresql produce this error not found in the catalog

I am using the puppet module postgresql from https://forge.puppet.com/modules/puppetlabs/postgresql/7.5.0 and in hiera have the following declared
postgresql::server::pg_hba_rules:
"allow_subnet_1”:
description: 'Allow subnet 1'
type: 'host'
address: ’10.10.56.0/24'
database: 'foreman'
user: 'foreman'
auth_method: 'md5'
order: '201'
Which produces the following warning,
Warning: /Stage[main]/Postgresql::Server/Postgresql::Server::Pg_hba_rule[allow1]/Concat::Fragment[pg_hba_rule_allow1]/Concat_fragment[pg_hba_rule_allow1]: Target Concat_file with path of /var/lib/pgsql/14/data/pg_hba.conf not found in the catalog
There is an attempt to create a hba rule then failes with "not found in the catalog” - can I get help to why doesn't work as expected?
I can provide more logs if needed.
Thanks
This worked.
To add rules:
postgresql::globals:
manage_pg_hba_conf: 'true'
postgresql::server::pg_hba_conf_path: "/nfs/pgsql/data/%{hiera('postgresql::globals::version')}/pg_hba.conf"
#postgresql::server::manage_pg_hba_conf: true
postgresql::server::pg_hba_rules:
"Allow xxx":
description: 'Allow trusted connection for the xxx server.'
type: 'host'
database: 'all'
user: 'postgres'
address: '10.10.10.1/32'
auth_method: 'trust'
"Allow xxx1":
description: 'Allow trusted connections from the monitoring host (xxx1).'
type: 'host'
database: 'postgres'
user: 'nagios'
address: '10.10.11.1/32'
auth_method: 'trust'

sails-sqlserver: multiple sql servers on same host

I'm using sails-sqlserver where my host is running both SQL Server 2008 and 2012. In connections.js - host: is set to 'SQLServerhost\2012' I am getting the error "error: A hook (orm) failed to load!" Is there a different way to specify which SQL Server to connect to?
I've found success with the below format in /config/connections.js when I need to work with different databases on the same server (but see below suggestion):
sqlserverLOCAL: {
adapter: 'sails-sqlserver',
user: 'username',
password: 'password',
host: 'localhost', // Name or IP Address of SQL Server
port: '1433',
database: 'YourDBName' // i.e. Initial Catalog
},
sqlserver: {
adapter: 'sails-sqlserver',
user: 'username',
password: 'password',
host: '11.222.333.444', // IP Address of SQL Server
port: '1433',
database: 'OtherDBName' // i.e. Initial Catalog
}
In your case, perhaps setting both host: attributes to the same server (just SQLServerhost rather than SQLServerhost\2012) and then set the database: attribute to the appropriate Initial Catalog would be best. Also, make sure you double-check what ports the two SQL Servers are running on and set that attribute value accordingly.

Connect session in PostgreSQL with SailsJS

I have a personal project in SailsJS, Passport-Local and PostgreSQL. I managed to get connection and save users in PostgreSQL DB. But I have big problem with session storing. From what I know SailsJS is using Connect to get it done.
Previous working code for MongoDB:
connections: {
prodMongodbServer: {
adapter: 'sails-mongo',
host: 'localhost',
port: 27017,
//user: '',
//password: '',
database: 'sails-auth'
}
},
session: {
adapter: 'mongo',
host: 'localhost',
port: 27017,
db: 'sails-auth',
collection: 'sessions'
}
My (working) connection to PostgreSQL:
connections: {
somePostgresqlServer: {
adapter: 'sails-postgresql',
host: 'localhost',
port: 5432,
user: 'postgres',
password: 'Password1',
database: 'sails-auth'
}
},
And the code I have problem with:
session: {
adapter: 'connect-pg-simple',
host: 'localhost',
port: 5432,
user: 'postgres',
password: 'Password1',
db: 'sails-auth'
}
I've installed connect-pg-simple, executed SQL code but when I am starting sails app I get an error:
$ sails lift
info: Starting app...
Init Express midleware
Failed to prune sessions: password authentication failed for user "myPcUser"
info:
info: .-..-.
info:
info: Sails <| .-..-.
info: v0.11.3 |\
info: /|.\
info: / || \
info: ,' |' \
info: .-'.-==|/_--'
info: `--'-------'
info: __---___--___---___--___---___--___
info: ____---___--___---___--___---___--___-__
info:
I thought that it may be beetter to use connect-pg, but it requires so many dependecy that I stayed with simple version. Anyone know what this problem is about? Im on windows so its weird that it have problem with my PC User...
Or maybe someone have some solution for using PostgreSQL for users, etc and Mongo for sessions. For what I've tested Passport doesnt allow to do that (user can sign up but can't sign in)
Perhaps you can fix this error open PostgreSQL client authentication configuration file:
/var/lib/pgsql/data/pg_hba.conf
and change:
local all all trust
host all 127.0.0.1/32 trust
Save and close the file. Restart Postgresql server:
service postgresql restart
To make it work
Install the connect-pg-simple node module: $ npm install connect-pg-simple
In session.js define the adapter and connection string:
adapter: 'connect-pg-simple',
conString: 'postgres://user:pass#host:5432/dbname',
3) run the SQL commands on file node_modules/connect-pg-simple/table.sql to create the table for sessions. :
CREATE TABLE "session" (
"sid" varchar NOT NULL COLLATE "default",
"sess" json NOT NULL,
"expire" timestamp(6) NOT NULL
)
WITH (OIDS=FALSE);
ALTER TABLE "session" ADD CONSTRAINT "session_pkey" PRIMARY KEY ("sid") NOT DEFERRABLE INITIALLY IMMEDIATE;
CREATE INDEX "IDX_session_expire" ON "session" ("expire");
I used for that sails-pg-session.
The information about sessions must be stored in config/session.js:
adapter: 'sails-pg-session',
database: 'dbname',
host: 'localhost',
user: 'dbuser',
password: 'dbpasswd',
port: 5432
Hope it helps