"org.postgresql.util.PSQLException: Connection to localhost:5432 refused

Request description

Nous avons rencontré cette erreur pendant l’exécution d’un batch d’export. Elle est arrivée dans la nuit. Et nous avons dû relancer le traitement.
Ce qui retient notre attention c’est cette donnée: INFO,"PostgreSQL database: localhost / 5432 / mla_simplicite_01_db / mla_simplicite_01_adm

Avez vous déjà rencontré le cas où le host devient localhost? Est ce un problème de configuration de votre point de vue?

Merci par avance de vos retours.

cdt

Steps to reproduce

This request concerns an up-to-date Simplicité instance
and those are the steps to reproduce it:

Technical information

Instance /health
[Platform]
Status=OK
Version=5.1.34
BuiltOn=2022-03-08 22:43
Git=release/c918537deac7126b956c24846fa872b3c10118d2
Encoding=UTF-8
EndpointIP=172.20.50.26
EndpointURL=http://mla-api-5497bb5976-kzcjt:8080
TimeZone=Europe/Paris
SystemDate=2022-04-27 14:27:05

[Application]
ApplicationVersion=0.10
ContextPath=
ContextURL=https://app-mla.gke.ope.gcp.renault.com
ActiveSessions=26
TotalUsers=191
EnabledUsers=190
LastLoginDate=2022-04-27 14:26:55

[Server]
ServerInfo=Apache Tomcat/9.0.59
ServerType=WEB
ServerActiveSessions=26

[OS]
Name=Linux
Architecture=amd64
Version=5.4.170+
DockerImageName=centos7
SystemEncoding=UTF-8

[Disk]
DiskFree=65465
DiskUsable=65449
DiskTotal=96551

[JavaVM]
Version=17.0.2
Vendor=Eclipse Adoptium
VMName=OpenJDK 64-Bit Server VM
VMVersion=17.0.2+8
ScriptEngine=rhino
ScriptEngineVersion=Rhino 1.7.13 2020 09 02
HeapFree=991312
HeapSize=1835008
HeapMaxSize=14262272
TotalFreeSize=13418576

[Cache]
GrantCache=0
GrantCacheMax=0
GrantCacheRatio=0
ObjectCache=2619
ObjectCacheMax=10000
ObjectCacheRatio=26
ProcessCache=8
ProcessCacheMax=10000
ProcessCacheRatio=0

[Database]
Vendor=3
ProductName=PostgreSQL
ProductVersion=11.13
DriverName=PostgreSQL JDBC Driver
DriverVersion=42.3.3
DBDate=2022-04-27 14:27:05
DBDateOffset=0
DBPatchLevel=5;P01;74fd319f80dece922d5e649c650e8f9b
UsingBLOBs=true

[Healthcheck]
Date=2022-04-27 14:27:05
ElapsedTime=19
Simplicité logs
gke-gke-irn-70740-ope-ext--ope-ext-np-cb2388f6-d6tp,mla-api,ope,IRN-70907,5497bb5976,mla-70907,mla,projects/irn-70740-ope-ext-2d/logs/stdout,,2022-04-17T04:05:09.535041364Z,,gke-irn-70740-ope-ext-cluster-1,mla-api,europe-west1,mla-70907-ope-ext,mla-api-5497bb5976-z29jc,irn-70740-ope-ext-2d,k8s_container,INFO,"org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
	at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:319)
	at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
	at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:223)
	at org.postgresql.Driver.makeConnection(Driver.java:400)
	at org.postgresql.Driver.connect(Driver.java:259)
	at org.apache.tomcat.dbcp.dbcp2.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:52)
	at org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:415)
	at org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:559)
	at org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:298)
	at org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:223)
	at org.apache.tomcat.dbcp.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:141)
	at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:731)
	at com.simplicite.util.engine.DBAccess.getConnection(DBAccess.java:227)
	at com.simplicite.util.engine.DBAccess.query(DBAccess.java:602)
	at com.simplicite.util.engine.ObjectManager.search(ObjectManager.java:401)
	at com.simplicite.util.engine.ObjectManager.search(ObjectManager.java:307)
	at com.simplicite.util.engine.ObjectDirect.search(ObjectDirect.java:302)
	at com.simplicite.util.ObjectDB.search(ObjectDB.java:880)
	at com.simplicite.util.engine.ObjectManager.searchExport(ObjectManager.java:549)
	at com.simplicite.util.engine.ObjectDirect.searchExport(ObjectDirect.java:319)
	at com.simplicite.util.ObjectDB.searchExport(ObjectDB.java:919)
	at com.simplicite.util.tools.CSVTool.objectToCSV(CSVTool.java:349)
	at com.simplicite.util.tools.CSVTool.export(CSVTool.java:492)
	at com.simplicite.objects.mla_export_file.MlaFile.generateExportFile(MlaFile.java:408)
