Could not connect to server connection refused postgresql windows

I have a problem to connect server for Postgres after I updated my windows.Before I update there is no problem to open the database. My database in Postgres also gone. When I want to create my new

I have a problem to connect server for Postgres after I updated my windows.Before I update there is no problem to open the database. My database in Postgres also gone. When I want to create my new database it show this error:

Unable to connect to server: could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host «localhost» (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host «localhost» (127.0.0.1) and accepting TCP/IP connections on port 5432?

a_horse_with_no_name's user avatar

asked Nov 10, 2016 at 16:23

SySyBy's user avatar

6

On windows, Just go to the ‘Services’. Start/Restart the postgresql-X64 service. It worked for me as my service was in stopped state somehow.

answered Feb 23, 2020 at 7:06

gagan chhabra's user avatar

gagan chhabragagan chhabra

1,3151 gold badge8 silver badges9 bronze badges

4

There are two items to configure if your server isn’t on localhost:

  • find your postgresql.conf and add your server’s public IP address to the end of the setting listen_addresses (separate multiple entries by commas); uncomment the line if it is commented out (e.g. with ‘#’)
  • add a line to pg_hba.conf containing your client’s IP address — you may copy the line containing 127.0.0.1 and change only the IP address

On Ubuntu, these files are in /etc/postgresql/<version>/main/.

answered Mar 14, 2017 at 1:12

Franc Drobnič's user avatar

1

In my case I couldnt’ open the pgAdmin4, for some reason. I use Postgresql 10 and pgAdmin4

The port in the postgresql.conf was not the same as in the pgAdmin4 —> postgreSQL 10 —> properties —> Connection —> port.

I fixed it and it worked. Check if those 2 are in line.

answered Sep 12, 2020 at 13:55

Andreas Alamanos's user avatar

2

First press win key+R
Search for services.msc
A window will open in that find postgresql-x64-13 and open that, in that tab click start option
For me its works perfectly.

answered May 31, 2021 at 5:03

VADHAN's user avatar

VADHANVADHAN

2213 silver badges2 bronze badges

1

  1. Go to PgAdmin
  2. Right click on PostgreSQL
    3.Choose properties
  3. At the top, select connection
  4. Try changing the port from 5433 to 5432 or vice versa.

And re-enter.

answered May 15, 2021 at 17:27

Никита Мельников's user avatar

1

Faced this problem immediately after installing on Windows. At startup the pgAdmin gave this error which means that the server is not running. For me the solution was: Start -> Control panel -> Administration -> Services -> postgresql-x64-12 — start or restart

answered Aug 7, 2020 at 21:49

Tim  Uzlov's user avatar

Tim UzlovTim Uzlov

1712 silver badges6 bronze badges

On windows, Just go to the ‘Services’. Start/Restart the postgresql-X64 service. It worked for me as my service was in stopped state somehow.

worked for me

answered Sep 10, 2020 at 18:00

devyan91's user avatar

devyan91devyan91

791 silver badge6 bronze badges

This happened because I installed two versions of Postgres (v12 and v13). Psql 12 was installed later so got the port 5433. I needed to use Postgres 12. To fix this particular case:

  • Go to Program Files/Postgres/<required_version>/data

    Open the postgresql.conf file

    Search for Port and change the port number to 5432.

  • Open Windows Services (Press Cmd + R then type services.msc)

  • Stop the service for the version you don’t want (You can stop it permanentally from the Right Click > Properties menu.)

  • Start the service for the version you want.

answered Aug 7, 2021 at 14:30

Nitin Nain's user avatar

Nitin NainNitin Nain

4,8921 gold badge38 silver badges51 bronze badges

I think the problem is with your server listening to default public IP address.
For example in the PostgreSQL package, your sever is set to listen to localhost as default public address which when you launch/ run database, the address might be something like ‘127.0.0.1’

To fix you can try change localhost to ‘‘ as in «listen_addresses = ‘‘».

As seen as "listen_addresses = 'localhost'" under «Connection Settings» in the postgresql.conf file.

Also to access your postgresql.conf file, go to:

On Windows, the file is in /Program Files/PostgreSQL/<version>/share/.
On Ubuntu, these files are in /etc/postgresql/<version>/main/.

P.S: Changing the defaults ‘localhost’; to ‘*’ will let your server listen to any public database address either «localhost, 127.0.0.1 etc.

I know you might have fix this, just for others that might run into the same issue in the future. Hope it was helpful

Harsha Biyani's user avatar

answered Jul 31, 2019 at 14:41

Damilare Oyediran's user avatar

Solutions:

  1. Open Services and make sure that postgresql-x64-14 is running.

  2. Go to C:Program FilesPostgreSQL14data and open postgresql.conf with notepad, find and change port to e.g 5432 and after that open Services and restart postgresql-x64-14.

answered Apr 11, 2022 at 16:06

Mace's user avatar

MaceMace

966 bronze badges

1

goto service and start postgresql-x64-10 service

steps

  • run -> services.msc -> find postgresql-x64-10 -> start the service
  • services image

answered Mar 12, 2021 at 14:33

B G's user avatar

This is a note for a normal user. If using an official installer, it should have a built-in service,

  1. Win+R and type services.msc
  2. Search Postgres service based on the version installed, e.g., «postgresql-x64-13 - PostgreSQL Server 13«
  3. Click stop, start, or restart the service option
  4. If you don’t see start/stop or if these buttons are disabled, then double-click on the PostgreSQL and change startup type to automatic and click on start. This will start the PostgreSQL every time automatically whenever you start your system.

answered Jul 6, 2021 at 2:54

Manoj Swami's user avatar

Manoj SwamiManoj Swami

672 silver badges12 bronze badges

1

I had the same issue, so, I uninstalled postgres. And during reinstallation I noticed the error:
"Failed to load SQL modules into the database cluster"
And:
"Problem running post installation step.Installition may not complete correctly. Error reading file C:/Program Files/PostgreSQL/14/data/postgresql.conf".

I cancelled the installation and then tried again, but with a plain-text password this time, and it worked. It turned out that the special characters in my password were the problem.

ouflak's user avatar

ouflak

2,43810 gold badges43 silver badges49 bronze badges

answered Oct 1, 2021 at 14:48

KanjooM's user avatar

When I run psql, it gave me the same error, and it was because I changed the port while setting Postgres in the installation process.

I had to change back to the default port 5432 in PostgreSQL.conf (which can be found in the data directory) i.e

C:Program FilesPostgreSQL14data>

The problem is no more!

answered Jul 19, 2022 at 15:19

James Karino Simel's user avatar

1

I got this error message when I moved my database to another computer.

I also got some error messages when starting the server first with

pg_ctl -D /wherever/your/database/is start

which were

pg_ctl: another server might be running; trying to start server anyway
server starting

DETAIL: File «/wherever/your/database/is/PG_VERSION» does not contain valid data.

HINT: You might need to initdb.

In my case rather than running initdb this command actually fixed the issue

pg_ctl -D /wherever/your/database/is restart

answered May 10, 2018 at 13:42

uosjead's user avatar

uosjeaduosjead

4166 silver badges5 bronze badges

You might have changed the permissions of the ‘PostgreSQL 12’ in ‘services.msc’. Or maybe it is not started and you are trying to start the server when Postgre 12 is not running.

Try these:

  1. Try to start the ‘PostgreSQL 12’ in ‘services.msc’ manually.
  2. Try restarting your PC
  3. If nothing helps, try reinstalling PostgreSQL (pgAdmin 4) from the scratch.

answered Mar 30, 2021 at 12:18

Nirmal's user avatar

Go to C:Program FilesPostgreSQL13data, edit postgresql.conf with notepad.

Change:

#port = 54XX

To:

port = 54XX

(change requires restart)

restart service at «service system» on window.

Tony Joseph's user avatar

Tony Joseph

1,7822 gold badges16 silver badges17 bronze badges

answered Apr 20, 2021 at 17:54

Charlycris's user avatar

Using psql with single quotes fails:

psql -c 'Select version();' 'postgresql://username:password@db.abcdefghi.ap-southeast-2.rds.amazonaws.com:8080/the_db'

psql: could not connect to server: Connection refused
(0x0000274D/10061)
Is the server running on host «localhost» (::1) and accepting
TCP/IP connections on port 5432? could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host «localhost» (127.0.0.1) and accepting
TCP/IP connections on port 5432?

Using double quotes works:

psql -c "Select version();" "postgresql://username:password@db.abcdefghi.ap-southeast-2.rds.amazonaws.com:8080/the_db"

PostgreSQL 10.14 on x86_64-pc-linux-gnu, compiled by x86_64-unknown-linux-gnu-gcc (GCC) 4.9.4, 64-bit
(1 row)

answered Jul 14, 2021 at 1:40

Jeremy Thompson's user avatar

Jeremy ThompsonJeremy Thompson

59.7k32 gold badges184 silver badges308 bronze badges

After a wasting 3-4 hrs i find the solution something like this

First set path in enviroment variable.And then make port and psql connecting same i.e 5432 or 5433

answered Sep 18, 2021 at 3:21

Ashok Mehta's user avatar

If you newly installed the pgAdmin, and you did not remember to install PostgreSQL at that time, you get that error. Make sure you install both pgAdmin And PostgreSQL.

Anurag A S's user avatar

answered Jan 6, 2022 at 11:14

sanket Walunj's user avatar

For me I was getting this error and unable to open the server in PgAdmin is because I very often forgot to start the server, one for the way you can start the server with is by running this commands on cmd, make sure you provide the right path

cd "C:Program FilesPostgreSQL14bin"
pg_ctl -D "C:Program FilesPostgreSQL14data" start

answered Apr 13, 2022 at 6:42

DINA TAKLIT's user avatar

DINA TAKLITDINA TAKLIT

5,8829 gold badges61 silver badges72 bronze badges

And so for the new arrivals. If you are using pgAdmin and a Windows operating system, do some research to resolve the issue.

Make sure you have Postgresql installed or active

  • To do this, go to windows services (press Cmd + R and run the services.msc command)

  • Look in the list for a service called postgresql-x{BIT}-{Version}-PostgreSQL Server {Version}

    enter image description here

Solution 1: If you don’t find the service, then PostgreSQL is not installed or has been uninstalled, install it again.

Solution 2: If you find the service, but you still can’t log in, then most likely the service is not active for some reason, select the service and click the Start or Restart button

answered Mar 24, 2022 at 4:41

Harvey Dent's user avatar

Harvey DentHarvey Dent

1,9113 gold badges8 silver badges15 bronze badges

An incorrect entry in the configuration file or firewall restriction generally triggers PostgreSQL connection refused error.

As a part of our PostgreSQL Management Services, we help webmasters and web hosts resolve PostgreSQL such as this every day.

postgresql connection refused

Today let’s discuss the top reasons for connection refused error in PostgreSQL and how to resolve the error.

What triggers PostgreSQL connection refused error?

PostgreSQL is a highly extensible and handy database management system. And thus it is one of the popular database systems.

But many times, when users try to connect to psql it ends up in connection errors. psql is the interactive terminal-based program, that enables PostgreSQL queries.

A typical error message looks like

Error: psql: could not connect to server: Connection refused Is the server running on host “xxx.xxx.xxx.xxx” and accepting TCP/IP connections on port 5432?

When the PostgreSQL’s server daemon is not running in the server, it can trigger connection refused error. At the same time, several other reasons can also trigger this error.

Let’s discuss a few reasons why the psql service fails. We will also discuss how our Support Engineers fix this error.

PostgreSQL service status

First parameter to cross-check during a psql connection refused error is the status of the PostgreSQL service.

We can confirm this by cross-checking if a Postgres process in running in the server. In a Linux like environment, we can use

ps -ef | grep postgres
service postgresql status

If the service is not running in the server, then we restart it using the command.

service postgresql restart

At times, this failure could be a result of a corrupted Postgresql service. A reinstall of the service with the apt-get install or yum install would be required to fix the issue.

Enable TCP/IP connections

If the error is not related to the failed status of the service, it is more likely to be related to TCP/IP connections disabled in the Postgresql configuration file.

To correct this, we need to edit posgresql.conf file. The file location in Ubuntu and Centos is :

In Ubuntu: vi /etc/postgresql/9.5/main/posgresql.conf

in CentOS 7: vi /usr/pgsql-10/share/postgresql.conf

The listen_address parameter in the configuration file determines the restrictions on TCP/IP connections. To allow TCP/IP connections, from all IP addresses it should be set to 0.0.0.0.  Alternatively, to allow connections to the specific IP address of the server, listen_address parameter need to be edited with only those IP addresses.

If this configuration is left blank or set to localhost, PostgreSQL will not allow external TCP/IP connections.

Finally, we restart the service to save the changes.

Allow remote host

If the users are not able to connect to psql from a remote IP, then also we get the same error.

In this case, the Support Team edits the postgresql.conf file and allow the IP from which the customer is trying to access.

Finally, we restart the service to save the changes.

Firewall restrictions

At times, the restrictions placed by the server firewall can also trigger connection refused error.

If the psql port 5432 is not open for connection or if there is any restriction on the IP address from which the TCP/IP connection occurs, it may trigger connection refused error.

Our Support engineers cross-check the firewall for any restrictions and then remove them to fix the issue.

[Still, having trouble connecting PostgreSQL? – We will fix it for you.]

Conclusion

In short, several reasons can trigger the PostgreSQL connection refused error. This includes corrupted Postgresql service, firewall restrictions, incorrect entries in the configuration file etc. We saw the top 4 reasons for this error and how our Support Engineers fix them.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = «owonCMyG5nEQ0aD71QM»;

The PostgreSQL error “Could not connect to server” can happen for various reasons. Often it is enough to restart the open source database management system or adjust the TCP/IP settings.

Contents

  1. Requirements
  2. “Could not connect to server: No such file or directory”
  3. “Could not connect to server: Connection refused”

Requirements

  • Cloud Server running Linux (CentOS 7 or Ubuntu 16.04)
  • PostgreSQL installed and running.

vServer (VPS) from IONOS

Low-cost, powerful VPS hosting for running your custom applications, with a personal assistant and 24/7 support.

100 % SSD storage

Ready in 55 sec.

SSL certificate

“Could not connect to server: No such file or directory”

The PostgreSQL error “Could not connect to server: No such file or directory” usually means that PostgreSQL is not running. However, the error is actually often related to issues withpermission.

First, use the systemctl status postgresql command to check PostgreSQL’s status:

user@localhost:~# systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
   Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
   Active: **active** (exited) since Thu 2017-03-23 21:34:03 UTC; 14s ago
 Main PID: 24289 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/postgresql.service
Mar 23 21:34:03 localhost.localdomain systemd[1]: Starting PostgreSQL RDBMS...
Mar 23 21:34:03 localhost.localdomain systemd[1]: Started PostgreSQL RDBMS.
Mar 23 21:34:08 localhost.localdomain systemd[1]: Started PostgreSQL RDBMS.

If the status is shown as active, restart PostgreSQL with the systemctl restart postgresql command. If the status is shown as inactive, start PostgreSQL with the systemctl start posgresql command.

If a restart does not fix the problem, look at the permissions of your directory with the path /var/lib/postgresql/9.6/main. The version number 9.6 may differ depending on your installation. It is expected that permissions for folders are set to “0700” and permissions for files are set to “0600”. This means that folders must have read, write, and execute permissions, and files must have read and write permissions. Use the ls command in the path above to display current permissions.

If you find permissions are different, run the following commands in the command line:

sudo chown -R postgres:postgres /var/lib/postgresql/9.6/
sudo chmod -R u=rwX,go= /var/lib/postgresql/9.6/

Restart PostgreSQL as shown above.

“Could not connect to server: Connection refused”

Another variant of the PostgreSQL error is “Could not connect to server: Connection refused”.

First, use the systemctl-status postgresql command to verify that PostgreSQL is running. To be sure that PostgreSQL is running, you can also restart it with systemctl restart postgresql.

If this does not fix the problem, the most likely cause of this error is that PostgreSQL is not configured to allow TCP/IP connections.

To correct this, edit your posgresql.conf file. These can be found in one of the following file paths, depending on your Linux distribution:

  • Ubuntu 16.04: sudo nano /etc/postgresql/9.5/main/posgresql.conf
  • CentOS 7: sudo nano /usr/pgsql-10/share/postgresql.conf

Check the listen_address configuration. To allow TCP/IP connections, it should be set to “0.0.0.0” (to allow connections from all IP addresses) or to the specific IP address of the server it will allow to connect.

If this configuration is left blank or set to localhost, PostgreSQL will not allow external TCP/IP connections. This also corresponds to the default setting of PostgreSQL.

PostgreSQL will not be able to connect to the server when the connection is blocked by a firewall. Note that all Cloud Servers are affected by the default Firewall Policy which is controlled from the Cloud Panel.

Cloud backup from IONOS

Make costly downtime a thing of the past and back up your business the easy way!

Related articles

PostgreSQL

PostgreSQL: a closer look at the object-relational database management system

The PostgreSQL database management system, also known to many as Postgres, has many decades of development behind it. It originally started as a project at Berkeley University in California. Today, the open source database continues to defy solutions from commercial competitors, since the development team is constantly working on its functionality and performance. But what exactly is PostgreSQL?…

PostgreSQL: a closer look at the object-relational database management system

Change the PHP Version on a Plesk Server

Change the PHP Version on a Plesk Server

Learn how to change the PHP version for a server with Plesk. This tutorial includes instructions on how to find the PHP version your Plesk server is using, change to a different PHP version, and install a different PHP version if necessary.

Change the PHP Version on a Plesk Server

Fixing SSH Errors

Fixing SSH Errors

Learn how to resolve some of the most common errors you may receive when connecting to a server with SSH. You can find the most common errors in this guide.

Fixing SSH Errors

Install PostgreSQL on Windows Server 2016

Install PostgreSQL on Windows Server 2016

PostgreSQL is an open source object-relational database system with over 15 years of active development and a reputation for reliability. Learn how to install PostgreSQL on Windows Server 2016.

Install PostgreSQL on Windows Server 2016

PostgreSQL backup

PostgreSQL backup with pg_dump and pg_restore

Creating database backups is one of the standard tasks of web and system admins. Each database management system comes with its own tools for creating backups. PostgreSQL has the command line programs pg_dump and pg_restore. The command line interface psql is also used. We’ll present you with the most common backup scenarios with examples of the required code.

PostgreSQL backup with pg_dump and pg_restore

When connecting to a PostgreSQL server, you may get an error message. If you
encounter an error message, please review the message carefully; each error
message attempts to incorporate the information you’ll need to resolve the
problem. For more details about specific errors, please locate the error
message in the list below:

Connection to the server has been lost

Connection to the server has been lost

This error message indicates that the connection attempt has taken longer than
the specified threshold; there may be a problem with the connection properties
provided on the Server dialog, network connectivity issues, or the server may
not be running.

could not connect to Server: Connection refused

Could not connect to server

If pgAdmin displays this message, there are two possible reasons for this:
  • the database server isn’t running — simply start it.

  • the server isn’t configured to accept TCP/IP requests on the address shown.

For security reasons, a PostgreSQL server “out of the box” doesn’t listen on
TCP/IP ports. Instead, it must be enabled to listen for TCP/IP requests. This
can be done by adding listen_addresses=’*’; this will make the server accept
connections on any IP interface.

For further information, please refer to the PostgreSQL documentation about
runtime configuration.

FATAL: no pg_hba.conf entry

No pg_hba.conf entry

If pgAdmin displays this message when connecting, your server can be contacted
correctly over the network, but is not configured to accept your connection.
Your client has not been detected as a legal user for the database.

To connect to a server, the pg_hba.conf file on the database server must be
configured to accept connections from the host of the pgAdmin client. Modify
the pg_hba.conf file on the database server host, and add an entry in the form:

  • host template1 postgres 192.168.0.0/24 md5 for an IPV4 network

  • host template1 postgres ::ffff:192.168.0.0/120 md5 for an IPV6 network

For more information, please refer to the PostgreSQL documentation about
client authentication.

FATAL: password authentication failed

Password authentication failed

The password authentication failed for user error message indicates there
may be a problem with the password you entered. Retry the password to confirm
you entered it correctly. If the error message returns, make sure that you have
the correct password, that you are authorized to access the server, and that
the access has been correctly configured in the server’s postgresql.conf
configuration file.

OS: Windows 7 64-bit

На рабочем компьютере потребовалось переустановить PostgreSQL.

После переустановки при попытке подключения к серверу PostgreSQL 9.3 (localhost: 5432) и создания нового сервера localhost (localhost: 5432) — появляется окно с ошибкой:

«Server doesn’t listen
The server doesn’t accept connections: the connection library reports
could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host «localhost» (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host «localhost» (127.0.0.1) and accepting TCP/IP connections on port 5432?

If you encounter this message, please check if the server you’re trying to contact is actually running PostgreSQL on the given port. Test if you have network connectivity from your client to the server host using ping or equivalent tools. Is your network / VPN / SSH tunnel / firewall configured correctly?

For security reasons, PostgreSQL does not listen on all available IP addresses on the server machine initially. In order to access the server over the network, you need to enable listening on the address first.

For PostgreSQL servers starting with version 8.0, this is controlled using the «listen_addresses» parameter in the postgresql.conf file. Here, you can enter a list of IP addresses the server should listen on, or simply use ‘*’ to listen on all available IP addresses. For earlier servers (Version 7.3 or 7.4), you’ll need to set the «tcpip_socket» parameter to ‘true’.

You can use the postgresql.conf editor that is built into pgAdmin III to edit the postgresql.conf configuration file. After changing this file, you need to restart the server process to make the setting effective.

If you double-checked your configuration but still get this error message, it’s still unlikely that you encounter a fatal PostgreSQL misbehaviour. You probably have some low level network connectivity problems (e.g. firewall configuration). Please check this thoroughly before reporting a bug to the PostgreSQL community. «

В интернете чаще всего советуют проверить корректиность pg_hba.conf.
Сравнил свой файл с файлом коллеги с работающим PostgreSQL — файлы идентичны.

Подскажите, пожалуйста, как решить проблему или в каком направлении искать решение?

UPD:
В службах при попытке запустить postgresql-службу появляется окно с текстом:

«Служба «postgresql-x64-9.3» на «Локальный компьютер» была запущена и затем остановлена. Некоторые службы автоматически останавливаются, если они не используются другими службами или программами.»

To avoid “Connection refused”, Configuration is required for client to access PostgreSQL database server.

When trying to connect to a new PostgreSQL database, the following error occurred:

C:Program Files (x86)pgAdmin 4v1runtime>psql -h 192.168.78.51 -d postgres
psql: could not connect to server: Connection refused (0x0000274D/10061)
 Is the server running on host "192.168.78.51" and accepting
 TCP/IP connections on port 5432?
Check postgresql server is up and running
$ systemctl status postgresql-9.6

● postgresql-9.6.service - PostgreSQL 9.6 database server
 Loaded: loaded (/usr/lib/systemd/system/postgresql-9.6.service; enabled; vendor preset: disabled)
 Active: active (running) since Sun 2017-07-16 18:08:47 AEST; 15min ago
 Process: 1238 ExecStartPre=/usr/pgsql-9.6/bin/postgresql96-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 1243 (postmaster)
 CGroup: /system.slice/postgresql-9.6.service
 ├─1243 /usr/pgsql-9.6/bin/postmaster -D /var/lib/pgsql/9.6/data/
 ├─1246 postgres: logger process
 ├─1248 postgres: checkpointer process
 ├─1249 postgres: writer process
 ├─1250 postgres: wal writer process
 ├─1251 postgres: autovacuum launcher process
 ├─1252 postgres: stats collector process
 └─1822 postgres: postgres postgres 192.168.78.1(56572) idle
From client telnet to server
C:Userspostgres>telnet 192.168.78.51 5432
Connecting To 192.168.78.51...Could not open connection to the host, on port 5432: Connect failed
From server check listener port 5432 not opened on IP 192.168.78.1
$ netstat -ntl|grep 5432
tcp  0 0 127.0.0.1:5432 0.0.0.0:* LISTEN
tcp6 0 0       ::1:5432 :::*      LISTEN
Allow remote IP address to access PostgreSQL
$ su - postgres
$ vi /var/lib/pgsql/9.6/data/pg_hba.conf

...
..
.

# IPv4 local connections:
host all all 127.0.0.1/32 ident
host all all 192.168.78.51/24 md5
...
..
.
Edit /var/lib/pgsql/9.6/data/postgresql.conf

# – Connection Settings –

...
..
.
listen_addresses = '192.168.78.51,localhost' # what IP address(es) to listen on;
 # comma-separated list of addresses;
 # defaults to 'localhost'; use '*' for all
 # (change requires restart)
port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
...
..
.
Stop and Start PostgreSQL server
$systemctl status postgresql-9.6

$systemctl stop postgresql-9.6

$systemctl start postgresql-9.6
Connect to PostgreSQL database successfully
C:Program Files (x86)pgAdmin 4v1runtime>psql -h 192.168.78.51 -d postgres -U postgres
Password for user postgres:
psql (9.6.3)
WARNING: Console code page (850) differs from Windows code page (1252)
 8-bit characters might not work correctly. See psql reference
 page "Notes for Windows users" for details.
Type "help" for help.

postgres=# l
 List of databases
 Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
 postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
 template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
 | | | | | postgres=CTc/postgres
 template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
 | | | | | postgres=CTc/postgres
(3 rows)

Problem scenario
With a SQL front end (e.g., pgAdmin or HeidiSQL) you get this error «could not connect to server: Connection refused 0x0000274D/10061) Is the server running on host «x.x.x.x» and accepting TCP/IP connections on port 5432?

You double checked you are trying to connect to the correct IP address (x.x.x.x).  You know port 5432 is not blocked.  You know the postgres service is listening on port 5432 on the destination server. How do you fix this problem?

Solution
With Postgres version 9 on Ubuntu 16.x, the «postmaster» service does not need to be running.  One of these below may solve the problem by itself.

Possible solution #1  Go to the server with Postgres.  Find the postgresql.conf file (e.g., with this find / -name postgresql.conf).  Find the listen_addresses stanza.  Make sure the server’s own IP address is listed next to the «localhost,» text separated by a space.  A common mistake is to have the IP address of a Postgres client.  The Postgres server’s IP address is the one that is needed.  Here is how it should look where x.x.x.x is the IP address of the PostgreSQL server:

listen_addresses = ‘localhost, x.x.x.x’      # Replace x.x.x.x with the IP address of the Postgres server.

Possible solution #2  Go to the /etc/hosts file.  Make sure that one IP address to DNS name maps «localhost» to the server’s IP address.

Possible solution #3  Make sure that postgresql.conf file does not have this stanza:

tcpip_socket = true

It used to be necessary.  This stanza will now cause this «connection refused» error.  Remove this stanza if it is there.


Like this post? Please share to your friends:
  • Copytrans photo для windows скачать бесплатно
  • Copytrans iphone transfer tool windows скачать
  • Copytrans heic для windows что это
  • Copytrans heic для windows скачать бесплатно торрент
  • Copytrans heic для windows 10 скачать бесплатно на русском