OperationalError:无法连接到服务器:连接被拒绝

时间:2018-02-20 18:42:15

标签: postgresql ubuntu-16.04

我正在使用Ubuntu 16.04和Postgres 9.5

我正在使用postgres.conf中的设置,现在我的网站出现以下日志时出现500错误:

OperationalError at /
could not connect to server: Connection refused
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?

当我运行sudo -u postgres psql时,我收到以下错误:

psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

我收到this question的类似错误,但没有答案。 postmaster.pid对我来说不存在。

我的Postgres服务器日志的最后一位是:

2018-02-20 17:39:12 UTC [1558-2] LOG:  autovacuum launcher shutting down
2018-02-20 17:39:12 UTC [1546-2] LOG:  received smart shutdown request
2018-02-20 17:39:12 UTC [1989-1] postgres@postgres FATAL:  terminating connection due to administrator command
2018-02-20 17:39:12 UTC [1971-1] postgres@postgres FATAL:  terminating connection due to administrator command
2018-02-20 17:39:12 UTC [1555-1] LOG:  shutting down
2018-02-20 17:39:12 UTC [1555-2] LOG:  database system is shut down

这是执行sudo systemctl status postgresql后的日志:

● postgresql.service - PostgreSQL RDBMS
   Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor prese
   Active: active (exited) since Tue 2018-02-20 18:25:22 UTC; 23min ago
 Main PID: 1766 (code=exited, status=0/SUCCESS)
    Tasks: 0
   Memory: 0B
      CPU: 0
   CGroup: /system.slice/postgresql.service

Feb 20 18:25:22 ubuntu-bungol-v0 systemd[1]: Starting PostgreSQL RDBMS...
Feb 20 18:25:22 ubuntu-bungol-v0 systemd[1]: Started PostgreSQL RDBMS.
Feb 20 18:47:57 ubuntu-bungol-v0 systemd[1]: Started PostgreSQL RDBMS.
Feb 20 18:48:15 ubuntu-bungol-v0 systemd[1]: Started PostgreSQL RDBMS.

sudo systemctl restart postgres不起作用。 sudo systemctl start postgressudo systemctl enable postgres

都不是。grep -Ev '^$|^\s*#' postgresql.conf and systemctl status postgresql@9.5-main.servicegrep: postgresql.conf: No such file or directory grep: and: No such file or directory grep: systemctl: No such file or directory grep: status: No such file or directory grep: postgresql@9.5-main.service: No such file or directory

我没有想法。任何人都可以提供一些解决方案吗?

编辑:

sudo ps aux |grep postgres的结果:

root      1728  0.0  0.3  51420  3932 pts/0    T    18:22   0:00 sudo systemctl status postgresql
root      1729  0.0  0.3  24888  3316 pts/0    T    18:22   0:00 systemctl status postgresql
root      1733  0.0  0.3  51420  3760 pts/0    T    18:24   0:00 sudo systemctl status postgresql
root      1734  0.0  0.3  24888  3372 pts/0    T    18:24   0:00 systemctl status postgresql
valachio  1782  0.0  0.2  13112  2912 pts/0    T    18:28   0:00 nano /usr/local/var/log/postgres.log
valachio  1783  0.0  0.2  13112  2940 pts/0    T    18:28   0:00 nano /usr/local/var/postgres/server.log
root      2058  0.0  0.3  51420  3840 pts/0    T    19:35   0:00 sudo systemctl status postgresql@9.5-main.service
root      2059  0.0  0.3  24888  3368 pts/0    T    19:35   0:00 systemctl status postgresql@9.5-main.service
valachio  2225  0.0  0.0  12944   924 pts/0    R+   19:43   0:00 grep --color=auto postgres

sudo ls -la /var/run/postgresql/的结果:

total 0
drwxrwsr-x  3 postgres postgres  60 Feb 20 19:41 .
drwxr-xr-x 25 root     root     940 Feb 20 19:43 ..
drwxr-s---  2 postgres postgres  40 Feb 20 19:41 9.5-main.pg_stat_tmp

