question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: No service definition found for 'postgres'

See original GitHub issue

Hi,

recently I am getting below error when running npx cds-pg deploy app --to postgres:

node ➜ /workspaces/cap-ratings $ npm run deploy       

> cap-ratings@0.1.0 deploy
> npx cds-pg deploy app --to postgres

[cds.connect] - No service definition found for 'postgres', as required by 'cds.requires.postgres': {
  impl: 'cds-pg',
  model: [ 'app' ],
  credentials: {
    host: 'postgres-svc',
    port: '5432',
    user: 'slonik',
    password: 'topsekret',
    database: 'cap-ratings',
    schema: 'public'
  }
}
(node:19603) UnhandledPromiseRejectionWarning: Error: No service definition found for 'postgres'
    at AsyncFunction.connect.to (/workspaces/cap-ratings/node_modules/@sap/cds/lib/connect/index.js:42:11)
    at async Object.to (/workspaces/cap-ratings/node_modules/@sap/cds/lib/deploy.js:21:23)
    at async deploy (/workspaces/cap-ratings/node_modules/cds-pg/bin/cds-pg.js:11:3)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:19603) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:19603) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
node ➜ /workspaces/cap-ratings $ 

Project setup look as follows:

cds

node ➜ /workspaces/cap-ratings $ cds -v
@sap/cds: 5.5.4
@sap/cds-compiler: 2.7.0
@sap/cds-dk: 4.5.3
@sap/cds-foss: 3.0.0
@sap/cds-odata-v2-adapter-proxy: 1.7.12
@sap/eslint-plugin-cds: 2.1.1
Node.js: v14.17.6
cap-ratings: 0.1.0
home: /workspaces/cap-ratings/node_modules/@sap/cds

.cdsrc.json

{
  "features": {
    "fiori_preview": true
  },
  "requires": {
    "db": {
      "kind": "postgres"
    },
    "postgres": {
      "impl": "cds-pg",
      "model": [
        "app"
      ]
    }
  }
}

default-env.json

{
  "PORT": 5005,
  "VCAP_SERVICES": {
    "postgres": [
      {
        "name": "postgres",
        "label": "postgres",
        "tags": [
          "postgres"
        ],
        "credentials": {
          "host": "postgres-svc",
          "port": "5432",
          "user": "slonik",
          "password": "topsekret",
          "database": "cap-ratings",
          "schema": "public"
        }
      }
    ]
  },
  "DEBUG": "ratings-service"
}

package.json

{
  "name": "cap-ratings",
  "version": "0.1.0",
  "description": "A simple CAP project.",
  "private": true,
  "dependencies": {
    "@sap/cds": "^5.5.4",
    "@sap/cds-odata-v2-adapter-proxy": "^1.7.12",
    "cds-pg": "^0.1.13",
    "express": "^4.17.1",
    "helmet": "^4.6.0",
    "passport": "^0.5.0"
  },
  "devDependencies": {
    "@sap/eslint-plugin-cds": "^2.1.1",
    "eslint": "^7.32.0",
    "eslint-config-standard": "^16.0.3",
    "eslint-plugin-import": "^2.24.2",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-promise": "^5.1.0",
    "sqlite3": "^5.0.2"
  },
  "scripts": {
    "deploy": "npx cds-pg deploy app --to postgres",
    "watch": "cds watch",
    "mock": "cds run --with-mocks --in-memory",
    "prestart": "npm run deploy",
    "start": "npx cds run",
    "build": "cds build",
    "predocker": "npm run build",
    "docker": "docker build -t pwasem/cap-ratings:latest ."
  }
}

Maybe an issue with recent @sap/cds-dk or sap/cds versions?

Thank you in advance for having a look!

Best regards,

Pascal

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sebastianeschcommented, Jan 27, 2022

Hi @pwasem,

change your .cdsrc.json to add the dialect to the postgres section:

{
  "features": {
    "fiori_preview": true
  },
  "requires": {
    "db": {
      "kind": "postgres"
    },
    "postgres": {
      "dialect": "plain", // << Add the dialect
      "impl": "cds-pg",
      "model": [
        "app"
      ]
    }
  }
}

And change your default-env.json to the tags “plain” and “db”:

{
  "PORT": 5005,
  "VCAP_SERVICES": {
    "postgres": [
      {
        "name": "postgres",
        "label": "postgres",
        "tags": ["plain", "db"], // << Change the tags here
        "credentials": {
          "host": "postgres-svc",
          "port": "5432",
          "user": "slonik",
          "password": "topsekret",
          "database": "cap-ratings",
          "schema": "public"
        }
      }
    ]
  },
  "DEBUG": "ratings-service"
}

That should do the trick.

Cheers, Sebastian

0reactions
pwasemcommented, Jan 26, 2022

Hi @pwasem,

The problem is in your default-env.json and in your deployment command.

In your default-env.json make sure to have the tags plain and/or db and in your deploy command you need to follow the example in the cds-pg README: npx cds-pg deploy srv --to db.

CAP merges the requires sections “db” and “postgres” in your package.json and actually forgets the “postgres” service and looks for the “db” service. That’s why the deploy command has --to db as a parameter. The “kind” information is also stripped during merging of the configuration values and only the “dialect” is left.

CAP then checks if there is a VCAP service whose name matches the service name (db), whose tag matches the context + ':' + service name (cds:db), whose tag match the dialect or kind (plain and undefined) or whose label matches the dialect or kind. See @sap/cds/lib/env/index.js - function _add_vcap_services_to.

Kind regards, Sebastian

@sebastianesch

How should the actual default-env.json look in this case?

Thx!

Read more comments on GitHub >

github_iconTop Results From Across the Web

PostgreSQL definition of service not found (pgAdmin, psql, ...)
Issue. Whenever I try to create a new server from pgAdmin III by setting 'service_name' under the option 'Service', I encounter this error...
Read more >
HANA Express 2.0 SP04 - Building HDI: Error No Service ...
it's saying that no service definition was found. Check that your yaml file contains all your services: db and srv services, all must...
Read more >
"Failed to logon to Database Server definition of service ...
​This issue may occur if your PostgreSQL pg_service.conf file doesn't contain the database information provided in the connection details or ...
Read more >
For Control-M/Server, when I run the command "psql", why do ...
For Control-M/Server, when I run the command "psql", why do I receive the error "PG::ConnectionBad definition of service XXXXX not found"?
Read more >
Documentation: 9.0: PostgreSQL Error Codes
Error Code Meaning Condition Name 00000 SUCCESSFUL COMPLETION successful_completion 01000 WARNING warning 0100C DYNAMIC RESULT SETS RETURNED dynamic_result_sets_returned
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found