The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →PG::ConnectionBad: connection refused is usually an endpoint or listener failure, not a bad password. Rails tried to reach the hostname, port, or Unix socket shown in the exception and found no PostgreSQL server accepting connections there. Copy that endpoint first, test it directly with pg_isready, then correct production’s DATABASE_URL, PostgreSQL listener, network rules, or provider wiring. Run migrations only after the database accepts a connection.
Need a server to try this on? Antihost offers Linux VPS plans with NVMe storage, full root access and a 14-day free trial.
What “connection refused” means in a Rails deployment
PostgreSQL uses the phrase for a client that cannot find a server to talk to at the requested TCP endpoint or Unix socket. The message does not mean that PostgreSQL received your request and rejected your credentials. As the PostgreSQL Global Development Group puts it, “Connection refused in this context does not mean that the server got your connection request and rejected it.”
As an Amazon Associate I earn from qualifying purchases.
Recommended Free Tools
That distinction determines your first move. Authentication errors happen after a server is reached; a refused connection happens before authentication. Rotating a password, changing a Rails model, or rerunning a migration cannot make a process start listening on the required endpoint.
| Exception detail | What it tells you | First check |
|---|---|---|
connection refused with a host and port |
No PostgreSQL listener answered at that TCP address, or the route is being refused. | Run pg_isready against the same host and port. |
No such file or directory for a Unix socket |
The expected local socket directory or socket file is absent. | Check whether PostgreSQL is running locally and whether Rails is unintentionally using a socket. |
Password, authentication, or pg_hba.conf rejection |
A server was reached and proceeded to access control. | Inspect credentials, SSL settings, and host-based authentication after connectivity is confirmed. |
PostgreSQL’s default TCP port is 5432 (PostgreSQL 16 documentation). Its default listen_addresses value is localhost, which allows loopback clients but not a separately hosted application. A production app therefore needs an address, port, firewall path, and authentication policy that are deliberately configured for its deployment topology.
#1 Best Overall
- BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
- EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
- COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
- LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
- WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.
Use the endpoint in the exception as your evidence
Do not begin with assumptions about where the database ought to be. Read the complete exception and record:
- the hostname or IP address;
- the port number;
- the database name, if Rails prints it;
- the Unix socket directory or file path, if the error is socket-based; and
- whether the failing release, web process, worker, or one-off command produced the message.
A surprising value is often the diagnosis. A production process trying localhost:5432 is not reaching a managed database elsewhere. A container using a private hostname from another network, or a URL with an old port, has the same practical problem even when PostgreSQL itself is healthy.
A repeatable diagnostic sequence
1. Preserve and redact the failing connection details
Copy the endpoint into your incident notes before changing variables. If the exception contains a full URL, remove the password before sharing logs. Keep the host, port, database, and socket path intact; those are the values needed for diagnosis.
Check the process environment without printing a secret-bearing URL to a public log. This Ruby command reports the URL’s scheme, host, port, and path while leaving user information and the password out of the output:
ruby -ruri -e 'u = URI(ENV.fetch("DATABASE_URL")); puts({scheme: u.scheme, host: u.host, port: u.port, database: u.path}.inspect)'
If the variable is absent, the command raises a missing-key error. That absence is itself useful: Rails may then fall back to values in config/database.yml, a local socket, or a localhost TCP endpoint.
2. Probe exactly the same host and port
From the same runtime environment as the Rails release or application process, run:
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsRank #2
- WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
- AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
- PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
- ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
- COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed
pg_isready -h "$DB_HOST" -p "$DB_PORT"
Substitute the host and port recorded from the exception. For a socket error, use the socket directory shown in the message, for example:
pg_isready -h /path/to/socket-directory -p 5432
pg_isready is a readiness probe, not a password test. PostgreSQL documents these exit statuses:
| Exit status | Meaning | Next action |
|---|---|---|
| 0 | The server is accepting connections. | Move up the stack: compare Rails’ URL, SSL options, credentials, and database name with the working endpoint. |
| 1 | The server is rejecting connections, commonly while starting. | Wait for startup to finish, inspect database logs, and probe again before releasing migrations. |
| 2 | No response was received. | Check the hostname, route, firewall or security group, port, listener interface, and whether the service is running. |
A successful readiness check proves that something at that endpoint is accepting PostgreSQL connections; it does not prove that Rails has the right password, database, SSL mode, or permissions. Conversely, a failed probe against a different host is not evidence about the endpoint Rails actually used.
3. Confirm production’s DATABASE_URL
Rails combines DATABASE_URL with config/database.yml. When the URL is present, its adapter and database values cannot be replaced by corresponding values in database.yml. This precedence can make an apparently correct YAML file irrelevant if the deployment platform injects an outdated or malformed URL.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Verify all of the following in the environment that runs the failing command:
DATABASE_URLexists in the release, web, and worker contexts that need it;- the URL uses the expected PostgreSQL scheme and points to the provider’s current hostname;
- the port is the provider’s port rather than an assumed local
5432; - the path names the intended database;
- the username is the one provisioned for that database; and
- SSL parameters required by the provider are present.
Check the variable in the platform’s dashboard or secret store as well as inside a one-off shell. A value configured for a web service may not automatically exist in a separate release command, worker, preview environment, or review app.
Rank #3
- Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
- Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
- Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
- ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
- Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)
4. Verify the PostgreSQL adapter and URL scheme
A PostgreSQL-backed Rails application must include the pg gem in its Gemfile and deploy it in the production bundle. A missing or development-only adapter normally produces a different error, but checking it prevents you from chasing a network symptom with an incomplete runtime.
Confirm that the connection URL identifies PostgreSQL and that the deployed bundle contains the same adapter expected by the Rails environment. If a platform supplies a URL with SSL requirements, preserve those parameters instead of replacing the entire URL with a hand-written localhost value.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware match5. Test migrations only after readiness succeeds
A migration command cannot repair a refused socket. First make the readiness probe succeed from the deployment environment. Then run the platform’s release, build, or pre-deploy migration hook. If a migration fails after pg_isready reports status 0, investigate authentication, database existence, permissions, schema state, or SSL negotiation rather than listener availability.
Why Rails tries localhost in production
The production variable was never injected
The most common explanation is a missing DATABASE_URL. Rails then uses the production section of config/database.yml. If that section omits a remote host, the PostgreSQL client can default to a local Unix socket or local TCP loopback. In a container or hosted dyno, “local” means that isolated machine, not your development computer and not a provider-managed database.
The wrong environment received the variable
Deployment systems often separate build, release, web, worker, and one-off command environments. A URL present during image creation may be absent during the release command, while a preview environment may retain a different value from production. Inspect the environment at the exact phase that logged the error.
A stale URL overrides correct YAML
Because Rails merges the URL with database.yml and gives the URL authority over adapter and database values, a stale platform secret can keep directing Rails to localhost even after YAML is fixed. Replace or remove the stale variable, redeploy the process that reads it, and re-run the endpoint probe.
Rank #4
- Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
- Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
- 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
- Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
- USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC
The URL was parsed differently than intended
Special characters in passwords must be URL-encoded. An unescaped character can truncate the password or alter parsing. That usually leads to authentication or parsing errors, but it can also leave the client with an unintended host or port. Inspect the parsed scheme, host, port, and path without exposing credentials.
Fixing a self-hosted PostgreSQL endpoint
Confirm the database service is running
On a self-managed server, verify that the PostgreSQL service is started and review its startup log. A service still initializing can produce readiness status 1; a stopped service generally produces status 2 or a refused TCP connection. Probe repeatedly during a controlled restart rather than launching migrations while startup is incomplete.
Check the listener and port
PostgreSQL listens on port 5432 by default, but administrators can change it. Compare the configured port with the port in Rails’ URL and with the port exposed by the host or container. Confirm that a PostgreSQL process is listening on the expected interface, not only on an internal address that the application cannot route to.
The default listen_addresses=localhost permits local loopback TCP connections only. A remote Rails process requires a reachable interface, a firewall or security-group rule allowing the chosen port, and a host name that resolves to the correct network. Exposing PostgreSQL broadly is not a safe shortcut: restrict inbound sources to the application network and use encrypted connections where the provider or topology requires them.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Match pg_hba.conf to the application network
After the listener and route work, PostgreSQL’s host-based authentication file, pg_hba.conf, must contain a rule that matches the application’s source address, database, user, and authentication method. A mismatch here normally changes the symptom from “connection refused” to an explicit access rejection, which is progress because the server has been reached.
Restart after startup-only settings change
Settings read when the server starts, including listener configuration, require a PostgreSQL restart after editing. Restart during a maintenance window, wait for readiness status 0, and only then release application traffic or migrations. Keep the firewall rule, listener address, port, and pg_hba.conf policy consistent; changing one layer cannot compensate for a blocked layer elsewhere.
Best Value
- Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
- Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
- Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
- Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
- Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.
Provider-specific wiring
Render
- Open the web service’s environment settings and set
DATABASE_URLto the Render Postgres connection string for the intended database. - Ensure the value is available to the release or pre-deploy phase that runs Rails commands, not only to the running web process.
- Provide
RAILS_MASTER_KEYwhen the application requires encrypted Rails credentials during build or boot. - Configure migrations in the build or pre-deploy command according to the service’s deployment flow.
- Deploy, open a shell in the same service context, and run
pg_isreadyagainst the host and port parsed from the URL before treating a migration failure as a schema problem.
The important Render distinction is wiring: the web service must receive the managed database endpoint, and the migration hook must run only after that endpoint is reachable.
Heroku
- Attach or provision Heroku Postgres for the application and use the connection configuration Heroku supplies rather than a localhost fallback.
- Keep the
pggem in the production bundle. - Account for Heroku Postgres TLS. Heroku’s current connection documentation (2026) requires TLS 1.2 or higher.
- If the client or driver requires it, include
sslmode=requirein the connection configuration while preserving the supplied host, port, database, and credentials. - Run the release migration only after a one-off command can reach the attached database.
A successful local connection does not validate a Heroku deployment if local PostgreSQL permits unencrypted loopback traffic while the hosted database requires TLS.
Fly.io
- Attach Managed Postgres to the Fly.io application using the platform’s supported integration.
- Confirm that the attachment stores the resulting
DATABASE_URLas an application secret and that the deployed process can read it. - Inspect the parsed host, port, and database from a Fly.io machine or release context; do not assume the endpoint is localhost.
- Place Rails migrations in the app’s
release_commandso they run as a release step rather than once per web machine. - Probe readiness before allowing the release command to proceed, and inspect service logs if the database is still starting.
Fly.io’s key failure mode is an incomplete attachment or a secret available to one process but not to the release process. Correct the attachment and secret first; changing Rails schema code will not fix a missing route.
Compare fixes by the layer they repair
| Fix path | Database model | How DATABASE_URL arrives |
Listener and firewall work | SSL/TLS consideration | Migration timing |
|---|---|---|---|---|---|
| Render Postgres | Managed PostgreSQL | Set the web service variable to the Render Postgres connection string. | Provider manages the database listener; the service must use the reachable provider endpoint. | Use the parameters supplied by the connection string. | Build or pre-deploy command. |
| Heroku Postgres | Managed PostgreSQL attached to the app | Use the attached Heroku configuration. | Provider manages listener access. | TLS 1.2 or higher; some clients require sslmode=require. |
Run in the application’s release flow after connectivity. |
| Fly.io Managed Postgres | Managed PostgreSQL attached to the app | Attachment stores DATABASE_URL as an app secret. |
Use the attachment’s network endpoint, not localhost. | Follow the supplied connection parameters. | release_command. |
| Self-hosted PostgreSQL | Your own server or private network | You provision and inject the URL. | You must configure listener address, port, routing, firewall or security group, and pg_hba.conf. |
Configure encryption and client parameters appropriate to the network. | Your release or pre-deploy hook, after readiness. |
This comparison prevents a missing provider attachment from being misdiagnosed as a bad password. Managed services remove much of the listener administration, but they still require the application to receive the correct URL and to honor provider TLS settings.
Branch troubleshooting by the probe result
pg_isready returns status 2
- Recheck the hostname for a typo, stale database, or wrong environment.
- Verify DNS resolution and that the application network can route to the address.
- Confirm the port in the URL matches the provider or self-hosted listener.
- Inspect firewall, security-group, private-network, and container-exposure rules.
- On self-hosted PostgreSQL, verify the service is running and not listening only on localhost.
pg_isready returns status 1
- Inspect PostgreSQL startup and recovery logs.
- Wait for initialization or failover to complete and probe again.
- Do not run migrations repeatedly while the server is rejecting startup connections.
pg_isready returns status 0 but Rails still fails
- Compare the exact host and port Rails parses with the values you probed; Rails may be using another environment or URL.
- Check database name, username, password encoding, and SSL parameters.
- Confirm the
pggem is included in the production bundle. - Look for an authentication, authorization, certificate, or database-not-found error that replaced the original refusal.
The exception names a Unix socket
- Determine whether the deployment is supposed to use a local PostgreSQL service. If not, inject a TCP
DATABASE_URLso Rails does not fall back to a socket. - If local PostgreSQL is intended, verify the socket directory and file exist and that the service created them.
- Check permissions for the process user and confirm the socket path in Rails matches the server’s configured path.
The endpoint is correct but connections fail intermittently
Separate startup timing from permanent configuration. A provider database waking, recovering, or failing over may briefly return readiness status 1. A permanently refused connection points back to listener, route, firewall, or port configuration. Capture timestamps, probe from the release environment, and correlate them with database and platform logs before changing credentials.
Release checklist before trying the deploy again
- The exception’s host, port, and socket path were recorded.
pg_isreadysucceeds from the same environment that runs Rails.DATABASE_URLexists in every required process and release context.- The URL’s scheme, host, port, database, and SSL options match the provider.
- The production bundle includes the
pggem. - Self-hosted PostgreSQL listens on a reachable interface and port.
- Firewall or security-group rules allow only the required application network.
pg_hba.confpermits the application source, user, and database.- Provider-specific secrets such as
RAILS_MASTER_KEYare present when required. - Migrations are attached to the correct build, pre-deploy, or release hook.
- The migration hook runs only after database readiness is established.
What not to do
- Do not rotate passwords first. A refused connection has not reached authentication.
- Do not hard-code localhost in production. It points to the application host or container, not automatically to a managed database.
- Do not expose PostgreSQL to the entire internet as a quick fix. Correct the route and restrict network sources.
- Do not treat a migration retry as a connectivity test. Use
pg_isreadyagainst the exact endpoint first. - Do not assume
database.ymlwins. A presentDATABASE_URLsupplies authoritative adapter and database values.
Final diagnosis
When Rails reports PG::ConnectionBad: connection refused, start at the endpoint, not at the password. Test the printed host, port, or socket; establish whether PostgreSQL is listening; then make production’s DATABASE_URL, provider attachment, listener address, firewall, SSL settings, and migration hook agree. Once pg_isready reports an accepting server from the deployment environment, any remaining failure is a higher-layer configuration issue that can be diagnosed with the now-reachable database.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