grep -Ev '^$|^\s*#' /etc/postgresql/9.5/main/postgresql.conf的结果:

data_directory = '/var/lib/postgresql/9.5/main'         # use data in another directory
hba_file = '/etc/postgresql/9.5/main/pg_hba.conf'       # host-based authentication file
ident_file = '/etc/postgresql/9.5/main/pg_ident.conf'   # ident configuration file
external_pid_file = '/var/run/postgresql/9.5-main.pid'                  # write an extra PID file
port = 5432                             # (change requires restart)
max_connections = 100                   # (change requires restart)
unix_socket_directories = '/var/run/postgresql' # comma-separated list of directories
ssl = true                              # (change requires restart)
ssl_cert_file = '/etc/ssl/certs/ssl-cert-snakeoil.pem'          # (change requires restart)
ssl_key_file = '/etc/ssl/private/ssl-cert-snakeoil.key'         # (change requires restart)
shared_buffers = 256MB                  # min 128kB
dynamic_shared_memory_type = posix      # the default is the first option
log_line_prefix = '%t [%p-%l] %q%u@%d '                 # special values:
log_timezone = 'UTC'
stats_temp_directory = '/var/run/postgresql/9.5-main.pg_stat_tmp'
datestyle = 'iso, mdy'
timezone = 'UTC'
lc_messages = 'en_US.UTF-8'                     # locale for system error message
lc_monetary = 'en_US.UTF-8'                     # locale for monetary formatting
lc_numeric = 'en_US.UTF-8'                      # locale for number formatting
lc_time = 'en_US.UTF-8'                         # locale for time formatting
default_text_search_config = 'pg_catalog.english'

sudo systemctl status postgresql@9.5-main.service

的结果
● postgresql@9.5-main.service - PostgreSQL Cluster 9.5-main
   Loaded: loaded (/lib/systemd/system/postgresql@.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2018-02-20 19:42:11 UTC; 5min ago
  Process: 2135 ExecStart=postgresql@%i --skip-systemctl-redirect %i start (code=exited, status=1/FAILURE)

Feb 20 19:41:41 ubuntu-bungol-v0 systemd[1]: Starting PostgreSQL Cluster 9.5-main...
Feb 20 19:42:11 ubuntu-bungol-v0 postgresql@9.5-main[2135]: The PostgreSQL server failed to start. Please check the log output.
Feb 20 19:42:11 ubuntu-bungol-v0 systemd[1]: postgresql@9.5-main.service: Control process exited, code=exited status=1
Feb 20 19:42:11 ubuntu-bungol-v0 systemd[1]: Failed to start PostgreSQL Cluster 9.5-main.
Feb 20 19:42:11 ubuntu-bungol-v0 systemd[1]: postgresql@9.5-main.service: Unit entered failed state.
Feb 20 19:42:11 ubuntu-bungol-v0 systemd[1]: postgresql@9.5-main.service: Failed with result 'exit-code'.

row_id varchar(4000) --> created by a trigger everytime a row is inserted into the 'LOAD' table UTCOffset Number Data_Date Varchar2(7) Data_Type Varchar2(4) PostedValue Varchar2(4000) UTCValue Timestamp(6) Hour Number Data_Code Varchar2(5) 的结果(日志输出保持与以前相同):

Value_id --> created by a trigger everytime a row is inserted into the 'LOAD' table
Product_Id NUMBER
Source_Id Number
Unit_Cd Varchar2(50)
VALUE_TX VARCHAR2(4000)
UTC_Offset (Number)
Data_date (VARCHAR2(7))
HR_UTC VARCHAR2(4)
HR Timestamp(6)
HR_num Number
Data_Code Varchar2(5)
Create_Dt (autogenerated?)
Create_User_id (autogenerated)
Modify_dt (always null)
Modify_user_id (always null)
effective_dt (always null)
inactive_dt (always null)

0 个答案:

没有答案