Browser logs
{

  "textPayload": "2022-04-17 04:05:06.776 UTC [1159363]: [1-1] db=,user= **FATAL:  terminating connection due to administrator command"**,

  "insertId": "s=0bf1ad7d6d954aacb855eba508170a58;i=f501c78;b=8e61c2bd9c4146b0a681a797080d9461;m=b2b66d44b97;t=5dcd1bfbebb98;x=5aa03a872ba679e6-0-0@a1",

  "resource": {

    "type": "cloudsql_database",

    "labels": {

      "region": "europe",

      "project_id": "irn-70907-ope-bd",

      "database_id": "irn-70907-ope-bd:pg-mla-70907-01-b7fe0fc6"

    }

  },

  "timestamp": "2022-04-17T04:05:06.776984Z",

  "severity": "ALERT",

  "labels": {

    "LOG_BUCKET_NUM": "75"

  },

  "logName": "projects/irn-70907-ope-bd/logs/cloudsql.googleapis.com%2Fpostgres.log",

  "receiveTimestamp": "2022-04-17T04:05:08.227666425Z"

}
Other relevant information

----E.g. type of deployment, browser vendor and version, etc.----

La database est un datasource managé par le serveur Tomcat. C’est déclaré dans le fichier /usr/local/tomcat/webapps/ROOT/META-INF/context.xml

Dans le code Simplicité on demande une connexion à ce datasource sans connaitre aucune de ses caractéristiques : ni host, ni port, ni username, ni password, etc.

Ca se voit d’ailleurs dans le stacktrace fournie où, au dessus de getConnection, on est dans les couches Tomcat et du driver JDBC PostgreSQL.

Bref, s’il y a bien une “confusion” inexplicable à un moment sur le hostame, c’est un pb au niveau Tomcat ou du driver JDBC PostgreSQL (ou de l’infra sous jacente), pas à notre niveau. Je vous laisse investiguer dans les forums liés à ces produits si d’autres personnes ont pu connaitre un pb similaire (ex: peut être que si le hostname déclaré dans la config du datasource n’est plus résolvable - au sens DNS - par le driver JDBC, il y a un fallback sur localhost… mais ça me semblerait étrange…)

En tout cas personnellement ça ne me dit absolument rien.

1 Like

Bonjour David,
Merci du retour.

Bonjour Thierry,
à ma connaissance, nos DevOps ont choisi un pattern d’intégration spécifique à GCP qui implémente un concept de “proxy SQL” qui est instancié dans le container (donc localhost) et qui assure la mise en relation avec l’équivalent AWS de la notion de BD managée.
→ il faut avant tout demander une analyse à nos DevOps car ce choix d’intégration me semble spécifique au monde Renault GCP…

C’est différent sur AWS ou en intra où on accède à une BD explicitement désignée par un hostname connu de nos DNS et du network de la grappe.

1 Like

Salut Bruno,
Je vais effectivement voir avec eux. Merci de ton retour.

cdt

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.