Postgres connect to database with URL
Published on
Last updated on
2 min read • --- views
Very often, cloud database services such as neon.tech allow you to connect via URL.
That is, without credentials such as user, password, etc.
Connection details
Connection URL
It's official PostgreSQL format for connection URLs
Base URL and path
Here's an example of a base URL and path structure using uppercase placeholder values:
postgresql://USER:PASSWORD@HOST:PORT/DATABASE
How this site connects to the database
Store your credentials in .env
Store your credentials in your .env file.
PGHOST='<endpoint_hostname>:<port>' PGDATABASE='<dbname>' PGUSER='<username>' PGPASSWORD='<password>' ENDPOINT_ID='<endpoint_id>'
where:
endpoint_hostnamethe hostname of the branch endpoint. The endpoint hostname has an ep- prefix and appears similar to this: ep-tight-salad-272396.us-east-2.aws.neon.techdbnameis the name of the database. The default Neon database is neondbuseris the database userpasswordis the database user's password, which is provided to you when you create a projectendpoint_idis the ID of the branch endpoint that you are connecting to. The endpoint_id has an ep- prefix and appears similar to this: ep-tight-salad-272396
Use prisma.io to connect Postgres
// You can create DATABASE_URL in your code const DATABASE_URL = `postgres://${PGUSER}:${PGPASSWORD}@${PGHOST}/${PGDATABASE}`;
# Or better to use .env file datasource db { provider = "postgresql" url = env("DATABASE_URL") referentialIntegrity = "prisma" }
Use Datagrip to connect Postgres
You can use same credentials like HOST, PORT, USER, PASSWORD, DATABSE for connection to Database with
DataGrip.
Related Content
- Installing PostgreSQL on macOS - step-by-step setup guide
- SQL Countries Table - ready-to-use seed data for your database
You might also like:
Conventional Commits
--- views
Master Conventional Commits to write clear, structured commit messages. Learn the format, types like feat and fix, and how to automate changelog generation.
Why Are JavaScript Naming Conventions Important?
--- views
Master JavaScript naming conventions with this guide. Learn best practices for naming variables, functions, and classes to write cleaner code.
How to decrease deployment time by 44% with pnpm
--- views
Migrate from npm to pnpm and cut your deployment time by 44%. Step-by-step guide covering installation, lockfile conversion, and CI/CD configuration.
Share it: