Prisma: Error validating datasource `db`: the URL must start with the protocol `postgresql://` or `postgres://` - prisma

I am trying to deploy my NestJS application with prisma in production. But when launching my server, I have this error:
nestjs | PrismaClientInitializationError: error: Error validating datasource `db`: the URL must start with the protocol `postgresql://` or `postgres://`.
nestjs | --> schema.prisma:11
nestjs | |
nestjs | 10 | provider = "postgresql"
nestjs | 11 | url = env("DATABASE_URL")
nestjs | |
nestjs |
nestjs | Validation Error Count: 1
nestjs | at Object.loadEngine (/app/node_modules/#prisma/client/runtime/index.js:35591:19)
nestjs | at async Object.instantiateLibrary (/app/node_modules/#prisma/client/runtime/index.js:35520:5)
nestjs | at async Object.start (/app/node_modules/#prisma/client/runtime/index.js:35670:5)
nestjs | at async Proxy.onModuleInit (/app/dist/prisma.service.js:14:9)
nestjs | at async Promise.all (index 0)
nestjs | at async callModuleInitHook (/app/node_modules/#nestjs/core/hooks/on-module-init.hook.js:43:5)
nestjs | at async NestApplication.callInitHook (/app/node_modules/#nestjs/core/nest-application-context.js:178:13)
nestjs | at async NestApplication.init (/app/node_modules/#nestjs/core/nest-application.js:96:9)
nestjs | at async NestApplication.listen (/app/node_modules/#nestjs/core/nest-application.js:155:33)
nestjs | at async bootstrap (/app/dist/main.js:8:5) {
nestjs | clientVersion: '3.11.1',
nestjs | errorCode: 'P1012'
nestjs | }
My docker-compose.yml :
version: "3.2"
services:
nestjs:
container_name: nestjs
build:
context: ./apps/nestjs
dockerfile: Dockerfile.prod
env_file:
- ./apps/nestjs/.env
My .env :
DATABASE_URL="postgres://myUser:myPassword#myHost:myPort/myDB?sslmode=require"
What I tried to do :
Check that my .env was taken into account. When I go into the container, my environment variable exists
Try replacing postgres to postgresql
Any ideas?
Thanks you!

Problem solved.
I didn't have to surround the URL with " in my .env..

You didn't have to put " around your URL but you may need it and it should have worked.
In fact, it is an issue on old docker-compose version. Upgrade it and welcome " back !

I had the same problem,
Check your .env file if the URI is good
Check the provider from your schema.prisma
try to remove your node_modules and reinstall them.
That should do it😉

Related

QueryFailedError: time/datevalue out of range in nest with TypeOrm and Docker

i docker a project made with nestJs and TypeOrm (postgresSql), two diferent apps, both comunicate each other by API REST, each one in an individual container, when i run it outside the container it works fine, but inside the container, one ask something to the other, but the other show in console this error:
/usr/src/app/src/driver/postgres/PostgresQueryRunner.ts:299
| throw new QueryFailedError(query, parameters, err)
| ^
| QueryFailedError: date/time field value out of range: «11/18/2022 4:03:59 PM»
| at PostgresQueryRunner.query (/usr/src/app/src/driver/postgres/PostgresQueryRunner.ts:299:19)
| at processTicksAndRejections (node:internal/process/task_queues:95:5)
| at InsertQueryBuilder.execute (/usr/src/app/src/query-builder/InsertQueryBuilder.ts:163:33)
| at SubjectExecutor.executeInsertOperations (/usr/src/app/src/persistence/SubjectExecutor.ts:428:42)
| at SubjectExecutor.execute (/usr/src/app/src/persistence/SubjectExecutor.ts:137:9)
| at EntityPersistExecutor.execute (/usr/src/app/src/persistence/EntityPersistExecutor.ts:194:21)
I know that i can change the DateStyle, but it connect to a external database, not in localhost, i guess that i have to change that to the client, but how, and why it works fine normally, outside the container?
I have tried using different version of node images for docker, alpine, bullseye, but nothing.

Prisma provider different in vercel than in code

In a previous push I've changed the provider from postgres to sqlite and it seems it is stucked and I can not change it back. In the vercel console I get the following error:
ERROR PrismaClientInitializationError: error: Error validating datasource `db`: the URL must start with the protocol `file:`.
--> schema.prisma:10
|
9 | provider = "sqlite"
10 | url = env("DATABASE_URL")
|
Validation Error Count: 1
Meanwhile in github you can see the code is the following:
datasource db {
provider = "postgres"
url = env("DATABASE_URL")
}
What is going on and how can I solve this?
Thanks

PostgreSQL - Etcd - Patroni Cluster Restoration Problem

I am trying to create PostgreSQL - Etcd - Patroni(PEP) cluster. There are lots of examples on the internet and I have created one and it runs perfect. Yet, this architecture should comply with my company' s backup solution which is NetApp. We are putting the database into backup mode with "SELECT pg_start_backup('test_backup', true);" and then copy all the data files to backup directory.
PEP cluster has a small problem with this solution. Taking backup is running fine, but restoration point is not that much good. In order to restore the leader of the PEP cluster I need stop the database and then move the backup files to the data directory and finally start the restoration. At this point Patroni says the restoration node is a new cluster. Here is the error:
raise PatroniFatalException('Failed to bootstrap cluster')
patroni.exceptions.PatroniFatalException: 'Failed to bootstrap cluster'
2022-04-11 12:49:29,930 INFO: No PostgreSQL configuration items changed, nothing to reload.
2022-04-11 12:49:29,942 INFO: Lock owner: None; I am pgsql_node1
2022-04-11 12:49:29,962 INFO: trying to bootstrap a new cluster
The files belonging to this database system will be owned by user "postgres".
Also, when I check the patroni cluster status I saw this:
root#4cddca032454:/data/backup# patronictl -c /etc/patroni/config.yml list
+ Cluster: pgsql (7085327534197401486) --------+----+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+-------------+------------+---------+---------+----+-----------+
| pgsql_node1 | 172.17.0.6 | Replica | stopped | | unknown |
| pgsql_node2 | 172.17.0.7 | Replica | running | 11 | 0 |
| pgsql_node3 | 172.17.0.8 | Replica | running | 11 | 0 |
+-------------+------------+---------+---------+----+-----------+
At this point I have a PEP cluster without a leader. So, how can I solve this issue?
(Note: The restoration node attempted to join right cluster because, before starting the restoration I check cluster status and got this result:
root#4cddca032454:/data/backup# patronictl -c /etc/patroni/config.yml list
+ Cluster: pgsql (7085327534197401486) --------+----+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+-------------+------------+---------+---------+----+-----------+
| pgsql_node2 | 172.17.0.7 | Replica | running | 11 | 0 |
| pgsql_node3 | 172.17.0.8 | Replica | running | 11 | 0 |
+-------------+------------+---------+---------+----+-----------+
pgsql_node1 is not there.
)
As explained here, "https://patroni.readthedocs.io/en/latest/existing_data.html#existing-data" I can create a new cluster after restoration but my priority saving the cluster. Or do I think wrong, all this steps are same with the converting a standalone PostgreSQL database to PEP cluster?
Please let me know if you need any data or something is not clear.
Here is my leader node patroni config file:
scope: "cluster"
namespace: "/cluster/"
name: 8d454a228d251
restapi:
listen: 172.17.0.2:8008
connect_address: 172.17.0.2:8008
etcd:
host: 172.17.0.2:2379
dcs:
ttl: 30
loop_wait: 10
retry_timeout: 10
maximum_lag_on_failover: 1048576
check_timeline: true
postgresql:
use_pg_rewind: true
remove_data_directory_on_rewind_failure: true
remove_data_directory_on_diverged_timelines: true
use_slots: true
postgresql:
listen: 0.0.0.0:5433
connect_address: 172.17.0.2:5432
use_unix_socket: true
data_dir: /data/postgresql/
bin_dir: /usr/lib/postgresql/14/bin
config_dir: /etc/postgresql/14/main
authentication:
replication:
username: "patroni_replication"
password: "123123"
superuser:
username: "patroni_superuser"
password: "123123"
parameters:
unix_socket_directories: '/var/run/postgresql/'
logging_collector: 'on'
log_directory: '/var/log/postgresql'
log_filename: 'postgresql-14-8d454a228d25.log'
restore_command: 'cp /data/backup/%f %p'
recovery_target_timeline: 'latest'
promote_trigger_file: '/tmp/promote'
Thanks!
If I understand well you want to restore the primary server (leader) restoring the data directory with a new set of backup files.
After doing the restore in data directory of leader you need to recreate the patroni cluster (remove the keys in DCS) with patronictl remove option.
Example:
stop pgsql_node2
stop pgsql_node3
stop pgsql_node1
on pgsql_node1:
patronictl -c /etc/patroni/config.yml remove <clustername>
start pgsql_node1
start pgsql_node2
start pgsql_node3

CSRF token is missing error in docker pgadmin

I am trying to create a docker-compose stack with pg and pgadmin as follows,
version: '3.1'
services:
pg-admin:
image: dpage/pgadmin4
volumes:
- /Users/pkaramol/Desktop/backup.tar:/pgadmin4/dvdrental.tar
ports:
- "8181:80"
environment:
PGADMIN_DEFAULT_EMAIL: user#domain.com
PGADMIN_DEFAULT_PASSWORD: 1234
depends_on:
- pg
pg:
image: postgres:12
volumes:
- ./pg-data:/var/lib/postgresql/data
environment:
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
restart: always
but pgadmin logs error out as follows:
pg-admin_1 | Traceback (most recent call last):
pg-admin_1 | File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1811, in full_dispatch_request
pg-admin_1 | rv = self.preprocess_request()
pg-admin_1 | File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 2087, in preprocess_request
pg-admin_1 | rv = func()
pg-admin_1 | File "/usr/local/lib/python3.8/site-packages/flask_wtf/csrf.py", line 224, in csrf_protect
pg-admin_1 | self.protect()
pg-admin_1 | File "/usr/local/lib/python3.8/site-packages/flask_wtf/csrf.py", line 259, in protect
pg-admin_1 | self._error_response(e.args[0])
pg-admin_1 | File "/usr/local/lib/python3.8/site-packages/flask_wtf/csrf.py", line 302, in _error_response
pg-admin_1 | raise CSRFError(reason)
pg-admin_1 | flask_wtf.csrf.CSRFError: 400 Bad Request: The CSRF session token is missing.
Any suggestions?
Make sure that you close tab that were connected to pgAdmin before start the container.
Maybe you are running multiple instances of pgAdmin on the same host? At least for us this was the problem. Shutting down one of them resolved the issue.
I stumbled upon this in Azure Conatiner Apps and Container Instances. Whenever PGAdmin sits behind a load balancer or Gateway the thing that worked for me was to simply disable the Enhanced Cookie protection flag in as an .env variable.
PGADMIN_CONFIG_ENHANCED_COOKIE_PROTECTION="False"
Hope this helps someone.
For me only clearing cookies solved the problem.
Update: clearing the cookies only helps for a short time.
Upgrading pgadmin v4.25 to v6.15 had no effect - same CSRF token missing issue.
The root cause is in Ngninx proxy cookie handling (my pgadmin docker is behind nginx proxy), or rather not handling :)
I moved the pgadmin app from nginx to AWS ALB and that worked around the issue.
I added this config line to nginx server block
proxy_pass_header Set-Cookie;
and that seems to fix the issue as well.
For me there were three issues. I'm not sure which one solved it:
Disabled cloudflare cache and then purged the cache
I am using a non-standard port, 8082 instead of 5050
I removed the environment variable PGADMIN_LISTEN_PORT: 8082
Note I am still using port 8082 and can successfully log in.

Can't connect Padrino to PostgreSQL db w/ activerecord

Trying to setup the Padrino web framework to connect to my local PostgreSQL database with the following info:
databases
List of databases
| Name | Owner
|------------------------|------------
| postgres | postgres
| template0 | postgres
| template1 | postgres
|trustmob_ui_development | postgres
|trustmob_ui_production | postgres
|trustmob_ui_test | postgres
(6 rows)
config/database.rb
https://gist.github.com/1046031
ActiveRecord::Base.configurations[:development] = {
:adapter => 'postgresql',
:host => 'localhost',
:port => '5432',
:database => 'trustmob_ui_development',
:username => 'postgres',
:password => ''
}
When I try to run padrino rake ar:migrate I get the following error. Full error Gist here: https://gist.github.com/1046044
rake aborted!
ActiveRecord::ConnectionNotEstablished
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.0.9/....
Not sure what I'm doing wrong. How do I get Padrino to see/talk to the databases?
~Dan
Have you call ActiveRecord::Base.establish_connection anywhere?
Can you connect with Navicat or other programs with your code?
The config is correct? Check your settings through postgresql.conf