转自 http://www.cyberciti.biz/faq/postgresql-remote-access-or-connection/
Q. When I try to connect remote Postgresql,I am reciving an error which read as follows:
psql: Could not connect to server: Connection refused
Is the server running on host host.domain.com and accepting
TCP/IP connections on port 5432?
How do I fix this problem? I am using CentOS 4.x version.
A. First make sure Postgresql server has been started to Remote Server.
# /etc/init.d/postgresql start
If it is running and you get above error,you need to add enable TCP/IP support. By default,the Postgresql server only allows connections to the database from the local machine or localhost. This is a security feature.
Step # 1: Allow remote IP address to access Postgresql
You need to open file called /var/lib/pgsql/data/pg_hba.conf. Login as postgres user using su command:$ su - postgres
$ vi /var/lib/pgsql/data/pg_hba.conf
Now append following line. Let us say you would like to give access to 192.168.1.0/24 network:host all all 192.168.1.0 255.255.255.0 trust
Please replace 192.168.1.0 and 255.255.255.0 to reflect the actual network IP address range of the clients system in your own network.
Save close the file.
Step # 2: Allow communication over TCP/IP
You need to open Postgresql configuration file /var/lib/pgsql/data/postgresql.conf$ vi /var/lib/pgsql/data/postgresql.conf
Now bind and open TCP/IP port by setting tcpip_socket to true:tcpip_socket = true
Save and close the file.
Step # 3: Restart Postgresql server
Restart the Postgresql server with the following command# /etc/init.d/postgresql restart
This will open default port 5432.
Step # 4: Test your setup
Use psql command from client system as follows:
psql -h Postgresql-IP-ADDRESS -U USERNAME -d DATABASENAME
Connect to Remote Server by IP address 192.168.1.5 and login using vivek user to connect to sales database,use:$ psql -h 192.168.1.5 -U vivek -d sales
Where,
-h 192.168.1.5: Specifies the host name of the machine or IP address (192.168.1.5) on which the server is running.
-U vivek: Connect to the database as the vivek username instead of the default. You must haveaccount and permissionto connect as vivek user.
-d sales: Specifies the name of the database (sales) to connect to.
See also:
=>How do I add a user to PostgreSQL database server?
march 23,2007,10:48 am
$ su � postgres
$ vi /var/lib/pgsql/data/pg_hba.confYou can also use 192.168.1.31/24 instead of 192.168.1.31 255.255.255.0 (CIDR-address),kinda config file will look “cleaner”,and I would use “md5” instead of “trust” for further peace-of-mind :)
January 9,2008,8:14 am
Thanks for the fantastic FAQ. Just what I needed as a newbie with pgsql.
Just wanted to mention here that was trying to connect a remote pgsql db on a Suse Linux 9. It did not have the tcpip_socket parameter in postgresql.conf
To overcome this,I had to uncomment the following settings:
#―――――――――――――――――――――――――
# CONNECTIONS AND AUTHENTICATION
#―――――――――――――――――――――――――# � Connection Settings �
listen_addresses = ‘*’
port = 5432Bounced the db and voila,I was able to connect and to run queries.
Hope this helps.
Thanks
RajeevForgot to mention the version of my postgresql db. It’s 8.1.4
January 31,5:51 am
Hi,
this guide was a good help for me.
only thing as rajeev said their is no parameter with the name tcpip_socket in Ubuntu also.so used following things in the postgresql.conf config file
listen_addresses = ‘*’
port = 5432August 22,3:34 pm
please help me.i try to connect to Postgresql sever by LAN
i already configured following step but not success
here my config on flatform Window
pg_hba.conf:
host all all 192.168.1.37/32 md5
postgresql.conf:
i try all
#listen_addresses = ‘*’
port = 5432or
tcpip_socket = true
it’s still not working
thanks anyway!October 23,2009,1:53 pm
I Remote Postgresql Access On the web
how can i Connect to my postgresql database on my server remotely through the web/internet and manage it directly from your PC?and even connect some application so i run transaction?
February 4,2010,8:24 am
I have the same problem as quocvietit. I’m also in Windows.
march 1,5:10 am
Can anybody help me with this…
I’ve postgre db on redhat linux. It’s been configured to a single network earlier viz.,192.168.0.1 but Now I want to access the same db from different vlans(192.168.0.1,192.168.1.1……to 192.168.20.1). there are about 20 machines on each network. I’m able to access from the client machines which are on 192.168.0.1… network but where as when I try to access from others it says “I don’t permissions to access the db”. Pls can anybody help in this regard…
how can I solve this
February 3,2011,6:35 am
user account postgres does exist but i can’t login to it hence postgres service does not start.how do i go about this?
April 19,10:10 am
hiii mohad mekhelfi ana algerie b/amer (algerie )
July 19,4:06 am
I have same problem.
I use Windows and Postgresql 9.0.4
anybody help?
So thanks!August 3,10:17 am
And how about this error in postgres 9.0?
FATAL: unrecognized configuration parameter “tcpip_socket”August 23,2012,6:25 am
while installing postgres sql 8.0 in windows an error occurs ‘port number already in use please specify another ‘ how can i solve this
October 8,6:58 pm
meu banco de dados postgresql no esta abrindo ele manda msg dizendo que no consegue se comunicar com o servidor,estou usando o servidor virtual apache,o que fao para no perder os meus dados ?,já até reinstalei o apache mais no resolve,o sistema é windows 7
August 14,2013,9:11 am
What a wonderful post and the tremendous response from Rajeev. It took me hardly 3 mins to configure this and access PG remotely.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。