postgresql – 重启vm后无法访问数据库

postgresql – 重启vm后无法访问数据库,第1张

概述我在VM中有这个数据库,可以重新启动VM,它可以正确访问 但是现在如果我在尝试通过pgAdmin III访问数据库时重新启动VM,我会收到以下消息 Server doesn’t listen The server doesn’t accept connections: the connection library reports could not connect to server: Conne 我在VM中有这个数据库,可以重新启动VM,它可以正确访问

但是现在如果我在尝试通过pgadmin III访问数据库时重新启动VM,我会收到以下消息

Server doesn’t Listen

The server doesn’t accept connections: the connection library reports

Could not connect to server: Connection refused Is the server running on host “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.

我通过VM快照进行了一些测试,并注意到在命令之后发生了这种行为

sudo a2enmod重写

但我没有发现任何可能表明某些链接或如何解决的问题,因为我需要运行sudo a2enmod重写

postgresql.conf连接设置:

# - Connection Settings -Listen_addresses = '*'      # 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)#superuser_reserved_connections = 3 # (change requires restart)unix_socket_directorIEs = '/var/run/postgresql' # comma-separated List of directorIEs                    # (change requires restart)#unix_socket_group = ''         # (change requires restart)#unix_socket_permissions = 0777     # begin with 0 to use octal notation                    # (change requires restart)#bonjour = off              # advertise server via Bonjour                    # (change requires restart)#bonjour_name = ''          # defaults to the computer name                    # (change requires restart)

我已经尝试重新启动postgres服务,但它没有用

这是调试对任何数据库的访问的一般过程的一部分.

Basic tests

旨在确定服务是否正常运行.

检查Postgresql是否正在运行:

pgrep -fl postgresservice postgresql status

(如果您的linux中有状态,那么您应该看到类似的内容):

mortiz@florIDa:~/.mozilla/firefox/hlmpduzp.default$sudo service postgresql status● postgresql.service - Postgresql RDBMS   Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)   Active: active (exited) since Mon 2018-06-11 14:05:04 -03; 3s ago  Process: 17522 ExecStart=/bin/true (code=exited,status=0/SUCCESS) Main PID: 17522 (code=exited,status=0/SUCCESS)Jun 11 14:05:04 florIDa systemd[1]: Starting Postgresql RDBMS...Jun 11 14:05:04 florIDa systemd[1]: Started Postgresql RDBMS.

如果服务正在运行,请检查端口的基本连接:

telnet 127.0.0.1 5432

如果您无法连接尝试使用localhost或IP地址(而不是环回):

telnet localhost 5432telnet <your_ip_address> 5432

>如果服务未运行,请尝试恢复postgresql.conf备份.
>如果服务正在运行但您无法连接到端口,
它可能是配置问题,请尝试恢复配置
从备份.

如果您能够使用telnet连接到端口,那么服务已启动且端口已打开,无论如何,实例或客户端可能存在配置问题.

如果telnet不能用于127.0.0.1但是它使用localhost或 – (your_ip_address / not loopback),那么在客户端设置中更改它.

如果服务正在运行,实例或客户端可能存在配置问题.

如果telnet不能与127.0.0.1一起使用,但它使用localhost,或者在客户端设置中更改.

Testing functionality

检查服务的预期行为.在linux中,某些服务即使出现错误也会启动并产生不良行为.

现在是时候看看服务是否正常工作,我们将使用Cli.运行此命令:

psql -h localhost --username=postgres --List

你应该看到数据库列表:

mortiz@florIDa:~/.mozilla/firefox/hlmpduzp.default$psql -h localhost --username=postgres --ListPassword for user postgres:                                   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)

如果这样可行,那么您的问题可能在客户端pgadmin中.尝试安装其他客户端或版本并尝试连接到数据库.

RevIEwing the configuration of the server
* Maybe someone changed the method of accessing the database.

小心,先备份你的文件.检查允许连接/方法和用户的Postgresql客户端身份验证配置文件主机 – > /etc/postgresql/9.6/main/pg_hba.conf

# This file controls: which hosts are allowed to connect,how clIEnts# are authenticated,which Postgresql user names they can use,which# databases they can access.  Records take one of these forms:## local      DATABASE  USER  METHOD  [OPTIONS]# host       DATABASE  USER  ADDRESS  METHOD  [OPTIONS]# hostssl    DATABASE  USER  ADDRESS  METHOD  [OPTIONS]# hostnossl  DATABASE  USER  ADDRESS  METHOD  [OPTIONS]# METHOD can be "trust","reject","md5","password","gss","sspi",# "IDent","peer","pam","ldap","radius" or "cert".  Note that# "password" sends passwords in clear text; "md5" is preferred since# it sends encrypted passwords.

如果有任何问题,请告诉我你每次测试的结果.

总结

以上是内存溢出为你收集整理的postgresql – 重启vm后无法访问数据库全部内容,希望文章能够帮你解决postgresql – 重启vm后无法访问数据库所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1181787.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存