![无法连接到 PostgreSQL](https://linux22.com/image/1136908/%E6%97%A0%E6%B3%95%E8%BF%9E%E6%8E%A5%E5%88%B0%20PostgreSQL.png)
我的 PostgreSQL 9.3 运行良好,但当我尝试升级到 9.5 时,我开始遇到错误。因此,我按照以下步骤从系统中清除了 Postgres这个问题的第一个答案。
然后我使用以下方法安装了 postgres 9.5
apt-get install postgresql-9.5 postgresql-contrib-9.5 postgresql-doc-9.5
一切都下载顺利。以下是日志:
sudo apt-get install postgresql-9.5 postgresql-contrib-9.5 postgresql-doc-9.5
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libntdb1 libossp-uuid16 python-ntdb
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
postgresql-client-9.5 postgresql-client-common postgresql-common
Suggested packages:
locales-all libdbd-pg-perl
The following NEW packages will be installed:
postgresql-9.5 postgresql-client-9.5 postgresql-client-common
postgresql-common postgresql-contrib-9.5 postgresql-doc-9.5
0 upgraded, 6 newly installed, 0 to remove and 14 not upgraded.
Need to get 1,867 kB/7,685 kB of archives.
After this operation, 40.9 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg/main postgresql-doc-9.5 all 9.5.3-1.pgdg14.04+1 [1,867 kB]
Fetched 1,867 kB in 15s (118 kB/s)
Preconfiguring packages ...
Selecting previously unselected package postgresql-client-common.
(Reading database ... 219906 files and directories currently installed.)
Preparing to unpack .../postgresql-client-common_174.pgdg14.04+1_all.deb ...
Unpacking postgresql-client-common (174.pgdg14.04+1) ...
Selecting previously unselected package postgresql-client-9.5.
Preparing to unpack .../postgresql-client-9.5_9.5.3-1.pgdg14.04+1_amd64.deb ...
Unpacking postgresql-client-9.5 (9.5.3-1.pgdg14.04+1) ...
Selecting previously unselected package postgresql-common.
Preparing to unpack .../postgresql-common_174.pgdg14.04+1_all.deb ...
Adding 'diversion of /usr/bin/pg_config to /usr/bin/pg_config.libpq-dev by postgresql-common'
Unpacking postgresql-common (174.pgdg14.04+1) ...
Selecting previously unselected package postgresql-9.5.
Preparing to unpack .../postgresql-9.5_9.5.3-1.pgdg14.04+1_amd64.deb ...
Unpacking postgresql-9.5 (9.5.3-1.pgdg14.04+1) ...
Selecting previously unselected package postgresql-contrib-9.5.
Preparing to unpack .../postgresql-contrib-9.5_9.5.3-1.pgdg14.04+1_amd64.deb ...
Unpacking postgresql-contrib-9.5 (9.5.3-1.pgdg14.04+1) ...
Selecting previously unselected package postgresql-doc-9.5.
Preparing to unpack .../postgresql-doc-9.5_9.5.3-1.pgdg14.04+1_all.deb ...
Unpacking postgresql-doc-9.5 (9.5.3-1.pgdg14.04+1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for ureadahead (0.100.0-16) ...
Processing triggers for doc-base (0.10.5) ...
Processing 1 added doc-base file...
Setting up postgresql-client-common (174.pgdg14.04+1) ...
Setting up postgresql-client-9.5 (9.5.3-1.pgdg14.04+1) ...
update-alternatives: using /usr/share/postgresql/9.5/man/man1/psql.1.gz to provide /usr/share/man/man1/psql.1.gz (psql.1.gz) in auto mode
Setting up postgresql-common (174.pgdg14.04+1) ...
Adding user postgres to group ssl-cert
Creating config file /etc/postgresql-common/createcluster.conf with new version
Creating config file /etc/logrotate.d/postgresql-common with new version
Building PostgreSQL dictionaries from installed myspell/hunspell packages...
en_us
Removing obsolete dictionary files:
* No PostgreSQL clusters exist; see "man pg_createcluster"
Setting up postgresql-doc-9.5 (9.5.3-1.pgdg14.04+1) ...
update-alternatives: using /usr/share/postgresql/9.5/man/man3/SPI_connect.3.gz to provide /usr/share/man/man3/SPI_connect.3.gz (SPI_connect.3.gz) in auto mode
Processing triggers for ureadahead (0.100.0-16) ...
Setting up postgresql-9.5 (9.5.3-1.pgdg14.04+1) ...
Creating new cluster 9.5/main ...
config /etc/postgresql/9.5/main
data /var/lib/postgresql/9.5/main
locale en_IN
socket /var/run/postgresql
port 5432
update-alternatives: using /usr/share/postgresql/9.5/man/man1/postmaster.1.gz to provide /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz) in auto mode
* Starting PostgreSQL 9.5 database server [ OK ]
Setting up postgresql-contrib-9.5 (9.5.3-1.pgdg14.04+1) ...
现在当我尝试运行 rails 命令时
bundle exec rake db:setup
我收到以下错误
rake aborted!
PG::ConnectionBad: 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.5433"?
事实上,如果我尝试通过 UI 连接,我会遇到同样的错误。
这是我最初尝试升级到 9.5 时遇到的相同问题。我已经为此挣扎了 5 个小时。任何帮助都将非常有帮助。
提前谢谢您 :)
答案1
请注意,错误中的端口号是 5433,但安装使用的是 5432。安装第二个 postgres 时,它将检查正在运行的安装,查看其端口,并使用下一个。这允许您同时运行两个安装,以便在关闭旧安装之前检查验证。您可以手动编辑文件 /etc/postgresql/9.5/main/postgresql.conf 并将端口更改为您想要使用的端口。我不知道 rake 是做什么的,也许它在配置文件中也有一个端口。
重新配置/重新启动 rake 以使其使用 5432 端口,因为它在端口 5433 上出现故障。